#farfa7886
1 messages ยท Page 1 of 1 (latest)
Hi there ๐ so that code looks like it will set metadata on both the Checkout Session object and the created Subscription object. Are either of those the object you're listening for with your webhook endpoint? Metadata is not automatically copied from one object to another, so if you're listening to Invoice, Payment Intent, or Charge events then extra steps are needed to fetch the metadata you're looking for.
sorry im still very very new to stripe and I dont' understand what you mean by "Are either of those the object you're listening for with your webhook endpoint?".
I just wanna say sorry in advise for understanding ๐
All good, no need to apologize. Do you know what type of Events you set your webhook endpoint to listen for?
I set it to listen for payment_intent.succeeded
Ups! just realised I sent the block of code twice thinking it was the webhook, i'll update it rq
midified
this is the webhook listener code https://discordapp.com/channels/841573134531821608/841573134531821616/1149003532884770836
Gotcha, so that is expected then. payment_intent.succeeded Events will contain a Payment Intent object, but that isn't where you're setting the metadata so you won't see it on that Payment Intent object.
You have two options here. One is to listen to a different type of Event that will contain the object where you're setting metadata. The part of the type before the . indicates the type of object that will be included in the Event. So you could listen for customer.subscription.created or checkout.session.completed Events.
The other is to change your event handling code, so that it uses the Payment Intent's ID to retrieve either the Subscription or Checkout Session object so you can inpsect the metadata on those.
but customer.subscription.created will trigger even if the user did not pay?
or payment went wrong?
That is a possibility, that Event is triggered whenever a Subscription is created. It doesn't guarantee that the Subscription is in an active state.
so I have to listen to checkout.session.completed
to get metadata and confirmation of payment success
right?
or it will trigger on cancel?
That is generated when a Checkout Session is completed, and should allow you to inspect the metadata on the Checkout Session object. I would recommend testing with asynchronous payment methods if you're planning to support those though. I believe with those the customer can complete the checkout experience, but then still encounter a failed payment later.
checkout.session.expired Events are triggered when the checkout session expires or is cancelled.
Any time!
sorry if this may seem sully but if i replace payment_intent.succeeded with payment_intent.completed, the ".completed" event wont trigger
payment_intent.completed is not a valid type of Event.
The full list of Event types can be found in our API reference here:
https://stripe.com/docs/api/events/types
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
what should i put then that supports metadata
Most objects and Event types support metadata. The key is that you need to listen for the same objects where you're putting the metadata, or adjust your flow to retrieve the objects that contain the metadata you're setting. Which one of those approaches are you planning to pursue?
i think i need to retrieve the objects that contain the metadata i'm setting
i'm not sure but i think
In that case, you wouldn't change the type of Events you're listening for, you can continue to listen for payment_intent.completed Events.
You can use the ID of the Payment Intent included in those Events to make a request to retrieve the associated Checkout Session. To do so you use this endpoint/function to make a request to list Checkout Sessions, and provide the ID of the payment intent to the payment_intent parameter, which will cause the request to only list Checkout Sessions associated with the payment intent you specify:
https://stripe.com/docs/api/checkout/sessions/list
Then you can read the metadata off of the Checkout Session object.
i will try
does the payment intent id start with "evt"?
No, it starts with pi_. The Event ID starts with evt_.