I want to test for the invoice_payment.failed event web hook in stripe. I have set a web hook end point and tried to send test data from stripe but that does not work because the event id is non existent. There are a few solutions mentioned in stripe guidelines. Here is the link I saw.
https://support.stripe.com/questions/test-failed-invoice-payment
It tells me to create a plan and subscribe a customer with the trial_end period set to 1-2 minutes and use a certain credit card number for creating the customer object. I set the trial_end period to "now" and got only the charge.failed using the credit card number given but not the invoice_payment.failed event. I am new to stripe and would like to know how to set the trial_end period to 1-2 minutes from now and how exactly to test for the invoice_payment.failed event. I am working in php. Any help would be appreciated.
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:
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"
]);
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();