我知道这customer.subscriptions.trial_will_end
件事.它会在审判结束前3天解雇.
当试验结束并且客户没有付款时,我找不到实际发生的事件.这对于做这样简单的事情来关闭功能会很有用:
customer.update_attributes(active_account: false)
如果没有像这样的webhook,我正在考虑安排一些任务来定期检查未经证实的客户并相应地关闭功能.webhook看起来更干净,不太容易出错.是否有符合这些目标的活动/ webhook?仅供参考,客户在开始试用时无需输入卡片 - 因此无法选择自动加注.
为了增加拉里的答案,并分享我如何解决缺乏审判结束webhook,这就是我做的.
在invoice.payment_failed
webhook中,我检查了:
这是自订阅开始以来的第一张发票吗?
客户是否已保存任何卡?
如果这些检查失败,那么我认为试验刚刚结束,没有输入结算明细,我取消订阅.
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()