verifyCoupon( )


Verifies a ticket coupon.

The verifyCoupon() function returns a Promise that resolves to an VerifyCouponResponse when the ticket coupon has been updated.

If the coupon has been verified, the VerifyCouponResponse will contain an invoice property with an invoice that includes the coupon discounts.

If the coupon fails verification, the VerifyCouponResponse will contain a discountErrors property including information about why the verification failed.

You may want to call the verifyCoupon() function in an input element's onCustomValidation() event handler to validate a coupon code while the form is being filled out.

Note: To work with the Wix Events API, you need to publish your site.

Method Declaration
Copy
function verifyCoupon(
  eventId: string,
  reservationId: string,
  coupon: string,
): Promise<VerifyCouponResponse>;
Method Parameters
eventIdstringRequired

ID of the event that the ticket coupon is for.


reservationIdstringRequired

ID of the reservation that the ticket coupon is for.


couponstringRequired

Code of the coupon to verify.

Returns
Return Type:Promise<VerifyCouponResponse>
JavaScript
import wixEventsFrontend from 'wix-events-frontend'; // ... const eventId = // Get the event ID // ... let reservationId = // Returned from the reserve() function // ... let coupon = // get coupon wixEventsFrontend.tickets.verifyCoupon(eventId, reservationId, coupon) .then((result) => { if (result.discountErrors) { // handle verification failure let firstErrorCode = result.discountErrors.error[0].code; } else { // handle coupon verified } }); /* result - error case: * * { * "discountErrors":{ * "error":[ * { * "code":"ERROR_COUPON_DOES_NOT_EXIST" * } * ] * } * } */ /* result - verified case * * { * "invoice": { * "items": [ * { * "id": "de8e3fd8-b257-40a7-933b-77c627d884e4", * "quantity": 2, * "name": "VIP ticket", * "price": { * "amount": "6.00", * "currency": "USD" * }, * "total": { * "amount": "12.00", * "currency": "USD" * }, * "discount":{ * "amount":{ * "amount":"2.0", * "currency":"USD" * }, * "afterDiscount":{ * "amount":"10.00", * "currency":"USD" * }, * "code":"CouponCode", * "name":"Coupon Name", * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59", * "discounts":[ * { * "amount":{ * "amount":"2.0", * "currency":"USD" * }, * "coupon":{ * "name":"Coupon Name", * "code":"CouponCode", * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59" * } * } * ] * }, * "fees": [ * { * "name": "WIX_FEE", * "type": "FEE_ADDED", * "rate": "2.5", * "amount": { * "amount": "0", * "currency": "USD" * } * } * ] * }, * { * "id": "9207637c-3d49-43af-b91e-32e496620c60", * "quantity": 1, * "name": "Regular ticket", * "price": { * "amount": "3.50", * "currency": "USD" * }, * "total": { * "amount": "3.50", * "currency": "USD" * }, * "discount":{ * "amount":{ * "amount":"1.0", * "currency":"USD" * }, * "afterDiscount":{ * "amount":"2.50", * "currency":"USD" * }, * "code":"CouponCode", * "name":"Coupon Name", * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59", * "discounts":[ * { * "amount":{ * "amount":"1.0", * "currency":"USD" * }, * "coupon":{ * "name":"Coupon Name", * "code":"CouponCode", * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59" * } * } * ] * }, * "fees": [ * { * "name": "WIX_FEE", * "type": "FEE_ADDED", * "rate": "2.5", * "amount": { * "amount": "0", * "currency": "USD" * } * } * ] * } * ], * "total":{ * "amount":"15.50", * "currency":"BIF" * }, * "discount":{ * "amount":{ * "amount":"3.0", * "currency":"BIF" * }, * "afterDiscount":{ * "amount":"12.50", * "currency":"BIF" * }, * "code":"CouponCode", * "name":"Coupon Name", * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59", * "discounts":[ * { * "amount":{ * "amount":"3.0", * "currency":"BIF" * }, * "coupon":{ * "name":"Coupon Name", * "code":"CouponCode", * "couponId":"3b2e333c-5376-4b36-8543-00bae6dd8f59" * } * } * ] * }, * "subTotal":{ * "amount":"15.50", * "currency":"BIF" * }, * "grandTotal":{ * "amount":"12.50", * "currency":"BIF" * }, * "fees":[], * "revenue":{ * "amount":"12.50", * "currency":"BIF" * } * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?