I followed the instructions almost line for line in step 4 of this guide:
Added the PlanEvents collection, and added the code:
export function wixPricingPlans_onOrderPurchased(event) {
if(event.order.price.amount === 0){
let orderData = {
"title": "Free Plan Purchased",
"data": event.order,
"orderId": event.order.orderId
}
console.log(orderData);
wixData.insert("PlanEvents", orderData);
}else{
let orderData = {
"title": "Plan Purchased",
"data": event.order,
"orderId": event.order.orderId
}
console.log(orderData);
wixData.insert("PlanEvents", orderData);
}
}
I am using checkout.startOnlinePurchase(planId) to supposedly trigger the onPlanPurchased function. I made sure the onPlanPurchased was located in events.js under src/backend but it will not run. I am getting confirmation emails that the free plan being purchased has successfully been ordered, but the events.js function does not run.
This is where the startOnlinePurchase function is located in my code:
function processPlan(planId, state) {
checkout.startOnlinePurchase(planId)
.then((orderObject) => {
let currentOrderId = orderObject.order._id;
addStateToPlanEvent(currentOrderId, state, userId);
$w('#multiStateBox1').changeState("confirmSignUp");
})
.catch((error) => {
console.error("Error: ", error.message);
});
}
I am relatively new to JavaScript so I’m not sure if I’m doing something wrong or if there is something I’m missing.
Any help would be appreciated!