Reputation:
I have a shopping cart. I want to integrate with the CCAvenue payment gateway. I always send order ID from database. After checkout, suddenly my system turns off. Then again I have to check out it send again. The order id from my database is duplicate for the payment gateway. This is my problem.
My question is: How do I send a unique order ID every time? My site is in PHP.
Upvotes: 1
Views: 2733
Reputation: 4538
With most payment gateways you can send a single auth+capture AKA "sale" transaction or you can send an authorize and capture transaction as two separate requests.
If you are worried about transactional consistency issues with sending a single sale transaction my recommendation is to send an authorize to first reserve the funds and then send a capture at the end of your ordering process.
If the system fails during the initial authorize worse case the funds are freed within three days when your auth expires. You should take care to not have the worse case for authorize occur as it blocks the authorized funds from being used until cleared which can occasionally lead to upset customers.
If the system fails during the final capture and you cannot record status you can simply rerun the capture later in which case the result will either be success or a message from the gateway indicating the capture already occurred which can then be used to update the payment status of your system.
Upvotes: 2
Reputation: 6419
Probably want a unique id like this https://www.php.net/uniqid though your question is kind of vague
Upvotes: 0
Reputation:
I think there should be a separate function for this - running all time, checking whether a previous version of the order is in the cart or not. Also, a copy of the process should be stored in the db always. This way, if for some reason, the server restarts, still, the order can be proceeded from the same position (thus there won't be any problem of duplication of orders).
Upvotes: 0