简体   繁体   中英

php - prevent using the same coupon code twice in paypal payment

The scenario is pretty simple.

In an e-commerce site, a certain user is given a coupon code and he can use it only once. Coupons are stored in database against each user's id.

Suppose the user adds a few products in the cart to make an order and enters the coupon and then clicks on the 'Pay Now' button and is redirected to the Paypal site for payment.

But the user uses a trick and does not pay just at that moment for the order he has just made. Instead he goes on to make another order by adding few other products in his cart and then again uses the single-time coupon and clicks the payment button to go to the Paypal site.

Now he makes payment for both the orders one after another and thus becomes successful to reuse the single-time coupon.

How to prevent the user from reusing the single-time coupon ? Should it take place before he is taken to the Pyapal site or after he is taken there ? and how above all?

I assume your coupon codes have two states, "used" and "unused" ..add a third state, "pending." When the user puts the coupon code in, validate it then mark it as pending. Once payment is confirmed mark it as "used" and don't let the user enter it again. If the user cancels their order you can make the coupon code "unused" again.

In case coupon is handled by you,

you can create single table, 2 columns:

coupon_id <-- primary key order_id <-- probably you want this to be unique.

then you store coupon there, or if coupon is already there, you are checking if it is for same order_id.

Is this helping? Please comment and I will improve the answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM