Skip to main content

Overview

Yabetoo’s promotion system consists of two entities:

Coupon

Defines the discount to apply (percentage or fixed amount)

Promo Code

Code usable by customers, linked to a coupon with additional restrictions
Coupon "Summer Sale 20%"
├── Promo Code "SUMMER20" (public, max 1000 uses)
├── Promo Code "SUMMERVIP" (VIP, min €50 purchase)
└── Promo Code "SUMMER-JOHN" (limited to customers: cus_xxx)

Coupons

What is a Coupon?

A Coupon defines the type and amount of discount. It can be reused by multiple promo codes with different restrictions.
Identifier format: coupon_ followed by 24 alphanumeric characters.Example: coupon_summer2024_20percent

Coupon Attributes

AttributeTypeDescription
idstringUnique identifier
namestringCoupon name (internal)
percentOffnumber | nullDiscount percentage (0-100)
amountOffnumber | nullFixed discount amount
currencyOptionsobjectAmounts per currency
durationenumonce, forever, repeating
durationInMonthsnumber | nullDuration in months (if repeating)
maxRedemptionsnumber | nullMaximum number of uses
timesRedeemednumberCurrent number of uses
redeemByDateTime | nullExpiration date
appliesToSkusstring[]Eligible SKUs (optional)
validbooleanCoupon active

Discount Types

Percentage Discount

Applies a percentage discount on the total amount.
curl -X POST https://api.yabetoo.com/v1/coupons \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Summer Sale 20%",
    "percentOff": 20,
    "duration": "once"
  }'
Example: 20% on a €100 cart = €80 to pay

Discount Duration

Once

One time onlyThe discount applies only to the first payment.Ideal for: welcome offers, first purchases

Forever

AlwaysThe discount applies to all future payments.Ideal for: permanent discounts, partnerships

Repeating

Limited timeThe discount applies for X months.Ideal for: temporary promotions on subscriptions
// Discount for 3 months on a subscription
{
  "name": "3 months at -50%",
  "percentOff": 50,
  "duration": "repeating",
  "durationInMonths": 3
}

SKU Restrictions

Limit a coupon to certain products/SKUs:
{
  "name": "Course Promo",
  "percentOff": 30,
  "duration": "once",
  "appliesToSkus": [
    "sku_course_js",
    "sku_course_react",
    "sku_course_node"
  ]
}
If appliesToSkus is defined, the discount only applies to the listed SKUs. Other cart items don’t get the discount.

Promo Codes

What is a Promo Code?

A Promo Code (PromotionCode) is the code customers use. It’s associated with a coupon and can have additional restrictions.
Identifier format: promo_ followed by 24 alphanumeric characters.Example: promo_summer20_public

Promo Code Attributes

AttributeTypeDescription
idstringUnique identifier
couponIdstringAssociated coupon
codestringUsable code (auto-uppercase)
activebooleanCode active
expiresAtDateTime | nullExpiration date
maxRedemptionsnumber | nullMaximum number of uses
timesRedeemednumberCurrent number of uses
minimumAmountnumber | nullMinimum purchase amount
minimumAmountCurrencystring | nullCurrency for minimum
firstTimeTransactionbooleanReserved for first purchases
customerIdsstring[]Customer whitelist

Create a Promo Code

curl -X POST https://api.yabetoo.com/v1/promotion-codes \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "couponId": "coupon_summer2024",
    "code": "SUMMER20",
    "maxRedemptions": 1000,
    "expiresAt": "2024-08-31T23:59:59Z"
  }'
The code is automatically converted to uppercase. summer20 becomes SUMMER20.

Advanced Restrictions

Require a minimum purchase amount:
{
  "couponId": "coupon_20percent",
  "code": "SAVE20",
  "minimumAmount": 50,
  "minimumAmountCurrency": "EUR"
}
The code only works if the cart exceeds €50.

Promo Code Validation

When using a promo code, the system performs several checks:
1

Code exists and active

The code must exist and active must be true
2

Not expired

Current date must be before expiresAt
3

Limit not reached

timesRedeemed must be less than maxRedemptions
4

Coupon valid

Associated coupon must be valid (valid: true)
5

Minimum amount

Cart must reach minimumAmount if defined
6

First purchase

If firstTimeTransaction, verify it’s the first order
7

