我知道 customer.subscriptions.trial_will_end
事件。它会在试用结束前 3 天触发。
当试用结束且客户尚未付款时,我找不到实际触发的事件。这对于做一些简单的事情来关闭功能很有用:customer.update_attributes(active_account: false)
如果没有这样的 webhook,我正在考虑安排一些任务来定期检查未确认的客户并相应地关闭功能。虽然 webhook 看起来更干净,而且我这边不太容易出错。是否有符合这些目标的事件/网络 Hook ?仅供引用,客户在开始试用时不必放入卡 - 所以自动计费不是一种选择。
最佳答案
要添加到拉里的答案并分享我如何解决缺乏试用结束的 webhook 的问题,这就是我所做的。
在 invoice.payment_failed
网络钩子(Hook),我检查了:
如果这些检查失败,那么我假设试用刚刚结束,没有输入账单详细信息,我取消订阅。
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()
关于ruby-on-rails - 试用结束时的 Stripe webhook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26984476/