mts-booking-library 1.3.17 → 1.3.19

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.
Files changed (62) hide show
  1. package/README.md +6 -20
  2. package/lib/booking/booking.d.ts +2 -0
  3. package/lib/booking/booking.js +3 -3
  4. package/lib/booking/journeyBooking.d.ts +17 -10
  5. package/lib/booking/journeyBooking.js +43 -27
  6. package/lib/booking/serviceBooking.d.ts +16 -9
  7. package/lib/booking/serviceBooking.js +28 -19
  8. package/lib/booking/subscriptionBooking.d.ts +16 -9
  9. package/lib/booking/subscriptionBooking.js +28 -20
  10. package/lib/booking/tplBooking.d.ts +16 -9
  11. package/lib/booking/tplBooking.js +28 -19
  12. package/lib/mtsStorage.d.ts +3 -1
  13. package/lib/mtsStorage.js +5 -2
  14. package/lib/types/Booking.js +1 -0
  15. package/lib/types/Cart.d.ts +79 -0
  16. package/lib/types/Details.d.ts +9 -0
  17. package/lib/types/ErrorResponse.js +4 -1
  18. package/lib/types/Info.d.ts +7 -0
  19. package/lib/types/Journeys/Journey.d.ts +8 -0
  20. package/lib/types/Line.d.ts +6 -0
  21. package/lib/types/Line.js +2 -0
  22. package/lib/types/Person.d.ts +7 -0
  23. package/lib/types/Person.js +2 -0
  24. package/lib/types/Subscriptions/SubscriptionAvailabilities.js +2 -0
  25. package/lib/types/Subscriptions/SubscriptionCart.js +2 -0
  26. package/lib/types/Subscriptions/SubscriptionInfo.js +2 -0
  27. package/lib/types/Subscriptions/Subscriptions.js +2 -0
  28. package/lib/types/Subscriptions/Subscrptions.d.ts +12 -0
  29. package/lib/types/Subscriptions/Subscrptions.js +2 -0
  30. package/lib/types/Subscriptions/ValidityTypes.d.ts +6 -0
  31. package/lib/types/Subscriptions/ValidityTypes.js +10 -0
  32. package/lib/types/TermsAndTariffs.d.ts +21 -0
  33. package/lib/types/TermsAndTariffs.js +2 -0
  34. package/lib/types/Tours/Tour.d.ts +18 -0
  35. package/lib/types/Tours/Tour.js +2 -0
  36. package/lib/types/common/Cart.d.ts +7 -1
  37. package/lib/utils/apiCall.js +21 -12
  38. package/package.json +1 -1
  39. package/lib/SubscriptionBooking.js +0 -148
  40. package/lib/utils/testUtils.d.ts +0 -8
  41. package/lib/utils/testUtils.js +0 -19
  42. /package/lib/{SubscriptionBooking.d.ts → types/Booking.d.ts} +0 -0
  43. /package/lib/types/{journeys/JourneyInfo.js → Cart.js} +0 -0
  44. /package/lib/types/{journeys/Stop.js → Details.js} +0 -0
  45. /package/lib/types/{journeys/Trip.js → Info.js} +0 -0
  46. /package/lib/types/{journeys → Journeys}/BusMatrix.d.ts +0 -0
  47. /package/lib/types/{journeys → Journeys}/BusMatrix.js +0 -0
  48. /package/lib/types/{subscriptions/SubscriptionAvailabilities.js → Journeys/Journey.js} +0 -0
  49. /package/lib/types/{journeys → Journeys}/JourneyCart.d.ts +0 -0
  50. /package/lib/types/{journeys → Journeys}/JourneyCart.js +0 -0
  51. /package/lib/types/{journeys → Journeys}/JourneyInfo.d.ts +0 -0
  52. /package/lib/types/{subscriptions/SubscriptionCart.js → Journeys/JourneyInfo.js} +0 -0
  53. /package/lib/types/{journeys → Journeys}/JourneySearch.d.ts +0 -0
  54. /package/lib/types/{journeys → Journeys}/JourneySearch.js +0 -0
  55. /package/lib/types/{journeys → Journeys}/Stop.d.ts +0 -0
  56. /package/lib/types/{subscriptions/SubscriptionInfo.js → Journeys/Stop.js} +0 -0
  57. /package/lib/types/{journeys → Journeys}/Trip.d.ts +0 -0
  58. /package/lib/types/{subscriptions/Subscriptions.js → Journeys/Trip.js} +0 -0
  59. /package/lib/types/{subscriptions → Subscriptions}/SubscriptionAvailabilities.d.ts +0 -0
  60. /package/lib/types/{subscriptions → Subscriptions}/SubscriptionCart.d.ts +0 -0
  61. /package/lib/types/{subscriptions → Subscriptions}/SubscriptionInfo.d.ts +0 -0
  62. /package/lib/types/{subscriptions → Subscriptions}/Subscriptions.d.ts +0 -0
