mts-booking-library 1.3.18 → 1.3.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,20 +13,23 @@ export declare class SubscriptionBooking extends Booking {
13
13
  constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
14
14
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
15
15
  cartId: number | undefined;
16
+ cartGuid: string | undefined;
16
17
  } & {
17
- updateCartId: (cartId: number | undefined) => void;
18
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
18
19
  resetState: () => void;
19
20
  }>, "persist"> & {
20
21
  persist: {
21
22
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
22
23
  cartId: number | undefined;
24
+ cartGuid: string | undefined;
23
25
  } & {
24
- updateCartId: (cartId: number | undefined) => void;
26
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
25
27
  resetState: () => void;
26
28
  }, {
27
29
  cartId: number | undefined;
30
+ cartGuid: string | undefined;
28
31
  } & {
29
- updateCartId: (cartId: number | undefined) => void;
32
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
30
33
  resetState: () => void;
31
34
  }>>) => void;
32
35
  clearStorage: () => void;
@@ -34,33 +37,37 @@ export declare class SubscriptionBooking extends Booking {
34
37
  hasHydrated: () => boolean;
35
38
  onHydrate: (fn: (state: {
36
39
  cartId: number | undefined;
40
+ cartGuid: string | undefined;
37
41
  } & {
38
- updateCartId: (cartId: number | undefined) => void;
42
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
39
43
  resetState: () => void;
40
44
  }) => void) => () => void;
41
45
  onFinishHydration: (fn: (state: {
42
46
  cartId: number | undefined;
47
+ cartGuid: string | undefined;
43
48
  } & {
44
- updateCartId: (cartId: number | undefined) => void;
49
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
45
50
  resetState: () => void;
46
51
  }) => void) => () => void;
47
52
  getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
48
53
  cartId: number | undefined;
54
+ cartGuid: string | undefined;
49
55
  } & {
50
- updateCartId: (cartId: number | undefined) => void;
56
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
51
57
  resetState: () => void;
52
58
  }, {
53
59
  cartId: number | undefined;
60
+ cartGuid: string | undefined;
54
61
  } & {
55
- updateCartId: (cartId: number | undefined) => void;
62
+ updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
56
63
  resetState: () => void;
57
64
  }>>;
58
65
  };
59
66
  }>;
60
67
  getCart(): SubscriptionCart | undefined;
61
68
  resetBooking(): void;
62
- fetchAndSetCart(cartId: number): Promise<void>;
63
- fetchCart(cartId: number): Promise<SubscriptionCart>;
69
+ fetchAndSetCart(cartGuid: string): Promise<void>;
70
+ fetchCart(cartGuid: string): Promise<SubscriptionCart>;
64
71
  /**
65
72
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
66
73
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -98,11 +98,14 @@ var SubscriptionBooking = /** @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
  SubscriptionBooking.prototype.getStorage = function () {
@@ -117,10 +120,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
117
120
  SubscriptionBooking.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 SubscriptionBooking = /** @class */ (function (_super) {
129
133
  console.log(e);
130
134
  }
131
135
  };
132
- SubscriptionBooking.prototype.fetchAndSetCart = function (cartId) {
136
+ SubscriptionBooking.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 SubscriptionBooking = /** @class */ (function (_super) {
160
165
  });
161
166
  });
162
167
  };
