diff --git a/README.md b/README.md index 58e98b4..c3102e7 100644 --- a/README.md +++ b/README.md @@ -405,14 +405,28 @@ amadeus.shopping.hotelOffersSearch.get({ // Check offer conditions of a specific offer id amadeus.shopping.hotelOfferSearch('XXX').get() -// Hotel Booking API +// Hotel Booking API v2 +amadeus.booking.hotelOrders.post( + JSON.stringfy({ + 'data': { + 'type': 'hotel-order', + 'guests': [], + 'travelAgent': {}, + 'roomAssociations': [], + 'payment': {} + }}) +) + + +// Hotel Booking API v1 amadeus.booking.hotelBookings.post( JSON.stringify({ - 'offerId': 'XXX', - 'guests': [], - 'payments': [] - } - ) + 'data': { + 'offerId': 'XXXX', + 'guests': [], + 'payments': [], + 'rooms': [] + }}) ) // On-Demand Flight Status diff --git a/spec/amadeus/namespaces.test.js b/spec/amadeus/namespaces.test.js index 4e94dce..b8d794c 100644 --- a/spec/amadeus/namespaces.test.js +++ b/spec/amadeus/namespaces.test.js @@ -156,6 +156,7 @@ describe('Namespaces', () => { expect(amadeus.shopping.flightOffers.pricing.post).toBeDefined(); expect(amadeus.shopping.seatmaps.post).toBeDefined(); expect(amadeus.booking.hotelBookings.post).toBeDefined(); + expect(amadeus.booking.hotelOrders.post).toBeDefined(); expect(amadeus.shopping.transferOffers.post).toBeDefined(); expect(amadeus.ordering.transferOrders.post).toBeDefined(); expect(amadeus.ordering.transferOrder('XXX').transfers.cancellation.post).toBeDefined(); @@ -447,6 +448,13 @@ describe('Namespaces', () => { .toHaveBeenCalledWith('/v1/booking/hotel-bookings', {}); }); + it('.amadeus.booking.hotelOrders.post', () => { + amadeus.client.post = jest.fn(); + amadeus.booking.hotelOrders.post(); + expect(amadeus.client.post) + .toHaveBeenCalledWith('/v2/booking/hotel-orders', {}); + }); + it('.amadeus.eReputation.hotelSentiments.get', () => { amadeus.client.get = jest.fn(); amadeus.eReputation.hotelSentiments.get(); diff --git a/src/amadeus/namespaces/booking.js b/src/amadeus/namespaces/booking.js index 35b34ec..083516f 100644 --- a/src/amadeus/namespaces/booking.js +++ b/src/amadeus/namespaces/booking.js @@ -1,6 +1,7 @@ import FlightOrders from './booking/flight_orders'; import FlightOrder from './booking/flight_order'; import HotelBookings from './booking/hotel_bookings'; +import HotelOrders from './booking/hotel_orders'; /** * A namespaced client for the @@ -17,6 +18,7 @@ import HotelBookings from './booking/hotel_bookings'; * @property {FlightOrders} flightOrders * @property {FlightOrder} flightOrder * @property {HotelBookings} hotelBookings + * @property {HotelOrders} hotelOrders * @protected */ class Booking { @@ -24,6 +26,7 @@ class Booking { this.client = client; this.flightOrders = new FlightOrders(client); this.hotelBookings = new HotelBookings(client); + this.hotelOrders = new HotelOrders(client); } flightOrder (orderId) { diff --git a/src/amadeus/namespaces/booking/flight_orders.js b/src/amadeus/namespaces/booking/flight_orders.js index 94554f1..886883c 100644 --- a/src/amadeus/namespaces/booking/flight_orders.js +++ b/src/amadeus/namespaces/booking/flight_orders.js @@ -28,7 +28,7 @@ class FlightOrders { * amadeus.booking.flightOrders.post({ * 'type': 'flight-order', * 'flightOffers': [], - * 'travelers_info': [] + * 'travelers': [] * }); * ``` */ diff --git a/src/amadeus/namespaces/booking/hotel_bookings.js b/src/amadeus/namespaces/booking/hotel_bookings.js index 7d3b8a4..7a46a15 100644 --- a/src/amadeus/namespaces/booking/hotel_bookings.js +++ b/src/amadeus/namespaces/booking/hotel_bookings.js @@ -25,11 +25,15 @@ class HotelBookings { * To book the hotel offer with ID 'XXX' with guests & payments info * * ```js - * amadeus.booking.hotelBookings.post({ - * 'offerId': 'XXX', - * 'guests': [], - * 'payments': [] - * }); + * amadeus.booking.hotelBookings.post( + * JSON.stringify({ + * 'data': { + * 'offerId': 'XXXX', + * 'guests': [], + * 'payments': [], + * 'rooms': [] + * }}) + * ) * ``` */ post(params = {}) { diff --git a/src/amadeus/namespaces/booking/hotel_orders.js b/src/amadeus/namespaces/booking/hotel_orders.js new file mode 100644 index 0000000..8bc1ff5 --- /dev/null +++ b/src/amadeus/namespaces/booking/hotel_orders.js @@ -0,0 +1,46 @@ +/** + * A namespaced client for the + * `/v2/booking/hotel-orders` endpoints + * + * Access via the {@link Amadeus} object + * + * ```js + * let amadeus = new Amadeus(); + * amadeus.booking.hotelOrders; + * ``` + * + * @param {Client} client + */ +class HotelOrders { + constructor(client) { + this.client = client; + } + + /** + * To book the offer retrieved from Hotel Search API. + * + * @param {Object} params + * @return {Promise.} a Promise + * + * To book the hotel offer with ID 'XXX' with guests, travel agents and payment info + * + * ```js + * amadeus.booking.hotelOrders.post( + * JSON.stringfy({ + * 'data': { + * 'type': 'hotel-order', + * 'guests': [], + * 'travelAgent': {}, + * 'roomAssociations': [], + * 'payment': {} + * }}) + *) + * ``` + */ + post(params = {}) { + + return this.client.post('/v2/booking/hotel-orders', params); + } +} + +export default HotelOrders; \ No newline at end of file