Duffel.Offers (Duffel v0.1.0)

Copy Markdown View Source

Retrieve the offers returned by an offer request.

An offer is a flight option (price, itinerary, conditions) that can be booked by creating an order.

See the Duffel documentation.

Summary

Functions

Retrieves a single offer by ID.

Lists one page of offers for an offer request.

Re-prices the offer with the airline and returns the updated offer.

Lazily streams all offers for an offer request across pages.

Updates a passenger on an offer, e.g. to add loyalty programme accounts.

Lists the upsell offers the airline has for the same journey as id.

Functions

get(client, id, opts \\ [])

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

Retrieves a single offer by ID.

Options

  • :params - query string parameters, e.g. params: [return_available_services: true]

list(client, params)

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

Lists one page of offers for an offer request.

Parameters

  • :offer_request_id - the offer request to list offers for (required)
  • :sort - "total_amount" or "total_duration", prefix with - for descending
  • :max_connections - maximum number of connections (default 1)
  • :limit / :after / :before - pagination (see Duffel.Page)

Examples

Duffel.Offers.list(client, offer_request_id: "orq_123", sort: "total_amount")

price(client, id, params \\ %{}, opts \\ [])

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

Re-prices the offer with the airline and returns the updated offer.

Parameters

  • :intended_payment_methods - the payment methods you intend to pay with, e.g. ["card"]. Prices the offer including any card fee
  • :intended_services - the services you intend to book alongside the offer, as %{id: ..., quantity: ...} maps

Examples

Duffel.Offers.price(client, "off_123", %{
  intended_payment_methods: ["card"],
  intended_services: [%{id: "ase_123", quantity: 1}]
})

stream(client, params)

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

Lazily streams all offers for an offer request across pages.

Takes the same parameters as list/2. Raises Duffel.Error if a page request fails.

update_passenger(client, offer_id, passenger_id, params)

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

Updates a passenger on an offer, e.g. to add loyalty programme accounts.

Examples

Duffel.Offers.update_passenger(client, "off_123", "pas_123", %{
  family_name: "Earhart",
  given_name: "Amelia",
  loyalty_programme_accounts: [
    %{airline_iata_code: "BA", account_number: "12901014"}
  ]
})

upsells(client, id)

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

Lists the upsell offers the airline has for the same journey as id.

Upsell offers cover higher fare brands and cabins for the itinerary the customer already picked, sorted cheapest first. Each one books like any other offer. Errors if the offer has expired or been booked, or if the airline does not support upselling.

Examples

Duffel.Offers.upsells(client, "off_123")