mts-booking-library 1.2.32 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -73,6 +73,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
73
73
  Object.defineProperty(exports, "__esModule", { value: true });
74
74
  exports.SubscriptionBooking = void 0;
75
75
  var config_1 = require("../config");
76
+ var mtsStorage_1 = require("../mtsStorage");
76
77
  var ErrorResponse_1 = require("../types/ErrorResponse");
77
78
  var Reduction_1 = require("../types/common/Reduction");
78
79
  var processBookingSteps_1 = require("../utils/processBookingSteps");
@@ -95,12 +96,18 @@ var SubscriptionBooking = /** @class */ (function (_super) {
95
96
  // Call Booking constructor
96
97
  var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
97
98
  // Set cartId
98
- var cartId = localStorage.getItem("cartId");
99
+ var cartId = _this.getStorage().getState().cartId;
99
100
  if (cartId) {
100
- _this.cartId = parseInt(cartId);
101
+ _this.cartId = cartId;
101
102
  }
102
103
  return _this;
103
104
  }
105
+ SubscriptionBooking.prototype.getStorage = function () {
106
+ if (this.config.ENV !== config_1.MTSEnvs.TEST) {
107
+ return (0, mtsStorage_1.useMtsBookingState)();
108
+ }
109
+ return (0, mtsStorage_1.useTestState)();
110
+ };
104
111
  SubscriptionBooking.prototype.getCart = function () {
105
112
  return this.cart;
106
113
  };
@@ -110,11 +117,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
110
117
  this.bookingStepsToStatus = new Map();
111
118
  this.bookingDueDate = undefined;
112
119
  try {
113
- localStorage.removeItem("cartId");
120
+ this.getStorage().getState().updateCartId(undefined);
114
121
  }
115
122
  catch (e) {
116
123
  if (this.config.ENV !== config_1.MTSEnvs.TEST) {
117
- throw new Error("Error while deleting cartId from localStorage");
124
+ throw new Error("Error while deleting cartId from storage");
118
125
  }
119
126
  console.log(e);
120
127
  }
@@ -154,7 +161,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
154
161
  var url;
155
162
  var _this = this;
156
163
  return __generator(this, function (_a) {
157
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
164
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
158
165
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
159
166
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
160
167
  _this.resetBooking();
@@ -183,7 +190,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
183
190
  if (!this.cart || !this.cartId) {
184
191
  throw Error("Cart is not initialized yet");
185
192
  }
186
- url = "".concat(this.config.API_ENDPOINT, "/booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
193
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
187
194
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
188
195
  _this.resetBooking();
189
196
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
@@ -199,7 +206,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
199
206
  return __awaiter(this, void 0, void 0, function () {
200
207
  var url;
201
208
  return __generator(this, function (_a) {
202
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/departures?");
209
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/departures?");
203
210
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
204
211
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.departures;
205
212
  })];
@@ -216,7 +223,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
216
223
  var searchParams, url;
217
224
  return __generator(this, function (_a) {
218
225
  searchParams = new URLSearchParams({ departureStopName: departureStopName });
219
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/destinations?").concat(searchParams);
226
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/destinations?").concat(searchParams);
220
227
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
221
228
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.destinations;
222
229
  })];
@@ -238,7 +245,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
238
245
  departureStopName: departureStopName,
239
246
  destinationStopName: destinationStopName
240
247
  });
241
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/validityTypes?").concat(searchParams);
248
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/validityTypes?").concat(searchParams);
242
249
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
243
250
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.validityTypes;
244
251
  })];
@@ -263,7 +270,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
263
270
  destinationStopName: destinationStopName,
264
271
  validityType: validityType
265
272
  });
266
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/search?").concat(searchParams);
273
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/search?").concat(searchParams);
267
274
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
268
275
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.subscriptions;
269
276
  })];
@@ -290,7 +297,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
290
297
  numberOfPassengers: request.numberOfPassengers.toString(),
291
298
  validityType: request.validityType
292
299
  });
293
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/availabilities?").concat(searchParams);
300
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/availabilities?").concat(searchParams);
294
301
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
295
302
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
296
303
  })];
