ruby-on-rails - 试用结束时的 Stripe webhook

标签 ruby-on-rails stripe-payments webhooks

我知道 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/

    相关文章:

    php - Laravel Cashier - $stripeToken 从哪里来?

    javascript - 重定向到 ReactJS 中的结帐

    java - 如何从 Slack API 获取 channel 列表?

    python - 变量传递给同一函数的多个线程

    python - 运行时错误: Working outside of application context with Celery and Flask in Python

    ruby-on-rails - Authlogic LDAP : encrypt communication

    ruby-on-rails - 未知验证器 : 'InValidator' on Ruby on Rails

    stripe-payments - Stripe 有问题 : Uncaught IntegrationError: stripe. redirectToCheckout : Invalid value for sessionId. 你指定了 'pi_1Fr...9sCWFtQr'

    ruby-on-rails - 在 Ruby on Rails 中创建动态页面

    用于交互式社区网站的 PHP 或 Ruby on Rails?