Hi everyone.
I am trying to use the wix-bookings-banckend Events (documentation here >> https://www.wix.com/velo/reference/wix-bookings-backend/events/onbookingconfirmed)..) I have created the events.js file in the backend and wrote the code below. But, it does not work. The item does not save in the collection I created.
Just to clarify, I am testing the event handler in the published site not in preview mode, as the documentation says.
Any idea?
import wixData from ‘wix-data’ ;
export function wixBookings_onBookingConfirmed ( event ) {
const eventTrigger = event.trigger ;
const bookingId = event.booking._id ;
let toInsert = {
'bookingId' : bookingId ,
'trigger' : eventTrigger
};
wixData . insert ( 'BookingEvents' , toInsert )
. then (( results ) => {
let itemInserted = results ;
console . log ( 'Item saved: ' , itemInserted );
})
. catch (( error ) => {
console . log ( 'An error ocurred: ' , error );
});
}
Hi, I am facing the same problem, onPlanPurchased event not triggered in events.js file, in fact none of the function is executed from events.js . Did you get any solution? Here is my code from events.js file in backend, also I am viewing it live not on preview mode.
export async function wixPricingPlans_onPlanPurchased ( event ) {
console . log ( ‘Plan Purchased by Affiliate’ )
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’ )
})
}
Hi @techanthere . Yes, I did. Do you have a message about what the backend console prints?
I am not getting any error while doing it live, and no console log as well. While in backend function, I have no idea how to execute this function without the event parameter, can you please guide me?
Just to be sure. Are you seeing the logs from the Developer Tools option like in the image below? Could you send me a screenshot of those logs when you run the function on the site?
Hello,
We are having the same problem with onBookingConfirmed( ). The event is never triggered. We are using a live site not preview mode.