mts-booking-library 1.3.6 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,16 +22,16 @@ export declare abstract class Booking {
22
22
  cartId: number | undefined;
23
23
  bookingDueDate: Date | undefined;
24
24
  /**
25
- * This is the constructor of the Booking class.
26
- * @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
27
- * @param {string} sub_key The subscription key for using the APIs
28
- * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
29
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
30
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
31
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
32
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
33
- * @param {number} [resellerId=undefined] The id of the reseller.
34
- */
25
+ * This is the constructor of the Booking class.
26
+ * @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
27
+ * @param {string} sub_key The subscription key for using the APIs
28
+ * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
29
+ * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
30
+ * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
31
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
32
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
33
+ * @param {number} [resellerId=undefined] The id of the reseller.
34
+ */
35
35
  constructor(env: MTSEnvs, sub_key: string, bookingType: Booking.BookingTypes, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
36
36
  /**
37
37
  * This method allows to update the sellerId. It is mostly important for Linkavel, as we start with sellerId = 0
@@ -55,16 +55,16 @@ var apiCall_1 = require("../utils/apiCall");
55
55
  var processBookingSteps_1 = require("../utils/processBookingSteps");
56
56
  var Booking = /** @class */ (function () {
57
57
  /**
58
- * This is the constructor of the Booking class.
59
- * @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
60
- * @param {string} sub_key The subscription key for using the APIs
61
- * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
62
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
63
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
64
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
65
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
66
- * @param {number} [resellerId=undefined] The id of the reseller.
67
- */
58
+ * This is the constructor of the Booking class.
59
+ * @param {string} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
60
+ * @param {string} sub_key The subscription key for using the APIs
61
+ * @param {Booking.BookingTypes} bookingType The type of booking. Can be "MLP", "SERVICE" or "MLP_SUBSCRIPTION"
62
+ * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
63
+ * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
64
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
65
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
66
+ * @param {number} [resellerId=undefined] The id of the reseller.
67
+ */
68
68
  function Booking(env, sub_key, bookingType, debug, language, access_token, sellerId, resellerId) {
69
69
  if (debug === void 0) { debug = false; }
70
70
  if (language === void 0) { language = Booking.Languages.EN; }
@@ -207,7 +207,11 @@ var Booking = /** @class */ (function () {
207
207
  if (!issueStep)
208
208
  throw Error("Booking step: ".concat(Booking.BookingSteps.ISSUE, " not found!"));
209
209
  if (!!issueStep[0]) return [3 /*break*/, 5];
210
- _i = 0, _a = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
210
+ _i = 0, _a = [
211
+ Booking.BookingSteps.SEATS_SELECTION,
212
+ Booking.BookingSteps.EXTRAS,
213
+ Booking.BookingSteps.DISCOUNTS
214
+ ];
211
215
  _c.label = 1;
212
216
  case 1:
213
217
  if (!(_i < _a.length)) return [3 /*break*/, 4];
@@ -231,7 +235,9 @@ var Booking = /** @class */ (function () {
231
235
  url = "".concat(this.config.API_ENDPOINT, "/v3_resources/sellers/").concat(this.sellerId, "/gateways?");
232
236
  // We use directly makeGet because we don't want to add sellerId to the query string (it is already present in the url)
233
237
  return [2 /*return*/, (0, apiCall_1.makeGet)(url).then(function (response) {
234
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
238
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
239
+ ? response
240
+ : response;
235
241
  })];
236
242
  }
237
243
  });
@@ -259,7 +265,9 @@ var Booking = /** @class */ (function () {
259
265
  searchParams = new URLSearchParams(__assign({ gatewayId: gatewayId.toString() }, (returnUrl && { returnUrl: returnUrl })));
260
266
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment?").concat(searchParams);
261
267
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
262
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
268
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
269
+ ? response
270
+ : response;
263
271
  })];
264
272
  });
265
273
  });
@@ -301,7 +309,11 @@ var Booking = /** @class */ (function () {
301
309
  if (!issueStep)
302
310
  throw Error("Booking step not found!");
303
311
  if (!!issueStep[0]) return [3 /*break*/, 7];
304
- _i = 0, _a = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
312
+ _i = 0, _a = [
313
+ Booking.BookingSteps.SEATS_SELECTION,
314
+ Booking.BookingSteps.EXTRAS,
315
+ Booking.BookingSteps.DISCOUNTS
316
+ ];
305
317
  _c.label = 3;
306
318
  case 3:
307
319
  if (!(_i < _a.length)) return [3 /*break*/, 6];
@@ -325,10 +337,12 @@ var Booking = /** @class */ (function () {
325
337
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/issue");
326
338
  body = {
327
339
  cartId: this.cartId,
328
- paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
340
+ paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet
329
341
  };
330
342
  return [2 /*return*/, this.callPostApi(url, body).then(function (response) {
331
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
343
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
344
+ ? response
345
+ : response;
332
346
  })];
333
347
  }
334
348
  });
@@ -10,16 +10,17 @@ import { Booking } from "./booking";
10
10
  export declare class JourneyBooking extends Booking {
11
11
  private cart?;
12
12
  /**
13
- * This is the constructor of the ServiceBooking class.
14
- * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
15
- * @param {string} sub_key The subscription key for using the APIs
16
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
17
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
18
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
19
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
20
- * @param {number} [resellerId=undefined] The id of the reseller.
21
- */
22
- constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
13
+ * This is the constructor of the ServiceBooking class.
14
+ * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
15
+ * @param {string} sub_key The subscription key for using the APIs
16
+ * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
17
+ * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
18
+ * @param {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
19
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
20
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
21
+ * @param {number} [resellerId=undefined] The id of the reseller.
22
+ */
23
+ constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
23
24
  getCart(): JourneyCart | undefined;
24
25
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
25
26
  cartId: number | undefined;
@@ -77,23 +78,23 @@ export declare class JourneyBooking extends Booking {
77
78
  */
78
79
  deleteCart(): Promise<ErrorResponse | any>;
79
80
  /**
80
- * This method returns the possible departures for all journeys (MLP) sold by this seller.
81
- * @returns {string[]} The list of possible departures
82
- */
81
+ * This method returns the possible departures for all journeys (MLP) sold by this seller.
82
+ * @returns {string[]} The list of possible departures
83
+ */
83
84
  getJourneysDepartures(): Promise<ErrorResponse | string[]>;
84
85
  /**
85
- * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
86
- * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
87
- * @returns {string[]} The list of possible destinations
88
- */
86
+ * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
87
+ * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
88
+ * @returns {string[]} The list of possible destinations
89
+ */
89
90
  getJourneysDestinations(departureStopName: string): Promise<ErrorResponse | string[]>;
90
91
  /**
91
- * This method returns the journeys that match the given parameters.
92
- * Note that it will always return the journeys for the one-way trip.
93
- * If you want to get the journeys for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
94
- * @param {JourneySearch} request an object of type {@link JourneySearch} containing the parameters of the search
95
- * @returns {JourneySearchResult[]} The returned journeys that match the given parameters
96
- */
92
+ * This method returns the journeys that match the given parameters.
93
+ * Note that it will always return the journeys for the one-way trip.
94
+ * If you want to get the journeys for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
95
+ * @param {JourneySearch} request an object of type {@link JourneySearch} containing the parameters of the search
96
+ * @returns {JourneySearchResult[]} The returned journeys that match the given parameters
97
+ */
97
98
  getJourneys(request: JourneySearchRequest): Promise<ErrorResponse | JourneySearchResult[]>;
98
99
  createJourneyCart(journeyCart: CreateJourneyCartRequest): Promise<ErrorResponse | JourneyCart>;
99
100
  /**
@@ -182,5 +183,5 @@ export declare class JourneyBooking extends Booking {
182
183
  useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
183
184
  }
184
185
  export declare namespace JourneyBooking {
185
- const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
186
+ const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
186
187
  }
@@ -81,23 +81,25 @@ var booking_1 = require("./booking");
81
81
  var JourneyBooking = /** @class */ (function (_super) {
82
82
  __extends(JourneyBooking, _super);
83
83
  /**
84
- * This is the constructor of the ServiceBooking class.
85
- * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
86
- * @param {string} sub_key The subscription key for using the APIs
87
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
88
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
89
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
90
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
91
- * @param {number} [resellerId=undefined] The id of the reseller.
92
- */
93
- function JourneyBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
84
+ * This is the constructor of the ServiceBooking class.
85
+ * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
86
+ * @param {string} sub_key The subscription key for using the APIs
87
+ * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
88
+ * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
89
+ * @param {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
90
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
91
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
92
+ * @param {number} [resellerId=undefined] The id of the reseller.
93
+ */
94
+ function JourneyBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
94
95
  if (debug === void 0) { debug = false; }
95
96
  if (language === void 0) { language = booking_1.Booking.Languages.EN; }
97
+ if (restoreState === void 0) { restoreState = true; }
96
98
  // Call Booking constructor
97
99
  var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
98
100
  // Set cartId
99
101
  var cartId = _this.getStorage().getState().cartId;
100
- if (cartId) {
102
+ if (cartId && restoreState) {
101
103
  _this.cartId = cartId;
102
104
  }
103
105
  return _this;
@@ -166,7 +168,7 @@ var JourneyBooking = /** @class */ (function (_super) {
166
168
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
167
169
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
168
170
  _this.resetBooking();
169
- throw new Error(response);
171
+ throw new Error(JSON.stringify(response, null, 2));
170
172
  }
171
173
  // Check that the cart does not have issued tickets
172
174
  if (response.cart.hasIssuedTickets) {
@@ -201,25 +203,27 @@ var JourneyBooking = /** @class */ (function (_super) {
201
203
  });
202
204
  };
203
205
  /**
204
- * This method returns the possible departures for all journeys (MLP) sold by this seller.
205
- * @returns {string[]} The list of possible departures
206
- */
206
+ * This method returns the possible departures for all journeys (MLP) sold by this seller.
207
+ * @returns {string[]} The list of possible departures
208
+ */
207
209
  JourneyBooking.prototype.getJourneysDepartures = function () {
208
210
  return __awaiter(this, void 0, void 0, function () {
209
211
  var url;
210
212
  return __generator(this, function (_a) {
211
213
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?");
212
214
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
213
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
215
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
216
+ ? response
217
+ : response.stops;
214
218
  })];
215
219
  });
216
220
  });
217
221
  };
218
222
  /**
219
- * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
220
- * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
221
- * @returns {string[]} The list of possible destinations
222
- */
223
+ * This method returns the possible destination for the journeys sold by this seller that start at the selected departure.
224
+ * @param {string} departureStopName The departure stop name (as returned by {@link getJourneysDepartures})
225
+ * @returns {string[]} The list of possible destinations
226
+ */
223
227
  JourneyBooking.prototype.getJourneysDestinations = function (departureStopName) {
224
228
  return __awaiter(this, void 0, void 0, function () {
225
229
  var searchParams, url;
@@ -227,18 +231,20 @@ var JourneyBooking = /** @class */ (function (_super) {
227
231
  searchParams = new URLSearchParams({ departureStopName: departureStopName });
228
232
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
229
233
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
230
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
234
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
235
+ ? response
236
+ : response.stops;
231
237
  })];
232
238
  });
233
239
  });
234
240
  };
235
241
  /**
236
- * This method returns the journeys that match the given parameters.
237
- * Note that it will always return the journeys for the one-way trip.
238
- * If you want to get the journeys for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
239
- * @param {JourneySearch} request an object of type {@link JourneySearch} containing the parameters of the search
240
- * @returns {JourneySearchResult[]} The returned journeys that match the given parameters
241
- */
242
+ * This method returns the journeys that match the given parameters.
243
+ * Note that it will always return the journeys for the one-way trip.
244
+ * If you want to get the journeys for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
245
+ * @param {JourneySearch} request an object of type {@link JourneySearch} containing the parameters of the search
246
+ * @returns {JourneySearchResult[]} The returned journeys that match the given parameters
247
+ */
242
248
  JourneyBooking.prototype.getJourneys = function (request) {
243
249
  return __awaiter(this, void 0, void 0, function () {
244
250
  var searchParams, url;
@@ -249,7 +255,9 @@ var JourneyBooking = /** @class */ (function (_super) {
249
255
  searchParams = new URLSearchParams(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), date: request.date, roundTripDate: request.roundTripDate ? request.roundTripDate : "null", currency: request.currency }, (this.cartId && { cartId: this.cartId.toString() })));
250
256
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys?").concat(searchParams);
251
257
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
252
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.journeys;
258
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
259
+ ? response
260
+ : response.journeys;
253
261
  })];
254
262
  });
255
263
  });