@@ -307,18 +314,18 @@ var SubscriptionBooking = /** @class */ (function (_super) {
307
314
  var url;
308
315
  var _this = this;
309
316
  return __generator(this, function (_a) {
310
- url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions");
317
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/cart");
311
318
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
312
319
  // Check for errors
313
320
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
314
- // If there was an error, reset cartId and remove it from the localStorage
321
+ // If there was an error, reset cartId and remove it from the mts-storage
315
322
  _this.resetBooking();
316
323
  return response;
317
324
  }
318
325
  _this.cart = response.cart;
319
326
  _this.cartId = response.cart.id;
320
- // Save the cartId in the localStorage
321
- localStorage.setItem("cartId", response.cart.id.toString());
327
+ // Save the cartId in the mts-storage
328
+ _this.getStorage().getState().updateCartId(response.cart.id);
322
329
  // Fill the booking process status
323
330
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
324
331
  _this.bookingDueDate = new Date(response.cart.bookingDueDate);
@@ -346,7 +353,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
346
353
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
347
354
  throw Error("The status of the cart does not allow to call this API");
348
355
  }
349
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?");
356
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details?");
350
357
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
351
358
  // Check for errors
352
359
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -405,7 +412,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
405
412
  throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
406
413
  }
407
414
  searchParams = new URLSearchParams(__assign(__assign({}, (linkavelCardNumber && { linkavelCardNumber: linkavelCardNumber })), (linkavelCardPhoneNumber && { linkavelCardPhoneNumber: linkavelCardPhoneNumber })));
408
- url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams);
415
+ url = "".concat(this.config.API_ENDPOINT, "/v3_resources/buyers?").concat(searchParams);
409
416
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
410
417
  // Check for errors
411
418
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -442,7 +449,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
442
449
  });
443
450
  request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
444
451
  });
445
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
452
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details");
446
453
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
447
454
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
448
455
  return response;
@@ -461,12 +468,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
461
468
  * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
462
469
  */
