#Yelax
1 messages · Page 1 of 1 (latest)
Hey there
Hi, let me know if that doesnt make sense ^
So first, let's clarify something, are you always creating a SetupIntent right before creating a Subscription?
Like.... is the customer going to be in your app when the Subscription is created?
not always. In some cases we create subscription from a checkout session where the user is present on the site
In this case, the user is not at the site
Got it
Okay and if authentication is required, you are bringing them back on session in this case to complete authentication?
yeah using the link provided in the webhook payment_intent.requires_action
Gotcha and now the question is how you should know they actually completed the authentication and the payment was successful
yeah, but specifically that the payment was for the subscription creation. I can see i get webhooks like invoice.paid but need to differentiate between the subscription creation payment as described and a normal recurring payment
Ah thanks for clarifying
You want to look at the billing_reason on the Invoice: https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
It will be subscription_create for the initial invoice
Okay great. Is there a way to differentiate this kind of webhook from another invoice.paid webhook with subscription_create as the billing reason?
For example - A user that creates a subscription on the site will trigger a subscription.created event: We will send them an activation key. This will also trigger an invoice.paid event as well. In this case we wouldnt want to send them a key though because we've already sent one using the subscription create event.
The other case is a user is off the site and we create the subscription for them and they have to auth the payment. In this case we only get a invoice.paid event where we would want to send them a key.
Alright so im probably better off changing it to only send a key on invoice.paid events i guess?
Yep exactly
Also important to note that it should be pretty rare for the customer to need to authenticate again if you have collected their payment method via a SetupIntent
It is definitely possible, and you should be prepared for it, but we request an exemption from the issuer in this case since the card has already been authenticated previously
ah okay brilliant
And just to confirm, I should only ever receive one invoice.paid with subscription_create as the billing reason for every subscription right?
Well, kind of. You should always be prepared to potentially handle duplicate events (see: https://stripe.com/docs/webhooks/best-practices#duplicate-events). But yes only the initial invoice for a Sub will have that billing reason
Mint thank you very much for the help
Happy to help
Just want to say Stripe is one of the best api's I have worked with, and this instant chat support is incredible. Thanks again