@@ -319,18 +327,20 @@ var JourneyBooking = /** @class */ (function (_super) {
319
327
  ];
320
328
  }));
321
329
  // Parse the return tariffs
322
- passenger.returnTariffs = passenger.returnTariffs ? new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
323
- var tripId = _a[0], tariffs = _a[1];
324
- return [
325
- +tripId,
326
- tariffs
327
- ];
328
- })) : null;
330
+ passenger.returnTariffs = passenger.returnTariffs
331
+ ? new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
332
+ var tripId = _a[0], tariffs = _a[1];
333
+ return [
334
+ +tripId,
335
+ tariffs
336
+ ];
337
+ }))
338
+ : null;
329
339
  });
330
340
  return {
331
341
  buyerDataStatus: response.buyerDataStatus,
332
342
  buyer: response.buyer,
333
- passengers: passengers,
343
+ passengers: passengers
334
344
  };
335
345
  })];
336
346
  });
@@ -435,7 +445,9 @@ var JourneyBooking = /** @class */ (function (_super) {
435
445
  });
436
446
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/").concat(tripId, "/seats?").concat(searchParams);
437
447
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
438
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.busMatrix;
448
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
449
+ ? response
450
+ : response.busMatrix;
439
451
  })];
440
452
  });
441
453
  });
