Skip to content

۱۵ — قوانین تخفیف (Discount)


۱. انواع

typevalueexample
percent0–10020% off
fixedtoman10,000 off

۲. Scope

scopevendor_idwho creates
platformnulladmin
vendorrequiredadmin or vendor (MVP: admin only)

۳. Validation rules (به ترتیب)

  1. is_active == true
  2. now between valid_from and valid_to
  3. usage_count < usage_limit_total (if set)
  4. user usage < usage_limit_per_user (if set)
  5. order.subtotal >= min_order_amount (if set)
  6. if vendor scope → order.vendor_id matches
  7. compute discount:
    • percent: min(subtotal * rate, max_discount_amount)
    • fixed: min(value, subtotal)
  8. total = subtotal - discount (min 0)

۴. Stacking

MVP: one code per order — no stack


۵. Application timing

Whenallowed
Before payment
After paid

۶. Examples

CodeTypeValueMin orderResult on 65K
WELCOME20percent2050K52,000
FIRST10Kfixed10K60K55,000
VIP30percent3045,500

۷. Admin UI fields

  • code (uppercase auto)
  • scope, vendor picker
  • type, value
  • min_order_amount, max_discount_amount
  • usage_limit_total, usage_limit_per_user
  • valid_from, valid_to
  • is_active toggle

۸. Abuse prevention

  • normalize code: trim, uppercase
  • rate limit validate endpoint
  • log failed attempts
  • deactivate after N fraud flags (v2)

۹. Reporting

  • usage_count per code
  • total discount given (GMV impact)
  • orders with discount vs without