how to restrict user for 10minutes for payment on paypal - php

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.

<?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

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.

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.

Related

Auction Expiration process using Php(CodeIgniter) Mysql Jquery

I'm developing an auction website. It is like: Auction is consists of X number of cars (let's say 10 cars in an auction). I have tables for auction, bid and product. My cronjob checks if any auction is ready to go live. If there is any then it flag the auction as active and update the bid time in product table.
Every product stays for 1 minute if in that time someone bid on the product time resets. if Minute is over it bring the next car for auction.
I'm wondering, if no user opens the window how i'm gonna expire the auction. All the request go from client. I'm using sockets for biding process.
Thank you

MySQL - automatically update row after x seconds of inactivity (set expiration time)

For an art project I am trying to set up an order site.
The concept allows users to book a max. of two time slots with each artist. There are 12 slots per artist, but each slot with a specific definition (so each is unique). The slots are only available for a very limited time and hopefully booked fast. So there will be a lot of requests in a short period of time. I have to make sure each article/slot is only offered to a single user at a time and cannot be double booked.
My idea was, to check for the next unbooked slot(s) (status="free) and on that request update the status of the corresponding row in the table to status="locked". If the user proceeds to actually book the slot, the status is updated to "booked".
If a user clicks "cancel" I can release the article by updating the row to status="free".
However, it is not unlikely that users just abandon the site and I don't see a way to check for that. The slot would remain "locked". I was thinking, there might be a way to automatically reset the status e.g. 120 seconds after is was "locked" and show a countdown to the users. This could even enhance the excitement factor.
I don't think a cron job would work as I need the anchor to be the last update of the row and not a specific datetime.
I looked into MySQL events but understood that I cannot manipulate the data of the table it is attached to.
I would greatly appreciate any ideas.
Thanks,
Sam
In your db your status table add a datetime field.
When someone lock a slot you also save the current time using NOW()
When someone consult the slots you perform and update and free the inactive slots
Update slots
SET locked = false
WHERE `datetime`> NOW() - INTERVAL 15 MINUTE;
SELECT *
FROM slots
WHERE locked = false;

PHP:update table automatically in mysql

I am building a simple coupon code buying application with apis.
Here is the work flow
User can select a coupon (getcoupon api)
If a coupon is obtained and its marked as pre_book then go the payment api for the payment.
If payment is success then coupon marked as booked
This works fine but i need help in the following:
If user is prebooked the coupon and aborted the payment i want to mark coupon code status as avaliable after sometime (say its 15 min) this should also happens when payment fails.
Structrue of coupon_code table
1.id-PK
2.coupon_code
3.status
Can i use a crone job for this?? but i don't think its possible because its not a periodic update .
Save the datetime of the payment attempt in the database
Create a cronjob that runs every minute
Update the table and set the payment_date as NULL using the following WHERE in your update query WHERE payment_date < DATE_SUB(NOW(),INTERVAL 15 MINUTE)

run a msql query after a specific amount of time without user interaction?

I will take the timestamp enter by a user as $tmp1
and server timestamp as $tmp2
I want to run a mysql query when $tmp1-$tmp2==0
I can do this by user interaction whith server and check it every time any user login, whether $tmp1-$tmp2==0
but this will require redundant if statement every time .
can it be done using corn jobs or trigger I haven't used them before please help
if there are 100 users interacting with another 100 user this came as 100*100 checking for the time every minute you should check up when user login or you can do is crate a event table and hit that event on a particular time
if event_time< now() and event_executed=0 then hit

PHP Login/Logout If Session Timeout = true Do Something

I have a script that will login and logout a user. It works perfectly. Now I have like a widget that counts how many users are registered and activated as well as how many users are online. I do this by having a field in my users database that says online = 1 or 0. When the person logs in, online = 1 and logs out online = 0. Now I haven't taken into account that this field is only being updated because the user is doing something. I haven't taken into account that the session would timeout.
How can I make a function that says something like if session timeout = true then update users set online=0 where username=$username and user_id=$user_id.
In your database table, add another column something like last_seen. Update this every time you see your users online. After a certain period of inactivity, they will be marked as inactive. In fact, I suggest you replace your online field with this.
For example,
ALTER TABLE users CHANGE COLUMN `online` `online` DATETIME; -- SAMPLE SQL query only
To check how many users are online:
SELECT * FROM users WHERE online>(NOW()-INTERVAL 1 HOUR); -- SELECTS all users online in the past hour.
If the user logs out, you can simply set the online = NOW()-INTERVAL 1 HOUR. Or, you can also retain your previous online field and you can check if the user is idle (using my suggestion) OR online=0.
Instead of trying to use a boolean value to see if somebody is logged in, try using a TIMESTAMP. Then you can perform more accurate logic based on how long somebody has been away. If the last time somebody has loaded a page on your website was 30 minutes ago, do you think they're online? Do you even think they're at their keyboard?
The session will only timeout if you want it to do so. This question is really a duplicate of 'How do I expire a PHP session?'
Code is only executed when a php page is served, so you will need to track the last time a user was active my using a session variable to track the last time a page was served to that user. Then, whenever serving any php page to the user, check to see if the timeout period has elapsed and log the user out if it has, see link for examples.
Add lastOnline field which stores the timestamp of last user activity.
Have some ajax function on the page which updates the timestamp every "n" seconds.
To check if user is online - check both: online field and timestamp. If timestamp was updates more than "n" seconds ago - user is offline even if online field is equal 1.

Categories