#itchtherightspot_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1369363815090749512
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi! During the initial creation of a Subscription & successful payment of its initial Invoice using Checkout, you'll actually see a number of events:
customer.subscription.updated
invoice.payment_succeeded
invoice.paid
invoice.updated
customer.subscription.created
invoice.finalized
invoice.created
checkout.session.completed
During a subsequent successful event using a saved card, you'd only get:
customer.subscription.updated
invoice.payment_succeeded
invoice.paid
invoice.updated
customer.subscription.created
invoice.finalized
invoice.created
A Subscription is the container for Invoices, represent the amounts owning for the period. Invoices are paid by one or more Payment Intents, and so you'll also see their events:
payment_intent.created
payment_intent.partially_funded
payment_intent.payment_failed
payment_intent.processing
payment_intent.requires_action
payment_intent.succeeded
In fact, you'll want to listen to payment_intent.requires_action events in case an associated Invoice requires action from the customer.
Wow thats alot of events to listen to.
You don't necessarily need them all, but there are a lot.
Is it safe to say for a simple case of subscription, I should listen for checkout.session.completed for initial payment and payment_intent.requires_action for reoccurring payment?
To do what?
For a monthly or yearly subscription
Also would you know if there is a v82 sample repo? https://github.com/stripe-samples/subscription-use-cases/blob/main/fixed-price-subscriptions/server/go/server.go#L316
Unlikely, as that is likely the only place that example exists.
To validate is a user is a active paying member. I essentially want to listen to monthly webhook for an enrolled user
fair enough
Right, so the two key questions are:
- How do I know that my customer's subscription has become "paid up"; and
- How do I know that my customer's subscription is no longer "paid up"
Right?
Right to point 1.
invoice.paid will be emitted whenever an Invoice is successfully paid. checkout.session.completed tells you only that the Checkout Session was completed; it doesn't (explicitly) tell you anyhting about the Subscription's status. In the case of the first Invoice / payment on a Subscription, you could use checkout.session.completed instead, but invoice.paid would be logical to use for future successful payments.
You will also want to listen for failures via invoice.payment_failed and things requiring additional steps via invoice.payment_action_required
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ahh so it is invoice.paid not invoice.payment_succeeded. Final question is am I to assume invoice.paid means a new subscription object is created as per your statement A Subscription is the container for Invoices, represent...
They both still exist I think.
No, only one Subscription Object is created per subscription.
Of course! Does that all make sense? Is it enough to get you moving forward here?
Yh I believe so. Turns out my understanding prior to this conversation was for every successful subscription, a new subscription object is created (new unique subscription id) which is wrong.
So a subscription is created once for a customer, and said subscription can or will have multiple invoices. The most recent invoice determines if the subscription is active (actively paying customer or not).
Thanks for the link. I got a bunch of refactoring to do hahaha
You're welcome! Been there, done that, wore out the t-shirt. ๐