@@ -460,7 +472,9 @@ var JourneyBooking = /** @class */ (function (_super) {
460
472
  searchParams = new URLSearchParams({ tripId: tripId.toString() });
461
473
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/seats?").concat(searchParams);
462
474
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
463
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
475
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
476
+ ? response
477
+ : response.assignedSeats;
464
478
  })];
465
479
  });
466
480
  });
@@ -513,7 +527,9 @@ var JourneyBooking = /** @class */ (function (_super) {
513
527
  }
514
528
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/payment/reduction/trips?");
515
529
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
516
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
530
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
531
+ ? response
532
+ : response.trips;
517
533
  })];
518
534
  });
519
535
  });
@@ -607,9 +623,11 @@ var JourneyBooking = /** @class */ (function (_super) {
607
623
  // Update the booking process status
608
624
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
609
625
  // Update the cart
610
- _this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) { return reduction.type === Reduction_1.ReductionType.WALLET ||
611
- reduction.type === Reduction_1.ReductionType.VOUCHER ||
612
- (reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId); })) !== null && _c !== void 0 ? _c : [] });
626
+ _this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) {
627
+ return reduction.type === Reduction_1.ReductionType.WALLET ||
628
+ reduction.type === Reduction_1.ReductionType.VOUCHER ||
629
+ (reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId);
630
+ })) !== null && _c !== void 0 ? _c : [] });
613
631
  return true;
