mts-booking-library 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ // import { MTSEnvs } from "../config";
3
+ // import { ServiceBooking } from "../booking/serviceBooking";
4
+ // import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
5
+ // import { Service, ServiceTripsResponse } from "../types/services/Service";
6
+ // import { GetBuyerPassengersDetailsResponse } from "../types/common/Person";
7
+ // import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
8
+ // import { useTestState } from "../mtsStorage";
9
+ // import { SubscriptionBooking } from "../booking/subscriptionBooking";
10
+ // // Load .env file
11
+ // require('dotenv').config();
12
+ // // How to run the test: npm run test -- SubscriptionBooking.test.ts
13
+ // describe("SubscriptionBooking", () => {
14
+ // const timeOut = 120000;
15
+ // const sub_key = process.env.OCP_SUB_KEY_MTS;
16
+ // const access_token = process.env.ACCESS_TOKEN;
17
+ // const sellerId = 8; // ATV
18
+ // // Define localStorage for local testing
19
+ // if (typeof localStorage === "undefined" || localStorage === null) {
20
+ // var LocalStorage = require("node-localstorage").LocalStorage;
21
+ // global.localStorage = new LocalStorage("./scratch");
22
+ // }
23
+ // test("search_tpl", async () => {
24
+ // const booking = new SubscriptionBooking(MTSEnvs.TEST, sub_key!, true, SubscriptionBooking.Languages.EN, access_token, sellerId);
25
+ // // First, get the departures and destinations
26
+ // const departures = await booking.getSubscriptionsDepartures() as string[];
27
+ // expect(departures.length).toBeGreaterThan(0);
28
+ // expect(departures).toContain("BARDOLINO AUTOSTAZIONE");
29
+ // const selectedDeparture = "BARDOLINO AUTOSTAZIONE";
30
+ // const destinations = await booking.getSubscriptionsDestinations(selectedDeparture) as string[];
31
+ // expect(destinations.length).toBeGreaterThan(0);
32
+ // expect(destinations).toContain("GARDA AUTOSTAZIONE");
33
+ // const selectedDestination = "GARDA AUTOSTAZIONE";
34
+ // // Then get the validity types
35
+ // const validityTypes = await booking.getSubscriptionsValidityTypes(selectedDeparture, selectedDestination) as SubscriptionBooking.ValidityTypes[];
36
+ // expect(validityTypes.length).toBeGreaterThan(0);
37
+ // for (const validityType of validityTypes) {
38
+ // // Check that all returned validity types are valid
39
+ // expect(Object.values(SubscriptionBooking.ValidityTypes).includes(validityType)).toBe(true);
40
+ // }
41
+ // }, timeOut);
42
+ // const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
43
+ // const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
44
+ // const services = servicesResponse as Service[];
45
+ // // Build create cart request
46
+ // let tariffsMatrix = services[0].tariffsMatrix;
47
+ // tariffsMatrix[0][0].quantity = 1;
48
+ // const createServiceCartRequest: CreateServiceCartRequest = {
49
+ // currency: ServiceBooking.Currencies.EUR,
50
+ // service: {
51
+ // serviceId: services[0].id,
52
+ // tariffsMatrix: tariffsMatrix
53
+ // }
54
+ // };
55
+ // // Create cart
56
+ // const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
57
+ // return cart;
58
+ // }
59
+ // test("create_service_cart", async () => {
60
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
61
+ // const cart = await createCart(booking);
62
+ // // Check that the cartId was saved to the local storage
63
+ // expect(useTestState().getState().cartId).toBe(cart.id);
64
+ // expect(booking.cartId).toBe(cart.id);
65
+ // // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
66
+ // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
67
+ // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
68
+ // // Test booking due date
69
+ // expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
70
+ // // Test expired tickets
71
+ // expect(cart.hasIssuedTickets).toBe(false);
72
+ // // Test seller data
73
+ // expect(booking.getSellerId()).toBe(cart.sellerId);
74
+ // expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
75
+ // expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
76
+ // // Now try to get the cart
77
+ // const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
78
+ // expect(newBooking.cartId).toBe(cart.id);
79
+ // expect(newBooking.getCart()?.id).toBe(cart.id)
80
+ // expect(newBooking.getSellerId()).toBe(cart.sellerId);
81
+ // // Finally try to delete the cart
82
+ // await booking.deleteCart();
83
+ // expect(booking.getCart()).toBe(undefined);
84
+ // expect(useTestState().getState().cartId).toBe(undefined);
85
+ // }, timeOut);
86
+ // test("get_edit_buyer_data", async () => {
87
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
88
+ // const cart = await createCart(booking);
89
+ // // First, try to get the buyer data
90
+ // let buyerDataResponse = await booking.getBuyerPassengersDetails();
91
+ // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
92
+ // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
93
+ // expect(buyer).toBe(null);
94
+ // // Now try to edit the buyer data
95
+ // buyer = {
96
+ // id: 0,
97
+ // name: "TestName",
98
+ // lastName: "TestSurname",
99
+ // email: "testBookingLib@infos.it",
100
+ // phoneNumber: "+391234567890"
101
+ // }
102
+ // await booking.updateBuyerPassengersDetails(buyer);
103
+ // // Finally, get the buyer data again and check that the data was updated
104
+ // buyerDataResponse = await booking.getBuyerPassengersDetails();
105
+ // const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
106
+ // expect(updatedBuyer.id).toBeGreaterThan(0);
107
+ // expect(updatedBuyer.name).toBe(buyer.name);
108
+ // expect(updatedBuyer.lastName).toBe(buyer.lastName);
109
+ // expect(updatedBuyer.email).toBe(buyer.email);
110
+ // expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
111
+ // // Finally try to delete the cart
112
+ // await booking.deleteCart();
113
+ // expect(booking.getCart()).toBe(undefined);
114
+ // expect(useTestState().getState().cartId).toBe(undefined);
115
+ // }, timeOut);
116
+ // test("get_gateway_info", async () => {
117
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
118
+ // const cart = await createCart(booking);
119
+ // booking.updateSellerId(cart.sellerId);
120
+ // // First, try to get the buyer data
121
+ // let buyerDataResponse = await booking.getBuyerPassengersDetails();
122
+ // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
123
+ // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
124
+ // expect(buyer).toBe(null);
125
+ // // Now try to edit the buyer data
126
+ // buyer = {
127
+ // id: 0,
128
+ // name: "TestName",
129
+ // lastName: "TestSurname",
130
+ // email: "testBookingLib@infos.it",
131
+ // phoneNumber: "+391234567890"
132
+ // }
133
+ // await booking.updateBuyerPassengersDetails(buyer);
134
+ // // Try to get the gateways
135
+ // const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
136
+ // if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
137
+ // throw new Error("No gateways found");
138
+ // }
139
+ // const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
140
+ // expect(gateway?.id).toBeGreaterThan(0);
141
+ // // Now try to get the info
142
+ // const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
143
+ // // Finally try to delete the cart
144
+ // await booking.deleteCart();
145
+ // expect(booking.getCart()).toBe(undefined);
146
+ // expect(useTestState().getState().cartId).toBe(undefined);
147
+ // }, timeOut);
148
+ // });
@@ -1,6 +1,6 @@
1
1
  import { MTSConfig, MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
- import { Cart, processedStepsToStatus } from "../types/common/Cart";
3
+ import { Cart, CreateUpdateCartRequest, processedStepsToStatus } from "../types/common/Cart";
4
4
  import { GetExtrasForBookingResponse, GetExtrasResponse } from "../types/common/Extra";
5
5
  import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueCartResponse } from "../types/common/Payment";
