#sxe-success-url

1 messages · Page 1 of 1 (latest)

haughty hollow
#

Hey there, can you tell me more about the issue you are having?

mild walrus
#

Hu

#

Hi

#

When my payment is confirmed and the url is being redirected to the one which i've set it on js, url_param

#

If I

echo $_GET['secret_code'] ```
#

Works fine. It shows the secret code.

#

But, if I check in my DB the secret code, it does not find it, even if, previously, i've inserted it inside the db.

haughty hollow
#

Sorry I don't really understand... you are seeing the data you want in your success Url, then you are inserting it into your database, then you query your database but that data doesn't show up in the database?

mild walrus
#

webhook php


if ($event->type == 'payment_intent.succeeded') 
    {
    $stmt = $con->prepare("INSERT INTO x (x) VALUES (x)");
.....
#

On webhook.php i'm inserting into database the payment id, the secret_Code as can we say it.

#

on success url, I'm doing this;

#
    $stmt = $con->prepare("SELECT ID FROM table
        WHERE secretcode = ?");
    $stmt->bind_param("s", $_GET['payment_intent']);
    $stmt->execute();
    $results = $stmt->get_result();
    while($row = $results->fetch_assoc()) {
        $ID = $row['ID'];
    }
    
echo $_GET['payment_intent'];
echo $ID ;
#

$ID is null

#

while $_Get['payment_intent'] is not null.

haughty hollow
#

Okay so then it seems you aren't retrieving from your database correctly or you aren't inserting correctly. So I'd first log our $results here

mild walrus
#

If I enter on the DB and check it with the query, I can find it.

haughty hollow
#

Okay so then log out $row and what do you see?

mild walrus
#

i need to make a payment, let's see.

#

var_dump($row) ?

haughty hollow
#

Yeah or $error_log($row)

#

I'm not the most familiar with PHP but I think one of those two options should return something

mild walrus
#

NULL

#

echo var_dump($row);

#
pi_3L07adLKPu9R0yzS1X72iO6O
NULL
#
echo $_GET['payment_intent'];
echo "<br>";
echo var_dump($row);
haughty hollow
#

Okay so I would assume that is the issue then

#

What is $results->fetch_assoc()

#

What is the definition of that method?

mild walrus
#

We're fetching the results get by the query.

#
$stmt = $con->prepare("SELECT Factura FROM PlatiEfectuate
        WHERE Identificare = ?");
    $stmt->bind_param("s", $_GET['payment_intent']);
    $stmt->execute();
    $results = $stmt->get_result();
    while($row = $results->fetch_assoc()) {
        $Factura = $row['Factura'];
    }
#
    $results = $stmt->get_result();
#

This gets the results from the query itself.

#
    while($row = $results->fetch_assoc()) {

This grabs them, fetch them as non-array values

#

I think that, my succes page loads before the insert query gets run.

haughty hollow
#

Oh fetch_assoc() is built in mysql method

#

Got it

#

So yeah, then the issue seems to be with the insert timing

#

If you are able to retrieve the PI ID from the URL but your query for that specific PI in your database isn't returning it, then you need to debug the insert

mild walrus
#

Is there any method to call the success url after a while?

#
 const { error } = await stripe.confirmPayment({
  elements,
    confirmParams: {
      return_url: 'url',
    },
  });
``` this
haughty hollow
#

No you would need to use setTimeout or something

mild walrus
#

Can you give me an example?

haughty hollow
#

You still would need to trigger that method somehow though

#

Mostly you can just reload your webpage, no?

#

and that will trigger the clientside action?

mild walrus
#

If I make a php code to reload the page once,

#

Actually let me try.

#

I refreshed the page.

#

with header

#

And still did not work.

#

I will try to header in 10 seconds, then.

#

Works fine, ty1

haughty hollow
#

What works? Refreshing the page to trigger the client action?

#

Or you are getting the data now?

mild walrus
haughty hollow
#

How you doing @mild walrus ?

mild walrus
#

I think I found why my page needs to be reloaded after 5 seconds.

#

I need to work on my queries, because I have 10 php queries right now

#

and let's say, each 0.5 second

#

0.5 x 10 = 5 sec

haughty hollow
#

Yep that makes sense

#

That said... why do you need to be able to retrieve the PI from your database immediately after it is inserted?

#

As you noted, you have it from the success URL

#

So you can handle your database stuff asynch and not worry about that immediately

mild walrus
#

Exactly lol

#

why should I run queries inside the webhook.php

#

whenI can run them inside the success page

haughty hollow
#

Yeah this should only be necessary if you need to pull past data

#

Which if these are new PIs... there is no past data 🙂

mild walrus
#

Actually I will try your method.

#

Hmm.