测试条带中的invoice_ payment.failed事件

问题描述 投票:0回答:4

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

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

它告诉我创建一个计划并订阅一个客户,并将试用期设置为 1-2 分钟,并使用特定的信用卡号来创建客户对象。我将 Trial_end 期限设置为“现在”,并使用给定的信用卡号仅获取 charge.failed,但未获取 Invoice_ payment.failed 事件。我是 stripe 新手,想知道如何将 Trial_end 期限设置为从现在开始的 1-2 分钟,以及如何准确测试 Invoice_ payment.failed 事件。我正在 php 工作。任何帮助将不胜感激。

stripe-payments stripe-connect
4个回答
24
投票

创建订阅时,您可以通过

trial_end
参数设置试用期。

为了测试

invoice.payment_failed
事件,你可以这样做:

  1. 首先,使用卡令牌(来自 CheckoutStripe.js)创建客户,该卡令牌是使用特殊的 测试号码

    4000 0000 0000 0341
    创建的:

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

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

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

如果您不想等待一小时,您可以在创建发票后手动检索发票触发付款尝试

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

9
投票

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


2
投票

在新终端(假设您有 Stripe CLI)中,只需键入:stripe 触发器发票. payment_failed

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


0
投票

使用资金不足的Stripe卡(例如

4000000000009995
),这会触发
invoice.payment_failed
钩子。

© www.soinside.com 2019 - 2024. All rights reserved.