6
6
  import { PersonDetails, GetBuyerPassengersDetailsResponse, GetPersonRequest } from "../types/common/Person";
@@ -40,10 +40,10 @@ export declare abstract class Booking {
40
40
  * @param {string} access_token The new access token
41
41
  */
42
42
  renewAccessToken(access_token: string): void;
43
- callGetApi(url: string, options?: ApiCallOptions): Promise<ErrorResponse | any>;
43
+ callGetApi(url: string, options?: ApiCallOptions): Promise<any>;
44
44
  callPostApi(url: string, body: any, options?: ApiCallOptions): Promise<any>;
45
45
  callPutApi(url: string, body: any, options?: ApiCallOptions): Promise<any>;
46
- callDeleteApi(url: string, options?: ApiCallOptions): Promise<ErrorResponse | any>;
46
+ callDeleteApi(url: string, options?: ApiCallOptions): Promise<any>;
47
47
  getBookingStepsToStatus(): processedStepsToStatus;
48
48
  changeCurrency(currency: Booking.Currencies): void;
49
49
  changeLanguage(language: string): void;
@@ -53,6 +53,7 @@ export declare abstract class Booking {
53
53
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
54
54
  */
55
55
  markBookingStepCompleted(bookingStep: Booking.BookingSteps, options?: ApiCallOptions): Promise<ErrorResponse | boolean>;
56
+ abstract createCart(request: CreateUpdateCartRequest): Promise<ErrorResponse | any>;
56
57
  abstract deleteCart(): Promise<ErrorResponse | any>;
57
58
  abstract resetBooking(): void;
58
59
  abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
@@ -130,7 +131,9 @@ export declare namespace Booking {
130
131
  SEATS_SELECTION = "BOOKING_STEP_SEATS_SELECTION",
131
132
  EXTRAS = "BOOKING_STEP_EXTRAS",
132
133
  DISCOUNTS = "BOOKING_STEP_DISCOUNTS",
133
- ISSUE = "BOOKING_STEP_ISSUE"
134
+ PAYMENT = "BOOKING_STEP_PAYMENT",
135
+ ISSUE = "BOOKING_STEP_ISSUE",
136
+ SUMMARY = "BOOKING_STEP_SUMMARY"
134
137
  }
135
138
  enum BookingTypes {
136
139
  MLP = "MLP",
@@ -185,9 +185,8 @@ var Booking = /** @class */ (function () {
185
185
  return [2 /*return*/, true];
186
186
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/bookingSteps");
187
187
  return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep, cartGuid: this.cartGuid }, options).then(function (response) {
188
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
188
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
189
189
  return response;
190
- }
191
190
  // Update the booking process status
192
191
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
193
192
  return true;
@@ -220,9 +219,8 @@ var Booking = /** @class */ (function () {
220
219
  url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
221
220
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
222
221
  // Check for errors
223
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
222
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
224
223
  return response;
225
- }
226
224
  // Return the person details
227
225
  var person = __assign(__assign({}, response.persons[0]), { socialSecurityNumber: response.persons[0].personDetails.socialSecurityNumber });
228
226
  return person;
@@ -341,9 +339,8 @@ var Booking = /** @class */ (function () {
341
339
  paymentMethodToSet = Payment_1.PaymentMethods.CASH;
342
340
  return true;
343
341
  }
344
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
342
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
345
343
  return response;
346
- }
347
344
  })];
348
345
  case 1:
349
346
  _c.sent();
@@ -384,9 +381,7 @@ var Booking = /** @class */ (function () {
384
381
  paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet
385
382
  };
386
383
  return [2 /*return*/, this.callPostApi(url, body, options).then(function (response) {
387
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
388
- ? response
389
- : response;
384
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
390
385
  })];
391
386
  }
392
387
  });
