mts-booking-library 1.3.6 → 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +10 -10
- package/lib/booking/booking.js +30 -16
- package/lib/booking/journeyBooking.d.ts +22 -22
- package/lib/booking/journeyBooking.js +61 -41
- package/lib/booking/serviceBooking.d.ts +30 -30
- package/lib/booking/serviceBooking.js +52 -40
- package/lib/booking/subscriptionBooking.d.ts +34 -34
- package/lib/booking/subscriptionBooking.js +70 -52
- package/lib/booking/tplBooking.d.ts +9 -9
- package/lib/booking/tplBooking.js +35 -20
- package/lib/mtsStorage.js +2 -2
- package/lib/types/ErrorResponse.d.ts +1 -1
- package/lib/types/ErrorResponse.js +1 -1
- package/lib/types/common/Payment.d.ts +4 -2
- package/lib/types/common/Person.d.ts +1 -1
- package/lib/types/common/Person.js +4 -4
- package/lib/types/journeys/JourneyCart.js +1 -1
- package/lib/types/journeys/JourneySearch.js +1 -1
- package/lib/utils/apiCall.js +9 -8
- package/package.json +5 -2
@@ -81,15 +81,15 @@ var booking_1 = require("./booking");
|
|
81
81
|
var ServiceBooking = /** @class */ (function (_super) {
|
82
82
|
__extends(ServiceBooking, _super);
|
83
83
|
/**
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
* This is the constructor of the ServiceBooking class.
|
85
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
86
|
+
* @param {string} sub_key The subscription key for using the APIs
|
87
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
88
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
89
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
90
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
91
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
92
|
+
*/
|
93
93
|
function ServiceBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
|
94
94
|
if (debug === void 0) { debug = false; }
|
95
95
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
@@ -166,7 +166,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
166
166
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
167
167
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
168
168
|
_this.resetBooking();
|
169
|
-
throw new Error(response);
|
169
|
+
throw new Error(JSON.stringify(response, null, 2));
|
170
170
|
}
|
171
171
|
// Check that the cart doe not have issued tickets
|
172
172
|
if (response.cart.hasIssuedTickets) {
|
@@ -178,10 +178,10 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
178
178
|
});
|
179
179
|
};
|
180
180
|
/**
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
182
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
183
|
+
* data will be deleted.
|
184
|
+
*/
|
185
185
|
ServiceBooking.prototype.deleteCart = function () {
|
186
186
|
return __awaiter(this, void 0, void 0, function () {
|
187
187
|
var url;
|
@@ -201,28 +201,30 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
201
201
|
});
|
202
202
|
};
|
203
203
|
/**
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
204
|
+
* This method returns the list of cities in which the seller offers tours.
|
205
|
+
* If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
|
206
|
+
* @returns {string[]} The list of possible cities
|
207
|
+
*/
|
208
208
|
ServiceBooking.prototype.getServiceCities = function () {
|
209
209
|
return __awaiter(this, void 0, void 0, function () {
|
210
210
|
var url;
|
211
211
|
return __generator(this, function (_a) {
|
212
212
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cities?");
|
213
213
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
214
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
214
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
215
|
+
? response
|
216
|
+
: response.cities;
|
215
217
|
})];
|
216
218
|
});
|
217
219
|
});
|
218
220
|
};
|
219
221
|
/**
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
222
|
+
* This method returns the tours sold by this seller in the given city.
|
223
|
+
* If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
|
224
|
+
* @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
|
225
|
+
* @param {Booking.Currencies} currency The currency in which the prices should be returned
|
226
|
+
* @returns {Tour[]} The returned tours
|
227
|
+
*/
|
226
228
|
ServiceBooking.prototype.getServices = function (currency, cityName) {
|
227
229
|
return __awaiter(this, void 0, void 0, function () {
|
228
230
|
var searchParams, url;
|
@@ -230,19 +232,21 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
230
232
|
searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
|
231
233
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services?").concat(searchParams);
|
232
234
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
233
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
235
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
236
|
+
? response
|
237
|
+
: response.services;
|
234
238
|
})];
|
235
239
|
});
|
236
240
|
});
|
237
241
|
};
|
238
242
|
/**
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
243
|
+
* This method returns the tours available for the given date. This method can be used if the seller wants the user to book a specific date
|
244
|
+
* and/or a specific hour for the tour.
|
245
|
+
* You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
|
246
|
+
* @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
|
247
|
+
* @param {string} date The date on which to get the tours, in ISO string format
|
248
|
+
* @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
|
249
|
+
*/
|
246
250
|
ServiceBooking.prototype.getServiceTrips = function (serviceId, date) {
|
247
251
|
return __awaiter(this, void 0, void 0, function () {
|
248
252
|
var searchParams, url;
|
@@ -250,7 +254,9 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
250
254
|
searchParams = new URLSearchParams({ date: date });
|
251
255
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/").concat(serviceId, "/trips?").concat(searchParams);
|
252
256
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
253
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
257
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
258
|
+
? response
|
259
|
+
: response;
|
254
260
|
})];
|
255
261
|
});
|
256
262
|
});
|
@@ -312,7 +318,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
312
318
|
return {
|
313
319
|
buyerDataStatus: response.buyerDataStatus,
|
314
320
|
buyer: response.buyer,
|
315
|
-
passengers: []
|
321
|
+
passengers: []
|
316
322
|
};
|
317
323
|
})];
|
318
324
|
});
|
@@ -374,7 +380,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
374
380
|
}
|
375
381
|
request = {
|
376
382
|
buyer: buyerDetails,
|
377
|
-
passengers: []
|
383
|
+
passengers: []
|
378
384
|
};
|
379
385
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
|
380
386
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
@@ -479,9 +485,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
479
485
|
// Update the booking process status
|
480
486
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
481
487
|
// Update the cart
|
482
|
-
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) {
|
483
|
-
reduction.type === Reduction_1.ReductionType.
|
484
|
-
|
488
|
+
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) {
|
489
|
+
return reduction.type === Reduction_1.ReductionType.WALLET ||
|
490
|
+
reduction.type === Reduction_1.ReductionType.VOUCHER ||
|
491
|
+
(reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId);
|
492
|
+
})) !== null && _c !== void 0 ? _c : [] });
|
485
493
|
return true;
|
486
494
|
})];
|
487
495
|
});
|
@@ -509,7 +517,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
509
517
|
if (!issueStep)
|
510
518
|
throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
|
511
519
|
if (!!issueStep[0]) return [3 /*break*/, 5];
|
512
|
-
_i = 0, _a = [
|
520
|
+
_i = 0, _a = [
|
521
|
+
booking_1.Booking.BookingSteps.SEATS_SELECTION,
|
522
|
+
booking_1.Booking.BookingSteps.EXTRAS,
|
523
|
+
booking_1.Booking.BookingSteps.DISCOUNTS
|
524
|
+
];
|
513
525
|
_c.label = 1;
|
514
526
|
case 1:
|
515
527
|
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
@@ -9,15 +9,15 @@ import { Booking } from "./booking";
|
|
9
9
|
export declare class SubscriptionBooking extends Booking {
|
10
10
|
private cart?;
|
11
11
|
/**
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
* This is the constructor of the ServiceBooking class.
|
13
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
14
|
+
* @param {string} sub_key The subscription key for using the APIs
|
15
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
16
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
17
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
18
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
19
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
20
|
+
*/
|
21
21
|
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
22
22
|
getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
23
23
|
cartId: number | undefined;
|
@@ -70,39 +70,39 @@ export declare class SubscriptionBooking extends Booking {
|
|
70
70
|
fetchAndSetCart(cartId: number): Promise<void>;
|
71
71
|
fetchCart(cartId: number): Promise<SubscriptionCart>;
|
72
72
|
/**
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
74
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
75
|
+
* data will be deleted.
|
76
|
+
*/
|
77
77
|
deleteCart(): Promise<ErrorResponse | any>;
|
78
78
|
/**
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
* This method returns the possible departures for all subscriptions sold by this seller.
|
80
|
+
* @returns {string[]} The list of possible departures
|
81
|
+
*/
|
82
82
|
getSubscriptionsDepartures(): Promise<ErrorResponse | string[]>;
|
83
83
|
/**
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
* This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
|
85
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
86
|
+
* @returns {string[]} The list of possible destinations
|
87
|
+
*/
|
88
88
|
getSubscriptionsDestinations(departureStopName: string): Promise<ErrorResponse | string[]>;
|
89
89
|
/**
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
* This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
|
91
|
+
* The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
|
92
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
93
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
94
|
+
* @returns {ValidityTypes[]} The list of possible validity types
|
95
|
+
*/
|
96
96
|
getSubscriptionsValidityTypes(departureStopName: string, destinationStopName: string): Promise<ErrorResponse | SubscriptionBooking.ValidityTypes[]>;
|
97
97
|
/**
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
* This method returns the subscriptions that match the given parameters.
|
99
|
+
* Note that it will always return the subscription for the one-way trip.
|
100
|
+
* If you want to get the subscription for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
|
101
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
102
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
103
|
+
* @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
|
104
|
+
* @returns {Array<Subscription>} The subscriptions that match the given parameters
|
105
|
+
*/
|
106
106
|
getSubscriptions(departureStopName: string, destinationStopName: string, validityType: string): Promise<ErrorResponse | Subscription[]>;
|
107
107
|
/**
|
108
108
|
* This method returns the availability of the subscription for the given parameters.
|
@@ -81,15 +81,15 @@ var booking_1 = require("./booking");
|
|
81
81
|
var SubscriptionBooking = /** @class */ (function (_super) {
|
82
82
|
__extends(SubscriptionBooking, _super);
|
83
83
|
/**
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
* This is the constructor of the ServiceBooking class.
|
85
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
86
|
+
* @param {string} sub_key The subscription key for using the APIs
|
87
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
88
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
89
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
90
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
91
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
92
|
+
*/
|
93
93
|
function SubscriptionBooking(env, sub_key, debug, language, access_token, sellerId, resellerId) {
|
94
94
|
if (debug === void 0) { debug = false; }
|
95
95
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
@@ -166,7 +166,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
166
166
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
167
167
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
168
168
|
_this.resetBooking();
|
169
|
-
throw new Error(response);
|
169
|
+
throw new Error(JSON.stringify(response, null, 2));
|
170
170
|
}
|
171
171
|
// Check that the cart doe not have issued tickets
|
172
172
|
if (response.cart.hasIssuedTickets) {
|
@@ -178,10 +178,10 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
178
178
|
});
|
179
179
|
};
|
180
180
|
/**
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
182
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
183
|
+
* data will be deleted.
|
184
|
+
*/
|
185
185
|
SubscriptionBooking.prototype.deleteCart = function () {
|
186
186
|
return __awaiter(this, void 0, void 0, function () {
|
187
187
|
var url;
|
@@ -200,25 +200,27 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
200
200
|
});
|
201
201
|
};
|
202
202
|
/**
|
203
|
-
|
204
|
-
|
205
|
-
|
203
|
+
* This method returns the possible departures for all subscriptions sold by this seller.
|
204
|
+
* @returns {string[]} The list of possible departures
|
205
|
+
*/
|
206
206
|
SubscriptionBooking.prototype.getSubscriptionsDepartures = function () {
|
207
207
|
return __awaiter(this, void 0, void 0, function () {
|
208
208
|
var url;
|
209
209
|
return __generator(this, function (_a) {
|
210
210
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/departures?");
|
211
211
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
212
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
212
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
213
|
+
? response
|
214
|
+
: response.departures;
|
213
215
|
})];
|
214
216
|
});
|
215
217
|
});
|
216
218
|
};
|
217
219
|
/**
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
220
|
+
* This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
|
221
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
222
|
+
* @returns {string[]} The list of possible destinations
|
223
|
+
*/
|
222
224
|
SubscriptionBooking.prototype.getSubscriptionsDestinations = function (departureStopName) {
|
223
225
|
return __awaiter(this, void 0, void 0, function () {
|
224
226
|
var searchParams, url;
|
@@ -226,18 +228,20 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
226
228
|
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
227
229
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/destinations?").concat(searchParams);
|
228
230
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
229
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
231
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
232
|
+
? response
|
233
|
+
: response.destinations;
|
230
234
|
})];
|
231
235
|
});
|
232
236
|
});
|
233
237
|
};
|
234
238
|
/**
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
239
|
+
* This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
|
240
|
+
* The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
|
241
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
242
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
243
|
+
* @returns {ValidityTypes[]} The list of possible validity types
|
244
|
+
*/
|
241
245
|
SubscriptionBooking.prototype.getSubscriptionsValidityTypes = function (departureStopName, destinationStopName) {
|
242
246
|
return __awaiter(this, void 0, void 0, function () {
|
243
247
|
var searchParams, url;
|
@@ -248,20 +252,22 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
248
252
|
});
|
249
253
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/validityTypes?").concat(searchParams);
|
250
254
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
251
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
255
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
256
|
+
? response
|
257
|
+
: response.validityTypes;
|
252
258
|
})];
|
253
259
|
});
|
254
260
|
});
|
255
261
|
};
|
256
262
|
/**
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
263
|
+
* This method returns the subscriptions that match the given parameters.
|
264
|
+
* Note that it will always return the subscription for the one-way trip.
|
265
|
+
* If you want to get the subscription for the round trip, you have to call this method twice (make sure to swap departureStopName and destinationStopName)
|
266
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
267
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
268
|
+
* @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
|
269
|
+
* @returns {Array<Subscription>} The subscriptions that match the given parameters
|
270
|
+
*/
|
265
271
|
SubscriptionBooking.prototype.getSubscriptions = function (departureStopName, destinationStopName, validityType) {
|
266
272
|
return __awaiter(this, void 0, void 0, function () {
|
267
273
|
var searchParams, url;
|
@@ -273,7 +279,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
273
279
|
});
|
274
280
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/search?").concat(searchParams);
|
275
281
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
276
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
282
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
283
|
+
? response
|
284
|
+
: response.subscriptions;
|
277
285
|
})];
|
278
286
|
});
|
279
287
|
});
|
@@ -300,7 +308,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
300
308
|
});
|
301
309
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/availabilities?").concat(searchParams);
|
302
310
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
303
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
311
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
312
|
+
? response
|
313
|
+
: response;
|
304
314
|
})];
|
305
315
|
});
|
306
316
|
});
|
@@ -374,18 +384,20 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
374
384
|
];
|
375
385
|
}));
|
376
386
|
// Parse the return tariffs
|
377
|
-
passenger.returnTariffs = passenger.returnTariffs
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
387
|
+
passenger.returnTariffs = passenger.returnTariffs
|
388
|
+
? new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
|
389
|
+
var tripId = _a[0], tariffs = _a[1];
|
390
|
+
return [
|
391
|
+
+tripId,
|
392
|
+
tariffs
|
393
|
+
];
|
394
|
+
}))
|
395
|
+
: null;
|
384
396
|
});
|
385
397
|
return {
|
386
398
|
buyerDataStatus: response.buyerDataStatus,
|
387
399
|
buyer: response.buyer,
|
388
|
-
passengers: passengers
|
400
|
+
passengers: passengers
|
389
401
|
};
|
390
402
|
})];
|
391
403
|
});
|
@@ -554,9 +566,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
554
566
|
// Update the booking process status
|
555
567
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
556
568
|
// Update the cart
|
557
|
-
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) {
|
558
|
-
reduction.type === Reduction_1.ReductionType.
|
559
|
-
|
569
|
+
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: (_c = (_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) === null || _b === void 0 ? void 0 : _b.filter(function (reduction) {
|
570
|
+
return reduction.type === Reduction_1.ReductionType.WALLET ||
|
571
|
+
reduction.type === Reduction_1.ReductionType.VOUCHER ||
|
572
|
+
(reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId);
|
573
|
+
})) !== null && _c !== void 0 ? _c : [] });
|
560
574
|
return true;
|
561
575
|
})];
|
562
576
|
});
|
@@ -584,7 +598,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
584
598
|
if (!issueStep)
|
585
599
|
throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
|
586
600
|
if (!!issueStep[0]) return [3 /*break*/, 5];
|
587
|
-
_i = 0, _a = [
|
601
|
+
_i = 0, _a = [
|
602
|
+
booking_1.Booking.BookingSteps.SEATS_SELECTION,
|
603
|
+
booking_1.Booking.BookingSteps.EXTRAS,
|
604
|
+
booking_1.Booking.BookingSteps.DISCOUNTS
|
605
|
+
];
|
588
606
|
_c.label = 1;
|
589
607
|
case 1:
|
590
608
|
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
@@ -11,15 +11,15 @@ import { Booking } from "./booking";
|
|
11
11
|
export declare class TplBooking extends Booking {
|
12
12
|
private cart?;
|
13
13
|
/**
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
* This is the constructor of the TplBooking class.
|
15
|
+
* @param {MTSEnvs} env The environment in which the app is running. Can be "DEV", "STAGING" or "PROD"
|
16
|
+
* @param {string} sub_key The subscription key for using the APIs
|
17
|
+
* @param {boolean} [debug=false] If true, the app will run in debug mode (meaning that will print requests and responses in the console)
|
18
|
+
* @param {string} [language=Booking.Languages.EN] The language in which the app is running. Can be "it", "en", "fr", "de" or "es"
|
19
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
20
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
21
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
22
|
+
*/
|
23
23
|
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
24
24
|
getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
25
25
|
cartId: number | undefined;
|