#sxe-paymentintent

1 messages · Page 1 of 1 (latest)

oak island
#

Hi! What is your question?

inner spruce
#

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.

oak island
#

can you share the PaymentIntent ID?

inner spruce
#

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.

oak island
#
  • When you created the PaymentIntent, it had amount_received: 0
  • Then after you captured the funds, there is amount_received: 3600
inner spruce
#

How can I call success url after capturing the funds?

#

Or, should I capture the funds on the success url?

oak island
#

Are you always capturing the funds just after confirmation?

inner spruce
#

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"]);


    }
oak island
#

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.

inner spruce
#

Thank you.

#

So, it will be ok now?

#

Yes, it's pkay now. okay*

inner spruce
oak island
#

I'm not sure what this code is supposed to do. Is this your webhook code?

inner spruce
#

Yes

#

I'm not doing anything on event types.

#

All I do is on success url

#

page server-side

oak island
#

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.

inner spruce
#
 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

oak island
#

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.

inner spruce
#

so I should add every php code inside the

#

if ($event->type == 'payment_intent.succeeded')
?

oak island
#

All code that handle the post payment logic (like updating your database) should be in the webhook code yes.

inner spruce
#

but which one

#

nvm, dumb question

oak island
#

payment_intent.succeeded is the right event.

inner spruce
#

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?

oak island
#

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?

inner spruce
#

I think so, yes. Because I was redirected to success url

#

and queries were not all executed.

verbal herald
#

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

inner spruce
#

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

verbal herald
#

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

inner spruce
#

So what should I do then on the success page?

#

Check if last query had been executed,

#

if so => do something

#

if not => ...... ?

verbal herald
#

possibly