@@ -440,9 +435,8 @@ var Booking = /** @class */ (function () {
440
435
  return [4 /*yield*/, this.callPutApi(url, body, options)];
441
436
  case 1:
442
437
  res = _a.sent();
443
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(res)) {
438
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(res))
444
439
  return [2 /*return*/, res];
445
- }
446
440
  return [4 /*yield*/, this.fetchAndSetCart(cartGuid)];
447
441
  case 2:
448
442
  _a.sent();
@@ -476,7 +470,9 @@ exports.Booking = Booking;
476
470
  BookingSteps["SEATS_SELECTION"] = "BOOKING_STEP_SEATS_SELECTION";
477
471
  BookingSteps["EXTRAS"] = "BOOKING_STEP_EXTRAS";
478
472
  BookingSteps["DISCOUNTS"] = "BOOKING_STEP_DISCOUNTS";
473
+ BookingSteps["PAYMENT"] = "BOOKING_STEP_PAYMENT";
479
474
  BookingSteps["ISSUE"] = "BOOKING_STEP_ISSUE";
475
+ BookingSteps["SUMMARY"] = "BOOKING_STEP_SUMMARY";
480
476
  })(BookingSteps = Booking.BookingSteps || (Booking.BookingSteps = {}));
481
477
  var BookingTypes;
