首页 文章

在stripe中测试invoice_payment.failed事件

提问于
浏览
4

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

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

它告诉我创建一个计划并订阅一个客户,其trial_end期限设置为1-2分钟,并使用某个信用卡号创建客户对象 . 我将trial_end期间设置为“now”并且仅使用给定的信用卡号而不是invoice_payment.failed事件获得charge.failed . 我是条纹新手,想知道如何将trial_end时间段设置为1-2分钟,以及如何测试invoice_payment.failed事件 . 我在php工作 . 任何帮助,将不胜感激 .

2 回答

  • 9

    creating a subscription时,可以使用trial_end参数设置试用期 .

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

    $customer = \Stripe\Customer::create(array(
         "source" => $token,
        "description" => "Test customer"
    ));
    
    • 然后,使用较短的试用期创建计划订阅:
    $subscription = \Stripe\Subscription::create(array(
        "customer" => $customer->id,
        "plan" => $plan,
        "trial_end" => strtotime("+1 minute")
    ));
    

    这将创建一分钟试用期的订阅 . 一分钟后,将创建发票,大约一小时后,将尝试支付发票 .

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

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

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

相关问题