Reputation: 67
I am trying to store order id of the payment using sample MasterCard payment gateway in PHP. I store order id in a session variable before redirecting to the gateway and I use this stored value after complete the payment. But I have doubt if I implement it on real gateway do gateway destroys the session itself. Then I can't store order id like this (in session variables). Please help me to solve this.
Upvotes: 1
Views: 84
Reputation: 8053
No, it would NOT be destroyed normally (I have coded many sites which connect with payment gateway to settle payment / fee) -- but with the following exceptions:
a) Unless the user quits (I mean he/she closes) the browser totally and then re-opens the browser, otherwise the session vairable persists after navigating to the payment gateway and returns back to your site ; or
b) Unless the user stays in the payment gateway site long time enough that it exceeded the session life time as specified in your server (e.g. as specified in php.ini) -- which should normally not happen for a normal transaction
For example, if you have shoppingcart1.php storing the following session variable:
<?php
session_start();
$_SESSION["var1"]="ken lee";
?>
Then the user clicks a button and redirect to payment.php with the following code
<?php
session_start();
echo $_SESSION["var1"];
?>
<form method=post action=https://www.[paymentgateway].com/creditcard/">
.... other codes
<input type=submit>
</form>
and when the user paid the fee at the payment gateway, it would, normally, either get redirected to https://yoursite/success.php
(upon successful payment) or https://yoursite/cancel.php
(if the user clicks cancel during the payment process), then the success.php and/or cancel.php can still access the session variable, unless (a) or (b) above is true
Of course, if (a) and (b) is true, then your site should have measures to cater for such exceptions.
Last but not least, you should rely on other API / IPN provided by the payment gateway to confirm the payment status
Upvotes: 2