482
478
  (function (BookingTypes) {
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
3
4
  import { AddReductionRequest } from "../types/common/Reduction";
4
5
  import { BusMatrix } from "../types/journeys/BusMatrix";
@@ -88,6 +89,12 @@ export declare class JourneyBooking extends Booking {
88
89
  * @returns The returned journeys that match the given parameters
89
90
  */
90
91
  getJourneys(request: JourneySearchRequest, options?: ApiCallOptions): Promise<ErrorResponse | JourneySearchResult[]>;
92
+ /**
93
+ * This method creates a journey cart (MLP) for the given parameters.
94
+ * @returns The created cart
95
+ */
96
+ createCart(request: CreateUpdateCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | JourneyCart>;
97
+ /** @deprecated Use {@link createCart} instead. */
91
98
  createJourneyCart(journeyCart: CreateJourneyCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | JourneyCart>;
92
99
  /**
93
100
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
@@ -198,7 +198,7 @@ var JourneyBooking = /** @class */ (function (_super) {
198
198
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
199
199
  // Clear all data
200
200
  _this.resetBooking();
201
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
201
+ return response;
202
202
  })];
203
203
  });
204
204
  });
@@ -213,9 +213,7 @@ var JourneyBooking = /** @class */ (function (_super) {
213
213
  return __generator(this, function (_a) {
214
214
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?");
215
215
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
216
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
217
- ? response
218
- : response.stops;
216
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
219
217
  })];
220
218
  });
221
219
  });
@@ -232,9 +230,7 @@ var JourneyBooking = /** @class */ (function (_super) {
232
230
  searchParams = new URLSearchParams({ departureStopName: departureStopName });
233
231
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
234
232
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
235
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
236
- ? response
237
- : response.stops;
233
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
238
234
  })];
239
235
  });
240
236
  });
@@ -263,6 +259,45 @@ var JourneyBooking = /** @class */ (function (_super) {
263
259
  });
264
260
  });
265
261
  };
262
+ /**
263
+ * This method creates a journey cart (MLP) for the given parameters.
264
+ * @returns The created cart
265
+ */
266
+ JourneyBooking.prototype.createCart = function (request, options) {
267
+ return __awaiter(this, void 0, void 0, function () {
268
+ var url;
269
+ var _this = this;
270
+ return __generator(this, function (_a) {
271
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts");
272
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
273
+ return __generator(this, function (_a) {
274
+ switch (_a.label) {
275
+ case 0:
276
+ // Check for errors
277
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
278
+ // If there was an error, reset cartGuid and remove it from the mts-storage
279
+ this.resetBooking();
280
+ return [2 /*return*/, response];
281
+ }
282
+ // Fetch the newly created cart & update local properties
283
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
284
+ case 1:
285
+ // Fetch the newly created cart & update local properties
286
+ _a.sent();
287
+ if (!this.cart) {
288
+ // Should already be handled, but just in case
289
+ throw new Error("Could not fetch cart");
290
+ }
291
+ // Update storage
292
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
293
+ return [2 /*return*/, this.cart];
294
+ }
295
+ });
296
+ }); })];
297
+ });
298
+ });
299
+ };
300
+ /** @deprecated Use {@link createCart} instead. */
266
301
  JourneyBooking.prototype.createJourneyCart = function (journeyCart, options) {
267
302
  return __awaiter(this, void 0, void 0, function () {
268
303
  var url, request;
@@ -334,9 +369,8 @@ var JourneyBooking = /** @class */ (function (_super) {
334
369
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
335
370
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
336
371
  // Check for errors
337
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
372
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
338
373
  return response;
339
- }
340
374
  // For each passenger, parse the outbound and return tariffs
341
375
  var passengers = response.passengers;
342
376
  passengers.map(function (passenger) {
@@ -396,9 +430,8 @@ var JourneyBooking = /** @class */ (function (_super) {
396
430
  });
397
431
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
398
432
  return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) {
399
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
433
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
400
434
  return response;
401
- }
402
435
  // Update the booking process status
403
436
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
404
437
  return true;
@@ -433,9 +466,7 @@ var JourneyBooking = /** @class */ (function (_super) {
433
466
  });
434
467
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/seats?").concat(searchParams);
435
468
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
436
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
437
- ? response
438
- : response.busMatrix;
469
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.busMatrix;
439
470
  })];
440
471
  });
