Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/booking/Offers/OfferTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,76 @@ export interface UpdateOffer {
family_name: string
age: number
}

export type OfferIntendedPaymentMethod =
| {
/**
* The type of payment method intended to use
*/
type: 'card'

/**
* The ID of the card intended to pay with
*/
card_id: string
}
| {
/**
* The type of payment method intended to use
*/
type: 'airline_credit'

/**
* The ID of the airline credit intended to pay with
*/
airline_credit_id: string
}

export interface OfferIntendedService {
/**
* The ID of the service to pay for
*/
id: string

/**
* The quantity of the service ID to pay for
*/
quantity: number
}

export interface GetOfferPricedParams {
/**
* The ID of the offer
*/
offerId: string

/**
* The payment methods intended to use to pay for the offer
*/
intended_payment_methods: OfferIntendedPaymentMethod[]

/**
* The services intended to book along with the offer
*/
intended_services: OfferIntendedService[]
}

/**
* Represents a priced offer, including the charge and surcharge amounts for the intended payment methods and services
*/
export interface OfferPriced extends Offer {
/**
* The payment methods intended to use to pay for the offer, along with the charge and surcharge amounts
*/
intended_payment_methods: (OfferIntendedPaymentMethod & {
charge_currency: string
charge_amount: string
surcharge_amount: string
surcharge_currency: string
})[]

/**
* The services intended to book along with the offer
*/
intended_services: OfferIntendedService[]
}
28 changes: 27 additions & 1 deletion src/booking/Offers/Offers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nock from 'nock'
import { Client } from '../../Client'
import { Duffel } from '../../index'
import { mockOffer, mockUpdatedOffer } from './mockOffer'
import { mockOffer, mockOfferPriced, mockUpdatedOffer } from './mockOffer'
import { Offers } from './Offers'

const duffel = new Duffel({ token: 'mockToken' })
Expand Down Expand Up @@ -109,4 +109,30 @@ describe('offers', () => {
1,
)
})

test('should get offer price', async () => {
nock(/(.*)/)
.post(`/air/offers/${mockOffer.id}/actions/price`)
.reply(200, { data: mockOfferPriced })

const response = await new Offers(
new Client({ token: 'mockToken' }),
).getPriced({
offerId: mockOffer.id,
intended_payment_methods: [
{
type: 'card',
card_id: 'card_00009htYpSCXrwaB9DnUm0',
},
],
intended_services: [
{
id: 'ase_00009UhD4ongolulWd9123',
quantity: 1,
},
],
})

expect(response.data).toStrictEqual(mockOfferPriced)
})
})
17 changes: 17 additions & 0 deletions src/booking/Offers/Offers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Client } from '../../Client'
import { Resource } from '../../Resource'
import {
DuffelResponse,
GetOfferPricedParams,
ListOffersParams,
Offer,
OfferPriced,
LoyaltyProgrammeAccounts,
UpdateOffer,
} from '../../types'
Expand Down Expand Up @@ -97,4 +99,19 @@ export class Offers extends Resource {
path: `${this.path}/${offerId}/passengers/${passengerId}`,
...(params && { data: params }),
})

/**
* Price the offer with intended payment methods and intended services. This will return the total amount that will be charged to the customer, including any applicable surcharges.
* @param {Object.<GetOfferPricedParams>} params - The intended payment methods and services of the offer
* @param {string} params.offerId - Duffel's unique identifier for the offer
*/
public getPriced = async ({
offerId,
...params
}: GetOfferPricedParams): Promise<DuffelResponse<OfferPriced>> =>
this.request({
method: 'POST',
path: `${this.path}/${offerId}/actions/price`,
data: params,
})
}
22 changes: 21 additions & 1 deletion src/booking/Offers/mockOffer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Offer } from '../../types'
import { Offer, OfferPriced } from '../../types'

export const mockOffer: Offer = {
updated_at: '2020-01-17T10:12:14.545Z',
Expand Down Expand Up @@ -275,3 +275,23 @@ export const mockUpdatedOffer = {
family_name: 'Earhart',
age: 14,
}

export const mockOfferPriced: OfferPriced = {
...mockOffer,
intended_payment_methods: [
{
type: 'card',
card_id: 'card_00009htYpSCXrwaB9DnUm0',
surcharge_amount: '2.50',
surcharge_currency: 'GBP',
charge_amount: '41.81',
charge_currency: 'GBP',
},
],
intended_services: [
{
id: 'ase_00009UhD4ongolulWd9123',
quantity: 1,
},
],
}