Duffel.Stays.Bookings (Duffel v0.1.0)

Copy Markdown View Source

Book accommodation from a quote, then manage and cancel the booking.

See the Duffel documentation.

Summary

Functions

Cancels a booking.

Creates a booking from a quote.

Creates payment instructions for a postpaid booking, providing the card the accommodation will charge.

Retrieves a single booking by ID.

Lists one page of bookings.

Lazily streams all bookings across pages.

Updates a booking's metadata or the customer users allowed to manage it.

Functions

cancel(client, id)

@spec cancel(Duffel.Client.t(), String.t()) ::
  {:ok, map()} | {:error, Duffel.Error.t()}

Cancels a booking.

create(client, params, opts \\ [])

@spec create(Duffel.Client.t(), map(), keyword()) ::
  {:ok, map()} | {:error, Duffel.Error.t()}

Creates a booking from a quote.

Options

  • :idempotency_key - value for the Idempotency-Key header. A key is generated when you do not pass one (see Duffel.Client.post/4).

Examples

Duffel.Stays.Bookings.create(
  client,
  %{
    quote_id: "quo_123",
    guests: [%{given_name: "Amelia", family_name: "Earhart"}],
    email: "amelia@duffel.com",
    phone_number: "+442080160508"
  },
  idempotency_key: "stay-booking-1"
)

create_payment_instruction(client, id, params)

@spec create_payment_instruction(Duffel.Client.t(), String.t(), map()) ::
  {:ok, map()} | {:error, Duffel.Error.t()}

Creates payment instructions for a postpaid booking, providing the card the accommodation will charge.

Examples

Duffel.Stays.Bookings.create_payment_instruction(client, "bok_123", %{
  card_id: "tcd_123"
})

get(client, id)

@spec get(Duffel.Client.t(), String.t()) :: {:ok, map()} | {:error, Duffel.Error.t()}

Retrieves a single booking by ID.

list(client, params \\ [])

@spec list(Duffel.Client.t(), keyword() | map()) ::
  {:ok, Duffel.Page.t()} | {:error, Duffel.Error.t()}

Lists one page of bookings.

Parameters

  • :user_id - filter by the customer user on the booking
  • :limit / :after / :before - pagination (see Duffel.Page)

stream(client, params \\ [])

@spec stream(Duffel.Client.t(), keyword() | map()) :: Enumerable.t()

Lazily streams all bookings across pages.

Raises Duffel.Error if a page request fails.

update(client, id, params)

@spec update(Duffel.Client.t(), String.t(), map()) ::
  {:ok, map()} | {:error, Duffel.Error.t()}

Updates a booking's metadata or the customer users allowed to manage it.

Examples

Duffel.Stays.Bookings.update(client, "bok_123", %{metadata: %{ref: "abc"}})