mts-booking-library 1.3.17 → 1.3.19
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +6 -20
- package/lib/booking/booking.d.ts +2 -0
- package/lib/booking/booking.js +3 -3
- package/lib/booking/journeyBooking.d.ts +17 -10
- package/lib/booking/journeyBooking.js +43 -27
- package/lib/booking/serviceBooking.d.ts +16 -9
- package/lib/booking/serviceBooking.js +28 -19
- package/lib/booking/subscriptionBooking.d.ts +16 -9
- package/lib/booking/subscriptionBooking.js +28 -20
- package/lib/booking/tplBooking.d.ts +16 -9
- package/lib/booking/tplBooking.js +28 -19
- package/lib/mtsStorage.d.ts +3 -1
- package/lib/mtsStorage.js +5 -2
- package/lib/types/Booking.js +1 -0
- package/lib/types/Cart.d.ts +79 -0
- package/lib/types/Details.d.ts +9 -0
- package/lib/types/ErrorResponse.js +4 -1
- package/lib/types/Info.d.ts +7 -0
- package/lib/types/Journeys/Journey.d.ts +8 -0
- package/lib/types/Line.d.ts +6 -0
- package/lib/types/Line.js +2 -0
- package/lib/types/Person.d.ts +7 -0
- package/lib/types/Person.js +2 -0
- package/lib/types/Subscriptions/SubscriptionAvailabilities.js +2 -0
- package/lib/types/Subscriptions/SubscriptionCart.js +2 -0
- package/lib/types/Subscriptions/SubscriptionInfo.js +2 -0
- package/lib/types/Subscriptions/Subscriptions.js +2 -0
- package/lib/types/Subscriptions/Subscrptions.d.ts +12 -0
- package/lib/types/Subscriptions/Subscrptions.js +2 -0
- package/lib/types/Subscriptions/ValidityTypes.d.ts +6 -0
- package/lib/types/Subscriptions/ValidityTypes.js +10 -0
- package/lib/types/TermsAndTariffs.d.ts +21 -0
- package/lib/types/TermsAndTariffs.js +2 -0
- package/lib/types/Tours/Tour.d.ts +18 -0
- package/lib/types/Tours/Tour.js +2 -0
- package/lib/types/common/Cart.d.ts +7 -1
- package/lib/utils/apiCall.js +21 -12
- package/package.json +1 -1
- package/lib/SubscriptionBooking.js +0 -148
- package/lib/utils/testUtils.d.ts +0 -8
- package/lib/utils/testUtils.js +0 -19
- /package/lib/{SubscriptionBooking.d.ts → types/Booking.d.ts} +0 -0
- /package/lib/types/{journeys/JourneyInfo.js → Cart.js} +0 -0
- /package/lib/types/{journeys/Stop.js → Details.js} +0 -0
- /package/lib/types/{journeys/Trip.js → Info.js} +0 -0
- /package/lib/types/{journeys → Journeys}/BusMatrix.d.ts +0 -0
- /package/lib/types/{journeys → Journeys}/BusMatrix.js +0 -0
- /package/lib/types/{subscriptions/SubscriptionAvailabilities.js → Journeys/Journey.js} +0 -0
- /package/lib/types/{journeys → Journeys}/JourneyCart.d.ts +0 -0
- /package/lib/types/{journeys → Journeys}/JourneyCart.js +0 -0
- /package/lib/types/{journeys → Journeys}/JourneyInfo.d.ts +0 -0
- /package/lib/types/{subscriptions/SubscriptionCart.js → Journeys/JourneyInfo.js} +0 -0
- /package/lib/types/{journeys → Journeys}/JourneySearch.d.ts +0 -0
- /package/lib/types/{journeys → Journeys}/JourneySearch.js +0 -0
- /package/lib/types/{journeys → Journeys}/Stop.d.ts +0 -0
- /package/lib/types/{subscriptions/SubscriptionInfo.js → Journeys/Stop.js} +0 -0
- /package/lib/types/{journeys → Journeys}/Trip.d.ts +0 -0
- /package/lib/types/{subscriptions/Subscriptions.js → Journeys/Trip.js} +0 -0
- /package/lib/types/{subscriptions → Subscriptions}/SubscriptionAvailabilities.d.ts +0 -0
- /package/lib/types/{subscriptions → Subscriptions}/SubscriptionCart.d.ts +0 -0
- /package/lib/types/{subscriptions → Subscriptions}/SubscriptionInfo.d.ts +0 -0
- /package/lib/types/{subscriptions → Subscriptions}/Subscriptions.d.ts +0 -0
@@ -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(
|
63
|
-
fetchCart(
|
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
|
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 (
|
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(
|
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 (
|
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({
|
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
|
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({
|
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
|
-
|
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/
|
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.
|
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/
|
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.
|
763
|
-
return [4 /*yield*/, booking.fetchAndSetCart(booking.
|
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(
|
65
|
-
fetchCart(
|
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
|
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 (
|
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(
|
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 (
|
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({
|
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
|
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({
|
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
|
-
|
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/
|
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.
|
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/
|
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.
|
754
|
-
return [4 /*yield*/, booking.fetchAndSetCart(booking.
|
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");
|
package/lib/mtsStorage.d.ts
CHANGED
@@ -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
|
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
|
}));
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { Booking } from "..";
|
2
|
+
import { Person } from "./Person";
|
3
|
+
import { TariffMatrix } from "./TermsAndTariffs";
|
4
|
+
export type Cart = {
|
5
|
+
id: number;
|
6
|
+
cartCode: string;
|
7
|
+
status: Booking.CartStatus;
|
8
|
+
nextStatus: Booking.CartStatus;
|
9
|
+
currency: string;
|
10
|
+
bookingDueDate: string;
|
11
|
+
bookings: {
|
12
|
+
type: string;
|
13
|
+
summary: {
|
14
|
+
quantity: number;
|
15
|
+
label: string;
|
16
|
+
value: number;
|
17
|
+
}[];
|
18
|
+
}[];
|
19
|
+
info: {
|
20
|
+
stops: {
|
21
|
+
id: number;
|
22
|
+
departureTime: Date;
|
23
|
+
destinationTime: Date;
|
24
|
+
name: string;
|
25
|
+
address: string;
|
26
|
+
}[];
|
27
|
+
};
|
28
|
+
buyer: Person;
|
29
|
+
reductions: {
|
30
|
+
tripId: number;
|
31
|
+
tripName: string;
|
32
|
+
value: number;
|
33
|
+
isPercentage: boolean;
|
34
|
+
voucherCode?: string;
|
35
|
+
}[];
|
36
|
+
isSeatsSelectionAllowed: boolean;
|
37
|
+
sellingMethod: string;
|
38
|
+
totalValue: number;
|
39
|
+
totalResellerFee?: number;
|
40
|
+
totalCreditFromChange: number;
|
41
|
+
totalAmountToPay: number;
|
42
|
+
extas: {
|
43
|
+
id: number;
|
44
|
+
resourceId: number;
|
45
|
+
name: string;
|
46
|
+
description: string;
|
47
|
+
notes: string;
|
48
|
+
tariff: {
|
49
|
+
tariffId: number;
|
50
|
+
tariffName: string;
|
51
|
+
};
|
52
|
+
}[];
|
53
|
+
};
|
54
|
+
export type TourCart = {
|
55
|
+
cartId?: number;
|
56
|
+
currency: Booking.Currencies;
|
57
|
+
tour: {
|
58
|
+
tourId: number;
|
59
|
+
date?: Date;
|
60
|
+
tripId?: number;
|
61
|
+
tariffsMatrix: TariffMatrix;
|
62
|
+
};
|
63
|
+
};
|
64
|
+
export type JourneyCart = {
|
65
|
+
cartId?: number;
|
66
|
+
currency: Booking.Currencies;
|
67
|
+
outboundJourney: {
|
68
|
+
departureStopId: number;
|
69
|
+
destinationStopId: number;
|
70
|
+
tripId: number;
|
71
|
+
tariffsMatrix: TariffMatrix;
|
72
|
+
}[];
|
73
|
+
returnJourney: {
|
74
|
+
tripId: number;
|
75
|
+
departureStopId: number;
|
76
|
+
destinationStopId: number;
|
77
|
+
tariffsMatrix: TariffMatrix;
|
78
|
+
}[] | null;
|
79
|
+
};
|
@@ -2,6 +2,9 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.objectIsMTSErrorResponse = void 0;
|
4
4
|
var objectIsMTSErrorResponse = function (error) {
|
5
|
-
|
5
|
+
if (typeof error !== "object" || error === null) {
|
6
|
+
return false;
|
7
|
+
}
|
8
|
+
return "mtsCode" in error && "httpStatus" in error && "message" in error;
|
6
9
|
};
|
7
10
|
exports.objectIsMTSErrorResponse = objectIsMTSErrorResponse;
|