New API: applyCoupon() in wix-pricing-plans-backend

You can now use the [applyCoupon()](https://www.wix.com/velo/reference/wix-pricing-plans-backend/checkout/applycoupon) function to apply a coupon code to a draft order before it is purchased.

To learn more about coupons, see the createCoupon() function and this article .

1 Like

Can you give me a suggestion how I can make a coupon only for one billing circle not lifetime circle? what I should adding to the code? thanks a lot
exportfunction myCreateCoupon ( discount , code ){
//let couponecode = Math.trunc(Math.random() * 1000).toString() +“E”+Math.trunc(Math.random() * 1000000).toString()
let couponInfo = {
“name” : “MyCoupon” ,
“code” : code ,
“startTime” : new Date (),
“expirationTime” : new Date ( new Date (). getTime () + 24 * 60 * 60 * 1000 * 90 ),
“usageLimit” : 1 ,
“limitedToOneItem” : true ,
“limitPerCustomer” : 1 ,
“active” : true ,
“scope” : { // Coupon applies to all pricing plans
“namespace” : “pricingPlans”
},
“percentOffRate” : discount ,
}
// return {“id”:coupons.createCoupon(couponInfo),“code”:couponInfo.code};
return coupons . createCoupon ( couponInfo );
}

Hi Xu, thank you for your question.

We have updated the docs to include the necessary fields to make a coupon that applies to specific payment cycles.

First, appliesToSubscriptions must be marked as TRUE.
Second, use the discountedCycleCount to specify the amount of billing cycles to apply the discount to.