Hi everyone! I want to update the plan name inside a collection when a user purchases a plan. I am using events.js file in the backend for that, but the onPlanPurchased event is not triggered. Here is my code:
export async function wixPricingPlans_onPlanPurchased ( event ) {
console . log ( ‘Plan Purchased by Affiliate’ ) // this won’t run as well
let affiliate = ( await wixData . query ( ‘Affiliations’ ). eq ( ‘email’ , wixUsers . currentUser . getEmail ()). find ()). items [ 0 ];
if ( event . order . planName === “Affiliation Basic” ){
affiliate . plan = “Basic” ;
}
if ( event . order . planName === “Affiliation Standard” ){
affiliate . plan = “Standard” ;
}
if ( event . order . planName === “Affiliation Premium” ){
affiliate . plan = “Premium” ;
}
affiliate . expiry = event . order . validUntil . toLocaleDateString ();
await wixData . update ( ‘Affiliations’ , affiliate ). then (()=>{
console . log ( ‘Affiliation plan updated’ )
})
}