set*_*ine 6 ruby-on-rails webhooks stripe-payments
我知道这customer.subscriptions.trial_will_end件事.它会在审判结束前3天解雇.
当试验结束并且客户没有付款时,我找不到实际发生的事件.这对于做这样简单的事情来关闭功能会很有用:
customer.update_attributes(active_account: false)
如果没有像这样的webhook,我正在考虑安排一些任务来定期检查未经证实的客户并相应地关闭功能.webhook看起来更干净,不太容易出错.是否有符合这些目标的活动/ webhook?仅供参考,客户在开始试用时无需输入卡片 - 因此无法选择自动加注.
Lar*_*man 18
试用期结束时,会有一个customer.subscription.updated事件和一个invoice.created事件.一小时(左右)之后,您将看到一个invoice.payment_succeeded事件或一个invoice.payment_failed事件.从那些,您将知道付款是否通过.
干杯,拉里
PS我在Stripe的支持工作.
为了增加拉里的答案,并分享我如何解决缺乏审判结束webhook,这就是我做的.
在invoice.payment_failedwebhook中,我检查了:
如果这些检查失败,那么我认为试验刚刚结束,没有输入结算明细,我取消订阅.
Python中的示例:
# get account from my database
account = models.account.get_one({ 'stripe.id': invoice['customer'] })
# get stripe customer and subscription
customer = stripe.Customer.retrieve(account['stripe']['id'])
subscription = customer.subscriptions.retrieve(account['stripe']['subscription']['id'])
# perform checks
cards_count = customer['sources']['total_count']
now = datetime.fromtimestamp(int(invoice['date']))
trial_start = datetime.fromtimestamp(int(subscription['start']))
days_since = (now - trial_start).days
# cancel if 14 days since subscription start and no billing details added
if days_since == 14 and cards_count < 1:
subscription.delete()Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2381 次 |
| 最近记录: |