#tounka
1 messages · Page 1 of 1 (latest)
hey there
The subscription items should only be the new ones, since its actually impossible to have two items with different billing intervals on a single subscription
This is why this kind of a change is one of the situation that forces an immediate invoice to prorate the change
thanks, also when I add metadata to the CheckoutSessionParam, when I get webhook events, will each event I receive (invoice.paid, invoice.paymentfailed) include that same metadata?
No, the metadata on the Checkout Session will be present on the session events (eg, checkout.session.completed but not the others. You can set up metadata to be passed through to the subscription or payment intent if needed, but nothing will be automatically propagated to the invoice object and related events.
how exactly can i get meta onto the subscription object or any other object?
Depending on whether you're using payment mode, subscription mode, or setup mode:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-setup_intent_data-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.
so for the CheckoutSession params if i do params.SubscriptionData.AddMetadata when i get webhook events, that metadata should always be present on the subscription
on the subscription object and subscription events, yes
If the event data object is the subscription, it will have the metadata on that subscription
what if the event data object is invoice. if i access the subscription object from the invoice, will the metadata be there?
No, it will not
Oh wait
Yes, if you retrieve the subscription or expand it when retrieving the invoice, yes the subscription object will show the metadata
It will not be in the invoice event object itself, though
got you. so when i receive events, for invoice, how can i expand the subscription object?
You'd need to retrieve the invoice and use expansion to get the subscription, or retrieve the subscription itself using that ID
Using either the Invoice or Subscription retrieve API endpoints, depending on which you want to do
when you say retrieve the event what do you mean? i thought event.Data would give me the invoice
Not the event, the invoice or subscription object:
https://stripe.com/docs/api/invoices/retrieve
https://stripe.com/docs/api/subscriptions/retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
is this correct: when the event comes in i deserialize the object to the invoice. then i have to make another api call just to get the subscription?
Correct
The subscription on the invoice event will provide the id, which you can then retrieve
there's no way to expand it or have it automatically included with the invoice?
or to avoid that extra api call perhaps there is a better place to add the meta data instead of the subscription?
also, if instead i populate the client_reference_id when creating a checkout session, will webhook events for invoice etc have the client_reference_id populated
No, there's no automatic expansion with webhook objects at all
Nope, you'd need to apply the metadata to the invoice yourself and there is no such field for the client reference on the invoice
Let's take a step back, what are you trying to do?
Why do you need this on the invoice event specifically?
(instead of say the checkout event or the subscription created event)
So basically, when i receive any webhook event i want to know what user_id (this is an internal id) this event corresponds to. im currently handling 4 events: checkout.session.completed invoice.paid invoice.payment_failed customer.subscription.updated
i was under the impression that when i add metadata when i initially create the checkout session that all webhook events objects would include that metadata
It depends on where you put that metadata, as explain above
If the metadata is on the session object, it will be present in the session related events, same goes for the subscription (via subscription_data)
But there's no way to automatically get it on the invoice object (and event)
Why do you need it there?
i don't need it on the event. i think i need it on the invoice so when i get invoice.paid i can continue to provision access to my product for the given user
so when creating a new session if i add metadata to the CheckoutSessionParams, AND the Subscription object, when i get checkout.session.completed the metadata will be there and similarly if i get any event that has the subscription as the object, the metadata will also be there?
yes, that's right
this should also solve the invoice events too right
No, the object there is the invoice object, but you can likely tie this together with your records of the subscription updated event
i didn't quite understand that
Here you describe setting the metadata on the Checkout Session + Subscription. This means you should get the metadata in the checkout.session.completed and customer.subscription.updated events, but not the invoice events
But if you're listening for customer.subscription.updated and invoice.paid you could set up your system to try to match those up by subscription id to access the data, if you really wanted to avoid a separate call
Alternatively you can use that customer.subscription.updated to roll forward the provisioning assuming payment succeeded
and only do something different in the payment failure case
i see okay that makes sense. so id just store these objects in my db and match them up
for invoice.paid, i technically don't need to do anything right since this event is just provisioning the SAME subscription?
Yes that's right, the subscription object on the subscription events is the same object you'd get if you retrieved it from the API following the invoice event (modulo any expansion or changes for events that don't happen at the same time, etc)
okay cool, i'll with that option them. thank you for all your help. much appreciated