#Kikkoman
1 messages · Page 1 of 1 (latest)
Hello
Yep all you need is checkout.session.completed. See: https://stripe.com/docs/payments/checkout/fulfill-orders
if the payment fails, would we want to get an event for that?
Yes you should see a payment_intent.payment_failed Event in that case.
Should be easy to test out as well
so would it be safe to assume this:
if a payment is successful, we would get a checkout.session.completed and also a payment_intent.succeeded
Sure thing
Follow up question
say we create a checkout session, and forward the user to the checkout page, how would we know which payment_intent is associated with that checkout? (so that we can monitor for the failure)
My guess would be that when creating the checkout session, the id of the payment_intent is already returned, for us to listen to the event
The Checkout Session itself will contain the PaymentIntent in its object: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_intent
That will be present in the checkout.session.completed event
You can also attach a client_reference_id (https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-client_reference_id) or metadata if you want to use that to help with reconciliation
Do you think the sesion.completed event will always be before the payment_intent.failed / succeeded event?
Nope we don't guranatee ordering: https://stripe.com/docs/webhooks#event-ordering
Why I ask, is if the session.completed event is where I would get the id of the payment_Intent, how can I handle the event coming from payment_intent.failed scenario when we don't have a relationship to the checkout session yet?
Well you have your Checkout Session ID from creating the Checkout Session on your server
Ah, would the following be a reliable process then? When checkout.session.completed is received --> retrieve the payment_intent Id associated with the session --> request via API the payment_intent object from stripe, and then check if it failed / succeeded?
(or pending if it's an async method)
You don't need to check anything when you receive checkout.session.completed
That event will only fire if the payment is successful
What do most people usually do? Just check for success and expired?
Cause it seems like the payment_intent returned from a failed event wouldn't let me know which checkout_session it came from
Why do you care about a failure?
Like the customer will still be in the Checkout UI if the payment fails
They will see an error presented in that UI
You don't need to do anything in this case
Ok, then if the user fails multiple times, and stopped continuing. Would it ended up as just expired?
e.g. they close the browser
Yep eventually it would expire
Understood. I think thats acceptable
Either in 24 hours or less if you set a lower expiry
We could certainly re-use the same checkout session if they want to close and come back to it later (assuming it hasn't expired yet?)
That's up to you
Either way is totally fine
The benefit of re-using it is that they don't accidentally save the link and then somehow make a duplicate payment if you create a new one
Ok, then it opens up to new possibilities. Yup. that's all I have, I think i got into too much of a nitty gritty, thanks for bearing with me.
No worries at all