#tounka

1 messages · Page 1 of 1 (latest)

simple glenBOT
spring bear
#

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

shrewd summit
#

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?

spring bear
#

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.

shrewd summit
#

how exactly can i get meta onto the subscription object or any other object?

spring bear
#
shrewd summit
#

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

spring bear
#

on the subscription object and subscription events, yes

#

If the event data object is the subscription, it will have the metadata on that subscription

shrewd summit
#

what if the event data object is invoice. if i access the subscription object from the invoice, will the metadata be there?

spring bear
#

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

shrewd summit
#

got you. so when i receive events, for invoice, how can i expand the subscription object?

spring bear
#

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

shrewd summit
#

when you say retrieve the event what do you mean? i thought event.Data would give me the invoice

spring bear
#
shrewd summit
#

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?

spring bear
#

Correct

#

The subscription on the invoice event will provide the id, which you can then retrieve

shrewd summit
#

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

spring bear
#

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)

shrewd summit
#

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

spring bear
#

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?

shrewd summit
#

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?

shrewd summit
#

this should also solve the invoice events too right

spring bear
#

No, the object there is the invoice object, but you can likely tie this together with your records of the subscription updated event

shrewd summit
#

i didn't quite understand that

spring bear
#

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

shrewd summit
#

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?

spring bear
#

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)

shrewd summit
#

okay cool, i'll with that option them. thank you for all your help. much appreciated