441
472
  });
@@ -463,9 +494,7 @@ var JourneyBooking = /** @class */ (function (_super) {
463
494
  });
464
495
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/seats?").concat(searchParams);
465
496
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
466
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
467
- ? response
468
- : response.assignedSeats;
497
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
469
498
  })];
470
499
  });
471
500
  });
@@ -495,9 +524,8 @@ var JourneyBooking = /** @class */ (function (_super) {
495
524
  newSeatsIds: newSeatsIds,
496
525
  cartGuid: this.cart.guid
497
526
  }, options).then(function (response) {
498
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
527
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
499
528
  return response;
500
- }
501
529
  // Update the booking process status
502
530
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
503
531
  return true;
@@ -523,9 +551,7 @@ var JourneyBooking = /** @class */ (function (_super) {
523
551
  searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
524
552
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction/trips?").concat(searchParams);
525
553
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
526
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
527
- ? response
528
- : response.trips;
554
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
529
555
  })];
530
556
  });
531
557
  });
@@ -575,9 +601,8 @@ var JourneyBooking = /** @class */ (function (_super) {
575
601
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
576
602
  return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid }), options).then(function (response) {
577
603
  var _a, _b;
578
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
604
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
579
605
  return response;
580
- }
581
606
  var reductionResponse = response;
582
607
  // Update the booking process status
583
608
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -615,9 +640,8 @@ var JourneyBooking = /** @class */ (function (_super) {
615
640
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
616
641
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
617
642
  var _a, _b, _c;
618
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
643
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
619
644
  return response;
620
- }
621
645
  var reductionResponse = response;
622
646
  // Update the booking process status
623
647
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -682,9 +706,8 @@ var JourneyBooking = /** @class */ (function (_super) {
682
706
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
683
707
  return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }, options).then(function (response) {
684
708
  var _a, _b;
685
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
709
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
686
710
  return response;
687
- }
688
711
  var reductionResponse = response;
689
712
  // Update the booking process status
690
713
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -714,9 +737,8 @@ var JourneyBooking = /** @class */ (function (_super) {
714
737
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
715
738
  return [2 /*return*/, this.callDeleteApi(url, options).then(function (response) {
716
739
  var _a, _b, _c;
717
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
740
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
718
741
  return response;
719
- }
720
742
  var reductionResponse = response;
721
743
  // Update the booking process status
722
744
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -774,9 +796,8 @@ var JourneyBooking = /** @class */ (function (_super) {
774
796
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
775
797
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }, options).then(function (response) {
776
798
  var _a, _b;
777
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
799
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
778
800
  return response;
779
- }
780
801
  var reductionResponse = response;
781
802
  // Update the booking process status
782
803
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { PersonDetails, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
3
4
  import { AddReductionRequest } from "../types/common/Reduction";
4
5
  import { Service, ServiceTripsResponse } from "../types/services/Service";
@@ -90,6 +91,12 @@ export declare class ServiceBooking extends Booking {
90
91
  * @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
91
92
  */
92
93
  getServiceTrips(serviceId: number, date: string, options?: ApiCallOptions): Promise<ErrorResponse | ServiceTripsResponse>;
94
+ /**
95
+ * This method creates a service cart for the given parameters.
96
+ * @returns The created cart
97
+ */
98
+ createCart(request: CreateUpdateCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | ServiceCart>;
99
+ /** @deprecated Use {@link createCart} instead. */
93
100
  createServiceCart(serviceCart: CreateServiceCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | ServiceCart>;
94
101
  /**
95
102
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.