Testing/automating/mocking orders on Stripe hosted checkout - stripe-payments

Is there any way to automate/mock placing an order in stripe hosted checkout in the Stripe test environment?
One can use the Stripe CLI to trigger an event like $ stripe trigger checkout.session.completed but this isn't enough for my use case.
With the event triggers, we don't have control over the data in the checkout session. It's random.
I want to trigger an order completed with defined line items, in a specific currency, with a particular test card, and a destination connect account.
But if I want to do that now, I must manually place the order in my dev environment and go through the test Stripe-hosted checkout flow.

You can use the --add and --override CLI flags to customize your CLI triggered checkout.session.created events. Otherwise, your best bet is to just mock the Session Completed response yourself here.

Related

Why stripe webhook trigger events with the CLI not triggering the events for desired product?

I am trying to trigger webhooks using the stripe CLI. Previously I had multiple products but I deleted all the products. Now I have created a new product for which I want to trigger events.
Now I followed the steps as per stripe:
Step 1: stripe login
step 2: stripe listen --forward-to localhost:8090/webhook
(then i pass the webhook signing secret to the server)
step 3:stripe trigger payment_intent.succeeded
Then I get output in the cmd as:
Setting up fixture for: payment_intent
Running fixture for: payment_intent
Trigger succeeded! Check dashboard for event details.
Now when I go to check events I see that the event is triggered for the previously deleted product and not for the product I want
Please guide me on what I am missing.

Stripe webhook account.updated never triggered, whenever an connected account status changes

I have a Stripe Connect integration with custom account.
When I create a Custom account, the account status is "Restricted". Then I fill the onboarding form and it changes to "Complete" (ready for payments and payouts).
Even though I have a webhook setup for the account.updated event, it's never triggered.
Following Stripe documentation it should be triggered for all the connected account, whenever a status changes.
However, as we can see here, no event was triggered since one week:
Do you have an idea why? (please note that I'm in test mode right now)
Is your webhook endpoint a Connect webhook endpoint? There are 2 types. I would make sure this webhook endpoint was created as a Connect one. If it is and you've configured it for account.updated events, then I would reach out to Stripe's support to see what's going on.

Testing Stripe webhooks that require data on localhost

The guide here says to monitor the invoice.paid event via webhook in order to provision a customers account when the payment is successful. How can I test fire the invoice.paid event with data? I need to be able to access the customer id and see what plan they purchased to provision it correctly.
I am able to test fire these events via the Stripe CLI, but I don't know how to fire them with mock data.
With the Stripe CLI you can trigger a invoice.payment_suceeded webhook event (which is almost exactly the same as invoice.paid):
stripe trigger invoice.payment_succeeded
That event will contain mock data. If you want to provide your own data, you'd have to mimic the event yourself. In that case you could do that by creating a new subscription in test mode, which will create an invoice and trigger the invoice.paid event.

At which stripe event should I update my db to grant subscriber access

I have a SaaS MERN app which is using Stripe for subscriptions. I'm using the new checkout feature of Stripe to handle all the payments. I have the stripe CLI installed to see the events that occur when a subscription is made. I have a few questions regarding the events that are emitted and how to handle them in my stripe webhook.
Which event below indicate that the payment was successful so that I can update my database.
Why is it that the payment_intent.succeeded occurs before payment_intent.created.
Why is a customer.subscription.updated event happening (I'm assuming it should just be the customer.subscription.created event that should occur on first purchase)
I use the customer.subscription.updated event in my webhook to allow customers to turn autoRenewal on and off. Because the customer.subscription.updated event is also shot off at initial payment when subscribing, how can I differentiate what to do as the same event is fired off in both cases.
This is not as important, but if anyone knows what that POST error is at the bottom, I would appreciate some insight. [EDIT] I fixed this by moving my res.status(200).json({received: true}) further up my code. Initially it was placed at the very end of my webhook, so I think it was timing out.
Thank you :)
If you specifically want to provision the subscription on successful payment, then you should listen for payment_intent.succeeded
Stripe doesn't guarantee the order of webhook events, it's possible to receive them out of order: https://stripe.com/docs/webhooks/best-practices#event-ordering
The subscription's status would be updated to show that the latest invoice was successfully paid, which triggers and update event
You probably want to use invoice.upcoming instead: https://stripe.com/docs/api/events/types?lang=java#event_types-invoice.upcoming
You'd have to debug this on your end to see where it came from. Looks like perhaps your local server wasn't running and so the Stripe CLI couldn't forward on the webhook event.

Change Stripe example email in webhooks triggers

I want to be able to pass an email into the webhook I trigger. I have a setup where after a user pays I want to update their record on Mailchimp. To properly test this without pushing to production (or running a local server open to the internet) I need to pass an email to stripe trigger checkout.session.completed so that it can find an email in Mailchimp. Right now the email is always stripe#example.com.
It's not possible to pass in custom data to stripe-cli triggers currently. Instead you probably want to use a service like ngrok.io to test this in a local environment.

Resources