【问题标题】:Test for invoice_payment.failed event in stripe测试条带中的 invoice_payment.failed 事件
【发布时间】:2016-10-10 22:54:20
【问题描述】:

我想在条带中测试 invoice_payment.failed 事件网络挂钩。我已经设置了一个网络挂钩端点并尝试从条带发送测试数据,但这不起作用,因为事件 ID 不存在。条带指南中提到了一些解决方案。这是我看到的链接。

https://support.stripe.com/questions/test-failed-invoice-payment

它告诉我创建一个计划并订阅一个将 trial_end 时间设置为 1-2 分钟的客户,并使用某个信用卡号来创建客户对象。我将 trial_end 期限设置为“现在”,并且仅使用给定的信用卡号得到了 charge.failed,但没有得到 invoice_payment.failed 事件。我是条带新手,想知道如何将 trial_end 时间设置为从现在开始的 1-2 分钟,以及如何准确测试 invoice_payment.failed 事件。我在 php 工作。任何帮助将不胜感激。

【问题讨论】:

    标签: stripe-payments stripe-connect


    【解决方案1】:

    在新终端中(假设您有 Stripe CLI)只需键入:stripe trigger invoice.payment_failed

    https://stripe.com/docs/webhooks/test#forward-events

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案2】:

    creating a subscription时,可以通过trial_end参数设置试用期。

    为了测试invoice.payment_failed 事件,您可以执行以下操作:

    1. 首先,create a customer 使用特殊的 testing number 4000 0000 0000 0341 创建的卡片令牌(来自 CheckoutStripe.js):

      $customer = \Stripe\Customer::create([
          "source" => $token,
          "description" => "Test customer"
      ]);
      
    2. 然后,创建试用期较短的计划订阅:

      $subscription = \Stripe\Subscription::create([
          "customer" => $customer->id,
          "plan" => $plan,
          "trial_end" => strtotime("+1 minute")
      ]);
      

    这将创建具有一分钟试用期的订阅。一分钟后,将创建一张发票,大约一小时后,将尝试为发票付款。

    如果您不想等待一小时,您可以在创建后手动retrieve the invoicetrigger the payment attempt

    $invoice = \Stripe\Invoice::retrieve($invoice_id);
    $invoice->pay();
    

    【讨论】:

    • 我的计划首先被创建,然后我尝试为客户订阅该计划。如果我在创建客户时尝试将 trial_end period 设置为 strtotime("+2 minutes") 会起作用吗?我还没有尝试过。
    • 我愿意等待 1 小时,我正在使用 api 做所有事情
    • 是的,您可以通过在客户创建请求中包含 plantrial_end 参数在单个 API 调用中创建客户和订阅。
    • 感谢。我让它工作了。 charge.declined 事件和 invoice_payment failed 事件都被触发。第一次有 0 美元的费用下降,然后发票被更新,然后在一小时后再次收费被拒绝和 invoice_payment 失败被解雇。我写了我的网络钩子端点。非常感谢。
    • 我已经按照你说的做了,但是当我手动点击 inovice pay 后显示卡被拒绝,但是为什么我的 webhook 在这种情况下不起作用。即使日志中没有条目。日志中最上面的条目是大约 402 卡被拒绝发票。我正在使用 invoice.payment_failed 这个 evint 仅在我的 webhook 中
    【解决方案3】:

    如果您只想测试和处理 invoice.payment_failed 事件以及其他您可以创建和无法创建的事件,那么您应该转到条带仪表板并在 webhook 设置下发送所需类型的测试事件。

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 2022-07-29
      • 1970-01-01
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多