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.
Test payment failures To test the effects of payment failure on an active subscription, attach the 4000 0000 0000 0341 card as the customer's default payment method, but use a trial period to defer the attempt (a trial of a few seconds or minutes is sufficient).
To begin, you'll need to log in to your Stripe account. Then click on Payments in the menu at the top of the screen. Next, near the top right corner of the screen, toggle on the Test Mode option. This will show you an overview of the test payments you've received in your Stripe account.
Go to the Issuing Cards page, find your newly-created card, and scroll to the Authorizations section. Then click Create test authorization. In some cases (such as fuel or hotel authorizations) you may be able to control the amount when approving the authorization.
Testing interactively Enter the card number in the Dashboard or in any payment form. Use a valid future date, such as 12/34. Use any three-digit CVC (four digits for American Express cards). Use any value you like for other form fields.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With