#bongowilliams
1 messages ยท Page 1 of 1 (latest)
Hi there, it's not always the case. payment_intent.succeeded event is fired when a payment is succeeded. However, a completed checkout session doesn't always mean the payment is succeeded.
ah, okay. is there a event i could rely on that would indicate payment status also to check before the user is returned?
For instance, if the customer choose a payment method that can't be immediately confirmed, the paymentIntent status will be pending even though the checkout session is completed.
sure
so should i look at the checkout.session.completed - event then as something that will fire before the user is returned?
or in most instances, like for card payments, will the payment intend be succeeded / completed and event fired before the user is returned?
im just wondering what the most reliable way to update our databse of the paid status is before the user is returned to our page (so we can show 'paid' in the UI)
As I explained earlier, checkout.session.completed doesn't always mean a payment is succeeded, it only means that the customer has completed the checkout session. You should listen to payment_intent.succeeded if you want to update your internal system for successful payments.
ok
thanks, are there any best practices in terms of delays, or was to handle the return url from checkout to allow time for the checkout.session.completed webhook to be received? or is it usually, for standard payments that can be confirmed by stripe straight away, safe to assume it will be fired before the return redirect process begins
I guess you want to present the payment result to your user in the page rendered by return URL, am I right?
You can add a ?session_id={CHECKOUT_SESSION_ID} at the end of the success_url, so that Stripe will substitute it with the session ID during redirection. So in you backend code, you can retrieve this session and its associated paymentIntent and inform your customer the payment status based on paymentIntent.
yeah that's correct, we'd like to do that
oh great, thats good advice, thank you! i'll do that
thats working! which php function can I then use to grab the payment intent using the checkout session id provided ?
really appreciate the tip Jack!
just trying to work it out in this format:
['stripe_account' => $from_connected_account_id
]);```
You can expand (https://stripe.com/docs/api/expanding_objects?lang=php#expanding_objects) the payment_intent field when retrieving a checkout session, so that the payment_intent object will be included in the response.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
oh that's really helpful, i didnt know that, i was making multiple calls in some cases
response expansion is very useful, you can save some round-trips ๐
yeah that's cool!
speeds things up too
'id' => $session_id,
'expand' => ['payment_intent'],
],['stripe_account' => $from_connected_account_id
]);```
does this seem like the right format here? if the session is creawted for a connected account user of ours?
all g, i confirm its correct. thank you so much
and im guessing i can just use the status of the payment intent? if status='succeeded' then we can assume its paid succesfully?
Yes you are right!
okay thats all worked wonderfully thanks so much