#Ema.subscription-events
1 messages ยท Page 1 of 1 (latest)
Hey there! What language are you using? There's a good example here that explains how webhooks work with subscriptions: https://stripe.com/docs/billing/subscriptions/build-subscription?ui=checkout#provision-and-monitor
Hello ynnoj! I fixed my webhook doubt for the question I initially submitted, and proceeded to create a webhook that executes successfully. I'm still doubtful about at which part of the transaction I should save the subscription in the database
I don't think these requests are ordered since I see payment_intent.succeeded before creation?
Also, I'm on MERN stack!
Yeah, we can't guarantee the order of events: https://stripe.com/docs/webhooks/best-practices#event-ordering
If this is to provision access to your product/service, you'd likely be best of listening to the invoice.* related events to act accordingly
Yes, it's about provisioning access, so I want to make sure people get access to the service once the payment is successful
Also would you have any insight about how to cancel subscriptions when managing them through Stripe? Is there any specific event I should listen for?
I'm sorry for the beginner questions but I recently started as a software engineer and this is my first exposure to Stripe!
Sounds like you want: https://stripe.com/docs/api/events/types#event_types-customer.subscription.deleted
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
More context here: https://stripe.com/docs/billing/subscriptions/overview#subscription-events
Thank you so much! I'll read up on that.
Np! Let me know if something isn't clear
I have a question about subscription renewals! If I want to provision the services through a boolean flag "subscribed: true/false", can I set up the webhook so that every month it sets the flag accordingly?
I have noticed your very well designed dashboard handles cancelling subscriptions, renewing them, switching tiers and more, but how would this connect to my app's backend?
And is there any way to set some extra headers for the requests I send to the webhook? e.g. I want to have the UID of the user that is doing things with their subscriptions so that I can perform operations on the related document in my DB (like setting the flag)
Yes, you'd probably want to listen for invoice.paid event. Equally, invoice.payment_failed to revoke access/prompt for payment
Are you referring to the Customer Portal?
You could manage this via metadata on the subscription: https://stripe.com/docs/api/subscriptions/create#create_subscription-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
You'd just listen for the corresponding events that the action in the Customer Portal would trigger
so the customer portal still fires back to my webhook and triggers the events?
Yep, exactly
Last question, and I'm sorry for asking so many!
I've seen that accessing the customer portal takes a Checkout Session ID, how would I approach getting to the customer portal without a checkout session? Like, the customer is in their personal area on my website and they want to access stripe settings
Hmm, think you mean a Customer Portal session? https://stripe.com/docs/api/customer_portal/sessions/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
But yes, you'll need to generate one via your server and return the URL to your app to redirect the user
This is what the example does right now!
I think checkoutSession just makes it so that the API pulls the customer ID on its own?
so I could just pass the customer ID
Hmm, I'm confused. You keep mentioning Checkout?
Yes! Sorry, let me clarify.
What I am doing right now is implementing this https://github.com/stripe-samples/checkout-single-subscription
if you go to server/node/server.js, you'll see the code I'm referring to.
Ah, the customer ID
You said Checkout Session ID and it confused me ๐
Yep, if you have the Customer ID from elsewhere then you can just pass that. Not need to fetch a Checkout Session
Thank you very much! I think this answered all my questions
Sure, np!