Bookings

Bookings allow you to assign an asset to a user for a certain period of time and/or quantity.

Availabilities and bookings both impact asset availabilities. The main difference between them is that availabilities are defined by the asset owner, while bookings are created by users who want to book them.

Let’s create a booking for the asset ast_2l7fQps1I3a1gJYz2I3a for 1 quantity and one day.

stelace.bookings.create({
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  startDate: '2019-09-13T00:00:00.000Z',
  nbTimeUnits: 1,
  quantity: 1
})

The asset being configured by the asset type, you don't need to provide time units.

Availability check

When creating a booking, Stelace handles the availability check for you.

Availabilities and other bookings can block the period or quantity a user wants to book.

If the following availability is defined

stelace.availabilities.create({
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  startDate: '2019-09-14T00:00:00.000Z',
  endDate: '2019-09-16T00:00:00.000Z',
  quantity: 0
})

the request below will generate an error because the quantity over the period is higher than the available quantity.

stelace.bookings.create({
  assetId: 'ast_2l7fQps1I3a1gJYz2I3a',
  startDate: '2019-09-13T00:00:00.000Z',
  nbTimeUnits: 3,
  quantity: 1
})

Booking process

Booking processes lets you configure assets’ availabilities.

Each booking has a status property representing its current state in the process. You can use whatever value you want to meet your business needs.

Let's take an ecommerce example with the following steps and see how they affect availabilities:

  • draft (initial step)
  • paid - block the availability
  • completed - block the availability
  • cancelled

Booking processes are configured via asset types:

stelace.assetTypes.update('typ_T3ZfQps1I3a1gJYz2I3a', {
  marketplaceConfig: {
    blockAvailabilityStatus: ['paid', 'completed']
  }
})

Now, any status update to 'paid' or 'completed' blocks availability. Search results and new booking creations will be impacted.