Creating Offline Bookings After the Fact

Our organization has some classes which are drop-in and have no onsite Internet. Therefore, we allow people to show up and sign up manually at the time of the class. We export and print out a list of contacts ahead of time. At the time of the class, we manually mark attendance on the sign-up sheet. People can pay cash onsite for the class, or they can use a pricing plan they have purchased in advance. That pricing play may be either a membership (unlimited) type or a package (punch pass). The attendance and payments from the paper sign-in sheet are entered into a spreadsheet, along with identifying info for the contact.

Last year, we held the same class, and were able to go into manage session from the dashboard calendar and manually enter each participant, including choosing a pricing plan if the person had one. This year, we want to automate this. I’m trying to create a dashboard page that will take the sign-in data (which I’ve loaded from CSV into a CMS collection) and create bookings.

This year, something seems to have changed. When creating bookings from the dashboard, it no longer seems to show package type pricing plans, but it does show membership type plans.

In my code to automate this, I thought the simplest thing would be to use the wix-bookings-frontend API, as it seemed like a pretty straightforward way to see what payment methods are available for a user for a particular session.

The first problem is that the getCheckoutOptions() function requires a userId, but there doesn’t seem to be any documentation of what that is. The sample code imports wixUsers from ‘wix-users’, but I get an error from the Editor when trying to do that. The module wix-users apparently doesn’t exist. I tried using contactId or memberId (which apparently are identical, although that’s not documented anywhere I found.) Lo and behold, using memberId as userId seems to work, and I can retrieve the available checkout options for the member for the session. However, this list of options includes membership-type plans but not package-type plans. Same behavior I found when trying to create the booking manually from the dashboard.

Note that there is an error in the documentation (and Wix Editor development environment). According to the documentation about getCheckoutOptions(), it returns an array of type checkoutOption. The Wix Editor syntax checker enforces that when you are entering your code. However, you must use checkoutOptions.checkoutMethods[i] rather than checkoutOptions[i] and ignore the flagging that checkoutMethods is an unknown field.

I looked at the object data for the slot I was trying to book. It has a field called bookable, which was false, and under constraints the bookableUntil field was set to the start date/time of the session. It appears that the slot is not allowing me to book the session after the fact if the user has a package-type pricing plan. However, it does show membership-type plans, as well as online and offline payments.

I looked at the affiliated service object (wix-bookings-v2). It has a field under bookingPolicy called bookAfterStartPolicy that is set to false. However, I could find no way, either by editing the service from the dashboard or by API, to change this field.

I’ve looked for other APIs to determine the valid payment methods for a particular contact for a particular session, but couldn’t find anything else.

Long story short, my question is, is there any API-supported method to determine what payment methods are available for a particular contact for a particular session after the session has happened, and then to create a booking using a particular one of those payment methods?

I have found a solution for my first problem. In order to get all of the checkout options for a particular contact for a particular service, you must use an UPCOMING session. So, instead of using the past session that I want to book, I find an upcoming session for the same service, and get the checkout options for that. It works in listing all of the options.

Now, I’m struggling with checkoutBooking(). The first problem is that I am getting an error “Name field is missing”, even though I copy/pasted the IDs from the Services/Booking schema used in the sample code in the API doc. Anyone have any thoughts on what I might be doing wrong?

        let slotList = await wixBookingsFrontend.getServiceAvailability( ); /* fill in the blanks */
        let paymentType = "membership";
        let formFieldValues = [{
            "_id": "20657271-c55f-43d6-adfd-39b7acc38e11", /* Name*/
            "value": "John Doe"
        }, {
            "_id": "87edd4e0-42b1-4802-8766-584f3eeb6436", /* Email */
            "value": "john@doe.com"
        }, {
            "_id": "61997cef-9fa2-4f67-9773-67ade57f8754", /* Street */
            "value": ""
        }, {
            "_id": "cf34b269-ddd7-4290-aa2e-5b535f5e9fbe", /* City */
            "value": ""
        }];
        let bookingInfo = {
            "slot": slotList.slots[0],
            "formFields": formFieldValues
        };
        let options = {
            "paymentType": paymentType
        }
        let thisBooking = await wixBookingsFrontend.checkoutBooking(bookingInfo, options);

Also, once I get past this problem, I have a couple of questions. First, it is going to work on a past booking? Second, if the user has more than one package option, is there any way to select which one to use?

Or do I need to abandon the use of the frontend booking functions, and use the backend ones? If so, I haven’t been able to figure out how to select and use a payment option. It would be one of: If the user has a membership, use that. If the user paid at check-in, mark it paid offline. If the user has a package of one type, use that preferentially. If the user has another type of package, only use it as a last resort. And, if none of the above, leave the booking marked as unpaid.