614
632
  })];
615
633
  });
@@ -637,7 +655,11 @@ var JourneyBooking = /** @class */ (function (_super) {
637
655
  if (!issueStep)
638
656
  throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
639
657
  if (!!issueStep[0]) return [3 /*break*/, 5];
640
- _i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
658
+ _i = 0, _a = [
659
+ booking_1.Booking.BookingSteps.SEATS_SELECTION,
660
+ booking_1.Booking.BookingSteps.EXTRAS,
661
+ booking_1.Booking.BookingSteps.DISCOUNTS
662
+ ];
641
663
  _c.label = 1;
642
664
  case 1:
643
665
  if (!(_i < _a.length)) return [3 /*break*/, 4];
@@ -771,12 +793,12 @@ var JourneyBooking = /** @class */ (function (_super) {
771
793
  exports.JourneyBooking = JourneyBooking;
772
794
  (function (JourneyBooking) {
773
795
  var _this = this;
774
- JourneyBooking.createBooking = function (env, sub_key, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
796
+ JourneyBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
775
797
  var booking, error_1;
776
798
  return __generator(this, function (_a) {
777
799
  switch (_a.label) {
778
800
  case 0:
779
- booking = new JourneyBooking(env, sub_key, debug, language, access_token, sellerId, resellerId);
801
+ booking = new JourneyBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
780
802
  _a.label = 1;
781
803
  case 1:
782
804
  _a.trys.push([1, 4, , 5]);
@@ -8,16 +8,17 @@ import { Booking } from "./booking";
8
8
  export declare class ServiceBooking extends Booking {
9
9
  private cart?;
10
10
  /**
11
- * This is the constructor of the ServiceBooking class.
12
- * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
13
- * @param {string} sub_key The subscription key for using the APIs
14
- * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
15
- * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
16
- * @param {string} [access_token=undefined] The access token for calling MTS APIs
17
- * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
18
- * @param {number} [resellerId=undefined] The id of the reseller.
19
- */
20
- constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
11
+ * This is the constructor of the ServiceBooking class.
12
+ * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
13
+ * @param {string} sub_key The subscription key for using the APIs
14
+ * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
15
+ * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
16
+ * @param {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
17
+ * @param {string} [access_token=undefined] The access token for calling MTS APIs
18
+ * @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
19
+ * @param {number} [resellerId=undefined] The id of the reseller.
20
+ */
21
+ constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
21
22
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
22
23
  cartId: number | undefined;
23
24
  } & {
@@ -69,33 +70,33 @@ export declare class ServiceBooking extends Booking {
69
70
  fetchAndSetCart(cartId: number): Promise<void>;
70
71
  fetchCart(cartId: number): Promise<ServiceCart>;
71
72
  /**
72
- * This method allows to delete a cart, thus allowing the user to exit from the booking process.
73
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
74
- * data will be deleted.
75
- */
73
+ * This method allows to delete a cart, thus allowing the user to exit from the booking process.
74
+ * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
75
+ * data will be deleted.
76
+ */
76
77
  deleteCart(): Promise<ErrorResponse | any>;
77
78
  /**
78
- * This method returns the list of cities in which the seller offers tours.
79
- * If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
80
- * @returns {string[]} The list of possible cities
81
- */
79
+ * This method returns the list of cities in which the seller offers tours.
80
+ * If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
81
+ * @returns {string[]} The list of possible cities
82
+ */
82
83
  getServiceCities(): Promise<ErrorResponse | string[]>;
83
84
  /**
84
- * This method returns the tours sold by this seller in the given city.
85
- * If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
86
- * @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
87
- * @param {Booking.Currencies} currency The currency in which the prices should be returned
88
- * @returns {Tour[]} The returned tours
89
- */
85
+ * This method returns the tours sold by this seller in the given city.
86
+ * If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
87
+ * @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
88
+ * @param {Booking.Currencies} currency The currency in which the prices should be returned
89
+ * @returns {Tour[]} The returned tours
90
+ */
90
91
  getServices(currency: Booking.Currencies, cityName?: string): Promise<ErrorResponse | Service[]>;
91
92
  /**
92
- * This method returns the tours available for the given date. This method can be used if the seller wants the user to book a specific date
93
- * and/or a specific hour for the tour.
94
- * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
95
- * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
96
- * @param {string} date The date on which to get the tours, in ISO string format
97
- * @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
98
- */
93
+ * This method returns the tours available for the given date. This method can be used if the seller wants the user to book a specific date
94
+ * and/or a specific hour for the tour.
95
+ * You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
96
+ * @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
97
+ * @param {string} date The date on which to get the tours, in ISO string format
98
+ * @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
99
+ */
99
100
  getServiceTrips(serviceId: number, date: string): Promise<ErrorResponse | ServiceTripsResponse>;
100
101
  createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
101
102
  /**
@@ -156,5 +157,5 @@ export declare class ServiceBooking extends Booking {
156
157
  useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
157
158
  }
158
159
  export declare namespace ServiceBooking {
159
- const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
160
+ const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
160
161
  }