Skip to main content

validateDiscountsCoupon

Validate a discount coupon code.

Description​

Checks whether a coupon code exists and can still be used. The lookup is case-insensitive. Resolves to an ICouponValidationResult: valid is false when the code is not found ("Coupon not found") or when a single-use coupon has already been used ("Coupon has already been used"; coupon is still returned in that case). The method doesn't check the discount's validity period (startDate/endDate). To check it, fetch the discount the coupon belongs to (identified by the coupon's discountId) and compare the dates yourself.

.validateDiscountsCoupon(

);

Parameters schema​

Schema

code(required): string
Coupon code to validate.

Examples​

Minimal example​

const response = await Discounts.validateDiscountsCoupon('SUMMER-KBWZ-2428');

Example response​

{
"valid": true,
"coupon": {
"id": 1,
"discountId": 1,
"code": "SUMMER-KBWZ-2428",
"usedAt": null,
"isUsed": false,
"isReusable": false,
"orderId": null
}
}

Response schema​

Schema: ICouponValidationResult

valid: boolean
Whether the coupon is valid.

coupon: ICouponEntity
The coupon record. Present when the code is found, including when a single-use coupon has already been used; absent when the code is not found.

coupon.id: number
Coupon record ID.
example: 1

coupon.discountId: number
ID of the discount the coupon belongs to.
example: 1

coupon.code: string
Coupon code.
example: "SUMMER-KBWZ-2428"

coupon.isReusable: boolean
Whether the coupon can be used more than once.
example: false

coupon.isUsed: boolean
Whether the coupon has already been used.
example: false

coupon.orderId: number | null
ID of the order the coupon was applied to, or null.
example: null

coupon.usedAt: string | null
When the coupon was used, or null.
example: null

error: string
Error message, if the coupon is invalid.