Page 1 of 1

Extracting next available order number from a payment module.

Posted: Mon Apr 05, 2021 6:57 pm
by Yahalimu
Hello,
My current payment module sends a time-stamp in UTC + 3 random numbers as a transaction ID to the payment processor as the order number is not set until payment has been completed successfully..

The accountant is complaining it's hard the match the Trans-ID to order numbers.
I was thinking to send the next available order number + 3 random numbers as the Trans-ID.
This will be wrong (one or two out on the order number) if several people are completing at once but not far out.

Any ideas how can I extract the next available order number from inside a payment module?

Re: Extracting next available order number from a payment module.

Posted: Mon Apr 05, 2021 8:25 pm
by ecartz
The way that PayPal does it: insert the order before redirecting off-site. Anything else is going to not match at least some of the time. Because if two people try to pay at the same time, both would get the same "next available order ID" unless you reserve it by inserting the order.

But if you reject that solution,

Code: Select all

$query = tep_db_query("SHOW TABLE STATUS LIKE 'orders'");
$data = $query->fetch_assoc();
echo $data['auto_increment'];
Reference: https://stackoverflow.com/q/2251463