Accepting Coupons

I wonder if anyone here has dealt with a process for accepting coupon codes? 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 receive 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, if I do a check for the amount paid I’ll find the buyer paid less than what is (at the time) the actual price.

So, I have trade-offs either way. How can I best handle this?