【问题标题】:stripe first time the user pays for a subscription用户第一次为订阅付费时的条带
【发布时间】:2021-03-26 15:56:46
【问题描述】:

如果这是该特定客户第一次为此特定订阅付费。 我必须根据选择的计划 ID 设置订阅的 cancel_at 字段。 (我不想在创建订阅时设置它)。为了解决这个第一次,我捕获了 invoice.payment_succeeded 事件并执行了以下操作:

 $invoices = \Stripe\Invoice::all([
                    "limit" => 3,  //no need to get all of the invoices just checking if their number is = 1.
                    "status" => 'paid',
                    "customer" => $customer_id,
                    "subscription" => $subscription_id,
                    "expand" => ["data.charge"],
                  ]);
 if ( count($invoices->data) == 1 ) {
            //First time this user pays for this specific subscription;

你能告诉我它是否正确,或者我是否错过了任何东西,因为我是 php 和 stripe 的新手。我应该做 count($invoices) 而不是我所做的吗?

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    您的代码看起来不错,但判断它是否有效的唯一方法是运行它并查看它是否符合您的预期。您可以使用您的测试模式 API 密钥和 Stripe CLI 来测试流程:

    stripe trigger customer.subscription.created
    

    这将创建一个测试客户、一个计划和一个订阅。后者将立即创建并支付发票,因此您应该获得一个 invoice.payment_succeeded webhook 事件来进行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 2020-11-14
      • 2021-05-10
      • 2020-01-16
      • 2018-09-19
      • 2022-08-12
      • 2021-03-16
      相关资源
      最近更新 更多