Reputation: 419
I am working on booking website. When any user come to site, select any date & time for booking and go to paypal for payment. Before going to paypal, I am adding this entry to booking, so any other user can not go for booking on that specific time for that date. Now if user does not make payment on paypal and stay idle. In this case that time gets blocked. I want user should have 10 minutes to make a payment on paypal. If time exceeds user should redirect to my website with any flag, so I can remove that booking and that time - date will be available for booking to users.
I can use cron job which can remove bookings which are in pending status in database for more than 10 mins. Major problem I am facing is
1) When I go to paypal for payment and stay idle, paypal automatically redirect after 5 min (giving error of session time out)
2) But when I go to paypal and log in with sandbox account and then stay idle, if after 5 min, I try to do any activity, it gives error of time out, and redirect to login screen of paypal. So it allow me to login again and proceed for payment.
By this way user can even pay after 1 hour. If I delete booking entry using cron, it will create conflict because payment is completed and there is no entry in database.
I want way to explicitly redirect user from paypal to my site after 10 mins.
Upvotes: 0
Views: 413
Reputation: 2286
<?php
// Create and start timer firing after 10 minute
$w1 = new EvTimer(600, 0, function () {
echo "10 minute elapsed\n";
//Your Condition
});
?>
use Timer and Write your condition in the Timer and check the user payment status
Upvotes: 1
Reputation: 9
Hope this may give you some idea :
1> After selecting date&time, you are adding entry to booking. Now before adding entry check whether the same 'date&time' is already present in database (because many may be booking simultaneously). If present 'display' message to users that it is already booked (redirect to booking page). If it is not present then add entry to database.
2> Create column 'status' in database entry table, While adding 'booking entry' to database , set 'status' as 'pending or 0'. At this time other users cant able to book this entry(same date&time).
3> After successful payment set 'status' as 'confirmed or 1'. If unsuccessful set 'status' as 'denied' or '-1'
4> I guess paypal has default time limit.
5> So, when the status is 'pending' and 'confirmed'. Others cant book on that.
6> If the status is 'denied' or 'empty' then others can book on that.
Upvotes: 0
Reputation: 2128
What you could do is store the booking in a table in your database, then have a cron job that runs every minute or so and deletes any entries older than 10 minutes:
mysql myDatabase < 'DELETE FROM bookings WHERE (now() - time_the_booking_was_made) > (120*60)'
Bookings in the database should not be displayed to other users as those bookings would be in the 10 minute reserved state. If you need the booking to become instantaneously available to other users after the 10 minute time period, you could save it to the table and run a timer like in the answer above that would remove the booking after the specified time.
Upvotes: 0