package/README.md CHANGED
@@ -1,20 +1,6 @@
1
- # Introduction
2
- TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
3
-
4
- # Getting Started
5
- TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
6
- 1. Installation process
7
- 2. Software dependencies
8
- 3. Latest releases
9
- 4. API references
10
-
11
- # Build and Test
12
- TODO: Describe and show how to build your code and run the tests.
13
-
14
- # Contribute
15
- TODO: Explain how other users and developers can contribute to make your code better.
16
-
17
- If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
18
- - [ASP.NET Core](https://github.com/aspnet/Home)
19
- - [Visual Studio Code](https://github.com/Microsoft/vscode)
20
- - [Chakra Core](https://github.com/Microsoft/ChakraCore)
1
+ # Publish
2
+ 1. ensure you have the most up to date `.env` file
3
+ 1. `npm i`
4
+ 1. `npm version patch`
5
+ 1. `git push && git push --tags`
6
+ 1. `npm publish`
@@ -20,7 +20,9 @@ export declare abstract class Booking {
20
20
  * - The third tells whether the section is required. <br/>
21
21
  */
22
22
  bookingStepsToStatus: processedStepsToStatus;
23
+ /** @deprecated Please use {@link Booking.cartGuid} instead */
23
24
  cartId: number | undefined;
25
+ cartGuid: string | undefined;
24
26
  bookingDueDate: Date | undefined;
25
27
  /**
26
28
  * This is the constructor of the Booking class. See {@link Booking.BookingConfig} for more information.
@@ -286,7 +286,7 @@ var Booking = /** @class */ (function () {
286
286
  switch (_c.label) {
287
287
  case 0:
288
288
  // First check that it is possible to call this API
289
- if (!this.cartId || this.cartId === 0) {
289
+ if (!this.cartGuid) {
290
290
  throw Error("Cart is not initialized yet");
291
291
  }
292
292
  paymentMethodToSet = paymentMethod;
@@ -334,9 +334,9 @@ var Booking = /** @class */ (function () {
334
334
  }
335
335
  _c.label = 7;
336
336
  case 7:
337
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/issue");
337
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/issue");
338
338
  body = {
339
- cartId: this.cartId,
339
+ cartGuid: this.cartGuid,
340
340
  paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet
341
341
  };
342
342
  return [2 /*return*/, this.callPostApi(url, body).then(function (response) {
@@ -15,20 +15,23 @@ export declare class JourneyBooking extends Booking {
15
15
  getCart(): JourneyCart | undefined;
16
16
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
17
17
  cartId: number | undefined;
18
+ cartGuid: string | undefined;
18
19
  } & {
19
- updateCartId: (cartId: number | undefined) => void;
20
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
20
21
  resetState: () => void;
21
22
  }>, "persist"> & {
22
23
  persist: {
23
24
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
24
25
  cartId: number | undefined;
26
+ cartGuid: string | undefined;
25
27
  } & {
26
- updateCartId: (cartId: number | undefined) => void;
28
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
27
29
  resetState: () => void;
28
30
  }, {
29
31
  cartId: number | undefined;
32
+ cartGuid: string | undefined;
30
33
  } & {
31
- updateCartId: (cartId: number | undefined) => void;
34
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
32
35
  resetState: () => void;
33
36
  }>>) => void;
34
37
  clearStorage: () => void;
@@ -36,32 +39,36 @@ export declare class JourneyBooking extends Booking {
36
39
  hasHydrated: () => boolean;
37
40
  onHydrate: (fn: (state: {
38
41
  cartId: number | undefined;
42
+ cartGuid: string | undefined;
39
43
  } & {
40
- updateCartId: (cartId: number | undefined) => void;
44
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
41
45
  resetState: () => void;
42
46
  }) => void) => () => void;
43
47
  onFinishHydration: (fn: (state: {
44
48
  cartId: number | undefined;
49
+ cartGuid: string | undefined;
45
50
  } & {
46
- updateCartId: (cartId: number | undefined) => void;
51
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
47
52
  resetState: () => void;
48
53
  }) => void) => () => void;
49
54
  getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
50
55
  cartId: number | undefined;
56
+ cartGuid: string | undefined;
51
57
  } & {
52
- updateCartId: (cartId: number | undefined) => void;
58
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
53
59
  resetState: () => void;
54
60
  }, {
55
61
  cartId: number | undefined;
62
+ cartGuid: string | undefined;
56
63
  } & {
57
- updateCartId: (cartId: number | undefined) => void;
64
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
58
65
  resetState: () => void;
59
66
  }>>;
60
67
  };
61
68
  }>;
62
69
  resetBooking(): void;
63
- fetchAndSetCart(cartId: number): Promise<void>;
64
- fetchCart(cartId: number): Promise<JourneyCart>;
70
+ fetchAndSetCart(cartGuid: string): Promise<void>;
71
+ fetchCart(cartGuid: string): Promise<JourneyCart>;
65
72
  /**
66
73
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
67
74
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -167,7 +174,7 @@ export declare class JourneyBooking extends Booking {
167
174
  * @description This method allows the user to use a voucher to pay the cart.
168
175
  * If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
169
176
  * Otherwise, the user will be asked to pay the remaining amount with another payment method.
170
- * @param {string} voucherCode The code of the voucher to use
177
+ * @param voucherCode The code of the voucher to use
171
178
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
172
179
  */
173
180
  useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
@@ -98,11 +98,14 @@ var JourneyBooking = /** @class */ (function (_super) {
98
98
  resellerId: resellerId,
99
99
  dbType: dbType
100
100
  }) || this;
101
- // Set cartId
102
- var cartId = _this.getStorage().getState().cartId;
101
+ // Set cartId & cartGuid
102
+ var _b = _this.getStorage().getState(), cartId = _b.cartId, cartGuid = _b.cartGuid;
103
103
  if (cartId && restoreState) {
104
104
  _this.cartId = cartId;
105
105
  }
106
+ if (cartGuid && restoreState) {
107
+ _this.cartGuid = cartGuid;
108
+ }
106
109
  return _this;
107
110
  }
108
111
  JourneyBooking.prototype.getCart = function () {
@@ -117,10 +120,11 @@ var JourneyBooking = /** @class */ (function (_super) {
117
120
  JourneyBooking.prototype.resetBooking = function () {
118
121
  this.cart = undefined;
119
122
  this.cartId = undefined;
123
+ this.cartGuid = undefined;
120
124
  this.bookingStepsToStatus = new Map();
121
125
  this.bookingDueDate = undefined;
122
126
  try {
123
- this.getStorage().getState().updateCartId(undefined);
127
+ this.getStorage().getState().updateCartId(undefined, undefined);
124
128
  }
125
129
  catch (e) {
126
130
  if (this.config.ENV !== config_1.MTSEnvs.TEST) {
@@ -129,18 +133,19 @@ var JourneyBooking = /** @class */ (function (_super) {
129
133
  console.log(e);
130
134
  }
131
135
  };
132
- JourneyBooking.prototype.fetchAndSetCart = function (cartId) {
136
+ JourneyBooking.prototype.fetchAndSetCart = function (cartGuid) {
133
137
  return __awaiter(this, void 0, void 0, function () {
134
138
  var _this = this;
135
139
  return __generator(this, function (_a) {
136
140
  switch (_a.label) {
137
- case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
141
+ case 0: return [4 /*yield*/, this.fetchCart(cartGuid).then(function (cart) {
138
142
  if (cart) {
139
143
  var cartDueDate = new Date();
140
144
  cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
141
145
  if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
142
146
  _this.cart = cart;
143
147
  _this.cartId = cart.id;
148
+ _this.cartGuid = cart.guid;
144
149
  _this.bookingDueDate = cartDueDate; // See Booking class
145
150
  // Update the sellerId. This is particularly important in Linkavel
146
151
  _this.updateSellerId(cart.sellerId);
@@ -160,12 +165,12 @@ var JourneyBooking = /** @class */ (function (_super) {
160
165
  });
161
166
  });
162
167
  };
163
- JourneyBooking.prototype.fetchCart = function (cartId) {
168
+ JourneyBooking.prototype.fetchCart = function (cartGuid) {
164
169
  return __awaiter(this, void 0, void 0, function () {
165
170
  var url;
166
171
  var _this = this;
167
172
  return __generator(this, function (_a) {
168
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
173
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: cartGuid }));
169
174
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
170
175
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
171
176
  _this.resetBooking();
@@ -191,10 +196,10 @@ var JourneyBooking = /** @class */ (function (_super) {
191
196
  var _this = this;
192
197
  return __generator(this, function (_a) {
193
198
  // First check that it is possible to call this API
194
- if (!this.cart || !this.cartId) {
199
+ if (!this.cart) {
195
200
  throw Error("Cart is not initialized yet");
196
201
  }
197
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
202
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: this.cart.guid }));
198
203
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
199
204
  // Clear all data
200
205
  _this.resetBooking();
@@ -279,8 +284,9 @@ var JourneyBooking = /** @class */ (function (_super) {
279
284
  }
280
285
  _this.cart = response.cart;
281
286
  _this.cartId = response.cart.id;
287
+ _this.cartGuid = response.cart.guid;
282
288
  // Save the cartId in the storage
283
- _this.getStorage().getState().updateCartId(response.cart.id);
289
+ _this.getStorage().getState().updateCartId(response.cart.id, response.cart.guid);
284
290
  // Fill the booking process status
285
291
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
286
292
  var cartDueDate = new Date();
@@ -300,7 +306,7 @@ var JourneyBooking = /** @class */ (function (_super) {
300
306
  */
301
307
  JourneyBooking.prototype.getBuyerPassengersDetails = function () {
302
308
  return __awaiter(this, void 0, void 0, function () {
303
- var buyerPassengersDetails, url;
309
+ var buyerPassengersDetails, searchParams, url;
304
310
  return __generator(this, function (_a) {
305
311
  // First check that it is possible to call this API
306
312
  if (!this.cart) {
@@ -310,7 +316,8 @@ var JourneyBooking = /** @class */ (function (_super) {
310
316
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
311
317
  throw Error("The status of the cart does not allow to call this API");
312
318
  }
313
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
319
+ searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
320
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
314
321
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
315
322
  // Check for errors
316
323
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -399,7 +406,7 @@ var JourneyBooking = /** @class */ (function (_super) {
399
406
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
400
407
  throw Error("The status of the cart does not allow to call this API");
401
408
  }
402
- request = __assign({}, passengersDetails);
409
+ request = __assign(__assign({}, passengersDetails), { cartGuid: this.cart.guid });
403
410
  passengersDetails.passengers.map(function (passenger, passengerIndex) {
404
411
  var tripsToTariffsToJson = {};
405
412
  passenger.tripsToTariffs.forEach(function (value, key) {
@@ -407,7 +414,7 @@ var JourneyBooking = /** @class */ (function (_super) {
407
414
  });
408
415
  request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
409
416
  });
410
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
417
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
411
418
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
412
419
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
413
420
  return response;
@@ -469,8 +476,11 @@ var JourneyBooking = /** @class */ (function (_super) {
469
476
  if (!seatSelectionStatus || !seatSelectionStatus[0]) {
470
477
  throw Error("The status of the cart does not allow to call this API");
471
478
  }
472
- searchParams = new URLSearchParams({ tripId: tripId.toString() });
473
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/seats?").concat(searchParams);
479
+ searchParams = new URLSearchParams({
480
+ tripId: tripId.toString(),
481
+ cartGuid: this.cart.guid
482
+ });
483
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/seats?").concat(searchParams);
474
484
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
475
485
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
476
486
  ? response
@@ -498,8 +508,12 @@ var JourneyBooking = /** @class */ (function (_super) {
498
508
  if (!seatSelectionStatus || !seatSelectionStatus[0]) {
499
509
  throw Error("The status of the cart does not allow to call this API");
500
510
  }
501
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/seats");
502
- return [2 /*return*/, this.callPostApi(url, { tripId: tripId, newSeatsIds: newSeatsIds }).then(function (response) {
511
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/seats");
512
+ return [2 /*return*/, this.callPostApi(url, {
513
+ tripId: tripId,
514
+ newSeatsIds: newSeatsIds,
515
+ cartGuid: this.cart.guid
516
+ }).then(function (response) {
503
517
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
504
518
  return response;
505
519
  }
@@ -519,13 +533,14 @@ var JourneyBooking = /** @class */ (function (_super) {
519
533
  */
520
534
  JourneyBooking.prototype.getCartTrips = function () {
521
535
  return __awaiter(this, void 0, void 0, function () {
522
- var url;
536
+ var searchParams, url;
523
537
  return __generator(this, function (_a) {
524
538
  // First check that it is possible to call this API
525
539
  if (!this.cart) {
526
540
  throw Error("Cart is not initialized yet");
527
541
  }
528
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/payment/reduction/trips?");
542
+ searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
543
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction/trips?").concat(searchParams);
529
544
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
530
545
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
531
546
  ? response
@@ -731,7 +746,7 @@ var JourneyBooking = /** @class */ (function (_super) {
731
746
  * @description This method allows the user to use a voucher to pay the cart.
732
747
  * If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
733
748
  * Otherwise, the user will be asked to pay the remaining amount with another payment method.
734
- * @param {string} voucherCode The code of the voucher to use
749
+ * @param voucherCode The code of the voucher to use
735
750
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
736
751
  */
737
752
  JourneyBooking.prototype.useVoucher = function (voucherCode) {
@@ -743,7 +758,7 @@ var JourneyBooking = /** @class */ (function (_super) {
743
758
  switch (_c.label) {
744
759
  case 0:
745
760
  // First check that it is possible to call this API
746
- if (!this.cartId || this.cartId === 0) {
761
+ if (!this.cartGuid) {
747
762
  throw Error("Cart is not initialized yet");
748
763
  }
749
764
  discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
@@ -771,8 +786,8 @@ var JourneyBooking = /** @class */ (function (_super) {
771
786
  }
772
787
  _c.label = 5;
773
788
  case 5:
774
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
775
- return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
789
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
790
+ return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }).then(function (response) {
776
791
  var _a, _b;
777
792
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
778
793
  return response;
@@ -814,8 +829,8 @@ exports.JourneyBooking = JourneyBooking;
814
829
  _c.label = 1;
815
830
  case 1:
816
831
  _c.trys.push([1, 4, , 5]);
817
- if (!booking.cartId) return [3 /*break*/, 3];
818
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
832
+ if (!booking.cartGuid) return [3 /*break*/, 3];
833
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartGuid)];
819
834
  case 2:
820
835
  _c.sent();
821
836
  _c.label = 3;
@@ -825,8 +840,9 @@ exports.JourneyBooking = JourneyBooking;
825
840
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
826
841
  // This error can occur when the user refreshes the page and the cart has expired
827
842
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
828
- booking.getStorage().getState().updateCartId(undefined);
843
+ booking.getStorage().getState().updateCartId(undefined, undefined);
829
844
  booking.cartId = undefined;
845
+ booking.cartGuid = undefined;
830
846
  return [2 /*return*/, booking];
831
847
  }
832
848
  throw new Error("Could not instantiate JourneyBooking");
@@ -12,20 +12,23 @@ export declare class ServiceBooking extends Booking {
12
12
  constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
13
13
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
14
14
  cartId: number | undefined;
15
+ cartGuid: string | undefined;
15
16
  } & {
16
- updateCartId: (cartId: number | undefined) => void;
17
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
17
18
  resetState: () => void;
18
19
  }>, "persist"> & {
19
20
  persist: {
20
21
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
21
22
  cartId: number | undefined;
23
+ cartGuid: string | undefined;
22
24
  } & {
23
- updateCartId: (cartId: number | undefined) => void;
25
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
24
26
  resetState: () => void;
25
27
  }, {
26
28
  cartId: number | undefined;
29
+ cartGuid: string | undefined;
27
30
  } & {
28
- updateCartId: (cartId: number | undefined) => void;
31
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
29
32
  resetState: () => void;
30
33
  }>>) => void;
31
34
  clearStorage: () => void;
@@ -33,33 +36,37 @@ export declare class ServiceBooking extends Booking {
33
36
  hasHydrated: () => boolean;
34
37
  onHydrate: (fn: (state: {
35
38
  cartId: number | undefined;
39
+ cartGuid: string | undefined;
36
40
  } & {
37
- updateCartId: (cartId: number | undefined) => void;
41
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
38
42
  resetState: () => void;
39
43
  }) => void) => () => void;
40
44
  onFinishHydration: (fn: (state: {
41
45
  cartId: number | undefined;
46
+ cartGuid: string | undefined;
42
47
  } & {
43
- updateCartId: (cartId: number | undefined) => void;
48
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
44
49
  resetState: () => void;
45
50
  }) => void) => () => void;
46
51
  getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
47
52
  cartId: number | undefined;
53
+ cartGuid: string | undefined;
48
54
  } & {
49
- updateCartId: (cartId: number | undefined) => void;
55
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
50
56
  resetState: () => void;
51
57
  }, {
52
58
  cartId: number | undefined;
59
+ cartGuid: string | undefined;
53
60
  } & {
54
- updateCartId: (cartId: number | undefined) => void;
61
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
55
62
  resetState: () => void;
56
63
  }>>;
57
64
  };
58
65
  }>;
59
66
  getCart(): ServiceCart | undefined;
60
67
  resetBooking(): void;
61
- fetchAndSetCart(cartId: number): Promise<void>;
62
- fetchCart(cartId: number): Promise<ServiceCart>;
68
+ fetchAndSetCart(cartGuid: string): Promise<void>;
69
+ fetchCart(cartGuid: string): Promise<ServiceCart>;
63
70
  /**
64
71
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
65
72
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -98,11 +98,14 @@ var ServiceBooking = /** @class */ (function (_super) {
98
98
  resellerId: resellerId,
99
99
  dbType: dbType
100
100
  }) || this;
101
- // Set cartId
102
- var cartId = _this.getStorage().getState().cartId;
101
+ // Set cartId & cartGuid
102
+ var _b = _this.getStorage().getState(), cartId = _b.cartId, cartGuid = _b.cartGuid;
103
103
  if (cartId && restoreState) {
104
104
  _this.cartId = cartId;
105
105
  }
106
+ if (cartGuid && restoreState) {
107
+ _this.cartGuid = cartGuid;
108
+ }
106
109
  return _this;
107
110
  }
108
111
  ServiceBooking.prototype.getStorage = function () {
@@ -117,10 +120,11 @@ var ServiceBooking = /** @class */ (function (_super) {
117
120
  ServiceBooking.prototype.resetBooking = function () {
118
121
  this.cart = undefined;
119
122
  this.cartId = undefined;
123
+ this.cartGuid = undefined;
120
124
  this.bookingStepsToStatus = new Map();
121
125
  this.bookingDueDate = undefined;
122
126
  try {
123
- this.getStorage().getState().updateCartId(undefined);
127
+ this.getStorage().getState().updateCartId(undefined, undefined);
124
128
  }
125
129
  catch (e) {
126
130
  if (this.config.ENV !== config_1.MTSEnvs.TEST) {
@@ -129,18 +133,19 @@ var ServiceBooking = /** @class */ (function (_super) {
129
133
  console.log(e);
130
134
  }
131
135
  };
132
- ServiceBooking.prototype.fetchAndSetCart = function (cartId) {
136
+ ServiceBooking.prototype.fetchAndSetCart = function (cartGuid) {
133
137
  return __awaiter(this, void 0, void 0, function () {
134
138
  var _this = this;
135
139
  return __generator(this, function (_a) {
136
140
  switch (_a.label) {
137
- case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
141
+ case 0: return [4 /*yield*/, this.fetchCart(cartGuid).then(function (cart) {
138
142
  if (cart) {
139
143
  var cartDueDate = new Date();
140
144
  cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
141
145
  if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
142
146
  _this.cart = cart;
143
147
  _this.cartId = cart.id;
148
+ _this.cartGuid = cart.guid;
144
149
  _this.bookingDueDate = cartDueDate; // See Booking class
145
150
  // Update the sellerId. This is particularly important in Linkavel
146
151
  _this.updateSellerId(cart.sellerId);
@@ -160,12 +165,12 @@ var ServiceBooking = /** @class */ (function (_super) {
160
165
  });
161
166
  });
162
167
  };
163
- ServiceBooking.prototype.fetchCart = function (cartId) {
168
+ ServiceBooking.prototype.fetchCart = function (cartGuid) {
164
169
  return __awaiter(this, void 0, void 0, function () {
165
170
  var url;
166
171
  var _this = this;
167
172
  return __generator(this, function (_a) {
168
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
173
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: cartGuid }));
169
174
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
170
175
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
171
176
  _this.resetBooking();
@@ -191,10 +196,10 @@ var ServiceBooking = /** @class */ (function (_super) {
191
196
  var _this = this;
192
197
  return __generator(this, function (_a) {
193
198
  // First check that it is possible to call this API
194
- if (!this.cart || !this.cartId) {
199
+ if (!this.cart) {
195
200
  throw Error("Cart is not initialized yet");
196
201
  }
197
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
202
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartGuid: this.cart.guid }));
198
203
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
199
204
  // Clear all data
200
205
  _this.resetBooking();
@@ -280,8 +285,9 @@ var ServiceBooking = /** @class */ (function (_super) {
280
285
  // Save the local data
281
286
  _this.cart = response.cart;
282
287
  _this.cartId = response.cart.id;
288
+ _this.cartGuid = response.cart.guid;
283
289
  // Save the cartId in the mts-storage
284
- _this.getStorage().getState().updateCartId(response.cart.id);
290
+ _this.getStorage().getState().updateCartId(response.cart.id, response.cart.guid);
285
291
  // Fill the booking process status
286
292
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
287
293
  var cartDueDate = new Date();
@@ -302,7 +308,7 @@ var ServiceBooking = /** @class */ (function (_super) {
302
308
  */
303
309
  ServiceBooking.prototype.getBuyerPassengersDetails = function () {
304
310
  return __awaiter(this, void 0, void 0, function () {
305
- var buyerPassengersDetails, url;
311
+ var buyerPassengersDetails, searchParams, url;
306
312
  return __generator(this, function (_a) {
307
313
  // First check that it is possible to call this API
308
314
  if (!this.cart) {
@@ -312,7 +318,8 @@ var ServiceBooking = /** @class */ (function (_super) {
312
318
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
313
319
  throw Error("The status of the cart does not allow to call this API");
314
320
  }
315
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
321
+ searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
322
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
316
323
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
317
324
  // Check for errors
318
325
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -381,10 +388,11 @@ var ServiceBooking = /** @class */ (function (_super) {
381
388
  throw Error("The status of the cart does not allow to call this API");
382
389
  }
383
390
  request = {
391
+ cartGuid: this.cart.guid,
384
392
  buyer: buyerDetails,
385
393
  passengers: []
386
394
  };
387
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
395
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
388
396
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
389
397
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
390
398
  return response;
@@ -607,7 +615,7 @@ var ServiceBooking = /** @class */ (function (_super) {
607
615
  switch (_c.label) {
608
616
  case 0:
609
617
  // First check that it is possible to call this API
610
- if (!this.cartId || this.cartId === 0) {
618
+ if (!this.cartGuid) {
611
619
  throw Error("Cart is not initialized yet");
612
620
  }
613
621
  discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
@@ -635,8 +643,8 @@ var ServiceBooking = /** @class */ (function (_super) {
635
643
  }
636
644
  _c.label = 5;
637
645
  case 5:
638
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
639
- return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
646
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
647
+ return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }).then(function (response) {
640
648
  var _a, _b;
641
649
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
642
650
  return response;
@@ -678,8 +686,8 @@ exports.ServiceBooking = ServiceBooking;
678
686
  _c.label = 1;
679
687
  case 1:
680
688
  _c.trys.push([1, 4, , 5]);
681
- if (!booking.cartId) return [3 /*break*/, 3];
682
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
689
+ if (!booking.cartGuid) return [3 /*break*/, 3];
690
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartGuid)];
683
691
  case 2:
684
692
  _c.sent();
685
693
  _c.label = 3;
@@ -689,8 +697,9 @@ exports.ServiceBooking = ServiceBooking;
689
697
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
690
698
  // This error can occur when the user refreshes the page and the cart has expired
691
699
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
692
- booking.getStorage().getState().updateCartId(undefined);
700
+ booking.getStorage().getState().updateCartId(undefined, undefined);
693
701
  booking.cartId = undefined;
702
+ booking.cartGuid = undefined;
694
703
  return [2 /*return*/, booking];
695
704
  }
696
705
  throw new Error("Could not instantiate JourneyBooking");