试用结束时条纹webhook

时间:2014-11-18 00:22:25

标签: ruby-on-rails stripe-payments webhooks

我知道customer.subscriptions.trial_will_end事件。它会在审判结束前3天解雇。

在审判结束且客户未付款时,我找不到实际触发的事件。这样可以做一些像这样简单的事情来关闭功能:

customer.update_attributes(active_account: false)

如果没有像这样的webhook,我正在考虑安排一些任务来定期检查未经证实的客户并相应地关闭功能。 webhook看起来更干净,不太容易出错。是否有符合这些目标的活动/ webhook?仅供参考,客户在开始试用时无需存入卡片 - 因此无法选择自动装载。

2 个答案:

答案 0 :(得分:15)

试用期结束后,会有customer.subscription.updated个事件和invoice.created个事件。大约一小时后,您将看到invoice.payment_succeeded事件或invoice.payment_failed事件。从那些,你会知道付款是否通过。

干杯, 拉里

PS我在Stripe的支持工作。

答案 1 :(得分:7)

为了增加Larry的答案并分享我如何解决缺乏审判结束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()