Currently I'm working on a project which includes the possibility to buy things on the website. Once you click on something like 'buy it now', the item gets assigned to you (the user), so that other users cannot buy it.
Now, I've got that all worked out. The item-object has a field status in the database which is 0 for open, 1 for reserved or 2 for bought. Once I buy the item, no one else can click on 'buy it now', and once I have paid, the status changes to 2 and everybody is happy.
But, where I am stuck at is the bit in the middle. How do I go about setting a time-limit to the reserved status? That once I have clicked the button, I need to complete the payment in say 20 minutes? And if I don't complete it within those 20 minutes, the item gets put back on the market with status=0? Or, if I don't fancy buying it anyway and just press the browsers 'back' button to return to the items overview, how do I intercept that and change the status to 0 immediately?
One option is to have a separate table to contain 'held' items, which is being checked every time someone visits a page. If the query finds an item which has been put on hold for longer than 20 minutes it will change the status back to 0. That's all good fun for the 'hmm I'm taking too long to pay' thing, but it won't put an item back on the market as soon as someone decides to skip the sale.
I have been searching for it the whole evening, but didn't get very far. I looked at Claweds' thread
too, which pretty much handles the first 20 minutes check, but doesn't involve the second bit.
If you do have a lead I can follow, please let me know.
Many thanks in advance,