Test for invoice_payment.failed event in stripe

If you just want to test and handle invoice.payment_failed event and others which you can and can't create, then you should go to stripe dashboard and under webhooks settings, send test event of required type.


When creating a subscription, you can set the trial period with the trial_end parameter.

In order to test the invoice.payment_failed event, you can do something like this:

  1. First, create a customer with a card token (from Checkout or Stripe.js) created with the special testing number 4000 0000 0000 0341:

    $customer = \Stripe\Customer::create([
        "source" => $token,
        "description" => "Test customer"
    ]);
    
  2. Then, create the subscription to the plan with a short trial period:

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

This will create the subscription with a one minute trial period. After one minute, an invoice will be created, and approximately one hour later, payment for the invoice will be attempted.

If you don't want to wait one hour, you can manually retrieve the invoice after it's been created and trigger the payment attempt:

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