What are some options for coupon logic/workflow?
I want to be able to accept coupon codes that can have limits -- either in the number that will be accepted or in the time period for acceptance -- and be sure that the limits are enforced.
Payment will be using PayPal Web Payments Standard, using Buy Now buttons. That means the customer leaves my site, pays at PayPal, and returns.
The customer applies the coupon code to a single item and the price is lowered before leaving for PayPal. Of course, this assumes the code is still valid. My questions:
Do I decrement the counter (assuming we're limited by number) before the user goes to PayPal? If the user doesn't complete the transaction (just checking if the code works), the code could be invalid before being used for the total number of discounted sales.
Do I decrement the counter after I re开发者_运维问答ceive PayPal's IPN? There could be several buyers in the pipeline (going to PayPal) before the limit is reached who pay after the limit is reached. Not only could I sell more than I planned at the discounted price, since my IPN handler has a check for the amount paid I'll find the buyer paid less than what is (at the time) the actual price.
[To be clear, I'm anticipating 1) saving the coupon codes in a db and 2) saving the coupon redemptions in a db along with a unique invoice number that passes through PayPal. That way, the IPN handler can check the invoice number against properly redeemed codes.]
So, I have trade-offs either way. How can I best handle this?
It seems to me that you should handle it the same way as you handle stock control. At some point during the transaction cycle you must prevent goods in excess of stock being sold. Limited quantity discount coupons should be able to handled in a similar manner.
So, if you check stock on adding to the basket, then do the same with coupons. If the basket expires, return the stock and coupons at the same time. If you check stock at a later time and tell the user if the order can't be fulfilled then do the same with coupons at this stage.
精彩评论