#sxe-paymentintent
1 messages · Page 1 of 1 (latest)
Hi
$amount_received = $payment_intent['amount_received'];
``` shows me 0
$stripe = new \Stripe\StripeClient(
'x'
);
$payment_intent = $stripe->paymentIntents->retrieve($payment,
['expand' => ['payment_method']]
);
at success url,
but, if I refresh it, it shows fine then.
can you share the PaymentIntent ID?
pi_3L0Ni7LKPu9R0yzS1E4s8Z8M
now it shows 3600
But, when success url is being called,
it shows 0.
If I refresh the page, it shows the correct value.
- When you created the PaymentIntent, it had
amount_received: 0 - Then after you captured the funds, there is
amount_received: 3600
How can I call success url after capturing the funds?
Or, should I capture the funds on the success url?
Are you always capturing the funds just after confirmation?
I'm capturing them on webhook api
if ($event->type == 'payment_intent.amount_capturable_updated')
{
$stripe->paymentIntents->capture(
$intent_id,
[]
);
}
if ($event->type == 'payment_intent.canceled')
{
unset($_SESSION["pretdeplata"]);
unset($_SESSION["CateProduse"]);
unset($_SESSION["payintent"]);
}
if ($event->type == 'payment_intent.payment_failed')
{
unset($_SESSION["pretdeplata"]);
unset($_SESSION["CateProduse"]);
unset($_SESSION["payintent"]);
}
if ($event->type == 'payment_intent.succeeded')
{
unset($_SESSION["pretdeplata"]);
unset($_SESSION["CateProduse"]);
unset($_SESSION["payintent"]);
}
But do you want to always capture after the confirmation? If so, you can remove capture_method: "manual when creating the PaymentIntent and the capture will be done automatically for you.
Do I need these anymore?
I'm not sure what this code is supposed to do. Is this your webhook code?
Yes
I'm not doing anything on event types.
All I do is on success url
page server-side
I'm not doing anything on event types.
All I do is on success url
What do you mean? To handle successful payments, you should use webhook events and not a success url.
This is explained here: https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-post-payment
If a payment was succesfull, I'm being redirected to success page
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: 'pge',
},
});
And on page, I'm retrieving the payment and do my server-side things as inserting in a database & and so on
Technically you can, but as mentioned in the link I just shared we con't recommend this:
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes.
so I should add every php code inside the
if ($event->type == 'payment_intent.succeeded')
?
All code that handle the post payment logic (like updating your database) should be in the webhook code yes.
payment_intent.succeeded is the right event.
Ok
I've added them inside the payment_intent.succeeded')
but, the problem is that success url is being called way before all queries are being executed.
How can I avoid that?
but, the problem is that success url is being called way before all queries are being executed.
You mean first the user goes to the success url, and then a few seconds later the webhook is fired?
I think so, yes. Because I was redirected to success url
and queries were not all executed.
Hi, I'm taking over for @oak island
just a few minutes so I could catch up
but a quick question, what do you mean by queries were not all executed
I have these queries
I have 10 queries, which they insert into a table, removes -x quantities from stock table, adds product to invoice table and so on .
When, user presses the pay button
He is being sent to success page
while, not every query is being executed
But only in couple seconds.
and when he's on success page, there has been executed only 2-3 queries yet (while other queries are being executed while he's on success page)
How can I call success page only when all queries are being executed?
(while other queries are being executed while he's on success page) - added this
you actually can't, the success page gets redirected to what comes first on these two events: 1-a success response from the webhooks 2-10secs have already passed
So what should I do then on the success page?
Check if last query had been executed,
if so => do something
if not => ...... ?
possibly