#mangle8582

1 messages · Page 1 of 1 (latest)

shell muralBOT
white shard
#

Hi, let me help you with this.

undone heath
#

So i add in database latest_invoice, payment_intents from invoice.payment_succeeded, but i need some data from customer.subscription.updated as well

#

So when everything is added i need to set loader to false

white shard
#

What do you mean by "setting the loader to false with pooling on frontend"?

#

You can access all the data using IDs from any of those events.

#

If it's a Subscription, I advice you to only listen to invoice.paid and the Invoice object in the payload contains payment_intent and subscription properties, that allows you to access those objects too.

undone heath
#

When user hits pay from @stripe/react-stripe-js, i set the loader to true with message: "Activating Subscription".

Behind, webhooks are triggering on backend, and add subscription to database + other patches on that particular subscription.

When everything is done, i set loader to false

#

The thing is that i'm not sure on which webhook to set loader to false. Because sometimes customer.subscription.updated is finishing later than invoice.payment_succeeded

white shard
#

It's usually seconds, so it doesn't really matter. It depends what is required for your business logic.

undone heath
#

So if i set user loader to false on invoice.payment_succeeded it's okay right?

white shard
#

I can't tell you that because I don't know what your application needs.

undone heath
#

It's just a loader when paying or upgrading subscription.

And making use of invoice.payment_succeeded to set it to false after you save the data in database from it and from customer.subscription.updated

white shard
#

In this case this is not even needed. Best practice is to show a message when the session on the frontend is done, and then just send an email confirming that the Subscription has started.

undone heath
#

I know that Stripe automatically sends emails that subscription has started.

Not sure what you mean by session on frontend is done, on frontend in ReactJS you have the loader activated, while webhook are doing their job, user sees the loader, my issue is when to set the loader to false so frontend can make the GET for the added subscription in database.

#

So subscription can appear with card etc

#

I use pooling for that boolean in the database on frontend, so when it's false, i make the GET for subscriptions and user can use the functionality or change their payment method, see details about subscription that we saved from webhook in the database

white shard
#

Are you using the Payment Element?

undone heath
#

Yes

#

It triggers a confirm api call to stripe with clientSecret

white shard
#

The confirm call will redirect/return a success. Then you can show the success message to the customer.

undone heath
#

Yea but the webhooks trigger after that call, so it can add to database

#

I cannot make the GET call immediately because subscription has not been added yet through webhooks

#

If i would take the subscription from stripe it could work, but i save to my database so i won t have 429 rate limiter on stripe calls from user subscriptions

white shard
#

What do you want to show to the customer after their payment succeeds?

undone heath
#

Their subscription from database where it shows active status, start and end date, buttons to cancel on period end, refund button or remove subscription button, this data comes from database and it s saved or updated through webhooks

white shard
#

Then it's fine. You just need one webhook event, and then you can fetch all the rest using IDs.

undone heath
#

Yea, i'm using invoice_payment_succeded to save data about invoice, payment intent and subscription

#

But also using customer.subscription.updated to patch some data

white shard
#

As I mentioned before, you don't need multiple webhook events to acceess all the necessary data. Please use invoice.paid and use the IDs provided in the payload, like payment_intent and subscription properties to fetch the other objects.

undone heath
#

Aa nice, one more thing.

When i used test clocks, i received a custumer.subscription.updated so i can show the invoice with the next payment when the invoice is draft one hour before reccuring payment

#

Can i use any other webhook for that?

#

Data like, your invoice has been generated, your payment will occur in one hour

#

I believe it was something with next_payment_action or something

white shard
undone heath
#

Thank you! Also why invoice.paid and not invoice.payment_succeeded? invoice_payment_succeded is after paid

white shard
#

invoice.paid is recommended because it's covering all the cases.

undone heath
#

Aa ok, thanks!!!

white shard
#

Happy to help.