463
470
  SubscriptionBooking.prototype.addReduction = function (request) {
464
- var _a;
465
471
  return __awaiter(this, void 0, void 0, function () {
466
- var discountsStep, _b, _c, _d, _i, step, url;
472
+ var discountsStep, _i, _a, step, url;
467
473
  var _this = this;
468
- return __generator(this, function (_e) {
469
- switch (_e.label) {
474
+ var _b;
475
+ return __generator(this, function (_c) {
476
+ switch (_c.label) {
470
477
  case 0:
471
478
  // First check that it is possible to call this API
472
479
  if (!this.cartId || this.cartId === 0) {
@@ -476,22 +483,16 @@ var SubscriptionBooking = /** @class */ (function (_super) {
476
483
  if (!discountsStep)
477
484
  throw Error("Booking step not found!");
478
485
  if (!!discountsStep[0]) return [3 /*break*/, 5];
479
- _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
480
- _c = [];
481
- for (_d in _b)
482
- _c.push(_d);
483
- _i = 0;
484
- _e.label = 1;
486
+ _i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
487
+ _c.label = 1;
485
488
  case 1:
486
- if (!(_i < _c.length)) return [3 /*break*/, 4];
487
- _d = _c[_i];
488
- if (!(_d in _b)) return [3 /*break*/, 3];
489
- step = _d;
490
- if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
489
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
490
+ step = _a[_i];
491
+ if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
491
492
  return [4 /*yield*/, this.markBookingStepCompleted(step)];
492
493
  case 2:
493
- _e.sent();
494
- _e.label = 3;
494
+ _c.sent();
495
+ _c.label = 3;
495
496
  case 3:
496
497
  _i++;
497
498
  return [3 /*break*/, 1];
@@ -501,9 +502,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
501
502
  if (!discountsStep || !discountsStep[0]) {
502
503
  throw Error("The status of the cart does not allow to call this API");
503
504
  }
504
- _e.label = 5;
505
+ _c.label = 5;
505
506
  case 5:
506
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction");
507
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction");
507
508
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
508
509
  var _a, _b;
509
510
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -540,7 +541,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
540
541
  throw Error("The status of the cart does not allow to call this API");
541
542
  }
542
543
  queryParams = new URLSearchParams({ tripId: tripId.toString() });
543
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
544
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
544
545
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
545
546
  var _a, _b, _c;
546
547
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -565,49 +566,43 @@ var SubscriptionBooking = /** @class */ (function (_super) {
565
566
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
566
567
  */
567
568
  SubscriptionBooking.prototype.useWallet = function () {
568
- var _a;
569
569
  return __awaiter(this, void 0, void 0, function () {
570
- var discountsStep, _b, _c, _d, _i, step, url;
570
+ var issueStep, _i, _a, step, url;
571
571
  var _this = this;
572
- return __generator(this, function (_e) {
573
- switch (_e.label) {
572
+ var _b;
573
+ return __generator(this, function (_c) {
574
+ switch (_c.label) {
574
575
  case 0:
575
576
  // First check that it is possible to call this API
576
577
  if (!this.cartId || this.cartId === 0) {
577
578
  throw Error("Cart is not initialized yet");
578
579
  }
579
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
580
- if (!discountsStep)
581
- throw Error("Booking step not found!");
582
- if (!!discountsStep[0]) return [3 /*break*/, 5];
583
- _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
584
- _c = [];
585
- for (_d in _b)
586
- _c.push(_d);
587
- _i = 0;
588
- _e.label = 1;
580
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
581
+ if (!issueStep)
582
+ throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
583
+ if (!!issueStep[0]) return [3 /*break*/, 5];
584
+ _i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
585
+ _c.label = 1;
589
586
  case 1:
590
- if (!(_i < _c.length)) return [3 /*break*/, 4];
591
- _d = _c[_i];
592
- if (!(_d in _b)) return [3 /*break*/, 3];
593
- step = _d;
594
- if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
587
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
588
+ step = _a[_i];
589
+ if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
595
590
  return [4 /*yield*/, this.markBookingStepCompleted(step)];
596
591
  case 2:
597
- _e.sent();
598
- _e.label = 3;
592
+ _c.sent();
593
+ _c.label = 3;
599
594
  case 3:
600
595
  _i++;
601
596
  return [3 /*break*/, 1];
602
597
  case 4:
603
598
  // Check again if the discounts step is accessible
604
- discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
605
- if (!discountsStep || !discountsStep[0]) {
606
- throw Error("The status of the cart does not allow to call this API");
599
+ issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
600
+ if (!issueStep || !issueStep[0]) {
601
+ throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
607
602
  }
608
- _e.label = 5;
603
+ _c.label = 5;
609
604
  case 5:
610
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
605
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
611
606
  return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
612
607
  var _a, _b;
613
608
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -638,7 +633,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
638
633
  if (!this.cartId || this.cartId === 0) {
639
634
  throw Error("Cart is not initialized yet");
640
635
  }
641
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
636
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
642
637
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
643
638
  var _a, _b, _c;
644
639
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -662,12 +657,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
662
657
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
663
658
  */
664
659
  SubscriptionBooking.prototype.useVoucher = function (voucherCode) {
665
- var _a;
666
660
  return __awaiter(this, void 0, void 0, function () {
667
- var discountsStep, _b, _c, _d, _i, step, url;
661
+ var discountsStep, _i, _a, step, url;
668
662
  var _this = this;
669
- return __generator(this, function (_e) {
670
- switch (_e.label) {
663
+ var _b;
664
+ return __generator(this, function (_c) {
665
+ switch (_c.label) {
671
666
  case 0:
672
667
  // First check that it is possible to call this API
673
668
  if (!this.cartId || this.cartId === 0) {
@@ -677,22 +672,16 @@ var SubscriptionBooking = /** @class */ (function (_super) {
677
672
  if (!discountsStep)
678
673
  throw Error("Booking step not found!");
679
674
  if (!!discountsStep[0]) return [3 /*break*/, 5];
680
- _b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
681
- _c = [];
682
- for (_d in _b)
683
- _c.push(_d);
684
- _i = 0;
685
- _e.label = 1;
675
+ _i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
676
+ _c.label = 1;
686
677
  case 1:
687
- if (!(_i < _c.length)) return [3 /*break*/, 4];
688
- _d = _c[_i];
689
- if (!(_d in _b)) return [3 /*break*/, 3];
690
- step = _d;
691
- if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
678
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
679
+ step = _a[_i];
680
+ if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
692
681
  return [4 /*yield*/, this.markBookingStepCompleted(step)];
693
682
  case 2:
694
- _e.sent();
695
- _e.label = 3;
683
+ _c.sent();
684
+ _c.label = 3;
696
685
  case 3:
697
686
  _i++;
698
687
  return [3 /*break*/, 1];
@@ -702,9 +691,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
702
691
  if (!discountsStep || !discountsStep[0]) {
703
692
  throw Error("The status of the cart does not allow to call this API");
704
693
  }
705
- _e.label = 5;
694
+ _c.label = 5;
706
695
  case 5:
707
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/voucher");
696
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/voucher");
708
697
  return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
709
698
  var _a, _b;
710
699
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -743,10 +732,10 @@ exports.SubscriptionBooking = SubscriptionBooking;
743
732
  case 3: return [2 /*return*/, booking];
744
733
  case 4:
745
734
  error_1 = _a.sent();
746
- // Check if the error is due to an expired cart. In this case, delete the cartId from the localStorage
735
+ // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
747
736
  // This error can occur when the user refreshes the page and the cart has expired
748
737
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
749
- localStorage.removeItem("cartId");
738
+ booking.getStorage().getState().updateCartId(undefined);
750
739
  booking.cartId = undefined;
751
740
  return [2 /*return*/, booking];
752
741
  }
@@ -0,0 +1,168 @@
1
+ import { MTSEnvs } from "../config";
2
+ import { ErrorResponse } from "../types/ErrorResponse";
3
+ import { City } from "../types/common/City";
4
+ import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
5
+ import { AddReductionRequest } from "../types/common/Reduction";
6
+ import { TermsType } from "../types/common/Tariffs";
7
+ import { GetTariffsResponse } from "../types/tpl/GetTariffsResponse";
8
+ import { SuperArea } from "../types/tpl/SuperArea";
9
+ import { TplCart } from "../types/tpl/TplCart";
10
+ import { Booking } from "./booking";
11
+ export declare class TplBooking extends Booking {
12
+ private cart?;
13
+ /**
14
+ * This is the constructor of the TplBooking class.
15
+ * @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
16
+ * @param {string} sub_key The subscription key for using the APIs
17
+ * @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
18
+ * @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
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, access_token?: string, sellerId?: number, resellerId?: number);
24
+ getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
25
+ cartId: number | undefined;
26
+ } & {
27
+ updateCartId: (cartId: number | undefined) => void;
28
+ resetState: () => void;
29
+ }>, "persist"> & {
30
+ persist: {
31
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
32
+ cartId: number | undefined;
33
+ } & {
34
+ updateCartId: (cartId: number | undefined) => void;
35
+ resetState: () => void;
36
+ }, {
37
+ cartId: number | undefined;
38
+ } & {
39
+ updateCartId: (cartId: number | undefined) => void;
40
+ resetState: () => void;
41
+ }>>) => void;
42
+ clearStorage: () => void;
43
+ rehydrate: () => void | Promise<void>;
44
+ hasHydrated: () => boolean;
45
+ onHydrate: (fn: (state: {
46
+ cartId: number | undefined;
47
+ } & {
48
+ updateCartId: (cartId: number | undefined) => void;
49
+ resetState: () => void;
50
+ }) => void) => () => void;
51
+ onFinishHydration: (fn: (state: {
52
+ cartId: number | undefined;
53
+ } & {
54
+ updateCartId: (cartId: number | undefined) => void;
55
+ resetState: () => void;
56
+ }) => void) => () => void;
57
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
58
+ cartId: number | undefined;
59
+ } & {
60
+ updateCartId: (cartId: number | undefined) => void;
61
+ resetState: () => void;
62
+ }, {
63
+ cartId: number | undefined;
64
+ } & {
65
+ updateCartId: (cartId: number | undefined) => void;
66
+ resetState: () => void;
67
+ }>>;
68
+ };
69
+ }>;
70
+ getCart(): undefined | TplCart;
71
+ resetBooking(): void;
72
+ fetchAndSetCart(cartId: number): Promise<void>;
73
+ fetchCart(cartId: number): Promise<TplCart>;
74
+ /**
75
+ * This method allows to delete a cart, thus allowing the user to exit from the booking process.
76
+ * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
77
+ * data will be deleted.
78
+ */
79
+ deleteCart(): Promise<ErrorResponse | any>;
80
+ /**
81
+ * This method allows to get the list of cities where it is possible to book a TPL service.
82
+ * @returns An array of {@link City} objects representing the cities where it is possible to book a TPL service
83
+ * if the call is successful, an {@link ErrorResponse} object otherwise.
84
+ */
85
+ getCities(): Promise<ErrorResponse | City[]>;
86
+ /**
87
+ * This method fetches the list of super areas for a given city. A super area is a region of the city in which
88
+ * the TPL service is available at a certain price.
89
+ * @returns An array of {@link SuperArea} objects representing the SuperAreas if the call is successful, an {@link ErrorResponse} object otherwise.
90
+ */
91
+ getSuperAreas(cityId: number): Promise<ErrorResponse | SuperArea[]>;
92
+ /**
93
+ * This method fetches the list of terms types in a given super area.
94
+ * @returns An array of {@link TermsType} objects representing the available terms types if the call is successful, an {@link ErrorResponse} object otherwise.
95
+ */
96
+ getTermsTypes(superAreaId: number): Promise<ErrorResponse | TermsType[]>;
97
+ /**
98
+ * This method fetches the list of available tariffs for the selected terms type in a given super area.
99
+ * @returns An array of {@link GetTariffsResponse} if the call is successful, an {@link ErrorResponse} object otherwise.
100
+ */
101
+ getTariffs(superAreaId: number, termsTypeId: number): Promise<ErrorResponse | GetTariffsResponse>;
102
+ /**
103
+ * This method allows to create a TPL cart.
104
+ * @param {Map<number, number>} tariffIdToQuantity A map that associates a tariff id (the one chosen by the user) to the number of tickets to buy for that tariff.
105
+ * @param {Booking.Currencies} currency The currency in which the ticket is priced.
106
+ * @param {string} [startDate] The start date of the ticket. This is optional and should be used only for subscriptions.
107
+ */
108
+ createTplCart(tariffIdToQuantity: Map<number, number>, currency: Booking.Currencies, startDate?: string): Promise<ErrorResponse | TplCart>;
109
+ /**
110
+ * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
111
+ * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
112
+ * as well as a list of the available tariffs for each trip.
113
+ */
114
+ getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
115
+ /**
116
+ * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
117
+ * @param {string} [linkavelCardNumber=undefined] The linkavel card number of the buyer. This parameter is required if linkavelCardPhoneNumber is not set.
118
+ * A linkavelCardNumber is a string of 9 digits.
119
+ * @param {string} [linkavelCardPhoneNumber=undefined] The linkavel card phone number of the buyer. This parameter is required if linkavelCardNumber is not set.
120
+ * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
121
+ * as well as a list of the available tariffs for each trip.
122
+ */
123
+ getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
124
+ /**
125
+ * @description This method shall be called when the user wants to update the buyer information.
126
+ * @param {Person | null} buyerDetails The object containing the buyer information.
127
+ * It should be null if the buyer data cannot be specified (see {@link GetBuyerPassengersDetailsResponse.buyerDataStatus}).
128
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
129
+ */
130
+ updateBuyerPassengersDetails(buyerDetails: Person | null): Promise<ErrorResponse | boolean>;
131
+ /**
132
+ * @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
133
+ * @param {AddReductionRequest} request The information about the reduction to add
134
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
135
+ */
136
+ addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
137
+ /**
138
+ * @description This method allows to remove a reduction from the whole cart or from a single trip in the cart.
139
+ * @param tripId The id of the trip from which the reduction should be removed. If the tripId is 0, then the reduction
140
+ * will be removed from the whole cart.
141
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
142
+ */
143
+ removeReduction(tripId: number): Promise<ErrorResponse | boolean>;
144
+ /**
145
+ * @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
146
+ * the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
147
+ * remaining amount with another payment method.
148
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
149
+ */
150
+ useWallet(): Promise<ErrorResponse | boolean>;
151
+ /**
152
+ * @description This method allows to remove a waller reduction from the cart.
153
+ *
154
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
155
+ */
156
+ removeWalletReduction(): Promise<ErrorResponse | boolean>;
157
+ /**
158
+ * @description This method allows the user to use a voucher to pay the cart.
159
+ * If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
160
+ * Otherwise, the user will be asked to pay the remaining amount with another payment method.
161
+ * @param {string} voucherCode The code of the voucher to use
162
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
163
+ */
164
+ useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
165
+ }
166
+ export declare namespace TplBooking {
167
+ const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<TplBooking>;
168
+ }