Redeems a customer's loyalty points for a loyalty reward and creates a loyalty coupon.
Creating a loyalty coupon also creates a corresponding "reference" coupon with the Coupons API.
The customer receives the reference coupon, which they can apply to their order. The loyalty coupon and its corresponding reference coupon
are linked and the loyalty coupon's status
reflects the current state of the reference coupon.
Check which loyalty rewards a site has available with List Rewards.
function redeemPointsForCoupon(
rewardId: string,
options: RedeemPointsForCouponOptions,
): Promise<RedeemPointsForCouponResponse>;
ID of the loyalty reward to redeem.
import { coupons } from "wix-loyalty.v2";
import { webMethod, Permissions } from "wix-web-module";
import { elevate } from "wix-auth";
/* Sample parameter values:
* {
* "rewardId": "00000000-0000-0000-0003-000000000000",
* "options": {
* "loyaltyAccountId": "d0dc5ba3-4a10-4cfc-b304-c976d8ac7303"
* }
* }
*/
const elevatedRedeemPointsForCoupon = elevate(coupons.redeemPointsForCoupon);
export const redeemPointsForCoupon = webMethod(
Permissions.Anyone,
async (rewardId, options) => {
try {
const result = await elevatedRedeemPointsForCoupon(rewardId, options);
return result;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
/* Promise resolves to:
*
* {
* "coupon": {
* "_createdDate": "2024-06-12T08:29:56.594Z",
* "_updatedDate": "2024-06-12T08:29:56.594Z",
* "_id": "56826083-0c4a-4e62-88e3-c6978482bde9",
* "accountId": "d0dc5ba3-4a10-4cfc-b304-c976d8ac7303",
* "couponReference": {
* "code": "6QLGQ9RNNR9R",
* "couponId": "a6df2aeb-50fc-4b15-b18d-765be38a6513",
* "name": "10% off all events",
* "specification": {
* "type": "PERCENT_OFF_RATE",
* "percentOffRate": 10,
* "scope": {
* "name": "ticket",
* "namespace": "events"
* },
* "limitedToOneItem": false
* }
* },
* "memberId": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32",
* "memberIdDeprecated": "7d368843-6f0c-4037-8d0e-b7e36a8a0c32",
* "revision": "1",
* "rewardName": "10% off all events",
* "status": "PENDING"
* }
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.