DOM Package

Orders and Bookings

List a signed-in customer's orders and bookings, cancel or reschedule bookings, and fetch receipts and booking tickets

List a signed-in customer's orders and bookings, let them cancel or move their bookings, and fetch receipts and booking tickets. First, complete the setup and sign the customer in.

Listing orders

const { orders, hasMore, nextCursor } = await tiquo.getOrders({ limit: 20 });

for (const order of orders) {
  console.log(order.orderNumber, order.status, order.paymentStatus);
}

status filters by the order lifecycle status (draft, processing, completed, cancelled, refunded, or open_tab), not payment status. From version 1.22.0, a booking line (type: "booking") has the bookingId it booked, so an order page can link to that booking from getBookings(). See List Orders for every field.

Listing bookings

// Booking history
const { bookings } = await tiquo.getBookings();

// Past bookings only
const past = await tiquo.getBookings({ range: 'past' });

// Upcoming bookings only, soonest first
const upcoming = await tiquo.getUpcomingBookings();

getBookings() accepts range: 'upcoming' | 'past'; getUpcomingBookings() is the convenience method for upcoming results sorted soonest first.

Each booking also has serviceImage (the service's featured image, first image, or category image), location (the venue and sublocation, with its address, coordinates, and timezone), and customerActions, which says whether the customer can cancel or move it.

From version 1.22.0, a booking also has:

  • eventName: what was booked, as Tiquo names it in emails and receipts. This is the service category, an en dash, then the service ("Sauna – Member"), or just the service name when it has no category.
  • description: the booking's description as the customer portal shows it (the booked event's, otherwise the service's). It can contain light formatting such as bold, links and lists, so render it with richDescriptionToHtml() or richDescriptionToPlainText() from @tiquo/dom-package rather than inserting it as HTML.
  • orderId and orderNumber: the order the booking was bought on. Pass orderId to getReceipt() or downloadReceipt(), or match it in getOrders(). Both are left out when the customer can't open that order, for example a booking imported from the venue's own system.
  • price and currency: what the booking was sold for, in major units (25.5 is £25.50).

A stay (a nightly or daily booking) also has checkOutDate, its check-out date in the same form as date.

See List Bookings for every field.

Pagination

getOrders() and getBookings() accept limit, cursor, and status options and return hasMore plus an optional nextCursor. The maximum page size is 100 and the default is 50. Pass nextCursor as cursor to load the next page.

let page = await tiquo.getOrders({ limit: 50 });
const allOrders = [...page.orders];

while (page.hasMore && page.nextCursor) {
  page = await tiquo.getOrders({ limit: 50, cursor: page.nextCursor });
  allOrders.push(...page.orders);
}

Cancelling and rescheduling bookings

Signed-in customers can cancel or move their own bookings with the same rules as the customer portal: the service's cancellation deadline (24 hours before the start unless the service sets another), availability, and advance-booking limits. These methods need DOM Package 1.11.0 or newer.

const { bookings } = await tiquo.getUpcomingBookings();
const booking = bookings[0];

// Cancel, or withdraw a waiting-list request
if (booking.customerActions.canCancel) {
  await tiquo.cancelBooking(booking.id);
}

// Move to another time
if (booking.customerActions.canReschedule) {
  const { options } = await tiquo.getBookingRescheduleOptions(booking.id);
  const next = options[0];
  if (next) {
    const moved = await tiquo.rescheduleBooking(booking.id, {
      date: next.date,
      startTime: next.startTime,
    });
    console.log(moved.date, moved.startTime, moved.endTime);
  }
}
MethodResolves
cancelBooking(bookingId){ bookingId, status: 'cancelled' }
getBookingRescheduleOptions(bookingId, { dateFrom?, dateTo? }){ canReschedule, reason?, bookingMethod?, firstDate?, lastDate?, options }, where each option has date, startTime, and endTime
rescheduleBooking(bookingId, { date, startTime }){ bookingId, status, date, startTime, endTime }

Slot bookings list every bookable slot. Calendar bookings list the next 31 days by default and at most 42 days per call, so page through later dates with dateFrom and dateTo (YYYY-MM-DD). Dates and times are in the venue's timezone.

Use booking.customerActions to decide which buttons to show. Imported bookings, such as hotel stays from Mews, can only be changed by the venue: their canCancel and canReschedule are false and cancellationBlockedReason is managed_by_venue, so show a message such as "Contact the venue to change this booking" instead. See Cancel and Reschedule Bookings for every reason value.

Tiquo emails the customer after each change. When a change isn't allowed, the method throws a TiquoAuthError with a readable message you can show, such as "The cancellation deadline for this booking has passed." or "That time has just sold out. Please choose another." The error codes are CANCEL_BOOKING_FAILED, GET_RESCHEDULE_OPTIONS_FAILED, and RESCHEDULE_BOOKING_FAILED.

Receipts

Use getReceipt() to retrieve a printable receipt payload for an order owned by the authenticated customer.

const receipt = await tiquo.getReceipt('order_123');

Receipts are available for orders that have been paid, refunded, or completed. Draft and pending orders do not have customer receipts yet. See Receipt for the payload.

From version 1.22.0, the receipt also carries what the issued receipt prints:

  • order.receiptNumber: the issued receipt's number, such as REC-ORD-BBDJEH, or the invoice number when the sale was invoiced. It is left out until the receipt is issued.
  • order.taxSummary: the VAT summary, one { rate, net, tax, gross } row per rate (rate: 20 is 20%).
  • order.items[].taxRate: each line's VAT percentage. Booking lines also have bookingId.
  • business.legalName: the seller's name as the receipt prints it. Show it instead of business.name, which is the venue's payment account name.

getReceipt() throws a TiquoAuthError with code RECEIPT_NOT_AVAILABLE when the order isn't the customer's or has no receipt yet.

Downloading the receipt PDF

From version 1.22.0, downloadReceipt(orderId) returns the issued receipt as a PDF Blob. It is the same file the customer portal downloads, or the invoice when the sale was invoiced, and works once the order has been paid.

const pdf = await tiquo.downloadReceipt(booking.orderId);
const link = document.createElement('a');
link.href = URL.createObjectURL(pdf);
link.download = `${receipt.order.receiptNumber ?? 'receipt'}.pdf`;
link.click();
URL.revokeObjectURL(link.href);

It throws RECEIPT_NOT_AVAILABLE when there is no issued receipt yet, or DOWNLOAD_RECEIPT_FAILED when the PDF couldn't be produced, in which case try again.

Booking tickets

Bookings include a ticketing object when ticket settings are available for the booking's sublocation.

const { bookings } = await tiquo.getUpcomingBookings();
const booking = bookings[0];

if (booking?.ticketing.qrCodeTicketsEnabled) {
  const ticketPdf = await tiquo.downloadBookingTicket(booking.id);
}

When wallet tickets are enabled, the booking also includes wallet links:

const walletUrl = booking.ticketing.walletTicketUrl;
const appleWalletUrl = booking.ticketing.appleWalletTicketUrl;
const googleWalletUrl = booking.ticketing.googleWalletTicketUrl;

These are tickets for one booking. For a customer's membership or loyalty card, use Wallet Cards instead.

Add to calendar

From version 1.24.0, addBookingToCalendar(booking) downloads a booking from getBookings() as a calendar file (.ics) that the customer's calendar app opens, so an Add to calendar button is one line. It makes no network request.

const { bookings } = await tiquo.getUpcomingBookings();

button.addEventListener('click', () => tiquo.addBookingToCalendar(bookings[0]));

The event is the same calendar entry as the customer portal's Add to calendar and the invite in Tiquo's booking confirmation email, because all of them use the event ID {bookingNumber}@tiquo.app. Adding the booking again updates that entry instead of adding a second one, and after a reschedule it moves to the new time. The times are the venue's, converted correctly for daylight saving. A stay (with checkOutDate) is an all-day event from check-in to check-out, and a cancelled booking is marked cancelled.

By default the event is titled with the booking's eventName, its notes list the booking and order numbers and the booking's description, and its location is the venue's name and address. Pass options to change them:

tiquo.addBookingToCalendar(booking, {
  title: 'Sauna session',
  description: 'Bring a towel.',
  location: 'Crafted at Powdermills',
  filename: 'sauna.ics',
});

buildBookingCalendarFile(booking, options) returns the file's text instead of downloading it. Both are also exported on their own:

import { addBookingToCalendar, buildBookingCalendarFile } from '@tiquo/dom-package';

They throw a TiquoAuthError with code BOOKING_HAS_NO_TIME when the booking has no date or start time, and addBookingToCalendar() throws ADD_TO_CALENDAR_UNAVAILABLE outside a browser.

Building the file yourself

On versions before 1.24.0, or to write the file another way, give the event these two lines so it behaves like the customer portal's file and the confirmation email's invite:

  • UID:{bookingNumber}@tiquo.app, for example UID:BKG-1CTYN6@tiquo.app. Calendar apps recognise an event by its UID: opening a file whose UID is already in the calendar updates that entry instead of adding a second one. The confirmation email and the customer portal use this same UID, so the email's invite, the portal's file and yours are one calendar entry. The UID is hidden inside the file. Calendar apps don't show it and it isn't an email address; the @tiquo.app part only stops it clashing with IDs from other systems.
  • SEQUENCE:, a number that is higher each time you make the file. Calendar apps keep the copy with the highest number, so when a customer reschedules and adds the booking again, the entry moves to the new time. The number of seconds since the booking was made (createdAt) works.
const toICalUtc = (date) => date.toISOString().replace(/[-:]/g, '').replace(/\.\d{3}/, '');
const toICalText = (text) => text.replace(/[\\;,]/g, '\\$&').replace(/\n/g, '\\n');

// start and end: the booking's start and end as Dates, from its date,
// startTime and endTime in its timezone.
const ics = [
  'BEGIN:VCALENDAR',
  'VERSION:2.0',
  'PRODID:-//Your venue//Bookings//EN',
  'METHOD:PUBLISH',
  'BEGIN:VEVENT',
  `UID:${booking.bookingNumber}@tiquo.app`,
  `SEQUENCE:${Math.max(0, Math.floor((Date.now() - booking.createdAt) / 1000))}`,
  `DTSTAMP:${toICalUtc(new Date())}`,
  `DTSTART:${toICalUtc(start)}`,
  `DTEND:${toICalUtc(end)}`,
  `SUMMARY:${toICalText(booking.eventName ?? booking.serviceName)}`,
  `DESCRIPTION:${toICalText(`Booking ${booking.bookingNumber}${booking.orderNumber ? `\nOrder ${booking.orderNumber}` : ''}`)}`,
  'END:VEVENT',
  'END:VCALENDAR',
].join('\r\n');

const link = document.createElement('a');
link.href = URL.createObjectURL(new Blob([ics], { type: 'text/calendar' }));
link.download = `booking-${booking.bookingNumber.toLowerCase()}.ics`;
link.click();
URL.revokeObjectURL(link.href);

Guest flows and invitations

To let a signed-in customer register guests for a visit, see Custom Guest Invitations. To show how many Guest Passes or Access Passes they have left, see Pass Balances.

On this page