163
- SubscriptionBooking.prototype.fetchCart = function (cartId) {
168
+ SubscriptionBooking.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 SubscriptionBooking = /** @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
  _this.resetBooking();
200
205
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
@@ -338,8 +343,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
338
343
  }
339
344
  _this.cart = response.cart;
340
345
  _this.cartId = response.cart.id;
346
+ _this.cartGuid = response.cart.guid;
341
347
  // Save the cartId in the mts-storage
342
- _this.getStorage().getState().updateCartId(response.cart.id);
348
+ _this.getStorage().getState().updateCartId(response.cart.id, response.cart.guid);
343
349
  // Fill the booking process status
344
350
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
345
351
  var cartDueDate = new Date();
@@ -359,7 +365,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
359
365
  */
360
366
  SubscriptionBooking.prototype.getBuyerPassengersDetails = function () {
361
367
  return __awaiter(this, void 0, void 0, function () {
362
- var buyerPassengersDetails, url;
368
+ var buyerPassengersDetails, searchParams, url;
363
369
  return __generator(this, function (_a) {
364
370
  // First check that it is possible to call this API
365
371
  if (!this.cart) {
@@ -369,7 +375,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
369
375
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
370
376
  throw Error("The status of the cart does not allow to call this API");
371
377
  }
372
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
378
+ searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
379
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
373
380
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
374
381
  // Check for errors
375
382
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -458,7 +465,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
458
465
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
459
466
  throw Error("The status of the cart does not allow to call this API");
460
467
  }
461
- request = __assign({}, passengersDetails);
468
+ request = __assign(__assign({}, passengersDetails), { cartGuid: this.cart.guid });
462
469
  passengersDetails.passengers.map(function (passenger, passengerIndex) {
463
470
  var tripsToTariffsToJson = {};
464
471
  passenger.tripsToTariffs.forEach(function (value, key) {
@@ -466,7 +473,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
466
473
  });
467
474
  request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
468
475
  });
469
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
476
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
470
477
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
471
478
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
472
479
  return response;
@@ -688,7 +695,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
688
695
  switch (_c.label) {
689
696
  case 0:
690
697
  // First check that it is possible to call this API
691
- if (!this.cartId || this.cartId === 0) {
698
+ if (!this.cartGuid) {
692
699
  throw Error("Cart is not initialized yet");
693
700
  }
694
701
  discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
@@ -716,8 +723,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
716
723
  }
717
724
  _c.label = 5;
718
725
  case 5:
719
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
720
- return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
726
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
727
+ return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }).then(function (response) {
721
728
  var _a, _b;
722
729
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
723
730
  return response;
@@ -759,8 +766,8 @@ exports.SubscriptionBooking = SubscriptionBooking;
759
766
  _c.label = 1;
760
767
  case 1:
761
768
  _c.trys.push([1, 4, , 5]);
762
- if (!booking.cartId) return [3 /*break*/, 3];
763
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
769
+ if (!booking.cartGuid) return [3 /*break*/, 3];
770
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartGuid)];
764
771
  case 2:
765
772
  _c.sent();
766
773
  _c.label = 3;
@@ -770,8 +777,9 @@ exports.SubscriptionBooking = SubscriptionBooking;
770
777
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
771
778
  // This error can occur when the user refreshes the page and the cart has expired
772
779
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
773
- booking.getStorage().getState().updateCartId(undefined);
780
+ booking.getStorage().getState().updateCartId(undefined, undefined);
774
781
  booking.cartId = undefined;
782
+ booking.cartGuid = undefined;
775
783
  return [2 /*return*/, booking];
776
784
  }
777
785
  throw new Error("Could not instantiate JourneyBooking");
@@ -15,20 +15,23 @@ export declare class TplBooking extends Booking {
15
15
  constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
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,33 +39,37 @@ export declare class TplBooking 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
  getCart(): undefined | TplCart;
63
70
  resetBooking(): void;
64
- fetchAndSetCart(cartId: number): Promise<void>;
65
- fetchCart(cartId: number): Promise<TplCart>;
71
+ fetchAndSetCart(cartGuid: string): Promise<void>;
72
+ fetchCart(cartGuid: string): Promise<TplCart>;
66
73
  /**
67
74
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
68
75
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -98,11 +98,14 @@ var TplBooking = /** @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
  TplBooking.prototype.getStorage = function () {
@@ -117,10 +120,11 @@ var TplBooking = /** @class */ (function (_super) {
117
120
  TplBooking.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 TplBooking = /** @class */ (function (_super) {
129
133
  console.log(e);
130
134
  }
131
135
  };
132
- TplBooking.prototype.fetchAndSetCart = function (cartId) {
136
+ TplBooking.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 TplBooking = /** @class */ (function (_super) {
160
165
  });
161
166
  });
162
167
  };
163
- TplBooking.prototype.fetchCart = function (cartId) {
168
+ TplBooking.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 TplBooking = /** @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();
@@ -340,8 +345,9 @@ var TplBooking = /** @class */ (function (_super) {
340
345
  }
341
346
  _this.cart = response.cart;
342
347
  _this.cartId = response.cart.id;
348
+ _this.cartGuid = response.cart.guid;
343
349
  // Save the cartId in the mts-storage
344
- _this.getStorage().getState().updateCartId(response.cart.id);
350
+ _this.getStorage().getState().updateCartId(response.cart.id, response.cart.guid);
345
351
  // Fill the booking process status
346
352
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
347
353
  var cartDueDate = new Date();
@@ -362,7 +368,7 @@ var TplBooking = /** @class */ (function (_super) {
362
368
  */
363
369
  TplBooking.prototype.getBuyerPassengersDetails = function () {
364
370
  return __awaiter(this, void 0, void 0, function () {
365
- var buyerPassengersDetails, url;
371
+ var buyerPassengersDetails, searchParams, url;
366
372
  return __generator(this, function (_a) {
367
373
  // First check that it is possible to call this API
368
374
  if (!this.cart) {
@@ -372,7 +378,8 @@ var TplBooking = /** @class */ (function (_super) {
372
378
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
373
379
  throw Error("The status of the cart does not allow to call this API");
374
380
  }
375
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
381
+ searchParams = new URLSearchParams({ cartGuid: this.cart.guid });
382
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details?").concat(searchParams);
376
383
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
377
384
  // Check for errors
378
385
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
@@ -447,6 +454,7 @@ var TplBooking = /** @class */ (function (_super) {
447
454
  throw Error("The status of the cart does not allow to call this API");
448
455
  }
449
456
  request = {
457
+ cartGuid: this.cart.guid,
450
458
  buyer: buyerDetails,
451
459
  passengers: subscriptionPersonCode
452
460
  ? [
@@ -456,7 +464,7 @@ var TplBooking = /** @class */ (function (_super) {
456
464
  ]
457
465
  : []
458
466
  };
459
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
467
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/details");
460
468
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
461
469
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
462
470
  return response;
@@ -679,7 +687,7 @@ var TplBooking = /** @class */ (function (_super) {
679
687
  switch (_c.label) {
680
688
  case 0:
681
689
  // First check that it is possible to call this API
682
- if (!this.cartId || this.cartId === 0) {
690
+ if (!this.cartGuid) {
683
691
  throw Error("Cart is not initialized yet");
684
692
  }
685
693
  discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
@@ -707,8 +715,8 @@ var TplBooking = /** @class */ (function (_super) {
707
715
  }
708
716
  _c.label = 5;
709
717
  case 5:
710
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
711
- return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
718
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/voucher");
719
+ return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode, cartGuid: this.cartGuid }).then(function (response) {
712
720
  var _a, _b;
713
721
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
714
722
  return response;
@@ -750,8 +758,8 @@ exports.TplBooking = TplBooking;
750
758
  _c.label = 1;
751
759
  case 1:
752
760
  _c.trys.push([1, 4, , 5]);
753
- if (!booking.cartId) return [3 /*break*/, 3];
754
- return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
761
+ if (!booking.cartGuid) return [3 /*break*/, 3];
762
+ return [4 /*yield*/, booking.fetchAndSetCart(booking.cartGuid)];
755
763
  case 2:
756
764
  _c.sent();
757
765
  _c.label = 3;
@@ -761,8 +769,9 @@ exports.TplBooking = TplBooking;
761
769
  // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
762
770
  // This error can occur when the user refreshes the page and the cart has expired
763
771
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
764
- booking.getStorage().getState().updateCartId(undefined);
772
+ booking.getStorage().getState().updateCartId(undefined, undefined);
765
773
  booking.cartId = undefined;
774
+ booking.cartGuid = undefined;
766
775
  return [2 /*return*/, booking];
767
776
  }
768
777
  throw new Error("Could not instantiate TplBooking");
@@ -1,8 +1,10 @@
1
1
  type MtsBookingState = {
2
+ /** @deprecated Please use {@link MtsBookingState.cartGuid} instead, where possible */
2
3
  cartId: number | undefined;
4
+ cartGuid: string | undefined;
3
5
  };
4
6
  type MtsBookingAction = {
5
- updateCartId: (cartId: MtsBookingState["cartId"]) => void;
7
+ updateCartId: (cartId: MtsBookingState["cartId"], cartGuid: MtsBookingState["cartGuid"]) => void;
6
8
  resetState: () => void;
7
9
  };
8
10
  export declare const useMtsBookingLocalState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<MtsBookingState & MtsBookingAction>, "persist"> & {
package/lib/mtsStorage.js CHANGED
@@ -16,13 +16,16 @@ var async_storage_1 = require("@react-native-async-storage/async-storage");
16
16
  var zustand_1 = require("zustand");
17
17
  var middleware_1 = require("zustand/middleware");
18
18
  var INITIAL_STATE = {
19
- cartId: 0
19
+ cartId: 0,
20
+ cartGuid: undefined
20
21
  };
21
22
  var useMtsBookingAsyncState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId) { return set(function () { return ({ cartId: cartId }); }); }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
22
23
  name: "mts-booking-storage",
23
24
  storage: (0, middleware_1.createJSONStorage)(function () { return async_storage_1.default; })
24
25
  }));
25
- exports.useMtsBookingLocalState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId) { return set(function () { return ({ cartId: cartId }); }); }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
26
+ exports.useMtsBookingLocalState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId, cartGuid) {
27
+ return set(function () { return ({ cartId: cartId, cartGuid: cartGuid }); });
28
+ }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
26
29
  name: "mts-booking-storage",
27
30
  storage: (0, middleware_1.createJSONStorage)(function () { return localStorage; })
28
31
  }));
@@ -13,10 +13,16 @@ export declare enum SellingMethod {
13
13
  * - TourCart: {@link ServiceCart}
14
14
  * - JourneyCart: {@link JourneyCart}
15
15
  * - SubscriptionCart: {@link SubscriptionCart}
16
+ * - TplCart: {@link TplCart}
16
17
  */
17
18
  export type Cart = {
18
- /** The id of the cart */
19
+ /**
20
+ * The id of the cart
21
+ * @deprecated Please use {@link Cart.guid} instead
22
+ */
19
23
  id: number;
24
+ /** The guid of the cart */
25
+ guid: string;
20
26
  /** The id of the seller of the tickets in the cart */
21
27
  sellerId: number;
22
28
  /** The url redirecting to the privacy policy of the seller */
@@ -106,13 +106,16 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
106
106
  mtsCode: ((_d = (_c = (_b = error_1.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
107
107
  message: ((_g = (_f = (_e = error_1.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
108
108
  };
109
- if (debug) {
110
- console.log("GET_ResponseError", url, resError);
109
+ if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
110
+ console.log("GET_ResponseAxiosError", url, resError);
111
111
  }
112
112
  reject(resError);
113
113
  }
114
114
  else {
115
115
  resError = __assign(__assign({}, error_1), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
116
+ if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
117
+ console.log("GET_ResponseError", url, resError);
118
+ }
116
119
  reject(resError);
117
120
  }
118
121
  return [3 /*break*/, 3];
@@ -136,7 +139,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
136
139
  throw new Error("MTS Library Error! makePost: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
137
140
  }
138
141
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
139
- var response, filteredResponse, error_2, resError;
142
+ var response, filteredResponse, error_2, resError, resError;
140
143
  var _a, _b, _c, _d, _e, _f, _g;
141
144
  return __generator(this, function (_h) {
142
145
  switch (_h.label) {
@@ -161,14 +164,17 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
161
164
  mtsCode: ((_d = (_c = (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
162
165
  message: ((_g = (_f = (_e = error_2.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
163
166
  };
164
- if (debug) {
165
- console.log("POST_ResponseError", url, resError);
167
+ if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
168
+ console.log("POST_ResponseAxiosError", url, resError);
166
169
  }
167
170
  reject(resError);
168
171
  }
169
172
  else {
170
- // Not a axios error, return the error as is
171
- reject(error_2);
173
+ resError = __assign(__assign({}, error_2), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
174
+ if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
175
+ console.log("POST_ResponseError", url, resError);
176
+ }
177
+ reject(resError);
172
178
  }
173
179
  return [3 /*break*/, 3];
174
180
  case 3: return [2 /*return*/];
@@ -191,7 +197,7 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
191
197
  throw new Error("MTS Library Error! makeDelete: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
192
198
  }
193
199
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
194
- var response, filteredResponse, error_3, resError;
200
+ var response, filteredResponse, error_3, resError, resError;
195
201
  var _a, _b, _c, _d, _e, _f, _g;
196
202
  return __generator(this, function (_h) {
197
203
  switch (_h.label) {
@@ -216,14 +222,17 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
216
222
  mtsCode: ((_d = (_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.code) || 0,
217
223
  message: ((_g = (_f = (_e = error_3.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.message) || "Unknown error"
218
224
  };
219
- if (debug) {
220
- console.log("DELETE_ResponseError", url, resError);
225
+ if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
226
+ console.log("DELETE_ResponseAxiosError", url, resError);
221
227
  }
222
228
  reject(resError);
223
229
  }
224
230
  else {
225
- // Not a axios error, return the error as is
226
- reject(error_3);
231
+ resError = __assign(__assign({}, error_3), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
232
+ if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
233
+ console.log("DELETE_ResponseError", url, resError);
234
+ }
235
+ reject(resError);
227
236
  }
228
237
  return [3 /*break*/, 3];
229
238
  case 3: return [2 /*return*/];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.3.18",
3
+ "version": "1.3.20",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
File without changes