Customer authorized

If customerIds defined, verify customer is in the list
8

Eligible SKUs

If coupon has appliesToSkus, verify cart contains these SKUs
9

Currency supported

Order currency must be supported by the coupon

Validation Errors

ErrorDescription
INVALID_CODENon-existent or inactive code
EXPIREDCode or coupon expired
MAX_REDEMPTIONSUsage limit reached
MINIMUM_NOT_METMinimum amount not reached
NOT_FIRST_PURCHASEReserved for first purchases
SKUS_NOT_ELIGIBLENo eligible SKU in cart
CURRENCY_MISMATCHCurrency not supported
CUSTOMER_NOT_ALLOWEDCustomer not authorized
COUPON_INVALIDCoupon deactivated

Usage History

Each coupon/promo code usage is recorded in CouponRedemption:
{
  "id": "redemption_abc123",
  "couponId": "coupon_summer2024",
  "promotionCodeId": "promo_summer20",
  "customerId": "cus_xyz789",
  "customerEmail": "customer@example.com",
  "orderId": "ord_def456",
  "discountAmount": 20,
  "currency": "EUR",
  "createdAt": "2024-07-15T14:30:00Z"
}
This history allows:
  • Auditing of granted discounts
  • Promotion performance analysis
  • Verification of uses per customer

Discount Calculation

Percentage Discount

const discount = (subtotal * coupon.percentOff) / 100;

Fixed Amount Discount

const discount = coupon.getAmountOffForCurrency(currency);
// Returns amount for currency or null if not supported

Complete Example

Cart: €120
Coupon: 20% discount

Calculation:
- Subtotal: €120
- Discount: 120 × 0.20 = €24
- Total: 120 - 24 = €96

API Responses

{
  "id": "coupon_summer2024_20percent",
  "object": "coupon",
  "name": "Summer Sale 20%",
  "percentOff": 20,
  "amountOff": null,
  "currencyOptions": {},
  "duration": "once",
  "durationInMonths": null,
  "maxRedemptions": 1000,
  "timesRedeemed": 156,
  "redeemBy": "2024-08-31T23:59:59.000Z",
  "appliesToSkus": null,
  "valid": true,
  "createdAt": "2024-06-01T00:00:00.000Z",
  "updatedAt": "2024-07-15T14:30:00.000Z"
}

Common Operations

Create a coupon

curl -X POST https://api.yabetoo.com/v1/coupons \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Black Friday 30%",
    "percentOff": 30,
    "duration": "once",
    "maxRedemptions": 500,
    "redeemBy": "2024-11-30T23:59:59Z"
  }'

Create a promo code

curl -X POST https://api.yabetoo.com/v1/promotion-codes \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "couponId": "coupon_blackfriday",
    "code": "BLACKFRIDAY30"
  }'

Validate a promo code

curl -X POST https://api.yabetoo.com/v1/promotion-codes/validate \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "code": "SUMMER20",
    "amount": 100,
    "currency": "EUR",
    "customerEmail": "customer@example.com"
  }'

Deactivate a promo code

curl -X PATCH https://api.yabetoo.com/v1/promotion-codes/promo_xxx \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "active": false
  }'

Best Practices

  • Use memorable and easy-to-type codes
  • Avoid ambiguous characters (0/O, 1/l)
  • Include context: SUMMER20, WELCOME15, VIP50
  • Keep codes short (6-12 characters)
  • Always define a limit (maxRedemptions or expiresAt)
  • Unlimited promotions can impact your margins
  • Plan a safety margin on limits
  • Analyze CouponRedemption regularly
  • Measure conversion rate per code
  • Compare performance of different promotions
  • Clearly display usage conditions
  • Indicate expiration date to customers
  • Explain why a code is rejected

Use Case Examples

{
  "coupon": {
    "name": "Welcome €10",
    "amountOff": 10,
    "currency": "EUR",
    "duration": "once"
  },
  "promotionCode": {
    "code": "WELCOME10",
    "firstTimeTransaction": true,
    "minimumAmount": 30,
    "minimumAmountCurrency": "EUR"
  }
}
Result: -€10 for new customers with cart > €30

Next Steps

Create a checkout session

Use promo codes in your checkout sessions

Webhooks

Receive notifications when promo codes are used