Duffel.Orders.CreateParams (Duffel v0.1.0)

Copy Markdown View Source

Build the request body for Duffel.Orders.create/3.

new/1 assembles the params map and checks the required fields are present. passenger/1, payment/1 and service/2 build the nested values.

params =
  Duffel.Orders.CreateParams.new(
    selected_offers: ["off_123"],
    passengers: [
      Duffel.Orders.CreateParams.passenger(
        id: "pas_123",
        title: "ms",
        given_name: "Amelia",
        family_name: "Earhart",
        gender: "f",
        born_on: "1987-07-24",
        email: "amelia@duffel.com",
        phone_number: "+442080160508"
      )
    ],
    payments: [
      Duffel.Orders.CreateParams.payment(
        type: "balance",
        currency: "GBP",
        amount: "30.20"
      )
    ]
  )

Duffel.Orders.create(client, params, idempotency_key: "booking-123")

Using the builder is optional — create/3 still accepts a plain map.

Summary

Functions

Builds an order params map.

Builds a passenger. The API requires :id, :title, :given_name, :family_name, :gender and :born_on; :email, :phone_number, :infant_passenger_id, :identity_documents, :loyalty_programme_accounts and :user_id are optional. Absent fields are omitted.

Builds a payment. Accepts :type ("balance", "arc_bsp_cash" or "card"), :amount, :currency, :card_id and :three_d_secure_session_id. Absent fields are omitted.

Builds a service to add to the order, by ID and quantity.

Functions

new(opts)

@spec new(keyword()) :: map()

Builds an order params map.

Required: :selected_offers (a list with one offer ID) and :passengers. Optional: :type ("instant" or "hold"), :payments, :services, :users and :metadata. Raises ArgumentError if a required option is missing.

passenger(opts)

@spec passenger(keyword()) :: map()

Builds a passenger. The API requires :id, :title, :given_name, :family_name, :gender and :born_on; :email, :phone_number, :infant_passenger_id, :identity_documents, :loyalty_programme_accounts and :user_id are optional. Absent fields are omitted.

payment(opts)

@spec payment(keyword()) :: map()

Builds a payment. Accepts :type ("balance", "arc_bsp_cash" or "card"), :amount, :currency, :card_id and :three_d_secure_session_id. Absent fields are omitted.

service(id, quantity)

@spec service(String.t(), pos_integer()) :: map()

Builds a service to add to the order, by ID and quantity.