← All packages

@lacspace/coupon

v1.0.0Commerce & Ledger0 deps

Discount & coupon engine — percent, fixed and free-shipping codes with validity windows, minimum-subtotal, discount caps and usage limits. Integer minor units, no float drift. Zero-dependency, isomorphic.

npm i @lacspace/coupon

Usage

coupon.ts
import { validateCoupon, applyCoupon } from "@lacspace/coupon";

const coupon = { code: "DASHAIN", type: "percent", value: 15, minSubtotal: 200000, cap: 50000 };

const check = validateCoupon(coupon, { subtotal: 350000, now: Date.now() });
if (check.ok) {
  const { discount, total } = applyCoupon(coupon, 350000); // discount capped at 50000
}

Exports 2

validateCouponapplyCoupon

Keywords

coupondiscountpromo-codevoucherfree-shippingcheckout

More in Commerce & Ledger