I have a backend function that assigns a pricing plan to a member. It uses a coupon to discount the entire price. If I go to the Subscriptions page after running this function, I can see that the order was created, and that the coupon was applied. The total amount due is zero. The subscription is marked ACTIVE, but is marked as UNPAID, and can’t be used by the member. Is this a Wix bug, or am I doing something wrong? I’ve tried it both with and without calling markAsPaid(), but it makes no difference.
By the way, the Wix Editor marks the third parameter to createOfflineOrder() as an error, saying 1-2 parameters are expected. However, I am following the calling sequence in the Velo API reference, and the call otherwise seems to work, including applying the coupon specified in the third parameter. I have found several other instances in which the Wix JavaScript Editor incorrectly finds something in error, so this doesn’t surprise me.
import { orders as planOrders } from 'wix-pricing-plans.v2';
import { elevate } from 'wix-auth';
export async function assignPricingPlan(planId, memberId, coupon) {
try {
let elevatedOrderPlan = elevate(planOrders.createOfflineOrder);
let thisOrder = await elevatedOrderPlan(planId, memberId, { couponCode: coupon, paid: true });
let elevatedMarkAsPaid = elevate(planOrders.markAsPaid);
await elevatedMarkAsPaid(thisOrder.order._id);
/* console.log(thisOrder); */
return thisOrder;
} catch (error) {
console.log('customBackend.jsw > assignPricingPlan error - details -' + error.message)
Promise.reject(
new Error('customBackend.jsw > assignPricingPlan error - details -' + error.message));
}
}