mts-booking-library 1.2.35 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +2 -1
- package/lib/booking/booking.js +31 -42
- package/lib/booking/journeyBooking.d.ts +46 -0
- package/lib/booking/journeyBooking.js +70 -81
- package/lib/booking/serviceBooking.d.ts +46 -0
- package/lib/booking/serviceBooking.js +67 -78
- package/lib/booking/subscriptionBooking.d.ts +46 -0
- package/lib/booking/subscriptionBooking.js +68 -79
- package/lib/booking/tplBooking.d.ts +168 -0
- package/lib/booking/tplBooking.js +705 -0
- package/lib/config.js +4 -4
- package/lib/index.d.ts +4 -0
- package/lib/index.js +3 -1
- package/lib/mtsStorage.d.ts +44 -0
- package/lib/mtsStorage.js +48 -0
- package/lib/types/common/City.d.ts +17 -0
- package/lib/types/common/City.js +2 -0
- package/lib/types/common/Tariffs.d.ts +9 -3
- package/lib/types/journeys/JourneyInfo.d.ts +3 -1
- package/lib/types/tpl/GetTariffsResponse.d.ts +12 -0
- package/lib/types/tpl/GetTariffsResponse.js +2 -0
- package/lib/types/tpl/SuperArea.d.ts +13 -0
- package/lib/types/tpl/SuperArea.js +2 -0
- package/lib/types/tpl/TplCart.d.ts +41 -0
- package/lib/types/tpl/TplCart.js +2 -0
- package/lib/utils/apiCall.js +4 -4
- package/package.json +8 -6
@@ -18,6 +18,52 @@ export declare class ServiceBooking extends Booking {
|
|
18
18
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
19
19
|
*/
|
20
20
|
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
21
|
+
getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
22
|
+
cartId: number | undefined;
|
23
|
+
} & {
|
24
|
+
updateCartId: (cartId: number | undefined) => void;
|
25
|
+
resetState: () => void;
|
26
|
+
}>, "persist"> & {
|
27
|
+
persist: {
|
28
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
|
29
|
+
cartId: number | undefined;
|
30
|
+
} & {
|
31
|
+
updateCartId: (cartId: number | undefined) => void;
|
32
|
+
resetState: () => void;
|
33
|
+
}, {
|
34
|
+
cartId: number | undefined;
|
35
|
+
} & {
|
36
|
+
updateCartId: (cartId: number | undefined) => void;
|
37
|
+
resetState: () => void;
|
38
|
+
}>>) => void;
|
39
|
+
clearStorage: () => void;
|
40
|
+
rehydrate: () => void | Promise<void>;
|
41
|
+
hasHydrated: () => boolean;
|
42
|
+
onHydrate: (fn: (state: {
|
43
|
+
cartId: number | undefined;
|
44
|
+
} & {
|
45
|
+
updateCartId: (cartId: number | undefined) => void;
|
46
|
+
resetState: () => void;
|
47
|
+
}) => void) => () => void;
|
48
|
+
onFinishHydration: (fn: (state: {
|
49
|
+
cartId: number | undefined;
|
50
|
+
} & {
|
51
|
+
updateCartId: (cartId: number | undefined) => void;
|
52
|
+
resetState: () => void;
|
53
|
+
}) => void) => () => void;
|
54
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
|
55
|
+
cartId: number | undefined;
|
56
|
+
} & {
|
57
|
+
updateCartId: (cartId: number | undefined) => void;
|
58
|
+
resetState: () => void;
|
59
|
+
}, {
|
60
|
+
cartId: number | undefined;
|
61
|
+
} & {
|
62
|
+
updateCartId: (cartId: number | undefined) => void;
|
63
|
+
resetState: () => void;
|
64
|
+
}>>;
|
65
|
+
};
|
66
|
+
}>;
|
21
67
|
getCart(): ServiceCart | undefined;
|
22
68
|
resetBooking(): void;
|
23
69
|
fetchAndSetCart(cartId: number): Promise<void>;
|
@@ -73,6 +73,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
73
73
|
Object.defineProperty(exports, "__esModule", { value: true });
|
74
74
|
exports.ServiceBooking = 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 ServiceBooking = /** @class */ (function (_super) {
|
|
95
96
|
// Call Booking constructor
|
96
97
|
var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
|
97
98
|
// Set cartId
|
98
|
-
var cartId =
|
99
|
+
var cartId = _this.getStorage().getState().cartId;
|
99
100
|
if (cartId) {
|
100
|
-
_this.cartId =
|
101
|
+
_this.cartId = cartId;
|
101
102
|
}
|
102
103
|
return _this;
|
103
104
|
}
|
105
|
+
ServiceBooking.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
|
ServiceBooking.prototype.getCart = function () {
|
105
112
|
return this.cart;
|
106
113
|
};
|
@@ -110,11 +117,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
110
117
|
this.bookingStepsToStatus = new Map();
|
111
118
|
this.bookingDueDate = undefined;
|
112
119
|
try {
|
113
|
-
|
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
|
124
|
+
throw new Error("Error while deleting cartId from storage");
|
118
125
|
}
|
119
126
|
console.log(e);
|
120
127
|
}
|
@@ -154,10 +161,10 @@ var ServiceBooking = /** @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, "/
|
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();
|
161
168
|
throw new Error(response);
|
162
169
|
}
|
163
170
|
// Check that the cart doe not have issued tickets
|
@@ -183,7 +190,7 @@ var ServiceBooking = /** @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, "/
|
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
|
// Clear all data
|
189
196
|
_this.resetBooking();
|
@@ -201,7 +208,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
201
208
|
return __awaiter(this, void 0, void 0, function () {
|
202
209
|
var url;
|
203
210
|
return __generator(this, function (_a) {
|
204
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
211
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cities?");
|
205
212
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
206
213
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.cities;
|
207
214
|
})];
|
@@ -220,7 +227,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
220
227
|
var searchParams, url;
|
221
228
|
return __generator(this, function (_a) {
|
222
229
|
searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
|
223
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
230
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services?").concat(searchParams);
|
224
231
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
225
232
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.services;
|
226
233
|
})];
|
@@ -240,7 +247,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
240
247
|
var searchParams, url;
|
241
248
|
return __generator(this, function (_a) {
|
242
249
|
searchParams = new URLSearchParams({ date: date });
|
243
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
250
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/").concat(serviceId, "/trips?").concat(searchParams);
|
244
251
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
245
252
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
|
246
253
|
})];
|
@@ -252,19 +259,19 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
252
259
|
var url;
|
253
260
|
var _this = this;
|
254
261
|
return __generator(this, function (_a) {
|
255
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
262
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cart");
|
256
263
|
return [2 /*return*/, this.callPostApi(url, serviceCart).then(function (response) {
|
257
264
|
// Check for errors
|
258
265
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
259
|
-
// If there was an error, reset cartId and remove it from the
|
266
|
+
// If there was an error, reset cartId and remove it from the mts-storage
|
260
267
|
_this.resetBooking();
|
261
268
|
return response;
|
262
269
|
}
|
263
270
|
// Save the local data
|
264
271
|
_this.cart = response.cart;
|
265
272
|
_this.cartId = response.cart.id;
|
266
|
-
// Save the cartId in the
|
267
|
-
|
273
|
+
// Save the cartId in the mts-storage
|
274
|
+
_this.getStorage().getState().updateCartId(response.cart.id);
|
268
275
|
// Fill the booking process status
|
269
276
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
270
277
|
_this.bookingDueDate = new Date(response.cart.bookingDueDate);
|
@@ -293,7 +300,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
293
300
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
294
301
|
throw Error("The status of the cart does not allow to call this API");
|
295
302
|
}
|
296
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
303
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details?");
|
297
304
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
298
305
|
// Check for errors
|
299
306
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -332,7 +339,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
332
339
|
throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
|
333
340
|
}
|
334
341
|
searchParams = new URLSearchParams(__assign(__assign({}, (linkavelCardNumber && { linkavelCardNumber: linkavelCardNumber })), (linkavelCardPhoneNumber && { linkavelCardPhoneNumber: linkavelCardPhoneNumber })));
|
335
|
-
url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams);
|
342
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_resources/buyers?").concat(searchParams);
|
336
343
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
337
344
|
// Check for errors
|
338
345
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -366,7 +373,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
366
373
|
buyer: buyerDetails,
|
367
374
|
passengers: [],
|
368
375
|
};
|
369
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
376
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details");
|
370
377
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
371
378
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
372
379
|
return response;
|
@@ -386,12 +393,12 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
386
393
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
387
394
|
*/
|
388
395
|
ServiceBooking.prototype.addReduction = function (request) {
|
389
|
-
var _a;
|
390
396
|
return __awaiter(this, void 0, void 0, function () {
|
391
|
-
var discountsStep,
|
397
|
+
var discountsStep, _i, _a, step, url;
|
392
398
|
var _this = this;
|
393
|
-
|
394
|
-
|
399
|
+
var _b;
|
400
|
+
return __generator(this, function (_c) {
|
401
|
+
switch (_c.label) {
|
395
402
|
case 0:
|
396
403
|
// First check that it is possible to call this API
|
397
404
|
if (!this.cartId || this.cartId === 0) {
|
@@ -401,22 +408,16 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
401
408
|
if (!discountsStep)
|
402
409
|
throw Error("Booking step not found!");
|
403
410
|
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
404
|
-
|
405
|
-
_c =
|
406
|
-
for (_d in _b)
|
407
|
-
_c.push(_d);
|
408
|
-
_i = 0;
|
409
|
-
_e.label = 1;
|
411
|
+
_i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
412
|
+
_c.label = 1;
|
410
413
|
case 1:
|
411
|
-
if (!(_i <
|
412
|
-
|
413
|
-
if (
|
414
|
-
step = _d;
|
415
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
414
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
415
|
+
step = _a[_i];
|
416
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
|
416
417
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
417
418
|
case 2:
|
418
|
-
|
419
|
-
|
419
|
+
_c.sent();
|
420
|
+
_c.label = 3;
|
420
421
|
case 3:
|
421
422
|
_i++;
|
422
423
|
return [3 /*break*/, 1];
|
@@ -426,9 +427,9 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
426
427
|
if (!discountsStep || !discountsStep[0]) {
|
427
428
|
throw Error("The status of the cart does not allow to call this API");
|
428
429
|
}
|
429
|
-
|
430
|
+
_c.label = 5;
|
430
431
|
case 5:
|
431
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
432
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction");
|
432
433
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
433
434
|
var _a, _b;
|
434
435
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -465,7 +466,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
465
466
|
throw Error("The status of the cart does not allow to call this API");
|
466
467
|
}
|
467
468
|
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
468
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
469
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
469
470
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
470
471
|
var _a, _b, _c;
|
471
472
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -490,12 +491,12 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
490
491
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
491
492
|
*/
|
492
493
|
ServiceBooking.prototype.useWallet = function () {
|
493
|
-
var _a;
|
494
494
|
return __awaiter(this, void 0, void 0, function () {
|
495
|
-
var issueStep,
|
495
|
+
var issueStep, _i, _a, step, url;
|
496
496
|
var _this = this;
|
497
|
-
|
498
|
-
|
497
|
+
var _b;
|
498
|
+
return __generator(this, function (_c) {
|
499
|
+
switch (_c.label) {
|
499
500
|
case 0:
|
500
501
|
// First check that it is possible to call this API
|
501
502
|
if (!this.cartId || this.cartId === 0) {
|
@@ -505,22 +506,16 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
505
506
|
if (!issueStep)
|
506
507
|
throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
|
507
508
|
if (!!issueStep[0]) return [3 /*break*/, 5];
|
508
|
-
|
509
|
-
_c =
|
510
|
-
for (_d in _b)
|
511
|
-
_c.push(_d);
|
512
|
-
_i = 0;
|
513
|
-
_e.label = 1;
|
509
|
+
_i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
|
510
|
+
_c.label = 1;
|
514
511
|
case 1:
|
515
|
-
if (!(_i <
|
516
|
-
|
517
|
-
if (
|
518
|
-
step = _d;
|
519
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
512
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
513
|
+
step = _a[_i];
|
514
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
|
520
515
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
521
516
|
case 2:
|
522
|
-
|
523
|
-
|
517
|
+
_c.sent();
|
518
|
+
_c.label = 3;
|
524
519
|
case 3:
|
525
520
|
_i++;
|
526
521
|
return [3 /*break*/, 1];
|
@@ -530,9 +525,9 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
530
525
|
if (!issueStep || !issueStep[0]) {
|
531
526
|
throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
|
532
527
|
}
|
533
|
-
|
528
|
+
_c.label = 5;
|
534
529
|
case 5:
|
535
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
530
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
|
536
531
|
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
537
532
|
var _a, _b;
|
538
533
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -563,7 +558,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
563
558
|
if (!this.cartId || this.cartId === 0) {
|
564
559
|
throw Error("Cart is not initialized yet");
|
565
560
|
}
|
566
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
561
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
|
567
562
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
568
563
|
var _a, _b, _c;
|
569
564
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -587,12 +582,12 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
587
582
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
588
583
|
*/
|
589
584
|
ServiceBooking.prototype.useVoucher = function (voucherCode) {
|
590
|
-
var _a;
|
591
585
|
return __awaiter(this, void 0, void 0, function () {
|
592
|
-
var discountsStep,
|
586
|
+
var discountsStep, _i, _a, step, url;
|
593
587
|
var _this = this;
|
594
|
-
|
595
|
-
|
588
|
+
var _b;
|
589
|
+
return __generator(this, function (_c) {
|
590
|
+
switch (_c.label) {
|
596
591
|
case 0:
|
597
592
|
// First check that it is possible to call this API
|
598
593
|
if (!this.cartId || this.cartId === 0) {
|
@@ -602,22 +597,16 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
602
597
|
if (!discountsStep)
|
603
598
|
throw Error("Booking step not found!");
|
604
599
|
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
605
|
-
|
606
|
-
_c =
|
607
|
-
for (_d in _b)
|
608
|
-
_c.push(_d);
|
609
|
-
_i = 0;
|
610
|
-
_e.label = 1;
|
600
|
+
_i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
601
|
+
_c.label = 1;
|
611
602
|
case 1:
|
612
|
-
if (!(_i <
|
613
|
-
|
614
|
-
if (
|
615
|
-
step = _d;
|
616
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
603
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
604
|
+
step = _a[_i];
|
605
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
|
617
606
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
618
607
|
case 2:
|
619
|
-
|
620
|
-
|
608
|
+
_c.sent();
|
609
|
+
_c.label = 3;
|
621
610
|
case 3:
|
622
611
|
_i++;
|
623
612
|
return [3 /*break*/, 1];
|
@@ -627,9 +616,9 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
627
616
|
if (!discountsStep || !discountsStep[0]) {
|
628
617
|
throw Error("The status of the cart does not allow to call this API");
|
629
618
|
}
|
630
|
-
|
619
|
+
_c.label = 5;
|
631
620
|
case 5:
|
632
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
621
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/voucher");
|
633
622
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
634
623
|
var _a, _b;
|
635
624
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -668,10 +657,10 @@ exports.ServiceBooking = ServiceBooking;
|
|
668
657
|
case 3: return [2 /*return*/, booking];
|
669
658
|
case 4:
|
670
659
|
error_1 = _a.sent();
|
671
|
-
// Check if the error is due to an expired cart. In this case, delete the cartId from the
|
660
|
+
// Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
|
672
661
|
// This error can occur when the user refreshes the page and the cart has expired
|
673
662
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
|
674
|
-
|
663
|
+
booking.getStorage().getState().updateCartId(undefined);
|
675
664
|
booking.cartId = undefined;
|
676
665
|
return [2 /*return*/, booking];
|
677
666
|
}
|
@@ -19,6 +19,52 @@ export declare class SubscriptionBooking extends Booking {
|
|
19
19
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
20
20
|
*/
|
21
21
|
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
22
|
+
getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
23
|
+
cartId: number | undefined;
|
24
|
+
} & {
|
25
|
+
updateCartId: (cartId: number | undefined) => void;
|
26
|
+
resetState: () => void;
|
27
|
+
}>, "persist"> & {
|
28
|
+
persist: {
|
29
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
|
30
|
+
cartId: number | undefined;
|
31
|
+
} & {
|
32
|
+
updateCartId: (cartId: number | undefined) => void;
|
33
|
+
resetState: () => void;
|
34
|
+
}, {
|
35
|
+
cartId: number | undefined;
|
36
|
+
} & {
|
37
|
+
updateCartId: (cartId: number | undefined) => void;
|
38
|
+
resetState: () => void;
|
39
|
+
}>>) => void;
|
40
|
+
clearStorage: () => void;
|
41
|
+
rehydrate: () => void | Promise<void>;
|
42
|
+
hasHydrated: () => boolean;
|
43
|
+
onHydrate: (fn: (state: {
|
44
|
+
cartId: number | undefined;
|
45
|
+
} & {
|
46
|
+
updateCartId: (cartId: number | undefined) => void;
|
47
|
+
resetState: () => void;
|
48
|
+
}) => void) => () => void;
|
49
|
+
onFinishHydration: (fn: (state: {
|
50
|
+
cartId: number | undefined;
|
51
|
+
} & {
|
52
|
+
updateCartId: (cartId: number | undefined) => void;
|
53
|
+
resetState: () => void;
|
54
|
+
}) => void) => () => void;
|
55
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
|
56
|
+
cartId: number | undefined;
|
57
|
+
} & {
|
58
|
+
updateCartId: (cartId: number | undefined) => void;
|
59
|
+
resetState: () => void;
|
60
|
+
}, {
|
61
|
+
cartId: number | undefined;
|
62
|
+
} & {
|
63
|
+
updateCartId: (cartId: number | undefined) => void;
|
64
|
+
resetState: () => void;
|
65
|
+
}>>;
|
66
|
+
};
|
67
|
+
}>;
|
22
68
|
getCart(): SubscriptionCart | undefined;
|
23
69
|
resetBooking(): void;
|
24
70
|
fetchAndSetCart(cartId: number): Promise<void>;
|