purchase / checkout flow

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-08-31 17:57:29 +08:00
parent 7413a296fb
commit 79203b1654
6 changed files with 40 additions and 19 deletions
+5 -2
View File
@@ -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.' };