I'm assuming there are a few around here who have dealt with this before. I on the other hand am attempting this for the first time.
I've been developing a site for a while now that uses a custom shopping cart. Users need to be able to add items to their cart without logging in, so the session ID is used to keep track of which items belong to which user.
I'm now at the point where I need to finalize the transaction. I have created a login system which is working fine. The client still has to set up a merchant account, so for now I'm just planning on having an empty function called processCreditCard() or something and have it return true.
My question is this:
I'm trying to figure out the best way to handle the data from the time the anonymous user adds items to their cart, to them logging in, to checking out. My thought is to have a column in the cart table to store the user ID. As soon as the user logs in, update the table and set the user ID in all rows containing their session ID.
As soon as they hit submit to process the credit card, copy all cart data to an "orders" table which will contain a status column. As soon as authorization is recieved, update the status column as "paid", send out confirmation emails and clear the shopping cart. Unless, of course, authorization fails. In which case I would remove all items from the orders table and leave the cart in tact.
Is this a sensible way of handling this? Can someone suggest a better way?
Thanks