mts-booking-library 1.4.0 → 2.0.0
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.
- package/lib/SubscriptionBooking.d.ts +0 -0
- package/lib/SubscriptionBooking.js +148 -0
- package/lib/booking/booking.d.ts +12 -9
- package/lib/booking/booking.js +44 -9
- package/lib/booking/journeyBooking.d.ts +8 -21
- package/lib/booking/journeyBooking.js +21 -58
- package/lib/booking/serviceBooking.d.ts +9 -22
- package/lib/booking/serviceBooking.js +23 -58
- package/lib/booking/subscriptionBooking.d.ts +8 -21
- package/lib/booking/subscriptionBooking.js +20 -55
- package/lib/booking/tplBooking.d.ts +13 -31
- package/lib/booking/tplBooking.js +29 -68
- package/lib/index.d.ts +8 -7
- package/lib/index.js +3 -3
- package/lib/mtsStorage.d.ts +1 -3
- package/lib/mtsStorage.js +4 -5
- package/lib/types/common/Cart.d.ts +0 -5
- package/lib/types/common/Payment.d.ts +3 -3
- package/lib/types/common/Payment.js +1 -1
- package/lib/types/common/Person.d.ts +8 -8
- package/lib/types/common/Person.js +3 -3
- package/lib/types/journeys/JourneyCart.d.ts +14 -9
- package/lib/types/journeys/JourneyCart.js +1 -1
- package/lib/types/services/ServiceCart.d.ts +4 -0
- package/lib/types/tpl/SuperArea.d.ts +6 -0
- package/lib/types/tpl/TplCart.d.ts +19 -0
- package/lib/utils/apiCall.js +2 -2
- package/lib/utils/testUtils.d.ts +8 -0
- package/lib/utils/testUtils.js +19 -0
- package/package.json +6 -6
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
|
-
import {
|
2
|
+
import { PersonDetails, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
3
3
|
import { AddReductionRequest } from "../types/common/Reduction";
|
4
4
|
import { Service, ServiceTripsResponse } from "../types/services/Service";
|
5
5
|
import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
|
@@ -11,54 +11,47 @@ export declare class ServiceBooking extends Booking {
|
|
11
11
|
*/
|
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
|
-
cartId: number | undefined;
|
15
14
|
cartGuid: string | undefined;
|
16
15
|
} & {
|
17
|
-
|
16
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
18
17
|
resetState: () => void;
|
19
18
|
}>, "persist"> & {
|
20
19
|
persist: {
|
21
20
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
|
22
|
-
cartId: number | undefined;
|
23
21
|
cartGuid: string | undefined;
|
24
22
|
} & {
|
25
|
-
|
23
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
26
24
|
resetState: () => void;
|
27
25
|
}, {
|
28
|
-
cartId: number | undefined;
|
29
26
|
cartGuid: string | undefined;
|
30
27
|
} & {
|
31
|
-
|
28
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
32
29
|
resetState: () => void;
|
33
30
|
}>>) => void;
|
34
31
|
clearStorage: () => void;
|
35
32
|
rehydrate: () => Promise<void> | void;
|
36
33
|
hasHydrated: () => boolean;
|
37
34
|
onHydrate: (fn: (state: {
|
38
|
-
cartId: number | undefined;
|
39
35
|
cartGuid: string | undefined;
|
40
36
|
} & {
|
41
|
-
|
37
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
42
38
|
resetState: () => void;
|
43
39
|
}) => void) => () => void;
|
44
40
|
onFinishHydration: (fn: (state: {
|
45
|
-
cartId: number | undefined;
|
46
41
|
cartGuid: string | undefined;
|
47
42
|
} & {
|
48
|
-
|
43
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
49
44
|
resetState: () => void;
|
50
45
|
}) => void) => () => void;
|
51
46
|
getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
|
52
|
-
cartId: number | undefined;
|
53
47
|
cartGuid: string | undefined;
|
54
48
|
} & {
|
55
|
-
|
49
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
56
50
|
resetState: () => void;
|
57
51
|
}, {
|
58
|
-
cartId: number | undefined;
|
59
52
|
cartGuid: string | undefined;
|
60
53
|
} & {
|
61
|
-
|
54
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
62
55
|
resetState: () => void;
|
63
56
|
}>>;
|
64
57
|
};
|
@@ -103,19 +96,13 @@ export declare class ServiceBooking extends Booking {
|
|
103
96
|
* as well as a list of the available tariffs for each trip.
|
104
97
|
*/
|
105
98
|
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
106
|
-
/**
|
107
|
-
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
108
|
-
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
109
|
-
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
110
|
-
*/
|
111
|
-
getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
112
99
|
/**
|
113
100
|
* @description This method shall be called when the user wants to update the buyer information.
|
114
101
|
* @param buyerDetails The object containing the buyer information.
|
115
102
|
* It should be null if the buyer data cannot be specified (see {@link GetBuyerPassengersDetailsResponse.buyerDataStatus}).
|
116
103
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
117
104
|
*/
|
118
|
-
updateBuyerPassengersDetails(buyerDetails:
|
105
|
+
updateBuyerPassengersDetails(buyerDetails: PersonDetails | null): Promise<ErrorResponse | boolean>;
|
119
106
|
/**
|
120
107
|
* @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
|
121
108
|
* @param {AddReductionRequest} request The information about the reduction to add
|
@@ -35,8 +35,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
35
35
|
});
|
36
36
|
};
|
37
37
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
39
|
-
return g =
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
39
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
40
40
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
41
41
|
function step(op) {
|
42
42
|
if (f) throw new TypeError("Generator is already executing.");
|
@@ -99,11 +99,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
99
99
|
resellerId: resellerId,
|
100
100
|
dbType: dbType
|
101
101
|
}) || this;
|
102
|
-
// Set
|
103
|
-
var
|
104
|
-
if (cartId && restoreState) {
|
105
|
-
_this.cartId = cartId;
|
106
|
-
}
|
102
|
+
// Set cartGuid
|
103
|
+
var cartGuid = _this.getStorage().getState().cartGuid;
|
107
104
|
if (cartGuid && restoreState) {
|
108
105
|
_this.cartGuid = cartGuid;
|
109
106
|
}
|
@@ -120,16 +117,15 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
120
117
|
};
|
121
118
|
ServiceBooking.prototype.resetBooking = function () {
|
122
119
|
this.cart = undefined;
|
123
|
-
this.cartId = undefined;
|
124
120
|
this.cartGuid = undefined;
|
125
121
|
this.bookingStepsToStatus = new Map();
|
126
122
|
this.bookingDueDate = undefined;
|
127
123
|
try {
|
128
|
-
this.getStorage().getState().
|
124
|
+
this.getStorage().getState().updateCartGuid(undefined);
|
129
125
|
}
|
130
126
|
catch (e) {
|
131
127
|
if (this.config.ENV !== config_1.MTSEnvs.TEST) {
|
132
|
-
throw new Error("Error while deleting
|
128
|
+
throw new Error("Error while deleting cartGuid from storage");
|
133
129
|
}
|
134
130
|
console.log(e);
|
135
131
|
}
|
@@ -145,7 +141,6 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
145
141
|
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
146
142
|
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
147
143
|
_this.cart = cart;
|
148
|
-
_this.cartId = cart.id;
|
149
144
|
_this.cartGuid = cart.guid;
|
150
145
|
_this.bookingDueDate = cartDueDate; // See Booking class
|
151
146
|
// Update the sellerId. This is particularly important in Linkavel
|
@@ -260,8 +255,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
260
255
|
return __awaiter(this, void 0, void 0, function () {
|
261
256
|
var searchParams, url;
|
262
257
|
return __generator(this, function (_a) {
|
263
|
-
searchParams = new URLSearchParams({ date: date });
|
264
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/
|
258
|
+
searchParams = new URLSearchParams({ serviceId: serviceId.toString(), date: date });
|
259
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/trips?").concat(searchParams);
|
265
260
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
266
261
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
267
262
|
? response
|
@@ -279,16 +274,15 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
279
274
|
return [2 /*return*/, this.callPostApi(url, serviceCart).then(function (response) {
|
280
275
|
// Check for errors
|
281
276
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
282
|
-
// If there was an error, reset
|
277
|
+
// If there was an error, reset cartGuid and remove it from the mts-storage
|
283
278
|
_this.resetBooking();
|
284
279
|
return response;
|
285
280
|
}
|
286
281
|
// Save the local data
|
287
282
|
_this.cart = response.cart;
|
288
|
-
_this.cartId = response.cart.id;
|
289
283
|
_this.cartGuid = response.cart.guid;
|
290
|
-
// Save the
|
291
|
-
_this.getStorage().getState().
|
284
|
+
// Save the cartGuid in the mts-storage
|
285
|
+
_this.getStorage().getState().updateCartGuid(response.cart.guid);
|
292
286
|
// Fill the booking process status
|
293
287
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
294
288
|
var cartDueDate = new Date();
|
@@ -301,7 +295,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
301
295
|
});
|
302
296
|
});
|
303
297
|
};
|
304
|
-
//#region
|
298
|
+
//#region PersonDetails data API
|
305
299
|
/**
|
306
300
|
* @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
|
307
301
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
@@ -335,39 +329,6 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
335
329
|
});
|
336
330
|
});
|
337
331
|
};
|
338
|
-
/**
|
339
|
-
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
340
|
-
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
341
|
-
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
342
|
-
*/
|
343
|
-
ServiceBooking.prototype.getBuyer = function (request) {
|
344
|
-
return __awaiter(this, void 0, void 0, function () {
|
345
|
-
var buyerPassengersDetails, searchParams, url;
|
346
|
-
var _a;
|
347
|
-
return __generator(this, function (_b) {
|
348
|
-
// First check that it is possible to call this API
|
349
|
-
if (!this.cart) {
|
350
|
-
throw Error("Cart is not initialized yet");
|
351
|
-
}
|
352
|
-
buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
|
353
|
-
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
354
|
-
throw Error("The status of the cart does not allow to call this API");
|
355
|
-
}
|
356
|
-
if (!request.personId && !request.personCode && !request.phoneNumber) {
|
357
|
-
throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
|
358
|
-
}
|
359
|
-
searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
|
360
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
|
361
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
362
|
-
// Check for errors
|
363
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
364
|
-
return response;
|
365
|
-
}
|
366
|
-
return response.persons[0];
|
367
|
-
})];
|
368
|
-
});
|
369
|
-
});
|
370
|
-
};
|
371
332
|
/**
|
372
333
|
* @description This method shall be called when the user wants to update the buyer information.
|
373
334
|
* @param buyerDetails The object containing the buyer information.
|
@@ -449,7 +410,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
449
410
|
_c.label = 5;
|
450
411
|
case 5:
|
451
412
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
452
|
-
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), {
|
413
|
+
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid })).then(function (response) {
|
453
414
|
var _a, _b;
|
454
415
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
455
416
|
return response;
|
@@ -484,7 +445,10 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
484
445
|
if (!discountsStep || !discountsStep[0]) {
|
485
446
|
throw Error("The status of the cart does not allow to call this API");
|
486
447
|
}
|
487
|
-
queryParams = new URLSearchParams({
|
448
|
+
queryParams = new URLSearchParams({
|
449
|
+
tripId: tripId.toString(),
|
450
|
+
cartGuid: this.cartGuid
|
451
|
+
});
|
488
452
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
489
453
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
490
454
|
var _a, _b, _c;
|
@@ -553,7 +517,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
553
517
|
_c.label = 5;
|
554
518
|
case 5:
|
555
519
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
556
|
-
return [2 /*return*/, this.callPostApi(url, {
|
520
|
+
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }).then(function (response) {
|
557
521
|
var _a, _b;
|
558
522
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
559
523
|
return response;
|
@@ -583,7 +547,9 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
583
547
|
if ((0, utils_1.isNullOrWhiteSpace)(this.cartGuid)) {
|
584
548
|
throw Error("Cart is not initialized yet");
|
585
549
|
}
|
586
|
-
queryParams = new URLSearchParams({
|
550
|
+
queryParams = new URLSearchParams({
|
551
|
+
cartGuid: this.cartGuid
|
552
|
+
});
|
587
553
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
588
554
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
589
555
|
var _a, _b, _c;
|
@@ -695,11 +661,10 @@ exports.ServiceBooking = ServiceBooking;
|
|
695
661
|
case 3: return [2 /*return*/, booking];
|
696
662
|
case 4:
|
697
663
|
error_1 = _c.sent();
|
698
|
-
// Check if the error is due to an expired cart. In this case, delete the
|
664
|
+
// Check if the error is due to an expired cart. In this case, delete the cartGuid from the mts-storage
|
699
665
|
// This error can occur when the user refreshes the page and the cart has expired
|
700
666
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
|
701
|
-
booking.getStorage().getState().
|
702
|
-
booking.cartId = undefined;
|
667
|
+
booking.getStorage().getState().updateCartGuid(undefined);
|
703
668
|
booking.cartGuid = undefined;
|
704
669
|
return [2 /*return*/, booking];
|
705
670
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
|
-
import {
|
2
|
+
import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
3
3
|
import { AddReductionRequest } from "../types/common/Reduction";
|
4
4
|
import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
|
5
5
|
import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
|
@@ -12,54 +12,47 @@ export declare class SubscriptionBooking extends Booking {
|
|
12
12
|
*/
|
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
|
-
cartId: number | undefined;
|
16
15
|
cartGuid: string | undefined;
|
17
16
|
} & {
|
18
|
-
|
17
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
19
18
|
resetState: () => void;
|
20
19
|
}>, "persist"> & {
|
21
20
|
persist: {
|
22
21
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
|
23
|
-
cartId: number | undefined;
|
24
22
|
cartGuid: string | undefined;
|
25
23
|
} & {
|
26
|
-
|
24
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
27
25
|
resetState: () => void;
|
28
26
|
}, {
|
29
|
-
cartId: number | undefined;
|
30
27
|
cartGuid: string | undefined;
|
31
28
|
} & {
|
32
|
-
|
29
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
33
30
|
resetState: () => void;
|
34
31
|
}>>) => void;
|
35
32
|
clearStorage: () => void;
|
36
33
|
rehydrate: () => Promise<void> | void;
|
37
34
|
hasHydrated: () => boolean;
|
38
35
|
onHydrate: (fn: (state: {
|
39
|
-
cartId: number | undefined;
|
40
36
|
cartGuid: string | undefined;
|
41
37
|
} & {
|
42
|
-
|
38
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
43
39
|
resetState: () => void;
|
44
40
|
}) => void) => () => void;
|
45
41
|
onFinishHydration: (fn: (state: {
|
46
|
-
cartId: number | undefined;
|
47
42
|
cartGuid: string | undefined;
|
48
43
|
} & {
|
49
|
-
|
44
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
50
45
|
resetState: () => void;
|
51
46
|
}) => void) => () => void;
|
52
47
|
getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
|
53
|
-
cartId: number | undefined;
|
54
48
|
cartGuid: string | undefined;
|
55
49
|
} & {
|
56
|
-
|
50
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
57
51
|
resetState: () => void;
|
58
52
|
}, {
|
59
|
-
cartId: number | undefined;
|
60
53
|
cartGuid: string | undefined;
|
61
54
|
} & {
|
62
|
-
|
55
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
63
56
|
resetState: () => void;
|
64
57
|
}>>;
|
65
58
|
};
|
@@ -122,12 +115,6 @@ export declare class SubscriptionBooking extends Booking {
|
|
122
115
|
* as well as a list of the available tariffs for each trip.
|
123
116
|
*/
|
124
117
|
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
125
|
-
/**
|
126
|
-
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
127
|
-
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
128
|
-
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
129
|
-
*/
|
130
|
-
getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
131
118
|
/**
|
132
119
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
133
120
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
@@ -35,8 +35,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
35
35
|
});
|
36
36
|
};
|
37
37
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
39
|
-
return g =
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
39
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
40
40
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
41
41
|
function step(op) {
|
42
42
|
if (f) throw new TypeError("Generator is already executing.");
|
@@ -99,11 +99,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
99
99
|
resellerId: resellerId,
|
100
100
|
dbType: dbType
|
101
101
|
}) || this;
|
102
|
-
// Set
|
103
|
-
var
|
104
|
-
if (cartId && restoreState) {
|
105
|
-
_this.cartId = cartId;
|
106
|
-
}
|
102
|
+
// Set cartGuid
|
103
|
+
var cartGuid = _this.getStorage().getState().cartGuid;
|
107
104
|
if (cartGuid && restoreState) {
|
108
105
|
_this.cartGuid = cartGuid;
|
109
106
|
}
|
@@ -120,16 +117,15 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
120
117
|
};
|
121
118
|
SubscriptionBooking.prototype.resetBooking = function () {
|
122
119
|
this.cart = undefined;
|
123
|
-
this.cartId = undefined;
|
124
120
|
this.cartGuid = undefined;
|
125
121
|
this.bookingStepsToStatus = new Map();
|
126
122
|
this.bookingDueDate = undefined;
|
127
123
|
try {
|
128
|
-
this.getStorage().getState().
|
124
|
+
this.getStorage().getState().updateCartGuid(undefined);
|
129
125
|
}
|
130
126
|
catch (e) {
|
131
127
|
if (this.config.ENV !== config_1.MTSEnvs.TEST) {
|
132
|
-
throw new Error("Error while deleting
|
128
|
+
throw new Error("Error while deleting cartGuid from storage");
|
133
129
|
}
|
134
130
|
console.log(e);
|
135
131
|
}
|
@@ -145,7 +141,6 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
145
141
|
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
146
142
|
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
147
143
|
_this.cart = cart;
|
148
|
-
_this.cartId = cart.id;
|
149
144
|
_this.cartGuid = cart.guid;
|
150
145
|
_this.bookingDueDate = cartDueDate; // See Booking class
|
151
146
|
// Update the sellerId. This is particularly important in Linkavel
|
@@ -338,15 +333,14 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
338
333
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
339
334
|
// Check for errors
|
340
335
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
341
|
-
// If there was an error, reset
|
336
|
+
// If there was an error, reset cartGuid and remove it from the mts-storage
|
342
337
|
_this.resetBooking();
|
343
338
|
return response;
|
344
339
|
}
|
345
340
|
_this.cart = response.cart;
|
346
|
-
_this.cartId = response.cart.id;
|
347
341
|
_this.cartGuid = response.cart.guid;
|
348
|
-
// Save the
|
349
|
-
_this.getStorage().getState().
|
342
|
+
// Save the cartGuid in the mts-storage
|
343
|
+
_this.getStorage().getState().updateCartGuid(response.cart.guid);
|
350
344
|
// Fill the booking process status
|
351
345
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
352
346
|
var cartDueDate = new Date();
|
@@ -414,39 +408,6 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
414
408
|
});
|
415
409
|
});
|
416
410
|
};
|
417
|
-
/**
|
418
|
-
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
419
|
-
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
420
|
-
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
421
|
-
*/
|
422
|
-
SubscriptionBooking.prototype.getBuyer = function (request) {
|
423
|
-
return __awaiter(this, void 0, void 0, function () {
|
424
|
-
var buyerPassengersDetails, searchParams, url;
|
425
|
-
var _a;
|
426
|
-
return __generator(this, function (_b) {
|
427
|
-
// First check that it is possible to call this API
|
428
|
-
if (!this.cart) {
|
429
|
-
throw Error("Cart is not initialized yet");
|
430
|
-
}
|
431
|
-
buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
|
432
|
-
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
433
|
-
throw Error("The status of the cart does not allow to call this API");
|
434
|
-
}
|
435
|
-
if (!request.personId && !request.personCode && !request.phoneNumber) {
|
436
|
-
throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
|
437
|
-
}
|
438
|
-
searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
|
439
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
|
440
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
441
|
-
// Check for errors
|
442
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
443
|
-
return response;
|
444
|
-
}
|
445
|
-
return response.persons[0];
|
446
|
-
})];
|
447
|
-
});
|
448
|
-
});
|
449
|
-
};
|
450
411
|
/**
|
451
412
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
452
413
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
@@ -529,7 +490,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
529
490
|
_c.label = 5;
|
530
491
|
case 5:
|
531
492
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
|
532
|
-
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), {
|
493
|
+
return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid })).then(function (response) {
|
533
494
|
var _a, _b;
|
534
495
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
535
496
|
return response;
|
@@ -564,7 +525,10 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
564
525
|
if (!discountsStep || !discountsStep[0]) {
|
565
526
|
throw Error("The status of the cart does not allow to call this API");
|
566
527
|
}
|
567
|
-
queryParams = new URLSearchParams({
|
528
|
+
queryParams = new URLSearchParams({
|
529
|
+
tripId: tripId.toString(),
|
530
|
+
cartGuid: this.cartGuid
|
531
|
+
});
|
568
532
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
|
569
533
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
570
534
|
var _a, _b, _c;
|
@@ -633,7 +597,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
633
597
|
_c.label = 5;
|
634
598
|
case 5:
|
635
599
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
|
636
|
-
return [2 /*return*/, this.callPostApi(url, {
|
600
|
+
return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }).then(function (response) {
|
637
601
|
var _a, _b;
|
638
602
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
639
603
|
return response;
|
@@ -663,7 +627,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
663
627
|
if ((0, utils_1.isNullOrWhiteSpace)(this.cartGuid)) {
|
664
628
|
throw Error("Cart is not initialized yet");
|
665
629
|
}
|
666
|
-
queryParams = new URLSearchParams({
|
630
|
+
queryParams = new URLSearchParams({
|
631
|
+
cartGuid: this.cartGuid
|
632
|
+
});
|
667
633
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
|
668
634
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
669
635
|
var _a, _b, _c;
|
@@ -775,11 +741,10 @@ exports.SubscriptionBooking = SubscriptionBooking;
|
|
775
741
|
case 3: return [2 /*return*/, booking];
|
776
742
|
case 4:
|
777
743
|
error_1 = _c.sent();
|
778
|
-
// Check if the error is due to an expired cart. In this case, delete the
|
744
|
+
// Check if the error is due to an expired cart. In this case, delete the cartGuid from the mts-storage
|
779
745
|
// This error can occur when the user refreshes the page and the cart has expired
|
780
746
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
|
781
|
-
booking.getStorage().getState().
|
782
|
-
booking.cartId = undefined;
|
747
|
+
booking.getStorage().getState().updateCartGuid(undefined);
|
783
748
|
booking.cartGuid = undefined;
|
784
749
|
return [2 /*return*/, booking];
|
785
750
|
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
2
|
import { City } from "../types/common/City";
|
3
|
-
import {
|
3
|
+
import { PersonDetails, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
4
4
|
import { AddReductionRequest } from "../types/common/Reduction";
|
5
5
|
import { TariffType, TermsType } from "../types/common/Tariffs";
|
6
6
|
import { GetTariffsResponse } from "../types/tpl/GetTariffsResponse";
|
7
|
-
import { SuperArea } from "../types/tpl/SuperArea";
|
8
|
-
import { TplCart } from "../types/tpl/TplCart";
|
7
|
+
import { GetSuperAreasRequest, SuperArea } from "../types/tpl/SuperArea";
|
8
|
+
import { CreateTplCartRequest, TplCart } from "../types/tpl/TplCart";
|
9
9
|
import { Booking } from "./booking";
|
10
10
|
export declare class TplBooking extends Booking {
|
11
11
|
private cart?;
|
@@ -14,54 +14,47 @@ export declare class TplBooking extends Booking {
|
|
14
14
|
*/
|
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
|
-
cartId: number | undefined;
|
18
17
|
cartGuid: string | undefined;
|
19
18
|
} & {
|
20
|
-
|
19
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
21
20
|
resetState: () => void;
|
22
21
|
}>, "persist"> & {
|
23
22
|
persist: {
|
24
23
|
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
|
25
|
-
cartId: number | undefined;
|
26
24
|
cartGuid: string | undefined;
|
27
25
|
} & {
|
28
|
-
|
26
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
29
27
|
resetState: () => void;
|
30
28
|
}, {
|
31
|
-
cartId: number | undefined;
|
32
29
|
cartGuid: string | undefined;
|
33
30
|
} & {
|
34
|
-
|
31
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
35
32
|
resetState: () => void;
|
36
33
|
}>>) => void;
|
37
34
|
clearStorage: () => void;
|
38
35
|
rehydrate: () => Promise<void> | void;
|
39
36
|
hasHydrated: () => boolean;
|
40
37
|
onHydrate: (fn: (state: {
|
41
|
-
cartId: number | undefined;
|
42
38
|
cartGuid: string | undefined;
|
43
39
|
} & {
|
44
|
-
|
40
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
45
41
|
resetState: () => void;
|
46
42
|
}) => void) => () => void;
|
47
43
|
onFinishHydration: (fn: (state: {
|
48
|
-
cartId: number | undefined;
|
49
44
|
cartGuid: string | undefined;
|
50
45
|
} & {
|
51
|
-
|
46
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
52
47
|
resetState: () => void;
|
53
48
|
}) => void) => () => void;
|
54
49
|
getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
|
55
|
-
cartId: number | undefined;
|
56
50
|
cartGuid: string | undefined;
|
57
51
|
} & {
|
58
|
-
|
52
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
59
53
|
resetState: () => void;
|
60
54
|
}, {
|
61
|
-
cartId: number | undefined;
|
62
55
|
cartGuid: string | undefined;
|
63
56
|
} & {
|
64
|
-
|
57
|
+
updateCartGuid: (cartGuid: string | undefined) => void;
|
65
58
|
resetState: () => void;
|
66
59
|
}>>;
|
67
60
|
};
|
@@ -87,7 +80,7 @@ export declare class TplBooking extends Booking {
|
|
87
80
|
* the TPL service is available at a certain price.
|
88
81
|
* @returns An array of {@link SuperArea} objects representing the SuperAreas if the call is successful, an {@link ErrorResponse} object otherwise.
|
89
82
|
*/
|
90
|
-
getSuperAreas(
|
83
|
+
getSuperAreas(request: GetSuperAreasRequest): Promise<ErrorResponse | SuperArea[]>;
|
91
84
|
/**
|
92
85
|
* This method fetches the list of terms types in a given super area.
|
93
86
|
* @returns An array of {@link TermsType} objects representing the available terms types if the call is successful, an {@link ErrorResponse} object otherwise.
|
@@ -110,25 +103,14 @@ export declare class TplBooking extends Booking {
|
|
110
103
|
getTariffs(superAreaId: number, termsTypeId: number | null, onlyTickets: boolean, onlySubscriptions: boolean): Promise<ErrorResponse | GetTariffsResponse>;
|
111
104
|
/**
|
112
105
|
* This method allows to create a TPL cart.
|
113
|
-
* @param tariffIdToQuantity A map that associates a tariff id (the one chosen by the user) to the number of tickets to buy for that tariff.
|
114
|
-
* @param currency The currency in which the ticket is priced.
|
115
|
-
* @param startDate The start date of the ticket. This is optional and should be used only for subscriptions.
|
116
|
-
* @param isCurrentPeriod Whether the subscription is for the current period. This is optional and should be used only for subscriptions.
|
117
|
-
* @param renewSubscriptionTicketPNR The PNR of the subscription ticket to renew. This is optional and should be used only for subscriptions.
|
118
106
|
*/
|
119
|
-
createTplCart(
|
107
|
+
createTplCart(tplCart: CreateTplCartRequest): Promise<ErrorResponse | TplCart>;
|
120
108
|
/**
|
121
109
|
* @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
|
122
110
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
123
111
|
* as well as a list of the available tariffs for each trip.
|
124
112
|
*/
|
125
113
|
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
126
|
-
/**
|
127
|
-
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
128
|
-
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
129
|
-
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
130
|
-
*/
|
131
|
-
getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
132
114
|
/**
|
133
115
|
* @description This method shall be called when the user wants to update the buyer information.
|
134
116
|
* @param buyerDetails The object containing the buyer information.
|
@@ -137,7 +119,7 @@ export declare class TplBooking extends Booking {
|
|
137
119
|
* with the subscription. This parameter is required if the cart contains a subscription.
|
138
120
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
139
121
|
*/
|
140
|
-
updateBuyerPassengersDetails(buyerDetails:
|
122
|
+
updateBuyerPassengersDetails(buyerDetails: PersonDetails | null, subscriptionPersonCode?: string): Promise<ErrorResponse | boolean>;
|
141
123
|
/**
|
142
124
|
* @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
|
143
125
|
* @param {AddReductionRequest} request The information about the reduction to add
|