0

I am creating a functionality called tentative booking.

When a user books a ticket, he is given a temporary pnr-number and he should be given about 10 minutes to perform his payment.

If he fails to pay within 10 minutes, the transaction should be cancelled. Otherwise a success-message should be displayed.

Please ignore the logic for the payment. It can be any method.

I'm generating the temporary pnr-number and storing it into the database.

I can't understand how should I proceed here.

Is there any functionality in php which I can use for this?

Here is my code :

    $pnr = getPnr();
        echo "You temporarary pnr num is : $pnr <br>";
    echo "Check you mail and save it for future use";
    if($book_ticket == 'true')
    {       DoTentativeBooking($userid,$book_ticket,$from,$to,$date,$pnr,$seats,$email);

    }
function DoTentativeBooking($userid,$book_ticket,$from,$to,$date,$pnr,$seats,$email)
{
        $con = mysqli_connect('server', 'user', 'password', 'database');                
        if (mysqli_connect_errno())
        {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
            return;
        }
        $insertQuery1 = "INSERT INTO tbl_user(`user_id`,`book_ticket`,`from`,`to`,`date`,`user_pnr`,`seat`,`email`,`isConfirm`) VALUES ('".$userid."','".$book_ticket."','".$from."','".$to."','".$date."','".$pnr."','".$seats."','".$email."','No')";
        if (!mysqli_query($con,$insertQuery1))
            {
            //  die('Error: ' . mysqli_error($con));
                echo "error";
            }       
        return; 
}
Brovoker
  • 896
  • 5
  • 16

2 Answers2

3
  1. Save a timestamp of when the order was created and/or when it expires together with the order in the database.
  2. Set some flag that you're awaiting payment, e.g. set the status column to "awaiting_payment" or whatever, in the database.
  3. Whenever handling any orders, filter them by their status flag/handle them accordingly.
  4. On the payment confirmation page, when flipping the status to "paid", check the expiration timestamp.

In other words, you're not doing anything at a specific time or are expiring anything at a specific time. You simply save enough information that lets you figure out at any time when you need it what the status of the order is.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • this logic I understand, i am facing probelm how to give time of 10 minutes. Any php code snippet will help me more –  Mar 31 '14 at 13:31
  • 1
    What's the exact problem? Creating a timestamp 10 minutes in the future? Checking if the current time is before or after a timestamp? – deceze Mar 31 '14 at 13:38
  • yes, waiting for 10 minutes for some action. If that does not occur withing stipulated time, so transaction failed –  Mar 31 '14 at 14:19
  • 1
    So, what is the concrete problem? Saving the timestamp into the database when you insert the order? Comparing the saved timestamp to the current time when you're about to accept or reject the payment? – deceze Mar 31 '14 at 14:20
  • Do i need to save it in db? I am not sure. Consider checking `isPaymentCompleted` variable in database after 10 minutes, if this is set to no, then display error message –  Mar 31 '14 at 14:24
  • I saved in database, but now do I need to check it continously? how to do it –  Mar 31 '14 at 14:43
  • 1
    You have obviously *not* understood the logic. Please try to read the individual rules I wrote again one by one. – deceze Mar 31 '14 at 14:48
-1

you can try this...

set a time variable while you are setting temporary pnr number..

$date = new DateTime();
$time1 = $date->getTimestamp(); // this will give you current timestamp..

and put a checking condition in header like..

$time2 = $date->getTimestamp();
if(round(abs($time1 - $time2) / 60,2) >= 10)
{
   unset($pnr);
}
Nishant Solanki
  • 2,119
  • 3
  • 19
  • 32