Hello,
I am hoping someone can help me… I am not getting a response from await wixBookings.checkoutBooking(bookingInfo, options);. I have tried everything I know to debug this but have been unsuccessful. Any help would be greatly appreciated. The code and develop console logs are below:
Corvid Code:
//-------------Request Approval-------------//
// Approve the requested appointment.
async function approveRequest(pendingRequest, index) {
// Get the requested appointment's slot object.
const slot = pendingRequest.requestedSlot;
console.log("slot: ", slot);
// Get the requested appointment's service data.
const service = await getService(slot.serviceId);
console.log("service id:", service);
// Create a form fields object with the values the user entered in the booking form.
console.log("checkpoint1");
let formFields = [{
// Set _id to the ID of the name field.
"_id": getFieldId(service, "Name"),
// Set value to the name the user entered.
"value": pendingRequest.name
},
{
// Set _id to the ID of the email field.
"_id": getFieldId(service, "Email"),
// Set value to the email address the user entered.
"value": pendingRequest.email
}
];
console.log("checkpoint2");
// Create the bookingInfo object needed when performing a booking. It consists of the
// requested appointment's slot and the form field values entered in the booking form.
const bookingInfo = {
"slot": slot,
"formFields": formFields
};
const options = {
"paymentType": "wixPay_Offline",
"couponCode": "thecouponcode"
}
console.log("bookingInfo:", bookingInfo);
// Perform the booking for the requested appointment.
console.log("checkpoint0");
const bookingResponse = await wixBookings.checkoutBooking(bookingInfo, options);
//If the booking is confirmed:
if (bookingResponse.status === "Confirmed") {
//Approve the requested appointment.
// Set the requested appointment's status to approved.
pendingRequest.status = "APPROVED";
// Update the requested appointment in the pendingAppointments collection.
wixData.update("pendingAppointments", pendingRequest);
// Refresh the page's data and update page elements.
refreshData();
}
// If the booking is not confirmed:
else {
// Enable the approve button.
$w("#approveButton").enable();
}
}
//-------------Service Helpers-------------//
// Get a service from the Services collection by ID.
function getService(id) {
return wixData.get("Bookings/Services", id);
}
// Get a field ID from a service for a given label.
function getFieldId(service, label) {
console.log("checkpoint3")
console.log(service.form.fields.filter(field => field.label === label)[0]._id);
return service.form.fields.filter(field => field.label === label)[0]._id;
}
Developer Console Feedback: