Wix Booking API problem

Help please!

I am receiving the following error message:
SyntaxError: Unexpected token < in JSON at position 0
when executing :

const response = await wixBookings.checkoutBooking(bookingInfo, paymentOptions);

this worked fine a few days ago. Anyone else having this problem? Below are form fields and payment options

formFields:
Array(4)

0:
{…}

_id:
“37a0448e-eff5-48c3-b8a8-4dac5ec725fd”

value:
“Rocky xxxxxxxx”

1:
{…}

_id:
“b7b714ed-f7b3-4bc4-b562-84d6d47741b4”

value:
“raltimore@xxxxxxxxx”

2:
{…}

_id:
“1afdcb80-1e84-45f3-aecb-b844bf8504e8”

value:
“804-xxx-xxxx, 804-xxx-xxxx”

3:
{…}

Contact
Line 164

{…}

paymentType:
“wixPay_online”

Contact
Line 165

Are you using one of these booking tutorials from the examples page here?
https://www.wix.com/corvid/examples
https://support.wix.com/en/article/corvid-ideas-for-working-with-your-wix-bookings-app-collections
https://support.wix.com/en/article/corvid-tutorial-creating-a-custom-bookings-experience
https://support.wix.com/en/article/corvid-creating-a-bookings-timetable

Or have you written up your own custom code?

Please paste your code used, plus any screenshots of the error etc.

Reference pages for you to look at too.
https://support.wix.com/en/corvid-by-wix/wix-bookings-with-corvid
https://www.wix.com/corvid/reference/wix-bookings.html

Thanks for your response. Below is the code followed by the console log. This code worked fine over the weekend, now it does not… One other item of interest. If the service is “Online Only” I receive a different error message “No payment info” (I have set up the services a Online and pay in person.)

Code: (the call to checkoutbooking is in blue)

