mts-booking-library 1.3.6 → 1.3.8
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/booking/booking.d.ts +10 -10
- package/lib/booking/booking.js +30 -16
- package/lib/booking/journeyBooking.d.ts +25 -24
- package/lib/booking/journeyBooking.js +67 -45
- package/lib/booking/serviceBooking.d.ts +33 -32
- package/lib/booking/serviceBooking.js +58 -44
- package/lib/booking/subscriptionBooking.d.ts +37 -36
- package/lib/booking/subscriptionBooking.js +76 -56
- package/lib/booking/tplBooking.d.ts +12 -11
- package/lib/booking/tplBooking.js +41 -24
- 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,23 +81,25 @@ 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
|
-
|
93
|
-
|
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 {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
|
90
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
91
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
92
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
93
|
+
*/
|
94
|
+
function ServiceBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
|
94
95
|
if (debug === void 0) { debug = false; }
|
95
96
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
97
|
+
if (restoreState === void 0) { restoreState = true; }
|
96
98
|
// Call Booking constructor
|
97
99
|
var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
|
98
100
|
// Set cartId
|
99
101
|
var cartId = _this.getStorage().getState().cartId;
|
100
|
-
if (cartId) {
|
102
|
+
if (cartId && restoreState) {
|
101
103
|
_this.cartId = cartId;
|
102
104
|
}
|
103
105
|
return _this;
|
@@ -166,7 +168,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
166
168
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
167
169
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
168
170
|
_this.resetBooking();
|
169
|
-
throw new Error(response);
|
171
|
+
throw new Error(JSON.stringify(response, null, 2));
|
170
172
|
}
|
171
173
|
// Check that the cart doe not have issued tickets
|
172
174
|
if (response.cart.hasIssuedTickets) {
|
@@ -178,10 +180,10 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
178
180
|
});
|
179
181
|
};
|
180
182
|
/**
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
183
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
184
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
185
|
+
* data will be deleted.
|
186
|
+
*/
|
185
187
|
ServiceBooking.prototype.deleteCart = function () {
|
186
188
|
return __awaiter(this, void 0, void 0, function () {
|
187
189
|
var url;
|
@@ -201,28 +203,30 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
201
203
|
});
|
202
204
|
};
|
203
205
|
/**
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
206
|
+
* This method returns the list of cities in which the seller offers tours.
|
207
|
+
* If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
|
208
|
+
* @returns {string[]} The list of possible cities
|
209
|
+
*/
|
208
210
|
ServiceBooking.prototype.getServiceCities = function () {
|
209
211
|
return __awaiter(this, void 0, void 0, function () {
|
210
212
|
var url;
|
211
213
|
return __generator(this, function (_a) {
|
212
214
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/cities?");
|
213
215
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
214
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
216
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
217
|
+
? response
|
218
|
+
: response.cities;
|
215
219
|
})];
|
216
220
|
});
|
217
221
|
});
|
218
222
|
};
|
219
223
|
/**
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
224
|
+
* This method returns the tours sold by this seller in the given city.
|
225
|
+
* If the sellerId is not set or it is 0, it will return the tours in the given city for all sellers.
|
226
|
+
* @param {string} [cityName=undefined] The name of the selected city (as returned by {@link getTourCities})
|
227
|
+
* @param {Booking.Currencies} currency The currency in which the prices should be returned
|
228
|
+
* @returns {Tour[]} The returned tours
|
229
|
+
*/
|
226
230
|
ServiceBooking.prototype.getServices = function (currency, cityName) {
|
227
231
|
return __awaiter(this, void 0, void 0, function () {
|
228
232
|
var searchParams, url;
|
@@ -230,19 +234,21 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
230
234
|
searchParams = new URLSearchParams(__assign(__assign({}, (cityName && { cityName: cityName })), { currency: currency }));
|
231
235
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services?").concat(searchParams);
|
232
236
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
233
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
237
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
238
|
+
? response
|
239
|
+
: response.services;
|
234
240
|
})];
|
235
241
|
});
|
236
242
|
});
|
237
243
|
};
|
238
244
|
/**
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
245
|
+
* 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
|
246
|
+
* and/or a specific hour for the tour.
|
247
|
+
* You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
|
248
|
+
* @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
|
249
|
+
* @param {string} date The date on which to get the tours, in ISO string format
|
250
|
+
* @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
|
251
|
+
*/
|
246
252
|
ServiceBooking.prototype.getServiceTrips = function (serviceId, date) {
|
247
253
|
return __awaiter(this, void 0, void 0, function () {
|
248
254
|
var searchParams, url;
|
@@ -250,7 +256,9 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
250
256
|
searchParams = new URLSearchParams({ date: date });
|
251
257
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/").concat(serviceId, "/trips?").concat(searchParams);
|
252
258
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
253
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
259
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
260
|
+
? response
|
261
|
+
: response;
|
254
262
|
})];
|
255
263
|
});
|
256
264
|
});
|
@@ -312,7 +320,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
312
320
|
return {
|
313
321
|
buyerDataStatus: response.buyerDataStatus,
|
314
322
|
buyer: response.buyer,
|
315
|
-
passengers: []
|
323
|
+
passengers: []
|
316
324
|
};
|
317
325
|
})];
|
318
326
|
});
|
@@ -374,7 +382,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
374
382
|
}
|
375
383
|
request = {
|
376
384
|
buyer: buyerDetails,
|
377
|
-
passengers: []
|
385
|
+
passengers: []
|
378
386
|
};
|
379
387
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
|
380
388
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
@@ -479,9 +487,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
479
487
|
// Update the booking process status
|
480
488
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
481
489
|
// 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
|
-
|
490
|
+
_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) {
|
491
|
+
return reduction.type === Reduction_1.ReductionType.WALLET ||
|
492
|
+
reduction.type === Reduction_1.ReductionType.VOUCHER ||
|
493
|
+
(reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId);
|
494
|
+
})) !== null && _c !== void 0 ? _c : [] });
|
485
495
|
return true;
|
486
496
|
})];
|
487
497
|
});
|
@@ -509,7 +519,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
509
519
|
if (!issueStep)
|
510
520
|
throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
|
511
521
|
if (!!issueStep[0]) return [3 /*break*/, 5];
|
512
|
-
_i = 0, _a = [
|
522
|
+
_i = 0, _a = [
|
523
|
+
booking_1.Booking.BookingSteps.SEATS_SELECTION,
|
524
|
+
booking_1.Booking.BookingSteps.EXTRAS,
|
525
|
+
booking_1.Booking.BookingSteps.DISCOUNTS
|
526
|
+
];
|
513
527
|
_c.label = 1;
|
514
528
|
case 1:
|
515
529
|
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
@@ -643,12 +657,12 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
643
657
|
exports.ServiceBooking = ServiceBooking;
|
644
658
|
(function (ServiceBooking) {
|
645
659
|
var _this = this;
|
646
|
-
ServiceBooking.createBooking = function (env, sub_key, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
660
|
+
ServiceBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
647
661
|
var booking, error_1;
|
648
662
|
return __generator(this, function (_a) {
|
649
663
|
switch (_a.label) {
|
650
664
|
case 0:
|
651
|
-
booking = new ServiceBooking(env, sub_key, debug, language, access_token, sellerId, resellerId);
|
665
|
+
booking = new ServiceBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
|
652
666
|
_a.label = 1;
|
653
667
|
case 1:
|
654
668
|
_a.trys.push([1, 4, , 5]);
|
@@ -9,16 +9,17 @@ 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
|
-
|
21
|
-
|
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 {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
|
18
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
19
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
20
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
21
|
+
*/
|
22
|
+
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
|
22
23
|
getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
23
24
|
cartId: number | undefined;
|
24
25
|
} & {
|
@@ -70,39 +71,39 @@ export declare class SubscriptionBooking extends Booking {
|
|
70
71
|
fetchAndSetCart(cartId: number): Promise<void>;
|
71
72
|
fetchCart(cartId: number): Promise<SubscriptionCart>;
|
72
73
|
/**
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
75
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
76
|
+
* data will be deleted.
|
77
|
+
*/
|
77
78
|
deleteCart(): Promise<ErrorResponse | any>;
|
78
79
|
/**
|
79
|
-
|
80
|
-
|
81
|
-
|
80
|
+
* This method returns the possible departures for all subscriptions sold by this seller.
|
81
|
+
* @returns {string[]} The list of possible departures
|
82
|
+
*/
|
82
83
|
getSubscriptionsDepartures(): Promise<ErrorResponse | string[]>;
|
83
84
|
/**
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
* This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
|
86
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
87
|
+
* @returns {string[]} The list of possible destinations
|
88
|
+
*/
|
88
89
|
getSubscriptionsDestinations(departureStopName: string): Promise<ErrorResponse | string[]>;
|
89
90
|
/**
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
* This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
|
92
|
+
* The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
|
93
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
94
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
95
|
+
* @returns {ValidityTypes[]} The list of possible validity types
|
96
|
+
*/
|
96
97
|
getSubscriptionsValidityTypes(departureStopName: string, destinationStopName: string): Promise<ErrorResponse | SubscriptionBooking.ValidityTypes[]>;
|
97
98
|
/**
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
* This method returns the subscriptions that match the given parameters.
|
100
|
+
* Note that it will always return the subscription for the one-way trip.
|
101
|
+
* 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)
|
102
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
103
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
104
|
+
* @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
|
105
|
+
* @returns {Array<Subscription>} The subscriptions that match the given parameters
|
106
|
+
*/
|
106
107
|
getSubscriptions(departureStopName: string, destinationStopName: string, validityType: string): Promise<ErrorResponse | Subscription[]>;
|
107
108
|
/**
|
108
109
|
* This method returns the availability of the subscription for the given parameters.
|
@@ -174,7 +175,7 @@ export declare class SubscriptionBooking extends Booking {
|
|
174
175
|
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
175
176
|
}
|
176
177
|
export declare namespace SubscriptionBooking {
|
177
|
-
const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
|
178
|
+
const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
|
178
179
|
enum ValidityTypes {
|
179
180
|
WORKING_WEEK = "WORKING_WEEK",
|
180
181
|
ONE_WEEK = "ONE_WEEK",
|
@@ -81,23 +81,25 @@ 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
|
-
|
93
|
-
|
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 {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
|
90
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
91
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
92
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
93
|
+
*/
|
94
|
+
function SubscriptionBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) {
|
94
95
|
if (debug === void 0) { debug = false; }
|
95
96
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
97
|
+
if (restoreState === void 0) { restoreState = true; }
|
96
98
|
// Call Booking constructor
|
97
99
|
var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
|
98
100
|
// Set cartId
|
99
101
|
var cartId = _this.getStorage().getState().cartId;
|
100
|
-
if (cartId) {
|
102
|
+
if (cartId && restoreState) {
|
101
103
|
_this.cartId = cartId;
|
102
104
|
}
|
103
105
|
return _this;
|
@@ -166,7 +168,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
166
168
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
167
169
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
168
170
|
_this.resetBooking();
|
169
|
-
throw new Error(response);
|
171
|
+
throw new Error(JSON.stringify(response, null, 2));
|
170
172
|
}
|
171
173
|
// Check that the cart doe not have issued tickets
|
172
174
|
if (response.cart.hasIssuedTickets) {
|
@@ -178,10 +180,10 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
178
180
|
});
|
179
181
|
};
|
180
182
|
/**
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
183
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
184
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
185
|
+
* data will be deleted.
|
186
|
+
*/
|
185
187
|
SubscriptionBooking.prototype.deleteCart = function () {
|
186
188
|
return __awaiter(this, void 0, void 0, function () {
|
187
189
|
var url;
|
@@ -200,25 +202,27 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
200
202
|
});
|
201
203
|
};
|
202
204
|
/**
|
203
|
-
|
204
|
-
|
205
|
-
|
205
|
+
* This method returns the possible departures for all subscriptions sold by this seller.
|
206
|
+
* @returns {string[]} The list of possible departures
|
207
|
+
*/
|
206
208
|
SubscriptionBooking.prototype.getSubscriptionsDepartures = function () {
|
207
209
|
return __awaiter(this, void 0, void 0, function () {
|
208
210
|
var url;
|
209
211
|
return __generator(this, function (_a) {
|
210
212
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/departures?");
|
211
213
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
212
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
214
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
215
|
+
? response
|
216
|
+
: response.departures;
|
213
217
|
})];
|
214
218
|
});
|
215
219
|
});
|
216
220
|
};
|
217
221
|
/**
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
+
* This method returns the possible destination for the subscriptions sold by this seller that start at the selected departure.
|
223
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
224
|
+
* @returns {string[]} The list of possible destinations
|
225
|
+
*/
|
222
226
|
SubscriptionBooking.prototype.getSubscriptionsDestinations = function (departureStopName) {
|
223
227
|
return __awaiter(this, void 0, void 0, function () {
|
224
228
|
var searchParams, url;
|
@@ -226,18 +230,20 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
226
230
|
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
227
231
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/destinations?").concat(searchParams);
|
228
232
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
229
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
233
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
234
|
+
? response
|
235
|
+
: response.destinations;
|
230
236
|
})];
|
231
237
|
});
|
232
238
|
});
|
233
239
|
};
|
234
240
|
/**
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
+
* This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
|
242
|
+
* The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
|
243
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
244
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
245
|
+
* @returns {ValidityTypes[]} The list of possible validity types
|
246
|
+
*/
|
241
247
|
SubscriptionBooking.prototype.getSubscriptionsValidityTypes = function (departureStopName, destinationStopName) {
|
242
248
|
return __awaiter(this, void 0, void 0, function () {
|
243
249
|
var searchParams, url;
|
@@ -248,20 +254,22 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
248
254
|
});
|
249
255
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/validityTypes?").concat(searchParams);
|
250
256
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
251
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
257
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
258
|
+
? response
|
259
|
+
: response.validityTypes;
|
252
260
|
})];
|
253
261
|
});
|
254
262
|
});
|
255
263
|
};
|
256
264
|
/**
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
+
* This method returns the subscriptions that match the given parameters.
|
266
|
+
* Note that it will always return the subscription for the one-way trip.
|
267
|
+
* 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)
|
268
|
+
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
269
|
+
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
270
|
+
* @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
|
271
|
+
* @returns {Array<Subscription>} The subscriptions that match the given parameters
|
272
|
+
*/
|
265
273
|
SubscriptionBooking.prototype.getSubscriptions = function (departureStopName, destinationStopName, validityType) {
|
266
274
|
return __awaiter(this, void 0, void 0, function () {
|
267
275
|
var searchParams, url;
|
@@ -273,7 +281,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
273
281
|
});
|
274
282
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/search?").concat(searchParams);
|
275
283
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
276
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
284
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
285
|
+
? response
|
286
|
+
: response.subscriptions;
|
277
287
|
})];
|
278
288
|
});
|
279
289
|
});
|
@@ -300,7 +310,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
300
310
|
});
|
301
311
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/availabilities?").concat(searchParams);
|
302
312
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
303
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
313
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
314
|
+
? response
|
315
|
+
: response;
|
304
316
|
})];
|
305
317
|
});
|
306
318
|
});
|
@@ -374,18 +386,20 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
374
386
|
];
|
375
387
|
}));
|
376
388
|
// Parse the return tariffs
|
377
|
-
passenger.returnTariffs = passenger.returnTariffs
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
389
|
+
passenger.returnTariffs = passenger.returnTariffs
|
390
|
+
? new Map(Object.entries(passenger.returnTariffs).map(function (_a) {
|
391
|
+
var tripId = _a[0], tariffs = _a[1];
|
392
|
+
return [
|
393
|
+
+tripId,
|
394
|
+
tariffs
|
395
|
+
];
|
396
|
+
}))
|
397
|
+
: null;
|
384
398
|
});
|
385
399
|
return {
|
386
400
|
buyerDataStatus: response.buyerDataStatus,
|
387
401
|
buyer: response.buyer,
|
388
|
-
passengers: passengers
|
402
|
+
passengers: passengers
|
389
403
|
};
|
390
404
|
})];
|
391
405
|
});
|
@@ -554,9 +568,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
554
568
|
// Update the booking process status
|
555
569
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
556
570
|
// 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
|
-
|
571
|
+
_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) {
|
572
|
+
return reduction.type === Reduction_1.ReductionType.WALLET ||
|
573
|
+
reduction.type === Reduction_1.ReductionType.VOUCHER ||
|
574
|
+
(reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId);
|
575
|
+
})) !== null && _c !== void 0 ? _c : [] });
|
560
576
|
return true;
|
561
577
|
})];
|
562
578
|
});
|
@@ -584,7 +600,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
584
600
|
if (!issueStep)
|
585
601
|
throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
|
586
602
|
if (!!issueStep[0]) return [3 /*break*/, 5];
|
587
|
-
_i = 0, _a = [
|
603
|
+
_i = 0, _a = [
|
604
|
+
booking_1.Booking.BookingSteps.SEATS_SELECTION,
|
605
|
+
booking_1.Booking.BookingSteps.EXTRAS,
|
606
|
+
booking_1.Booking.BookingSteps.DISCOUNTS
|
607
|
+
];
|
588
608
|
_c.label = 1;
|
589
609
|
case 1:
|
590
610
|
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
@@ -718,12 +738,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
718
738
|
exports.SubscriptionBooking = SubscriptionBooking;
|
719
739
|
(function (SubscriptionBooking) {
|
720
740
|
var _this = this;
|
721
|
-
SubscriptionBooking.createBooking = function (env, sub_key, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
741
|
+
SubscriptionBooking.createBooking = function (env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
722
742
|
var booking, error_1;
|
723
743
|
return __generator(this, function (_a) {
|
724
744
|
switch (_a.label) {
|
725
745
|
case 0:
|
726
|
-
booking = new SubscriptionBooking(env, sub_key, debug, language, access_token, sellerId, resellerId);
|
746
|
+
booking = new SubscriptionBooking(env, sub_key, debug, language, restoreState, access_token, sellerId, resellerId);
|
727
747
|
_a.label = 1;
|
728
748
|
case 1:
|
729
749
|
_a.trys.push([1, 4, , 5]);
|
@@ -11,16 +11,17 @@ 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
|
-
|
23
|
-
|
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 {boolean} [restoreState=true] If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage
|
20
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
21
|
+
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
22
|
+
* @param {number} [resellerId=undefined] The id of the reseller.
|
23
|
+
*/
|
24
|
+
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, restoreState?: boolean, access_token?: string, sellerId?: number, resellerId?: number);
|
24
25
|
getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
25
26
|
cartId: number | undefined;
|
26
27
|
} & {
|
@@ -169,5 +170,5 @@ export declare class TplBooking extends Booking {
|
|
169
170
|
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
170
171
|
}
|
171
172
|
export declare namespace TplBooking {
|
172
|
-
const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<TplBooking>;
|
173
|
+
const createBooking: (env: MTSEnvs, sub_key: string, debug: boolean, language: string, restoreState: boolean, access_token?: string, sellerId?: number, resellerId?: number) => Promise<TplBooking>;
|
173
174
|
}
|