Skip to main content

validateDiscountsCoupon

Validate a discount coupon code.

Description

This method validates a discount coupon code and checks whether it exists and is currently active. It takes a coupon code as input and returns a Promise that resolves to true if the coupon is valid or false if the coupon does not exist or has expired.

Discounts.validateDiscountsCoupon(

code*

);

Parameters schema

Schema

code(required): string
The coupon code to validate

Examples

Minimal example

const response = await Discounts.validateDiscountsCoupon('SUMMER20');

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
Coupon data if the coupon is valid.

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

coupon.discountId: number
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
Order id where the coupon was applied, 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.