mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
purchase / checkout flow
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -59,10 +59,13 @@ async function evaluatePromo(policy, plan, rawCode, effectivePrice = null) {
|
||||
if (rule.expires_at && new Date(rule.expires_at) < new Date())
|
||||
return { valid: false, reason: 'Promo code has expired.' };
|
||||
|
||||
// Count how many completed payments used this code for this plan
|
||||
// Count how many completed payments used this code for this plan. Scoped to
|
||||
// 'completed' only — pending/failed/cancelled attempts must NOT consume a
|
||||
// limited-use code, or anyone can exhaust max_uses by creating orders they
|
||||
// never pay for.
|
||||
if (rule.max_uses != null) {
|
||||
const uses = await mdl_Payments.count({
|
||||
where: { promo_code: code, plan_id: plan.plan_id },
|
||||
where: { promo_code: code, plan_id: plan.plan_id, status: 'completed' },
|
||||
});
|
||||
if (uses >= Number(rule.max_uses))
|
||||
return { valid: false, reason: 'Promo code has reached its usage limit.' };
|
||||
|
||||
Reference in New Issue
Block a user