import wixWindow from “wix-window”;
import wixBookings from ‘wix-bookings’;
import wixData from ‘wix-data’
import {session} from ‘wix-storage’;
let member;
let member1;
let couponcode;
let Dogs;
let slot;
let MyClass
let MyMember
let rdocmem
let cid
let MyDog;
let NField;
let myid;
let _id;
let D_id;
let selectflag;
let ackflag;
let classname;
$w.onReady( function () {
//TODO: write your page related code here…
// Get the data sent from the Schedule page.
const context = wixWindow.lightbox.getContext();
slot=context.Class
classname=context.Cname
NField=context.form.fields
member1=session.getItem(‘member’)

member=context.member 
$w('#name').value=member.member + ' ' + member.lastName 

$w(‘#name’).required= true
$w(‘#address’).value=member.street
$w(‘#address’).required= true
$w(‘#city’).value=member.city
$w(‘#city’).required= true
$w(‘#state’).value=member.state
$w(‘#state’).required= true
$w(‘#zip’).value=member.zipPlus
$w(‘#zip’).required= true
$w(‘#phone’).value=member.telephone
$w(‘#phone’).required= true
$w(‘#email’).value=member.emailAddress
$w(‘#email’).required= true
Dogs=context.Dogs
cid=context.cid

// Create an empty form fields list.
Getclass();

$w('#table1').rows=Dogs.map(item => { 

return {
dogName: item.dogName,
dogid: item.dogid
}

 });     
 $w('#table1').columns[1].width=1;  

$w(“#table1”).onRowSelect( (event,$w) => {
MyDog = event.rowData.dogName;
D_id=event.rowData.dogid
selectflag=‘y’
if (ackflag===‘y’) {
$w(‘#Paybutton’).enable()
}
else {
$w(‘#Paybutton’).disable()
}
// prepgetdog ()

});

});

async function prepgetdog() {
const ADog= await Getdog()
for ( const CheckDog of ADog) {
console.log(CheckDog)
let now= new Date()
let rdate=CheckDog.rabbiesCert
console.log(rdate)
if (now > rdate) {
$w(‘#errorText’).text= ’ Rabies Certificate for ’ + MyDog + ’ is out of date ’
$w(‘#errorText’).show()
selectflag=‘’
$w(‘#Paybutton’).disable()
}
else {
$w(‘#errorText’).text= ’ ’
$w(‘#errorText’).hide()
selectflag=‘y’
$w(‘#Paybutton’).disable()
if (ackflag===‘y’) {
$w(‘#Paybutton’).enable()
}

    } 
} 

}
async function Getdog() {

const Ref2 = await wixData.query(“Dog”)
.eq(‘_id’,D_id)
.find();
return Ref2.items

}
async function Getclass() {

MyClass = await Getmyclass();

cid=MyClass[0]._id

}
async function Getmyclass () {
const results= await wixData.query(“Classes”)
.eq(‘bookingid’,cid)
.find();
return results.items

}

export async function Paybutton_click(event) {
//Add your code for this event here:

let formFields=;
// Disable the book button.
$w(“#Paybutton”).disable();
// Hide the error text.
$w(“#errorText”).hide();
// Set the validity indicator to true.
let isValid = true ;
// For each item in the form:

// If its value is not valid.
// if (!$w(“#name”).valid) {
// Set the validity indicator to false.
// isValid = false;
// }
// Get the Name value.
let value = $w(“#name”).value;
// Get the Name ID.
_id = NField[0]._id;
// Add the item’s value and ID to the list of form fields.
formFields.push({ _id, value });

// Get the Email value.
value = $w(“#email”).value;
// Get the Name ID.
_id = NField[1]._id;
// Add the item’s value and ID to the list of form fields.
formFields.push({_id, value });
// Get the Phone value.
value = $w(“#phone”).value;
// Get the Name ID.
_id = NField[2]._id;
// Add the item’s value and ID to the list of form fields.
formFields.push({ _id, value });

// Get the Selected Dog value.
value = MyDog

// Get the Dog ID.
_id = NField[3]._id;
// Add the item’s value and ID to the list of form fields.
formFields.push({ _id, value });

// Create a booking info object using the slot passed from the Schedule page
// and the form field data collected in this lightbox.
const bookingInfo = {
slot,
formFields
};

// Set the payment options to an online payment.
if (member1===‘y’) {

    couponcode=session.getItem('couponcode') 
} 

if (member1===‘’) {
couponcode=“”
}
const paymentOptions = {
paymentType: “wixPay_online”,
couponCode: couponcode

}; 

// If all the fields have valid values:
if (isValid) {
try {
console.log(bookingInfo)
console.log(paymentOptions)
// Perform the booking for the requested slot using the booking info and payment options from above.
const response = await wixBookings.checkoutBooking(bookingInfo, paymentOptions);
// If the booking is confirmed:
console.log(response)
if (response.status === “Confirmed”) {
// Place slot data in session storage to be used on the thank you page.
// session.setItem(“bookedStart”, new Date(slot.startDateTime));
// session.setItem(“bookedEnd”, new Date(slot.endDateTime));
// session.setItem(“serviceId”, slot.serviceId);

// Navigate to the thank you page.
// wixLocation.to(“/thank-you”);
session.setItem(‘couponcode’, ‘’)
$w(‘#dataset1’). new ()
.then( ( ) => {
prepUpdateRec()
} )
. catch ( (err) => {
$w(‘#errorText’).text=‘Record Add 1 Failed ’ + err
} );
}
// If the booking is not confirmed:
else {
// Show the error text.
$w(“#errorText”).show();
}
}
// If an error occurred in the booking process:
catch (error) {
console.log(error)
session.setItem(‘couponcode’, ‘’)
if (error.message===‘No Premium package’){
$w(’#errorText’).text=‘no premium plan’
$w(“#errorText”).show();
// Enable the book button.
$w(“#Paybutton”).enable();

} 

// Show the error text.
else {
$w(“#errorText”).show();
// Enable the book button.
$w(“#Paybutton”).enable();
}
}
}
// If some of the fields have invalid values:
else {
// Show the error text.
$w(“#errorText”).show();
// Enable the book button.
$w(“#Paybutton”).enable();
}

}
async function prepUpdateRec() {
MyMember= await getmember()
rdocmem= MyMember[0].rdocMember
console.log(rdocmem)
await UpdateRec()

// wixWindow.lightbox.close()
}

async function getmember () {
const results= await wixData.query(“Member”)
.eq(‘emailAddress’,$w(‘#email’).value)
.find();
return results.items
}

async function UpdateRec() {

$w('#dataset1').setFieldValue('name',$w('#name').value) 
$w('#dataset1').setFieldValue('address',$w('#address').value) 
$w('#dataset1').setFieldValue('city',$w('#city').value) 
$w('#dataset1').setFieldValue('state',$w('#state').value) 
$w('#dataset1').setFieldValue('zip',$w('#zip').value) 
$w('#dataset1').setFieldValue('phone',$w('#phone').value) 
$w('#dataset1').setFieldValue('email',$w('#email').value) 
$w('#dataset1').setFieldValue('rdocmember',rdocmem) 
$w('#dataset1').save() 
.then(() => { 
         UpdateRef() 
 }) 

. catch ( (error) => {
$w(‘#errorText’).text='Record Update Failed ’ + error

})   

//})

}

async function UpdateRef () {

let Ref1=$w(‘#dataset1’).getCurrentItem()
myid=Ref1._id
const Ref2 = await wixData.query(“Dog”)
.eq(‘_id’,D_id)
.find();
let myid2=Ref2.items[0]._id
// console.log(myid2)
await wixData.insertReference(“Rosters”, “dog”, myid, myid2)
.then( () => {

// $w(‘#errorText’).text=‘Record Successfully Saved’
} )
. catch ( (error) => {
$w(‘#errorText’).text='Record3 Update Failed ’ + error
} );

await wixData.insertReference(“Rosters”, “class”, myid, cid)
.then( () => {

        $w('#errorText').text='Record Successfully Saved' 
        wixWindow.openLightbox("Thank You", { 
        Class:classname, 
        cid:cid, 
        sid:myid, 
        did:D_id     
    }) 

} )
. catch ( (error) => {
$w(‘#errorText’).text='Record3 Update Failed ’ + error
});

}

export function Ackbox1_change(event) {
//Add your code for this event here:
if ($w(‘#Ackbox1’).checked=== true ) {
ackflag=‘y’
if (selectflag===‘y’) {
$w(‘#Paybutton’).enable()
}

} 

else {
$w(‘#Paybutton’).disable()
ackflag=‘’

} 

}

export function cancel_click(event) {

//Add your code for this event here:
wixWindow.lightbox.close()

}

Console log:
Loading the code for the Contact popup. To debug this code, open kjt0b.js in Developer Tools.
{…}
slot: {…}
_id: “820PSBuhmrXZt0cKXspsx1qDnOGu0AdYD9H5R9W8fU4GplcFPtnCsTm6Rt1QHBym1wJMq8SgNsglp5QIIKIDgUdQ66gmjlsDqIVtVJ66GmjoCnuLvPJkFt5qxpntU79awVDtrCU0SVfDCon6N3S08nziYU3aglNtgtD5eLqBGGUK1OoBot1uhsTXc0lprawlxcEFKoLEAbMvWLhjV48uF5pL1T11L9TXDurmXLbITInYyUMC5t6pCNJIDoJ6FffASJ738bMBPqolEGkHyxglmwW72OY7X78f5dUdSvE0bIMs30OaGpUj”
startDateTime: “2019-09-19T00:00:00.000Z”
endDateTime: “2019-09-19T01:00:00.000Z”
startDate: “2019-09-18T04:00:00.000Z”
endDate: “2019-10-30T04:00:00.000Z”
serviceId: “69e490c0-4540-4dcc-aacf-53a3e3cc02ba”
capacity: 12
remainingSpots: 8
staffMemberId: “f8279117-1f7b-4ec9-8427-9d417da377c9”
instructor: “Susan xxxxx”
dayofWeek: “Wednesday”
stime: “20:00:00.000”
endtime: “21:00:00.000”
cost: 110
formFields: Array(4)
0: {…}
_id: “37a0448e-eff5-48c3-b8a8-4dac5ec725fd”
value: “Rocky xxxx”
1: {…}
_id: “b7b714ed-f7b3-4bc4-b562-84d6d47741b4”
value: “raltimore@comcast.net
2: {…}
_id: “1afdcb80-1e84-45f3-aecb-b844bf8504e8”
value: “804-xxx-xxxx, 804-xxx-xxxx”
3: {…}
_id: “e84bc883-7663-4c39-a940-56c9155bb50a”
value: “Comet”
{…}
paymentType: “wixPay_online”
SyntaxError: Unexpected token < in JSON at position 0

Yikes! This is embarrassing… I found my problem… I had coded the payment option as paymentType: “wixPay_online”, it should be paymentType: “wixPay_Online”, The capital ‘O’ in online made all the difference…

Well done for spotting it, glad it is all working now.