duffel

package module
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 17 Imported by: 2

README

Duffel API Go Client

A Go (golang) client library for the Duffel Flights API implemented by the Airheart team.

Tests

Installation

We've designed this pkg to be familiar and ideomatic to any Go developer. Go get it the usual way:

NOTE: Requires at least Go 1.18 since we use generics on the internal API client

go get github.com/airheartdev/duffel

Usage examples

See the examples/* directory

Getting Started

The easiest way to get started, assuming you have a Duffel account set up and an API key ready, is to create an API instance and make your first request:

// Create a new client:
dfl := duffel.New(os.Getenv("DUFFEL_TOKEN"))

For available methods, see:

And familiarise yourself with the implementation notes:

Monetary amounts

All models that have fields for an amount and a currency implement a method to return a parsed currency.Amount{}

total:= order.TotalAmount() // currency.Amount
total.Currency // USD
total.Amount // 100.00
total.String() // 100.00 USD
Working with iterators

All requests that return more than one record will return an iterator. An Iterator automatically paginates results and respects rate limits, reducing the complexity of the overall programming model.

dfl := duffel.New(os.Getenv("DUFFEL_TOKEN"))
iter := dfl.ListAirports(ctx, duffel.ListAirportsParams{
  IATACountryCode: "AU",
})

for iter.Next() {
  airport := iter.Current()
  fmt.Printf("%s\n", airport.Name)
}

// If there was an error, the loop above will exit so that you can
// inspect the error here:
if iter.Err() != nil {
  log.Fatalln(iter.Err())
}

We've added a convenience method to collect all items from the iterator into a single slice in one go:

airports, err := duffel.Collect(iter)
if err != nil  {
  // Handle error from iter.Err()
}

// airports is a []*duffel.Airport

Request IDs

Every response from Duffel includes a request ID that can be used to help debug issues with Duffel support. You should log the request ID for each operation in your app so that you can track down issues later on.

dfl := duffel.New(os.Getenv("DUFFEL_TOKEN"))

// Request IDs from Iterators:
iter := dfl.ListAirports(ctx, duffel.ListAirportsParams{
  IATACountryCode: "AU",
})

for iter.Next() {
  airport := iter.Current()
  fmt.Printf("%s\n", airport.Name)

  if lastRequestID, ok:= iter.LastRequestID(); ok {
    fmt.Printf("Last request ID: %s\n", lastRequestID)
    // Note: each iteration might be from the same page of data with the same request ID.
  }
}

// Request IDs from other operations
data, err := client.CreateOfferRequest(context.Background(), duffel.OfferRequestInput{}
// ...
if lastRequestID, ok:= dfl.LastRequestID(); ok {
  fmt.Printf("Last request ID: %s\n", lastRequestID)
}

Error Handling

Each API method returns an error or an iterator that returns errors at each iteration. If an error is returned from Duffel, it will be of type DuffelError and expose more details on how to handle it.

// Example error inspection after making an API call:
offer, err := dfl.GetOffer(ctx, "off_123")
if err != nil {
  // Simple error code check
  if duffel.IsErrorCode(err, duffel.AirlineInternal) {
    // Don't retry airline errors, contact support
  }

  // Access the DuffelError object to see more detail
  if derr, ok:= err.(*duffel.DuffelError); ok {
    // derr.Errors[0].Type etc
    // derr.IsCode(duffel.BadRequest)
  }else{
    // Do something with regular Go error
  }
}
duffel.IsErrorCode(err, code)

IsErrorCode is a concenience method to check if an error is a specific error code from Duffel. This simplifies error handling branches without needing to type cast multiple times in your code.

duffel.IsErrorType(err, typ)

IsErrorType is a concenience method to check if an error is a specific error type from Duffel. This simplifies error handling branches without needing to type cast multiple times in your code.

You can also check the derr.Retryable field, which will be false if you need to contact Duffel support to resolve the issue, and should not be retried. Example, creating an order.

Implementation status

To maintain simplicity and ease of use, this client library is hand-coded (instead of using Postman to Go code generation) and contributions are greatly apprecicated.

  • Types for all API models
  • API Client
  • Error handling
  • Pagination (using iterators)
  • Rate Limiting (automatically throttles requests to stay under limit)
  • Offer Requests
  • Offers
  • Orders
  • Seat Maps
  • Order Cancellations
  • Order Change Requests
  • Order Change Offers
  • Order Changes
  • Airports
  • Airlines
  • Equipment (Aircraft)
  • Payments
  • Places

License

This source code is licensed under the Apache 2.0 license found in the LICENSE file in the root directory of this source tree.

Documentation

Overview

Order change flow: 1. Get an existing order by ID using client.GetOrder(...) 2. Create a new order change request using client.CreateOrderChangeRequest(...) 3. Get the order change offer using client.CreatePendingOrderChange(...)

Index

Constants

View Source
const (
	// deprecated
	PassengerTypeAdult PassengerType = "adult"
	// deprecated
	PassengerTypeChild PassengerType = "child"
	// deprecated
	PassengerTypeInfantWithoutSeat PassengerType = "infant_without_seat"

	CabinClassEconomy  CabinClass = "economy"
	CabinClassPremium  CabinClass = "premium_economy"
	CabinClassBusiness CabinClass = "business"
	CabinClassFirst    CabinClass = "first"

	GenderMale   Gender = "m"
	GenderFemale Gender = "f"

	PassengerTitleMr   PassengerTitle = "mr"
	PassengerTitleMs   PassengerTitle = "ms"
	PassengerTitleMrs  PassengerTitle = "mrs"
	PassengerTitleMiss PassengerTitle = "miss"

	PaymentMethodBalance  PaymentMethod = "balance"
	ARCBSPCash            PaymentMethod = "arc_bsp_cash"
	Card                  PaymentMethod = "card"
	Voucher               PaymentMethod = "voucher"
	AwaitingPayment       PaymentMethod = "awaiting_payment"
	OriginalFormOfPayment PaymentMethod = "original_form_of_payment"
)
View Source
const (
	AuthenticationError ErrorType = "authentication_error"
	AirlineError        ErrorType = "airline_error"
	InvalidStateError   ErrorType = "invalid_state_error"
	RateLimitError      ErrorType = "rate_limit_error"
	ValidationError     ErrorType = "validation_error"
	InvalidRequestError ErrorType = "invalid_request_error"
	ApiError            ErrorType = "api_error"

	// The access token used is not recognized by our system
	AccessTokenNotFound ErrorCode = "access_token_not_found"

	// The airline has responded with an internal error, please contact support
	AirlineInternal ErrorCode = "airline_internal"

	// The airline responded with an unexpected error, please contact support
	AirlineUnknown ErrorCode = "airline_unknown"

	// Requested ancillary service item(s) (e.g. seats) are no longer available, please update your requested services or create a new offer request
	AncillaryServiceNotAvailable ErrorCode = "ancillary_service_not_available"

	// The provided order has already been cancelled
	AlreadyCancelled ErrorCode = "already_cancelled"

	// The request was unacceptable
	BadRequest ErrorCode = "bad_request"

	// A booking with the same details was already found for the selected itinerary, please select another offer
	DuplicateBooking ErrorCode = "duplicate_booking"

	// The order cannot contain more than one passenger with with the same name
	DuplicatePassengerName ErrorCode = "duplicate_passenger_name"

	// The provided access token has expired
	ExpiredAccessToken ErrorCode = "expired_access_token"

	// There wasn't enough balance in the wallet for the operation - for example, you booked a flight for £300 with only £200 available in the wallet
	InsufficientBalance ErrorCode = "insufficient_balance"

	// The provided token doesn't have sufficient permissions to perform the requested action
	InsufficientPermissions ErrorCode = "insufficient_permissions"

	// There was something wrong on our end, please contact support
	InternalServerError ErrorCode = "internal_server_error"

	// The Authorization header must conform to the following format: Bearer API_TOKEN
	InvalidAuthorizationHeader ErrorCode = "invalid_authorization_header"

	// The Content-Type should be set to application/json
	InvalidContentTypeHeader ErrorCode = "invalid_content_type_header"

	// The data in the request body should be a JSON object
	InvalidDataParam ErrorCode = "invalid_data_param"

	// The airline did not recognise the loyalty programme account details for one or more of the passengers
	InvalidLoyaltyCard ErrorCode = "invalid_loyalty_card"

	// The Duffel-Version header must be a known version of our API as indicated in our Docs
	InvalidVersionHeader ErrorCode = "invalid_version_header"

	// The data in the request body is not valid
	MalformedDataParam ErrorCode = "malformed_data_param"

	// The Authorization header must be set and contain a valid API token
	MissingAuthorizationHeader ErrorCode = "missing_authorization_header"

	// The Content-Type header needs to be set to application/json
	MissingContentTypeHeader ErrorCode = "missing_content_type_header"

	// The data in the request body should be nested under the data key
	MissingDataParam ErrorCode = "missing_data_param"

	// The Duffel-Version header is required and must be a valid API version
	MissingVersionHeader ErrorCode = "missing_version_header"

	// The resource you are trying to access does not exist
	NotFound ErrorCode = "not_found"

	// The provided offer is no longer available, please select another offer or create a new offer request to get the latest availability
	OfferNoLongerAvailable ErrorCode = "offer_no_longer_available"

	// Too many requests have hit the API too quickly. Please retry your request after the time specified in the ratelimit-reset header returned to you
	RateLimitExceeded ErrorCode = "rate_limit_exceeded"

	// The feature you requested is not available. Please contact help@duffel.com if you are interested in getting access to it
	UnavailableFeature ErrorCode = "unavailable_feature"

	// The resource does not support the following action
	UnsupportedAction ErrorCode = "unsupported_action"

	// The API does not support the format set in the Accept header, please use a supported format
	UnsupportedFormat ErrorCode = "unsupported_format"

	// The version set to the Duffel-Version header is no longer supported by the API, please upgrade
	UnsupportedVersion ErrorCode = "unsupported_version"
)
View Source
const (
	ListOrdersSortPaymentRequiredByAsc  ListOrdersSort = "payment_required_by"
	ListOrdersSortPaymentRequiredByDesc ListOrdersSort = "-payment_required_by"

	OrderTypeHold    OrderType = "hold"
	OrderTypeInstant OrderType = "instant"
)
View Source
const (
	PaymentTypeBalance = PaymentType("balance")
	PaymentTypeCash    = PaymentType("arc_bsp_cash")
)
View Source
const DateFormat = "2006-01-02"
View Source
const PlaceTypeAirport = "airport"
View Source
const PlaceTypeCity = "city"
View Source
const RequestIDHeader = "x-request-id"

Variables

View Source
var ErrNullValue = fmt.Errorf("null value")

Functions

func Collect

func Collect[T any](it *Iter[T]) ([]*T, error)

func ErrIsRetryable added in v0.2.4

func ErrIsRetryable(err error) bool

ErrIsRetryable returns true if the request that generated this error is retryable.

func IsErrorCode added in v0.2.3

func IsErrorCode(err error, code ErrorCode) bool

IsErrorCode is a concenience method to check if an error is a specific error code from Duffel. This simplifies error handling branches without needing to type cast multiple times in your code.

func IsErrorType added in v0.2.3

func IsErrorType(err error, typ ErrorType) bool

IsErrorType is a concenience method to check if an error is a specific error type from Duffel. This simplifies error handling branches without needing to type cast multiple times in your code.

func RequestIDFromError added in v0.2.4

func RequestIDFromError(err error) (string, bool)

RequestIDFromError returns the request ID from the error. Use this when contacting Duffel support for non-retryable errors such as `AirlineInternal` or `AirlineUnknown`.

Types

type API

type API struct {
	APIToken string
	// contains filtered or unexported fields
}

func (*API) Cities added in v0.4.2

func (a *API) Cities(ctx context.Context) *Iter[City]

func (*API) City added in v0.4.2

func (a *API) City(ctx context.Context, id string) (*City, error)

func (*API) ConfirmOrderCancellation added in v0.2.0

func (a *API) ConfirmOrderCancellation(ctx context.Context, orderCancellationID string) (*OrderCancellation, error)

func (*API) ConfirmOrderChange added in v0.2.0

func (a *API) ConfirmOrderChange(ctx context.Context, orderChangeRequestID string, payment PaymentCreateInput) (*OrderChange, error)

func (*API) CreateOfferRequest

func (a *API) CreateOfferRequest(ctx context.Context, requestInput OfferRequestInput) (*OfferRequest, error)

func (*API) CreateOrder

func (a *API) CreateOrder(ctx context.Context, input CreateOrderInput) (*Order, error)

CreateOrder creates a new order.

func (*API) CreateOrderCancellation added in v0.2.0

func (a *API) CreateOrderCancellation(ctx context.Context, orderID string) (*OrderCancellation, error)

func (*API) CreateOrderChangeRequest added in v0.2.0

func (a *API) CreateOrderChangeRequest(ctx context.Context, params OrderChangeRequestParams) (*OrderChangeRequest, error)

func (*API) CreatePayment added in v0.2.2

func (a *API) CreatePayment(ctx context.Context, req CreatePaymentRequest) (*Payment, error)

func (*API) CreatePendingOrderChange added in v0.2.0

func (a *API) CreatePendingOrderChange(ctx context.Context, offerID string) (*OrderChange, error)

func (*API) GetAircraft

func (a *API) GetAircraft(ctx context.Context, id string) (*Aircraft, error)

func (*API) GetAirline

func (a *API) GetAirline(ctx context.Context, id string) (*Airline, error)

func (*API) GetAirport

func (a *API) GetAirport(ctx context.Context, id string) (*Airport, error)

func (*API) GetOffer

func (a *API) GetOffer(ctx context.Context, offerID string, params ...GetOfferParams) (*Offer, error)

GetOffer gets a single offer by ID.

func (*API) GetOfferRequest

func (a *API) GetOfferRequest(ctx context.Context, id string) (*OfferRequest, error)

func (*API) GetOrder

func (a *API) GetOrder(ctx context.Context, id string) (*Order, error)

CreateOrder creates a new order.

func (*API) GetOrderCancellation added in v0.2.0

func (a *API) GetOrderCancellation(ctx context.Context, orderCancellationID string) (*OrderCancellation, error)

func (*API) GetOrderChangeRequest added in v0.2.0

func (a *API) GetOrderChangeRequest(ctx context.Context, orderChangeRequestID string) (*OrderChangeRequest, error)

func (*API) GetSeatmap added in v0.4.3

func (a *API) GetSeatmap(ctx context.Context, offerID string) ([]*Seatmap, error)

func (*API) LastRequestID added in v0.4.2

func (a *API) LastRequestID() (string, bool)

func (*API) ListAircraft

func (a *API) ListAircraft(ctx context.Context) *Iter[Aircraft]

func (*API) ListAirlines

func (a *API) ListAirlines(ctx context.Context) *Iter[Airline]

func (*API) ListAirports

func (a *API) ListAirports(ctx context.Context, params ...ListAirportsParams) *Iter[Airport]

func (*API) ListOfferRequests

func (a *API) ListOfferRequests(ctx context.Context) *Iter[OfferRequest]

func (*API) ListOffers

func (a *API) ListOffers(ctx context.Context, offerRequestID string, options ...ListOffersParams) *Iter[Offer]

ListOffers lists all the offers for an offer request. Returns an iterator.

func (*API) ListOrders

func (a *API) ListOrders(ctx context.Context, params ...ListOrdersParams) *Iter[Order]

func (*API) PlaceSuggestions added in v0.3.1

func (a *API) PlaceSuggestions(ctx context.Context, query string) ([]*Place, error)

func (*API) SeatmapForOffer added in v0.4.3

func (a *API) SeatmapForOffer(ctx context.Context, offer Offer) ([]*Seatmap, error)

func (*API) UpdateOfferPassenger

func (a *API) UpdateOfferPassenger(ctx context.Context, offerRequestID, passengerID string, input PassengerUpdateInput) (*OfferRequestPassenger, error)

UpdateOfferPassenger updates a single offer passenger.

func (*API) UpdateOrder

func (a *API) UpdateOrder(ctx context.Context, id string, params OrderUpdateParams) (*Order, error)

type Aircraft

type Aircraft struct {
	IATACode string `json:"iata_code"`
	ID       string `json:"id"`
	Name     string `json:"name"`
}

type AircraftClient

type AircraftClient interface {
	ListAircraft(ctx context.Context) *Iter[Aircraft]
	GetAircraft(ctx context.Context, id string) (*Aircraft, error)
}

type Airline

type Airline struct {
	Name          string `json:"name"`
	IATACode      string `json:"iata_code"`
	ID            string `json:"id"`
	LogoSymbolURL string `json:"logo_symbol_url"`
	LogoLockupURL string `json:"logo_lockup_url"`
}

type AirlinesClient

type AirlinesClient interface {
	ListAirlines(ctx context.Context) *Iter[Airline]
	GetAirline(ctx context.Context, id string) (*Airline, error)
}

type Airport

type Airport struct {
	ID              string  `json:"id" `
	Name            string  `json:"name" `
	City            City    `json:"city,omitempty" `
	CityName        string  `json:"city_name" `
	IATACode        string  `json:"iata_code" `
	IATACountryCode string  `json:"iata_country_code" `
	ICAOCode        string  `json:"icao_code" `
	Latitude        float32 `json:"latitude" `
	Longitude       float32 `json:"longitude" `
	TimeZone        string  `json:"time_zone" `
}

type AirportsClient

type AirportsClient interface {
	ListAirports(ctx context.Context, params ...ListAirportsParams) *Iter[Airport]
	GetAirport(ctx context.Context, id string) (*Airport, error)
}

type AvailableService added in v0.4.6

type AvailableService struct {
	// Duffel's unique identifier for service
	ID               string                   `json:"id"`
	MaximumQuantity  int                      `json:"maximum_quantity"`
	Metadata         AvailableServiceMetadata `json:"metadata"`
	PassengerIDs     []string                 `json:"passenger_ids"`
	SegmentIDs       []string                 `json:"segment_ids"`
	RawTotalAmount   string                   `json:"total_amount"`
	RawTotalCurrency string                   `json:"total_currency"`

	// Possible values: "baggage"
	Type string `json:"type"`
}

type AvailableServiceMetadata added in v0.4.6

type AvailableServiceMetadata struct {
	MaximumDepthCM  int `json:"maximum_depth_cm,omitempty"`
	MaximumHeightCM int `json:"maximum_height_cm,omitempty"`
	MaximumLengthCM int `json:"maximum_length_cm,omitempty"`
	MaximumWeightKg int `json:"maximum_weight_kg,omitempty"`
	// Possible values: "checked", "carry_on"
	Type string `json:"type"`
}

type Baggage

type Baggage struct {
	Quantity int    `json:"quantity"`
	Type     string `json:"type"`
}

type BaseSlice

type BaseSlice struct {
	OriginType      string    `json:"origin_type"`
	Origin          Location  `json:"origin"`
	DestinationType string    `json:"destination_type"`
	Destination     Location  `json:"destination"`
	DepartureDate   Date      `json:"departure_date,omitempty"`
	CreatedAt       time.Time `json:"created_at,omitempty"`
}

type Cabin

type Cabin struct {
	Aisles     int        `json:"aisles"`
	CabinClass CabinClass `json:"cabin_class"`
	Deck       int        `json:"deck"`
	// A list of rows in this cabin.
	Rows []Row `json:"rows"`

	// Where the wings of the aircraft are in relation to rows in the cabin.
	Wings Wing `json:"wings"`
}

type CabinClass

type CabinClass string

func (CabinClass) String added in v0.2.0

func (p CabinClass) String() string

type ChangeCondition

type ChangeCondition struct {
	Allowed            bool    `json:"allowed"`
	RawPenaltyAmount   *string `json:"penalty_amount,omitempty"`
	RawPenaltyCurrency *string `json:"penalty_currency,omitempty"`
}

func (*ChangeCondition) PenaltyAmount

func (c *ChangeCondition) PenaltyAmount() *currency.Amount

type City added in v0.2.3

type City struct {
	ID              string  `json:"id,omitempty" csv:"city_id"`
	Name            string  `json:"name" csv:"city_name"`
	IATACountryCode *string `json:"iata_country_code,omitempty" csv:"city_iata_country_code"`
	IATACode        string  `json:"iata_code,omitempty" csv:"city_iata_code"`
}

type Conditions

type Conditions struct {
	RefundBeforeDeparture *ChangeCondition `json:"refund_before_departure,omitempty"`
	ChangeBeforeDeparture *ChangeCondition `json:"change_before_departure,omitempty"`
}

type CreateOrderInput

type CreateOrderInput struct {
	Type OrderType `json:"type"`

	// Metadata contains a set of key-value pairs that you can attach to an object.
	// It can be useful for storing additional information about the object, in a
	// structured format. Duffel does not use this information.
	//
	// You should not store sensitive information in this field.
	Metadata Metadata `json:"metadata,omitempty"`

	// The personal details of the passengers, expanding on
	// the information initially provided when creating the offer request.
	Passengers []OrderPassenger `json:"passengers"`

	Payments []PaymentCreateInput `json:"payments,omitempty"`

	// The ids of the offers you want to book. You must specify an array containing exactly one selected offer.
	SelectedOffers []string `json:"selected_offers"`

	Services []ServiceCreateInput `json:"services,omitempty"`
}

type CreatePayment added in v0.2.2

type CreatePayment struct {
	Amount   string      `json:"amount"`
	Currency string      `json:"currency"`
	Type     PaymentType `json:"type"`
}

type CreatePaymentRequest added in v0.2.2

type CreatePaymentRequest struct {
	OrderID string        `json:"order_id"`
	Payment CreatePayment `json:"payment"`
}

type Date

type Date time.Time

func (Date) MarshalJSON

func (t Date) MarshalJSON() ([]byte, error)

func (Date) String

func (t Date) String() string

func (*Date) UnmarshalJSON

func (t *Date) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler from date string to time.Time

type DateTime

type DateTime time.Time

func (DateTime) MarshalJSON

func (t DateTime) MarshalJSON() ([]byte, error)

func (DateTime) String

func (t DateTime) String() string

func (*DateTime) UnmarshalJSON

func (t *DateTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler from date string to time.Time

type Distance

type Distance float64

func (Distance) MarshalJSON

func (t Distance) MarshalJSON() ([]byte, error)

func (*Distance) UnmarshalJSON

func (t *Distance) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler from date string to time.Time

type Document

type Document struct {
	Type             string `json:"type"`
	UniqueIdentifier string `json:"unique_identifier"`
}

type DuffelError

type DuffelError struct {
	Meta       ErrorMeta `json:"meta"`
	Errors     []Error   `json:"errors"`
	StatusCode int       `json:"-"`
	Retryable  bool      `json:"-"`
}

func (*DuffelError) Error

func (e *DuffelError) Error() string

func (*DuffelError) IsCode

func (e *DuffelError) IsCode(t ErrorCode) bool

func (*DuffelError) IsType

func (e *DuffelError) IsType(t ErrorType) bool

type Duration

type Duration time.Duration

func (Duration) MarshalGQL added in v0.2.2

func (d Duration) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (Duration) MarshalJSON

func (t Duration) MarshalJSON() ([]byte, error)

func (Duration) String added in v0.2.2

func (t Duration) String() string

func (*Duration) UnmarshalGQL added in v0.2.2

func (d *Duration) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Unmarshaler interface

func (*Duration) UnmarshalJSON

func (t *Duration) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler from date string to time.Time

type ElementType

type ElementType string
const (
	ElementTypeSeat     ElementType = "seat"
	ElementTypeBassinet ElementType = "bassinet"
	ElementTypeEmpty    ElementType = "empty"
	ElementTypeExitRow  ElementType = "exit_row"
	ElementTypeLavatory ElementType = "lavatory"
	ElementTypeGalley   ElementType = "galley"
	ElementTypeCloset   ElementType = "closet"
	ElementTypeStairs   ElementType = "stairs"
)

func (ElementType) String

func (e ElementType) String() string

type EmptyPayload

type EmptyPayload struct{}

type Error

type Error struct {
	Type             ErrorType `json:"type"`
	Title            string    `json:"title"`
	Message          string    `json:"message"`
	DocumentationURL string    `json:"documentation_url"`
	Code             ErrorCode `json:"code"`
}

type ErrorCode

type ErrorCode string

ErrorCode represents the error code returned by the API.

type ErrorMeta added in v0.2.0

type ErrorMeta struct {
	Status    int64  `json:"status"`
	RequestID string `json:"request_id"`
}

type ErrorType

type ErrorType string

type Flight

type Flight struct {
	ID                           string             `json:"id"`
	Passengers                   []SegmentPassenger `json:"passengers"`
	Origin                       Location           `json:"origin"`
	OriginTerminal               string             `json:"origin_terminal"`
	OperatingCarrierFlightNumber string             `json:"operating_carrier_flight_number"`
	OperatingCarrier             Airline            `json:"operating_carrier"`
	MarketingCarrierFlightNumber string             `json:"marketing_carrier_flight_number"`
	MarketingCarrier             Airline            `json:"marketing_carrier"`
	Duration                     Duration           `json:"duration"`
	Distance                     Distance           `json:"distance,omitempty"`
	DestinationTerminal          string             `json:"destination_terminal"`
	Destination                  Location           `json:"destination"`
	RawDepartingAt               string             `json:"departing_at"`
	RawArrivingAt                string             `json:"arriving_at"`
	Aircraft                     *Aircraft          `json:"aircraft,omitempty"`
}

func (*Flight) ArrivingAt

func (f *Flight) ArrivingAt() (time.Time, error)

func (*Flight) DepartingAt

func (f *Flight) DepartingAt() (time.Time, error)

type Gender

type Gender string

func (Gender) String added in v0.2.0

func (p Gender) String() string

type GetOfferParams added in v0.2.0

type GetOfferParams struct {
	ReturnAvailableServices bool
}

func (GetOfferParams) Encode added in v0.2.0

func (o GetOfferParams) Encode(q url.Values) error

type IdentityDocument

type IdentityDocument struct {
	// The unique identifier of the identity document.
	// We currently only support passport so this would be the passport number.
	UniqueIdentifier string `json:"unique_identifier"`

	// The date on which the identity document expires
	ExpiresOn Date `json:"expires_on"`

	// The ISO 3166-1 alpha-2 code of the country that issued this identity document
	IssuingCountryCode string `json:"issuing_country_code"`

	Type string `json:"type"`
}

type Iter

type Iter[T any] struct {
	// contains filtered or unexported fields
}

Iter is an iterator for a list of items. Based on the iterator used in https://github.com/stripe/stripe-go

func ErrIter

func ErrIter[T any](err error) *Iter[T]

ErrIter creates an iterators that always returns the given error.

func GetIter

func GetIter[T any](pager PageFn[T]) *Iter[T]

GetIter returns a new Iter for a given query and type.

func (*Iter[T]) Current

func (it *Iter[T]) Current() *T

Current returns the most recent item visited by a call to Next.

func (*Iter[T]) Err

func (it *Iter[T]) Err() error

Err returns the error, if any, that caused the Iter to stop. It must be inspected after Next returns false.

func (*Iter[T]) LastRequestID added in v0.4.2

func (it *Iter[T]) LastRequestID() (string, bool)

func (*Iter[T]) List

func (it *Iter[T]) List() ListContainer[T]

List returns the current list object which the iterator is currently using. List objects will change as new API calls are made to continue pagination.

func (*Iter[T]) Meta

func (it *Iter[T]) Meta() *ListMeta

Meta returns the list metadata.

func (*Iter[T]) Next

func (it *Iter[T]) Next() bool

Next advances the Iter to the next item in the list, which will then be available through the Current method. It returns false when the iterator stops at the end of the list.

type List

type List[T any] struct {

	// *Iter[T]
	*ListMeta
	// contains filtered or unexported fields
}

func (*List[T]) GetItems

func (l *List[T]) GetItems() []*T

func (*List[T]) LastRequestID added in v0.4.2

func (l *List[T]) LastRequestID() (string, bool)

func (*List[T]) SetItems

func (l *List[T]) SetItems(items []*T)

func (*List[T]) SetListMeta

func (l *List[T]) SetListMeta(meta *ListMeta)

type ListAirportsParams

type ListAirportsParams struct {
	IATACountryCode string `url:"iata_country_code,omitempty"`
}

func (ListAirportsParams) Encode added in v0.2.0

func (p ListAirportsParams) Encode(q url.Values) error

type ListContainer

type ListContainer[T any] interface {
	SetListMeta(*ListMeta)
	GetListMeta() *ListMeta
	GetItems() []*T
	SetItems(items []*T)
	LastRequestID() (string, bool)
}

ListContainer is a general interface for which all list object structs should comply. They achieve this by embedding a ListMeta struct and inheriting its implementation of this interface.

type ListMeta

type ListMeta struct {

	// After is a string that contains the token for the next page of results
	After string `json:"after,omitempty" url:"after,omitempty"`

	// Before is a string that contains the token for the previous page of results
	Before string `json:"before,omitempty" url:"-"`

	// Limit is a number that indicates the maximum number of items to return
	Limit int `json:"limit,omitempty" url:"limit,omitempty"`
}

ListMeta is the structure that contains the common properties of List iterators.

func (*ListMeta) GetListMeta

func (l *ListMeta) GetListMeta() *ListMeta

GetListMeta returns a ListMeta struct (itself). It exists because any structs that embed ListMeta will inherit it, and thus implement the ListContainer interface.

func (*ListMeta) HasMore

func (l *ListMeta) HasMore() bool

type ListOffersParams

type ListOffersParams struct {
	Sort           ListOffersSortParam `url:"sort,omitempty"`
	MaxConnections int                 `url:"max_connections,omitempty"`
}

func (ListOffersParams) Encode added in v0.2.0

func (o ListOffersParams) Encode(q url.Values) error

type ListOffersSortParam

type ListOffersSortParam string
const (
	ListOffersSortTotalAmount   ListOffersSortParam = "total_amount"
	ListOffersSortTotalDuration ListOffersSortParam = "total_duration"
)

type ListOrdersParams

type ListOrdersParams struct {
	// Filters orders by their booking reference.
	// The filter requires an exact match but is case insensitive.
	BookingReference string `url:"booking_reference,omitempty"`

	// Whether to filter orders that are awaiting payment or not.
	// If not specified, all orders regardless of their payment state will be returned.
	AwaitingPayment bool `url:"awaiting_payment,omitempty"`

	// By default, orders aren't returned in any specific order.
	// This parameter allows you to sort the list of orders by the payment_required_by date
	Sort ListOrdersSort `url:"sort,omitempty"`

	// Filters the returned orders by owner.id. Values must be valid airline.ids.
	// Check the Airline schema for details.
	OwnerIDs []string `url:"owner_id,omitempty"`

	// Filters the returned orders by origin. Values must be valid origin identifiers.
	// Check the Order schema for details.
	OriginIDs []string `url:"origin_id,omitempty"`

	// Filters the returned orders by destination. Values must be valid destination identifiers.
	// Check the Order schema for details.
	DestinationIDs []string `url:"destination_id,omitempty"`

	// Filters the returned orders by departure datetime.
	// Orders will be included if any of their segments matches the given criteria
	DepartingAt *TimeFilter `url:"departing_at,omitempty"`

	// Filters the returned orders by arrival datetime.
	// Orders will be included if any of their segments matches the given criteria.
	ArrivingAt *TimeFilter `url:"arriving_at,omitempty"`

	// Filters the returned orders by creation datetime.
	CreatedAt *TimeFilter `url:"created_at,omitempty"`

	// Orders will be included if any of their passengers matches any of the given names.
	// Matches are case insensitive, and include partial matches.
	PassengerNames []string `url:"passenger_name,omitempty"`
}

func (ListOrdersParams) Encode added in v0.2.0

func (o ListOrdersParams) Encode(q url.Values) error

type ListOrdersSort

type ListOrdersSort string

type Location

type Location struct {
	ID              string    `json:"id"`
	Type            string    `json:"type"`
	Name            string    `json:"name"`
	TimeZone        string    `json:"time_zone,omitempty"`
	Longitude       *float64  `json:"longitude,omitempty"`
	Latitude        *float64  `json:"latitude,omitempty"`
	ICAOCode        string    `json:"icao_code,omitempty"`
	IATACountryCode *string   `json:"iata_country_code,omitempty"`
	IATACode        string    `json:"iata_code,omitempty"`
	IATACityCode    *string   `json:"iata_city_code,omitempty"`
	CityName        *string   `json:"city_name,omitempty"`
	City            *City     `json:"city,omitempty"`
	Airports        []Airport `json:"airports,omitempty"`
}

type LoyaltyProgrammeAccount

type LoyaltyProgrammeAccount struct {
	AirlineIATACode string `json:"airline_iata_code"`
	AccountNumber   string `json:"account_number"`
}

type Metadata

type Metadata map[string]any

type Offer

type Offer struct {
	ID                                    string                  `json:"id"`
	LiveMode                              bool                    `json:"live_mode"`
	CreatedAt                             time.Time               `json:"created_at"`
	UpdatedAt                             time.Time               `json:"updated_at"`
	ExpiresAt                             time.Time               `json:"expires_at"`
	TotalEmissionsKg                      string                  `json:"total_emissions_kg"`
	RawTotalCurrency                      string                  `json:"total_currency"`
	RawTotalAmount                        string                  `json:"total_amount"`
	RawTaxAmount                          string                  `json:"tax_amount"`
	RawTaxCurrency                        string                  `json:"tax_currency"`
	RawBaseAmount                         string                  `json:"base_amount"`
	RawBaseCurrency                       string                  `json:"base_currency"`
	Owner                                 Airline                 `json:"owner"`
	Slices                                []Slice                 `json:"slices"`
	Passengers                            []OfferRequestPassenger `json:"passengers"`
	Partial                               bool                    `json:"partial"`
	PassengerIdentityDocumentsRequired    bool                    `json:"passenger_identity_documents_required"`
	AllowedPassengerIdentityDocumentTypes []string                `json:"allowed_passenger_identity_document_types"`
	PaymentRequirements                   OfferPaymentRequirement `json:"payment_requirements"`
	AvailableServices                     []AvailableService      `json:"available_services"`
	Conditions                            Conditions              `json:"conditions"`
}

func (*Offer) BaseAmount added in v0.4.4

func (o *Offer) BaseAmount() currency.Amount

func (*Offer) TaxAmount

func (o *Offer) TaxAmount() currency.Amount

func (*Offer) TotalAmount

func (o *Offer) TotalAmount() currency.Amount

type OfferClient

type OfferClient interface {
	UpdateOfferPassenger(ctx context.Context, offerRequestID, passengerID string, input PassengerUpdateInput) (*OfferRequestPassenger, error)
	ListOffers(ctx context.Context, reqId string, options ...ListOffersParams) *Iter[Offer]
	GetOffer(ctx context.Context, id string, params ...GetOfferParams) (*Offer, error)
}

type OfferPaymentRequirement added in v0.2.2

type OfferPaymentRequirement struct {
	RequiresInstantPayment  bool      `json:"requires_instant_payment"`
	PriceGuaranteeExpiresAt *DateTime `json:"price_guarantee_expires_at"`
	PaymentRequiredBy       *DateTime `json:"payment_required_by"`
}

type OfferRequest

type OfferRequest struct {
	ID         string                  `json:"id"`
	LiveMode   bool                    `json:"live_mode"`
	CreatedAt  time.Time               `json:"created_at"`
	Slices     []BaseSlice             `json:"slices"`
	Passengers []OfferRequestPassenger `json:"passengers"`
	CabinClass CabinClass              `json:"cabin_class"`
	Offers     []Offer                 `json:"offers"`
}

OfferRequest is the response from the OfferRequest endpoint, created using the OfferRequestInput.

type OfferRequestClient

type OfferRequestClient interface {
	CreateOfferRequest(ctx context.Context, requestInput OfferRequestInput) (*OfferRequest, error)
	GetOfferRequest(ctx context.Context, id string) (*OfferRequest, error)
	ListOfferRequests(ctx context.Context) *Iter[OfferRequest]
}

type OfferRequestInput

type OfferRequestInput struct {
	// The passengers who want to travel. If you specify an age for a passenger, the type may differ for the same passenger in different offers due to airline's different rules. e.g. one airline may treat a 14 year old as an adult, and another as a young adult. You may only specify an age or a type – not both.
	Passengers []OfferRequestPassenger `json:"passengers" url:"-"`
	// The slices that make up this offer request. One-way journeys can be expressed using one slice, whereas return trips will need two.
	Slices []OfferRequestSlice `json:"slices" url:"-"`
	// The cabin that the passengers want to travel in
	CabinClass CabinClass `json:"cabin_class" url:"-"`
	// The maximum number of connections within any slice of the offer. For example 0 means a direct flight which will have a single segment within each slice and 1 means a maximum of two segments within each slice of the offer.
	MaxConnections *int `json:"max_connections,omitempty" url:"-"`
	// When set to true, the offer request resource returned will include all the offers returned by the airlines
	ReturnOffers bool `json:"-" url:"return_offers"`
	// The maximum amount of time in milliseconds to wait for each airline to respond
	SupplierTimeout int `json:"-" url:"supplier_timeout,omitempty"`
}

func (OfferRequestInput) Encode added in v0.2.0

func (o OfferRequestInput) Encode(q url.Values) error

Encode implements the ParamEncoder interface.

type OfferRequestPassenger

type OfferRequestPassenger struct {
	ID                       string                    `json:"id,omitempty"`
	FamilyName               string                    `json:"family_name,omitempty"`
	GivenName                string                    `json:"given_name,omitempty"`
	Age                      int                       `json:"age,omitempty"`
	LoyaltyProgrammeAccounts []LoyaltyProgrammeAccount `json:"loyalty_programme_accounts,omitempty"`
	// deprecated
	Type PassengerType `json:"type,omitempty"`
}

type OfferRequestSlice

type OfferRequestSlice struct {
	DepartureDate Date   `json:"departure_date"`
	Destination   string `json:"destination"`
	Origin        string `json:"origin"`
}

type Offers

type Offers []Offer

Offers is slice of offers that implement the sort.Sort interface By default, offers are sorted cheapest first.

func (Offers) Len added in v0.2.2

func (o Offers) Len() int

func (Offers) Less added in v0.2.2

func (o Offers) Less(i, j int) bool

Less will sort ascending by total amount

func (Offers) Swap added in v0.2.2

func (o Offers) Swap(i, j int)

type Option

type Option func(*Options)

func WithAPIVersion

func WithAPIVersion(version string) Option

WithVersion allows you to specify "Duffel-Version" header for the API version that you are targeting.

func WithDebug added in v0.2.2

func WithDebug() Option

WithDebug enables debug logging of requests and responses. DO NOT USE IN PRODUCTION.

func WithDefaultAPI

func WithDefaultAPI() Option

WithAPIToken sets the API host to the default Duffel production host.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient allows you to specify a custom http.Client to use for making requests. This is useful if you want to use a custom transport or proxy.

func WithHost

func WithHost(host string) Option

WithHost allows you to specify the Duffel API host to use for making requests.

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent allows you to specify a custom user agent string to use for making requests.

type Options

type Options struct {
	Version   string
	Host      string
	UserAgent string
	HttpDoer  *http.Client
	Debug     bool
}

type Order

type Order struct {
	ID               string           `json:"id"`
	LiveMode         bool             `json:"live_mode"`
	Metadata         Metadata         `json:"metadata"`
	RawBaseAmount    *string          `json:"base_amount,omitempty"`
	RawBaseCurrency  *string          `json:"base_currency,omitempty"`
	BookingReference string           `json:"booking_reference"`
	CancelledAt      *time.Time       `json:"cancelled_at,omitempty"`
	CreatedAt        time.Time        `json:"created_at"`
	Conditions       Conditions       `json:"conditions,omitempty"`
	Documents        []Document       `json:"documents,omitempty"`
	Owner            Airline          `json:"owner"`
	Passengers       []OrderPassenger `json:"passengers,omitempty"`
	PaymentStatus    PaymentStatus    `json:"payment_status"`
	Services         []Service        `json:"services,omitempty"`
	Slices           []Slice          `json:"slices,omitempty"`
	SyncedAt         time.Time        `json:"synced_at"`
	RawTaxAmount     *string          `json:"tax_amount,omitempty"`
	RawTaxCurrency   *string          `json:"tax_currency,omitempty"`
	RawTotalAmount   string           `json:"total_amount"`
	RawTotalCurrency string           `json:"total_currency"`
}

func (*Order) BaseAmount

func (o *Order) BaseAmount() *currency.Amount

func (*Order) TaxAmount

func (o *Order) TaxAmount() *currency.Amount

func (*Order) TotalAmount

func (o *Order) TotalAmount() currency.Amount

type OrderCancellation added in v0.2.0

type OrderCancellation struct {
	ID                string        `json:"id"`
	OrderID           string        `json:"order_id"`
	RefundTo          PaymentMethod `json:"refund_to"`
	RawRefundCurrency string        `json:"refund_currency"`
	RawRefundAmount   string        `json:"refund_amount"`
	ExpiresAt         string        `json:"expires_at"`
	CreatedAt         string        `json:"created_at"`
	ConfirmedAt       string        `json:"confirmed_at"`
	LiveMode          bool          `json:"live_mode"`
}

OrderCancellationRequest is response from the OrderCancellation API.

Once you've created a pending order cancellation, you'll know the `refund_amount` you're due to get back.

To actually cancel the order, you'll need to confirm the cancellation. The booking with the airline will be cancelled, and the `refund_amount` will be returned to the original payment method (i.e. your Duffel balance). You'll then need to refund your customer (e.g. back to their credit/debit card).

func (*OrderCancellation) RefundAmount added in v0.2.0

func (o *OrderCancellation) RefundAmount() currency.Amount

type OrderCancellationClient added in v0.2.0

type OrderCancellationClient interface {
	CreateOrderCancellation(ctx context.Context, orderID string) (*OrderCancellation, error)
	ConfirmOrderCancellation(ctx context.Context, orderCancellationID string) (*OrderCancellation, error)
	GetOrderCancellation(ctx context.Context, orderCancellationID string) (*OrderCancellation, error)
}

OrderCancellationClient

type OrderCancellationRequest added in v0.2.0

type OrderCancellationRequest struct {
	OrderID string `json:"order_id"`
}

type OrderChange added in v0.2.0

type OrderChange struct {
	ID                      string         `json:"id"`
	OrderID                 string         `json:"order_id"`
	Slices                  SliceChangeset `json:"slices"`
	RefundTo                PaymentMethod  `json:"refund_to"`
	RawPenaltyTotalCurrency string         `json:"penalty_total_currency"`
	RawPenaltyTotalAmount   string         `json:"penalty_total_amount"`
	RawNewTotalCurrency     string         `json:"new_total_currency"`
	RawNewTotalAmount       string         `json:"new_total_amount"`
	RawChangeTotalCurrency  string         `json:"change_total_currency"`
	RawChangeTotalAmount    string         `json:"change_total_amount"`
	ExpiresAt               string         `json:"expires_at"`
	CreatedAt               string         `json:"created_at"`
	UpdatedAt               string         `json:"updated_at"`
	LiveMode                bool           `json:"live_mode"`
}

type OrderChangeClient added in v0.2.0

type OrderChangeClient interface {
	CreateOrderChangeRequest(ctx context.Context, params OrderChangeRequestParams) (*OrderChangeRequest, error)
	GetOrderChangeRequest(ctx context.Context, id string) (*OrderChangeRequest, error)
	CreatePendingOrderChange(ctx context.Context, orderChangeRequestID string) (*OrderChange, error)
	ConfirmOrderChange(ctx context.Context, id string, payment PaymentCreateInput) (*OrderChange, error)
}

type OrderChangeOffer added in v0.2.0

type OrderChangeOffer struct {
	ID string `json:"id"`
	// OrderChangeID is the ID for an order change if one has already been created from this order change offer
	OrderChangeID           string         `json:"order_change_id"`
	Slices                  SliceChangeset `json:"slices"`
	RefundTo                PaymentMethod  `json:"refund_to"`
	RawPenaltyTotalCurrency string         `json:"penalty_total_currency"`
	RawPenaltyTotalAmount   string         `json:"penalty_total_amount"`
	RawNewTotalCurrency     string         `json:"new_total_currency"`
	RawNewTotalAmount       string         `json:"new_total_amount"`
	RawChangeTotalCurrency  string         `json:"change_total_currency"`
	RawChangeTotalAmount    string         `json:"change_total_amount"`
	ExpiresAt               time.Time      `json:"expires_at"`
	CreatedAt               time.Time      `json:"created_at"`
	UpdatedAt               time.Time      `json:"updated_at"`
	LiveMode                bool           `json:"live_mode"`
}

func (*OrderChangeOffer) ChangeTotalAmount added in v0.2.0

func (o *OrderChangeOffer) ChangeTotalAmount() currency.Amount

func (*OrderChangeOffer) NewTotalAmount added in v0.2.0

func (o *OrderChangeOffer) NewTotalAmount() currency.Amount

func (*OrderChangeOffer) PenaltyTotalAmount added in v0.2.0

func (o *OrderChangeOffer) PenaltyTotalAmount() currency.Amount

PenaltyTotalAmount returns the penalty imposed by the airline for making this change.

type OrderChangeRequest added in v0.2.0

type OrderChangeRequest struct {
	ID                string             `json:"id"`
	OrderID           string             `json:"order_id"`
	Slices            SliceChange        `json:"slices"`
	OrderChangeOffers []OrderChangeOffer `json:"order_change_offers"`
	CreatedAt         string             `json:"created_at"`
	UpdatedAt         string             `json:"updated_at"`
	LiveMode          bool               `json:"live_mode"`
}

OrderChangeRequest is the input to the OrderChange API. To change an order, you'll need to create an order change request. An order change request describes the slices of an existing paid order that you want to remove and search criteria for new slices you want to add.

type OrderChangeRequestParams added in v0.2.0

type OrderChangeRequestParams struct {
	OrderID string      `json:"order_id"`
	Slices  SliceChange `json:"slices,omitempty"`
}

type OrderClient

type OrderClient interface {
	// Get a single order by ID.
	GetOrder(ctx context.Context, id string) (*Order, error)

	// Update a single order by ID.
	UpdateOrder(ctx context.Context, id string, params OrderUpdateParams) (*Order, error)

	// List orders.
	ListOrders(ctx context.Context, params ...ListOrdersParams) *Iter[Order]

	// Create an order.
	CreateOrder(ctx context.Context, input CreateOrderInput) (*Order, error)
}

type OrderPassenger

type OrderPassenger struct {
	// ID is id of the passenger, returned when the offer request was created
	ID string `json:"id"`
	// Title is passengers' title. Possible values: "mr", "ms", "mrs", or "miss"
	Title PassengerTitle `json:"title"`
	// FamilyName is the family name of the passenger.
	FamilyName string `json:"family_name"`
	// GivenName is the passenger's given name.
	GivenName string `json:"given_name"`
	// BornOn is the passengers DoB according to their travel documents.
	BornOn Date `json:"born_on"`
	// Email is the passengers email address.
	Email string `json:"email"`
	// Gender is the passengers gender.
	Gender Gender `json:"gender"`
	// The passenger's identity documents. You may only provide one identity document per passenger.
	IdentityDocuments []IdentityDocument `json:"identity_documents,omitempty"`
	// The `id` of the infant associated with this passenger
	InfantPassengerID string `json:"infant_passenger_id,omitempty"`
	// The Loyalty Programme Accounts for this passenger
	LoyaltyProgrammeAccounts []LoyaltyProgrammeAccount `json:"loyalty_programme_accounts,omitempty"`
	// (Required) The passenger's phone number in E.164 (international) format
	PhoneNumber string `json:"phone_number"`

	// Type is the type of passenger. This field is deprecated.
	// @Deprecated
	// Possible values: "adult", "child", or "infant_without_seat"
	Type PassengerType `json:"type"`
}

type OrderPaymentClient added in v0.2.2

type OrderPaymentClient interface {
	CreatePayment(ctx context.Context, req CreatePaymentRequest) (*Payment, error)
}

type OrderType

type OrderType string

type OrderUpdateParams

type OrderUpdateParams struct {
	Metadata map[string]any
}

OrderUpdateParams is used as the input to UpdateOrder. Only certain order fields are updateable. Each field that can be updated is detailed in the `OrderUpdateParams` object.

type PageFn

type PageFn[T any] func(meta *ListMeta) (*List[T], error)

type ParamEncoder added in v0.2.0

type ParamEncoder[T any] interface {
	Encode(v url.Values) error
}

type PassengerTitle

type PassengerTitle string

func (PassengerTitle) String added in v0.2.0

func (p PassengerTitle) String() string

type PassengerType

type PassengerType string

func (PassengerType) String

func (p PassengerType) String() string

type PassengerUpdateInput

type PassengerUpdateInput struct {
	FamilyName               string                    `json:"family_name"`
	GivenName                string                    `json:"given_name"`
	LoyaltyProgrammeAccounts []LoyaltyProgrammeAccount `json:"loyalty_programme_accounts,omitempty"`
}

type Payload

type Payload[T any] struct {
	Data T `json:"data"`
}

type Payment added in v0.2.2

type Payment struct {
	Amount    string      `json:"amount"`
	CreatedAt DateTime    `json:"created_at"`
	Currency  string      `json:"currency"`
	ID        string      `json:"id"`
	LiveMode  bool        `json:"live_mode"`
	Type      PaymentType `json:"type"`
}

type PaymentCreateInput

type PaymentCreateInput struct {
	// The amount of the payment. This should be the same as the total_amount of the offer specified in selected_offers, plus the total_amount of all the services specified in services.
	Amount string `json:"amount"`
	// The currency of the amount, as an ISO 4217 currency code. This should be the same as the total_currency of the offer specified in selected_offers.
	Currency string `json:"currency"`

	// Possible values: "arc_bsp_cash" or "balance"
	Type PaymentMethod `json:"type"`
}

The payment details to use to pay for the order. This key should be omitted when the order’s type is hold.

type PaymentMethod added in v0.2.0

type PaymentMethod string

func (PaymentMethod) String added in v0.2.0

func (p PaymentMethod) String() string

type PaymentStatus

type PaymentStatus struct {
	AwaitingPayment         bool       `json:"awaiting_payment"`
	PaymentRequiredBy       *time.Time `json:"payment_required_by,omitempty"`
	PriceGuaranteeExpiresAt *time.Time `json:"price_guarantee_expires_at,omitempty"`
}

The payment status for an order.

type PaymentType added in v0.2.2

type PaymentType string

type Place added in v0.3.1

type Place struct {
	ID              string     `json:"id"`
	Airports        []*Airport `json:"airports"`
	City            *City      `json:"city"`
	CityName        string     `json:"city_name"`
	CountryName     string     `json:"country_name"`
	IATACityCode    string     `json:"iata_city_code"`
	IATACode        string     `json:"iata_code"`
	IATACountryCode string     `json:"iata_country_code"`
	ICAOCode        string     `json:"icao_code"`
	Latitude        float64    `json:"latitude"`
	Longitude       float64    `json:"longitude"`
	Name            string     `json:"name"`
	TimeZone        string     `json:"time_zone"`
	Type            PlaceType  `json:"type"`
}

type PlaceType added in v0.3.1

type PlaceType string

type PlacesClient added in v0.3.1

type PlacesClient interface {
	PlaceSuggestions(ctx context.Context, query string) ([]*Place, error)
	Cities(ctx context.Context) *Iter[City]
	City(ctx context.Context, id string) (*City, error)
}

type RateLimit

type RateLimit struct {
	Limit     int
	Remaining int
	ResetAt   time.Time
	Period    time.Duration
}

type RequestBuilder added in v0.2.0

type RequestBuilder[Req any, Resp any] struct {
	// contains filtered or unexported fields
}

func (*RequestBuilder[Req, Resp]) Body added in v0.2.0

func (r *RequestBuilder[Req, Resp]) Body(body *Req) *RequestBuilder[Req, Resp]

func (*RequestBuilder[Req, Resp]) Get added in v0.2.0

func (r *RequestBuilder[Req, Resp]) Get(path string, opts ...RequestOption) *RequestBuilder[Req, Resp]

Get sets the request method to GET and the request path to the given path. Global request options are applied.

func (*RequestBuilder[Req, Resp]) Getf added in v0.2.0

func (r *RequestBuilder[Req, Resp]) Getf(path string, a ...any) *RequestBuilder[Req, Resp]

Getf is like Get but accepts a format string and args.

func (*RequestBuilder[Req, Resp]) Iter added in v0.3.1

func (r *RequestBuilder[Req, Resp]) Iter(ctx context.Context) *Iter[Resp]

Iter finalizes the request and returns an iterator over the response.

func (*RequestBuilder[Req, Resp]) Patch added in v0.2.0

func (r *RequestBuilder[Req, Resp]) Patch(path string, body *Req, opts ...RequestOption) *RequestBuilder[Req, Resp]

Patch sets the request method to PATCH, the request path to the given path, and the request payload to body. Global request options are applied.

func (*RequestBuilder[Req, Resp]) Post added in v0.2.0

func (r *RequestBuilder[Req, Resp]) Post(path string, body *Req, opts ...RequestOption) *RequestBuilder[Req, Resp]

Post sets the request method to POST, the request path to the given path, and the request payload to body. Global request options are applied.

func (*RequestBuilder[Req, Resp]) Postf added in v0.2.0

func (r *RequestBuilder[Req, Resp]) Postf(path string, a ...any) *RequestBuilder[Req, Resp]

func (*RequestBuilder[Req, Resp]) Single added in v0.3.1

func (r *RequestBuilder[Req, Resp]) Single(ctx context.Context) (*Resp, error)

Single finalizes the request and returns a single item response.

func (*RequestBuilder[Req, Resp]) Slice added in v0.3.1

func (r *RequestBuilder[Req, Resp]) Slice(ctx context.Context) ([]*Resp, error)

Slice finalizes the request and returns the first page of items as a slice along with the error. This is only needed for endpoints without pagination, such as place suggestions.

func (*RequestBuilder[Req, Resp]) WithOptions added in v0.2.0

func (r *RequestBuilder[Req, Resp]) WithOptions(opts ...RequestOption) *RequestBuilder[Req, Resp]

func (*RequestBuilder[Req, Resp]) WithParam added in v0.2.0

func (r *RequestBuilder[Req, Resp]) WithParam(key, value string) *RequestBuilder[Req, Resp]

WithParam adds a single query param to the URL. These operations will be applied in defined order after the request is initialized.

func (*RequestBuilder[Req, Resp]) WithParams added in v0.2.0

func (r *RequestBuilder[Req, Resp]) WithParams(obj ...ParamEncoder[Req]) *RequestBuilder[Req, Resp]

WithParams sets the URL query params for the request. These operations will be applied in defined order after the request is initialized.

type RequestMiddleware added in v0.2.0

type RequestMiddleware func(r *http.Request) error

type RequestOption

type RequestOption func(req *http.Request) error

func WithEncodableParams added in v0.2.0

func WithEncodableParams[T any](params ...ParamEncoder[T]) RequestOption

func WithRequestPagination

func WithRequestPagination(meta *ListMeta) RequestOption

func WithURLParam

func WithURLParam(key, value string) RequestOption

func WithURLParams

func WithURLParams[T any](params ...T) RequestOption

type ResponseMiddleware added in v0.2.0

type ResponseMiddleware func(r *http.Response) error

type ResponsePayload

type ResponsePayload[T any] struct {
	Meta *ListMeta `json:"meta"`
	Data T         `json:"data"`
}

type Row

type Row struct {
	// A list of sections. Each row is divided into sections by one or more aisles.
	Sections []SeatSection `json:"sections"`
}

Row represents a row in a cabin.

type Seat added in v0.2.5

type Seat struct {
	Name        string   `json:"name,omitempty"`
	Disclosures []string `json:"disclosures,omitempty"`
	Designator  string   `json:"designator,omitempty"`
}

type SeatSection

type SeatSection struct {
	// The elements that make up this section.
	Elements []SectionElement `json:"elements"`
}

SeatSection represents a section of a row.

type Seatmap

type Seatmap struct {
	Cabins    []Cabin `json:"cabins"`
	ID        string  `json:"id"`
	SegmentID string  `json:"segment_id"`
	SliceID   string  `json:"slice_id"`
}

type SeatmapClient

type SeatmapClient interface {
	// GetSeatmap returns an iterator for the seatmaps of a given Offer.
	GetSeatmap(ctx context.Context, offerID string) ([]*Seatmap, error)
	SeatmapForOffer(ctx context.Context, offer Offer) ([]*Seatmap, error)
}

type SectionElement

type SectionElement struct {
	// The element type, e.g. seat, exit_row, stairs, etc.
	Type ElementType `json:"type"`

	// Seats are considered a special kind of service.
	// There will be at most one service per seat per passenger.
	// A seat can only be booked for one passenger. If a seat has no available services (which will be represented as an empty list : []) then it's unavailable.
	AvailableServices []SectionService `json:"available_services"`

	// The designator used to uniquely identify the seat, usually made up of a row number and a column letter
	Designator string `json:"designator"`

	// Each disclosure is text, in English, provided by the airline that describes the terms and conditions of this seat. We recommend showing this in your user interface to make sure that customers understand any restrictions and limitations.
	Disclosures []string `json:"disclosures"`

	// A name which describes the type of seat, which you can display in your user interface to help customers to understand its features.
	// Example: "Exit row seat"
	Name string `json:"name"`
}

SectionElement represents an element in a section.

type SectionService

type SectionService struct {
	ID               string `json:"id"`
	PassengerID      string `json:"passenger_id"`
	RawTotalAmount   string `json:"total_amount"`
	RawTotalCurrency string `json:"total_currency"`
}

func (*SectionService) TotalAmount

func (s *SectionService) TotalAmount() currency.Amount

type SegmentPassenger

type SegmentPassenger struct {
	ID                      string     `json:"passenger_id"`
	FareBasisCode           string     `json:"fare_basis_code"`
	CabinClassMarketingName string     `json:"cabin_class_marketing_name"`
	CabinClass              CabinClass `json:"cabin_class"`
	Baggages                []Baggage  `json:"baggages"`
	Seat                    Seat       `json:"seat"`
}

type Service

type Service struct {
	// Duffel's unique identifier for the booked service
	ID string `json:"id"`

	// The metadata varies by the type of service.
	// It includes further data about the service. For example, for
	// baggages, it may have data about size and weight restrictions.
	Metadata Metadata `json:"metadata"`

	// List of passenger ids the service applies to.
	// The service applies to all the passengers in this list.
	PassengerIDs []string `json:"passenger_ids"`

	// The quantity of the service that was booked
	Quantity int `json:"quantity"`

	// List of segment ids the service applies to. The service applies to all the segments in this list.
	SegmentIDs []string `json:"segment_ids"`

	// The total price of the service for all passengers and segments it applies to, accounting for quantity and including taxes
	RawTotalAmount   string `json:"total_amount,omitempty"`
	RawTotalCurrency string `json:"total_currency,omitempty"`

	// Possible values: "baggage" or "seat"
	Type string `json:"type"`
}

func (*Service) TotalAmount

func (s *Service) TotalAmount() currency.Amount

type ServiceCreateInput

type ServiceCreateInput struct {
	// The id of the service from the offer's available_services that you want to book
	ID string `json:"id"`

	// The quantity of the service to book. This will always be 1 for seat services.
	Quantity int `json:"quantity"`
}

The services you want to book along with the first selected offer. This key should be omitted when the order’s type is hold, as we do not support services for hold orders yet.

type Slice

type Slice struct {
	*BaseSlice
	ID string `json:"id"`

	// Whether this slice can be changed. This can only be true for paid orders.
	Changeable bool `json:"changeable,omitempty"`

	// The conditions associated with this slice, describing the kinds of modifications you can make and any penalties that will apply to those modifications.
	Conditions    SliceConditions `json:"conditions,omitempty"`
	Duration      Duration        `json:"duration,omitempty"`
	Segments      []Flight        `json:"segments,omitempty"`
	FareBrandName string          `json:"fare_brand_name,omitempty"`
}

TODO: We probably need an OfferRequestSlice and an OrderSlice since not all fields apply to both.

type SliceAdd added in v0.2.0

type SliceAdd struct {
	DepartureDate Date       `json:"departure_date"`
	Destination   string     `json:"destination"`
	Origin        string     `json:"origin"`
	CabinClass    CabinClass `json:"cabin_class"`
}

type SliceChange added in v0.2.0

type SliceChange struct {
	Add    []SliceAdd    `json:"add,omitempty"`
	Remove []SliceRemove `json:"remove,omitempty"`
}

type SliceChangeset added in v0.2.0

type SliceChangeset struct {
	Add    []Slice `json:"add"`
	Remove []Slice `json:"remove"`
}

type SliceConditions added in v0.4.5

type SliceConditions struct {
	ChangeBeforeDeparture *ChangeCondition `json:"change_before_departure,omitempty"`
}

type SliceRemove added in v0.2.0

type SliceRemove struct {
	SliceID string `json:"slice_id"`
}

type TimeFilter

type TimeFilter struct {
	Before *time.Time `url:"before,omitempty"`
	After  *time.Time `url:"after,omitempty"`
}

type Wing

type Wing struct {
	// The index of the first row which is overwing, starting from the front of the aircraft.
	FirstRowIndex int `json:"first_row_index"`
	// The index of the last row which is overwing, starting from the front of the aircraft.
	LastRowIndex int `json:"last_row_index"`
}

Wing represents a wing of the aircraft in relation to rows in the cabin.

Directories

Path Synopsis
examples
e2e

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL