【问题标题】:Stripe webhook for when trial ends试用结束时的 Stripe webhook
【发布时间】:2015-01-15 01:27:15
【问题描述】:

我知道customer.subscriptions.trial_will_end 事件。它会在试用结束前 3 天触发。

我找不到在试用结束且客户尚未付款时实际触发的事件。这对于做一些简单的事情来关闭功能很有用:

customer.update_attributes(active_account: false)

如果没有这样的 webhook,我正在考虑安排一些任务来定期检查未确认的客户并相应地关闭功能。虽然 webhook 看起来更干净,而且我这边不太容易出错。是否有符合这些目标的事件/网络挂钩?仅供参考,客户在开始试用时不必输入卡片 - 因此不能选择自动计费。

【问题讨论】:

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


    【解决方案1】:

    当试用期结束时,将会有一个customer.subscription.updated 事件和一个invoice.created 事件。一小时(左右)后,您将看到invoice.payment_succeeded 事件或invoice.payment_failed 事件。从这些中,您将知道付款是否通过。

    干杯, 拉里

    PS 我在 Stripe 从事支持工作。

    【讨论】:

    • 如何判断这是否是订阅的第一张发票?如果用户注册了免费试用版,但从未输入信用卡,然后付款失败,那么最好将其区别于对待活跃用户的正常付款失败。
    • customer.subscription.updated 事件具有这些属性时,您可以判断是试用结束:"previous_attributes" : { "status" : "trialing"...
    • 我在最新的条带文档中没有看到“previous_attributes”字段。 stripe.com/docs/api#subscription_object,被删除了吗?
    • @VivekKothari 它在customer.subscription.updated webhook 中,而不是invoice.payment_failed
    【解决方案2】:

    要添加到 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()

    【讨论】:

      猜你喜欢
      • 2013-10-24
      • 1970-01-01
      • 2021-08-17
      • 2020-06-10
      • 2021-10-24
      • 2016-11-10
      • 2019-04-14
      • 1970-01-01
      • 2021-04-03
      相关资源
      最近更新 更多