Skip to content

Commit

Permalink
Merge pull request #216 from amadeus4dev/HotelBookingV2
Browse files Browse the repository at this point in the history
Added Hotel booking v2
  • Loading branch information
tsolakoua authored Jun 20, 2024
2 parents 04c6938 + 6b18472 commit a22a453
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 12 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/amadeus/namespaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/amadeus/namespaces/booking.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,13 +18,15 @@ import HotelBookings from './booking/hotel_bookings';
* @property {FlightOrders} flightOrders
* @property {FlightOrder} flightOrder
* @property {HotelBookings} hotelBookings
* @property {HotelOrders} hotelOrders
* @protected
*/
class Booking {
constructor(client) {
this.client = client;
this.flightOrders = new FlightOrders(client);
this.hotelBookings = new HotelBookings(client);
this.hotelOrders = new HotelOrders(client);
}

flightOrder (orderId) {
Expand Down
2 changes: 1 addition & 1 deletion src/amadeus/namespaces/booking/flight_orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FlightOrders {
* amadeus.booking.flightOrders.post({
* 'type': 'flight-order',
* 'flightOffers': [],
* 'travelers_info': []
* 'travelers': []
* });
* ```
*/
Expand Down
14 changes: 9 additions & 5 deletions src/amadeus/namespaces/booking/hotel_bookings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
46 changes: 46 additions & 0 deletions src/amadeus/namespaces/booking/hotel_orders.js
Original file line number Diff line number Diff line change
@@ -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.<Response,ResponseError>} 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;

0 comments on commit a22a453

Please sign in to comment.