Replies: 1 comment
-
Hi @RealMrHex! Unfortunately, we cannot revert a coupon once it’s used (you can recreate it). I recommend that instead of applying the coupon immediately, you use Coupon::get('code') and apply it during the successful payment operation. This will return the discount value, allowing you to use it on your frontend. To address the race condition issue, we can implement a "Pessimistic Locking" mechanism to prevent multiple uses in parallel sessions. This will avoid the exploit where a user can use the coupon across multiple checkout pages. Even I believe that, in the current API, if the user applies the coupon to multiple carts, they can only proceed with the discount once. As for the conditions, the current API doesn’t support product-specific restrictions, but this could definitely be a useful feature to add in the future. |
Beta Was this translation helpful? Give feedback.
-
Hi again @Safemood,
I've implemented your package in our system and encountered a few scenarios that raise some concerns. I have a couple of questions regarding coupon usage and condition handling:
1. Undoing Coupon Usage
How can we revert a coupon usage in specific scenarios? Here's our issue:
For single-use coupons, this behavior causes problems since the coupon is effectively lost even if no payment occurs.
Proposed Solution:
A way to verify coupon usage, perhaps with
usingBy
andusedBy
attributes in the coupon's JSON data, could help. AverifyUsage
method might allow the system to associate the coupon with a user temporarily and finalize its usage only upon successful payment.2. Preventing Multiple Usages in Parallel Sessions
Another issue arises when a user opens multiple checkout pages:
This creates a serious issue where single-use coupons can be exploited.
3. Applying Conditions to Coupons
We also need a way to apply conditions based on specific products/items. For example, we may want to:
Currently, I couldn't find a built-in way to set such conditions. Do you have any suggestions on how we can achieve this?
Looking forward to your thoughts! Thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions