#Linas
1 messages ยท Page 1 of 1 (latest)
Hi there,
You set metadata at checkout level, they won't be propagated to other object, you may need to listen to checkout.session.completed instead
You can't pass metadata from checkout session to charges automatically
thanks. maybe i won't need metadata. We are listening "charge"succeded" webhooks.
What would be the best way via "charge.succeeded" to access purchase items ? we charge for multiple items.
items are listed via: $checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[ ]]);
You should listen to checkout.session.completed, once you get the Checkout Session Id, you make this API call, to fetch its line items
so, there is no way to achieve that via listening charge.succeeded ? I don't want to overwrite half of our system ๐
maybe i could get items via paymentintentid?
Nope the items are linked to the Checkout Session,
from the Checkout Session object you can get the PaymentIntentId and the ChargeId, but not the reverse
You need to follow this guide:
https://stripe.com/docs/payments/checkout/fulfill-orders
got it.
Do i have to check if "checkout.session.completed" transaction was successful ? Or if payment fails, "checkout.session.completed" is not created at all ?
That will depends on the payment methods used, for example for card payments, listening to that event is enough, but for delayed payment methods you need to listen to other webhooks, they are mentioned in this section of the link I shared:
https://stripe.com/docs/payments/checkout/fulfill-orders#delayed-notification
Perfect. and my last quesiton:
since all other purchases are delivered via "charge.succeeded". Is there any way to identify "charge.suceeded" webhook, that it came via "checkout.session" ? I need somehow these sales ignore on "charge.succedded" and process on "checkout.session.completed"....
Nope, you need to implement complementary like logic, on both events
you do some treatment on charge.succeeded on complete treatment on checkout.session.completed. Not doing exclusive logics
but we have a lot of other stripe integrations which are running not by "stripe checkout".
I understand that, but. you need to adapt it
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
hmm, maybe i could come with "dirty workaround" and look for charge API version? And if api version is older, i could process charges as we are doing now. And if API version is new, then i could know, that it came via Stripe Checkout and i could ignore that charge and process fulfilment via checkout.session.completed ? I think, that could work ?
sorry I need to get some context here, let me read through the thread
ok so let's go one step back before answering your latest Q
are you still using the Charges API and haven't moved yet to the PaymentIntents API?
we use both.
we have a lot of old projects, which are using charges API.
and our fulfilment process is based on "charges.succeded" webhook.
Hi, my colleague has stepped away, I need a moment to catch up.
So, the last question is how to ignore charge.succeeded events that are not attached to a Checkout Session?
how to ignore charge.succeded, that are attached to Checkout session.
Actually, you can retrieve a Checkout Session based on the PaymentIntent ID: https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent
This way you can keep your old integration and only listen to charge.succeeded.
Something like this:
const sessions = await stripe.checkout.sessions.list({
payment_intent: charge.payment_intent,
});
Sorry, this is in JavaScript, I don't know what lanaguage are u using. But you got the idea, right?
i use php, let me check, i think, it could work.
$stripe->checkout->sessions->all(['payment_intent' => charge->payment_intent]);