Testing Stripe webhooks that require data on localhost - node.js

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.

Related

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.

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.

Which webhooks to look after in Stripe Checkout?

I'm implementing subscription with Stripe Checkout, but I have some questions that I couldn't get definitive answers for even from their support.
I have following scenario:
User clicks on a Subscribe button
User gets redirected to Stripe Checkout page (along with session token)
User successfully pays (and from now on is a Customer)
and here I get 14 webhook calls (each one is different event type):
checkout.session.completed
payment_method.attached
invoice.created
customer.updated
customer.subscription.created
customer.created (even though I used the same email - test mode, but still...)
invoice.finalized
invoice.updated
invoice.payment_succeeded
customer.subscription.updated
charge.succeeded
payment_intent.succeeded
payment_intent.created
invoice.updated
edit: I get all of them at once because I use Stripe CLI's listen feature and it probably shows all calls which normally wouldn't happen because they have to be defined in dashboard event by event. For instance if I create invoice in the dashboard and pay it then if no webhook is defined explicitly then my server won't know about anything
Until here it all works good. My concern is that:
if a Customer will be charged next month which webhook should I listen to? I need to differentiate between first-time Customer (because I create new account for that user) and existing Customer that I just need to note in database that this user is still active (or listen for event of subscription cancellation? subscription_schedule.canceled maybe?). One idea is to just listen to successful payment and upon that check if customer exists in database - if he does just update, if not then create account.
when I do another subscription payment using the very same email I get exactly the same webhooks (including customer.created which I think shouldn't be there) or am I missing something?
is there any possibility to double-charge a Customer by accident like I read in other Stripe implementations (see: idempotency)?
what are other things to take into account while implementing Stripe Checkout? I feel like their instructions are not reassuring that I've done everything that is considered good practice.
Flow that I want to achieve:
User successful payment (as above in points from 1 - 3). Already done!
Register new customer in database (Firebase in this case) and log him in automatically so after payment he has instant access.
As long as customer's card is charged he has access. While he cancels or card has no insufficient funds I need to have my server notified about this to downgrade access.

How to get the charge Id after subscribing a customer to a plan with recurring payment?

I have successfully created a customer in stripe with a subscription of plan .After successful payment I am not able to get the charge Id because after subscribing a customer to a plan.It automatically generates an invoice.So what is the way that I can get that particular charge stripe Id from stripe and store it in my system database.
Getting the charge ID for a subscription (or an invoice) can be done via their webhooks integration. You need to expose an API in your app where Stripe can fire these requests. You can subscribe to various events there, but in your case you'd need to do so on charge.succeeded. The charge ID will be in the data structure of the event object.
Take a look at the various other lifecycle events you can use with webhooks.

Authorize.Net Recurring Billing Events

I have successfully deployed Authorize.net API(currently sandbox mode) for subscription purposes. I have also configured its webhooks that are also working. But I have a confusion that still exists even after a week on working with the said API.
The question is, when a subscription starts in case of recurring billing(in my scenario subscription is monthly) the event that is called is
net.authorize.customer.subscription.created
When a month passes on a subscription and next bill payment is made by the API, what event will get called? How can I capture Or to what event should I be listening to? . Is it going to be
net.authorize.customer.subscription.updated
Currently I have clicked yes on all the all the events that are there for the webhooks
The event will be a payment related event, not a subscription related event. Subscription related events only happen when you do something to a subscription (i.e. create, modify, or delete) not with it (make payment).
So you would look out for any of the following:
net.authorize.payment.capture.created
net.authorize.payment.fraud.approved
net.authorize.payment.fraud.declined
net.authorize.payment.fraud.held

Resources