mts-booking-library 1.2.32 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +2 -1
- package/lib/booking/booking.js +33 -44
- package/lib/booking/journeyBooking.d.ts +46 -0
- package/lib/booking/journeyBooking.js +77 -88
- package/lib/booking/serviceBooking.d.ts +46 -0
- package/lib/booking/serviceBooking.js +74 -85
- package/lib/booking/subscriptionBooking.d.ts +46 -0
- package/lib/booking/subscriptionBooking.js +75 -86
- package/lib/booking/tplBooking.d.ts +168 -0
- package/lib/booking/tplBooking.js +705 -0
- package/lib/config.js +5 -5
- package/lib/index.d.ts +4 -0
- package/lib/index.js +3 -1
- package/lib/mtsStorage.d.ts +44 -0
- package/lib/mtsStorage.js +48 -0
- package/lib/types/common/City.d.ts +17 -0
- package/lib/types/common/City.js +2 -0
- package/lib/types/common/Tariffs.d.ts +9 -3
- package/lib/types/journeys/JourneyInfo.d.ts +3 -1
- package/lib/types/tpl/GetTariffsResponse.d.ts +12 -0
- package/lib/types/tpl/GetTariffsResponse.js +2 -0
- package/lib/types/tpl/SuperArea.d.ts +13 -0
- package/lib/types/tpl/SuperArea.js +2 -0
- package/lib/types/tpl/TplCart.d.ts +41 -0
- package/lib/types/tpl/TplCart.js +2 -0
- package/lib/utils/apiCall.js +26 -26
- package/package.json +8 -6
package/lib/booking/booking.d.ts
CHANGED
package/lib/booking/booking.js
CHANGED
@@ -176,7 +176,7 @@ var Booking = /** @class */ (function () {
|
|
176
176
|
// Booking step is already completed, no need to call the API
|
177
177
|
if (currentStepStatus[0])
|
178
178
|
return [2 /*return*/, true];
|
179
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
179
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/bookingSteps");
|
180
180
|
return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep }).then(function (response) {
|
181
181
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
182
182
|
return response;
|
@@ -195,11 +195,11 @@ var Booking = /** @class */ (function () {
|
|
195
195
|
* @returns An {@link ErrorResponse} object in case of error, a {@link GetSellerGatewaysResponse} object otherwise.
|
196
196
|
*/
|
197
197
|
Booking.prototype.getSellerGateways = function () {
|
198
|
-
var _a;
|
199
198
|
return __awaiter(this, void 0, void 0, function () {
|
200
|
-
var issueStep,
|
201
|
-
|
202
|
-
|
199
|
+
var issueStep, _i, _a, step, url;
|
200
|
+
var _b;
|
201
|
+
return __generator(this, function (_c) {
|
202
|
+
switch (_c.label) {
|
203
203
|
case 0:
|
204
204
|
// First check that it is possible to call this API
|
205
205
|
if (!this.cartId || this.cartId === 0) {
|
@@ -207,36 +207,30 @@ var Booking = /** @class */ (function () {
|
|
207
207
|
}
|
208
208
|
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
|
209
209
|
if (!issueStep)
|
210
|
-
throw Error("Booking step not found!");
|
210
|
+
throw Error("Booking step: ".concat(Booking.BookingSteps.ISSUE, " not found!"));
|
211
211
|
if (!!issueStep[0]) return [3 /*break*/, 5];
|
212
|
-
|
213
|
-
_c =
|
214
|
-
for (_d in _b)
|
215
|
-
_c.push(_d);
|
216
|
-
_i = 0;
|
217
|
-
_e.label = 1;
|
212
|
+
_i = 0, _a = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
|
213
|
+
_c.label = 1;
|
218
214
|
case 1:
|
219
|
-
if (!(_i <
|
220
|
-
|
221
|
-
if (
|
222
|
-
step = _d;
|
223
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
215
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
216
|
+
step = _a[_i];
|
217
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
|
224
218
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
225
219
|
case 2:
|
226
|
-
|
227
|
-
|
220
|
+
_c.sent();
|
221
|
+
_c.label = 3;
|
228
222
|
case 3:
|
229
223
|
_i++;
|
230
224
|
return [3 /*break*/, 1];
|
231
225
|
case 4:
|
232
226
|
// Check again if the issue step is accessible
|
233
|
-
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.
|
227
|
+
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
|
234
228
|
if (!issueStep || !issueStep[0]) {
|
235
229
|
throw Error("The status of the cart does not allow to call this API");
|
236
230
|
}
|
237
|
-
|
231
|
+
_c.label = 5;
|
238
232
|
case 5:
|
239
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
233
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_resources/sellers/").concat(this.sellerId, "/gateways?");
|
240
234
|
// We use directly makeGet because we don't want to add sellerId to the query string (it is already present in the url)
|
241
235
|
return [2 /*return*/, (0, apiCall_1.makeGet)(url).then(function (response) {
|
242
236
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
@@ -265,7 +259,7 @@ var Booking = /** @class */ (function () {
|
|
265
259
|
throw Error("The status of the cart does not allow to call this API");
|
266
260
|
}
|
267
261
|
searchParams = new URLSearchParams(__assign({ gatewayId: gatewayId.toString() }, (returnUrl && { returnUrl: returnUrl })));
|
268
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
262
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment?").concat(searchParams);
|
269
263
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
270
264
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
271
265
|
})];
|
@@ -279,11 +273,11 @@ var Booking = /** @class */ (function () {
|
|
279
273
|
* @returns An {@link IssueTicketsResponse} object.
|
280
274
|
*/
|
281
275
|
Booking.prototype.issueTickets = function (paymentMethod) {
|
282
|
-
var _a;
|
283
276
|
return __awaiter(this, void 0, void 0, function () {
|
284
|
-
var paymentMethodToSet, issueStep,
|
285
|
-
|
286
|
-
|
277
|
+
var paymentMethodToSet, issueStep, _i, _a, step, url, body;
|
278
|
+
var _b;
|
279
|
+
return __generator(this, function (_c) {
|
280
|
+
switch (_c.label) {
|
287
281
|
case 0:
|
288
282
|
// First check that it is possible to call this API
|
289
283
|
if (!this.cartId || this.cartId === 0) {
|
@@ -302,29 +296,23 @@ var Booking = /** @class */ (function () {
|
|
302
296
|
}
|
303
297
|
})];
|
304
298
|
case 1:
|
305
|
-
|
306
|
-
|
299
|
+
_c.sent();
|
300
|
+
_c.label = 2;
|
307
301
|
case 2:
|
308
302
|
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
|
309
303
|
if (!issueStep)
|
310
304
|
throw Error("Booking step not found!");
|
311
305
|
if (!!issueStep[0]) return [3 /*break*/, 7];
|
312
|
-
|
313
|
-
_c =
|
314
|
-
for (_d in _b)
|
315
|
-
_c.push(_d);
|
316
|
-
_i = 0;
|
317
|
-
_e.label = 3;
|
306
|
+
_i = 0, _a = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
|
307
|
+
_c.label = 3;
|
318
308
|
case 3:
|
319
|
-
if (!(_i <
|
320
|
-
|
321
|
-
if (
|
322
|
-
step = _d;
|
323
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 5];
|
309
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
310
|
+
step = _a[_i];
|
311
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 5];
|
324
312
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
325
313
|
case 4:
|
326
|
-
|
327
|
-
|
314
|
+
_c.sent();
|
315
|
+
_c.label = 5;
|
328
316
|
case 5:
|
329
317
|
_i++;
|
330
318
|
return [3 /*break*/, 3];
|
@@ -334,9 +322,9 @@ var Booking = /** @class */ (function () {
|
|
334
322
|
if (!issueStep || !issueStep[0]) {
|
335
323
|
throw Error("The status of the cart does not allow to call this API");
|
336
324
|
}
|
337
|
-
|
325
|
+
_c.label = 7;
|
338
326
|
case 7:
|
339
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
327
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/issue");
|
340
328
|
body = {
|
341
329
|
cartId: this.cartId,
|
342
330
|
paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
|
@@ -380,5 +368,6 @@ exports.Booking = Booking;
|
|
380
368
|
BookingTypes["MLP"] = "MLP";
|
381
369
|
BookingTypes["SERVICE"] = "SERVICE";
|
382
370
|
BookingTypes["MLP_SUBSCRIPTION"] = "MLP_SUBSCRIPTION";
|
371
|
+
BookingTypes["TPL"] = "TPL";
|
383
372
|
})(BookingTypes = Booking.BookingTypes || (Booking.BookingTypes = {}));
|
384
373
|
})(Booking || (exports.Booking = Booking = {}));
|
@@ -21,6 +21,52 @@ export declare class JourneyBooking extends Booking {
|
|
21
21
|
*/
|
22
22
|
constructor(env: MTSEnvs, sub_key: string, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
23
23
|
getCart(): JourneyCart | undefined;
|
24
|
+
getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
25
|
+
cartId: number | undefined;
|
26
|
+
} & {
|
27
|
+
updateCartId: (cartId: number | undefined) => void;
|
28
|
+
resetState: () => void;
|
29
|
+
}>, "persist"> & {
|
30
|
+
persist: {
|
31
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
|
32
|
+
cartId: number | undefined;
|
33
|
+
} & {
|
34
|
+
updateCartId: (cartId: number | undefined) => void;
|
35
|
+
resetState: () => void;
|
36
|
+
}, {
|
37
|
+
cartId: number | undefined;
|
38
|
+
} & {
|
39
|
+
updateCartId: (cartId: number | undefined) => void;
|
40
|
+
resetState: () => void;
|
41
|
+
}>>) => void;
|
42
|
+
clearStorage: () => void;
|
43
|
+
rehydrate: () => void | Promise<void>;
|
44
|
+
hasHydrated: () => boolean;
|
45
|
+
onHydrate: (fn: (state: {
|
46
|
+
cartId: number | undefined;
|
47
|
+
} & {
|
48
|
+
updateCartId: (cartId: number | undefined) => void;
|
49
|
+
resetState: () => void;
|
50
|
+
}) => void) => () => void;
|
51
|
+
onFinishHydration: (fn: (state: {
|
52
|
+
cartId: number | undefined;
|
53
|
+
} & {
|
54
|
+
updateCartId: (cartId: number | undefined) => void;
|
55
|
+
resetState: () => void;
|
56
|
+
}) => void) => () => void;
|
57
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
|
58
|
+
cartId: number | undefined;
|
59
|
+
} & {
|
60
|
+
updateCartId: (cartId: number | undefined) => void;
|
61
|
+
resetState: () => void;
|
62
|
+
}, {
|
63
|
+
cartId: number | undefined;
|
64
|
+
} & {
|
65
|
+
updateCartId: (cartId: number | undefined) => void;
|
66
|
+
resetState: () => void;
|
67
|
+
}>>;
|
68
|
+
};
|
69
|
+
}>;
|
24
70
|
resetBooking(): void;
|
25
71
|
fetchAndSetCart(cartId: number): Promise<void>;
|
26
72
|
fetchCart(cartId: number): Promise<JourneyCart>;
|
@@ -73,6 +73,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
73
73
|
Object.defineProperty(exports, "__esModule", { value: true });
|
74
74
|
exports.JourneyBooking = void 0;
|
75
75
|
var config_1 = require("../config");
|
76
|
+
var mtsStorage_1 = require("../mtsStorage");
|
76
77
|
var ErrorResponse_1 = require("../types/ErrorResponse");
|
77
78
|
var Reduction_1 = require("../types/common/Reduction");
|
78
79
|
var processBookingSteps_1 = require("../utils/processBookingSteps");
|
@@ -95,26 +96,32 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
95
96
|
// Call Booking constructor
|
96
97
|
var _this = _super.call(this, env, sub_key, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
|
97
98
|
// Set cartId
|
98
|
-
var cartId =
|
99
|
+
var cartId = _this.getStorage().getState().cartId;
|
99
100
|
if (cartId) {
|
100
|
-
_this.cartId =
|
101
|
+
_this.cartId = cartId;
|
101
102
|
}
|
102
103
|
return _this;
|
103
104
|
}
|
104
105
|
JourneyBooking.prototype.getCart = function () {
|
105
106
|
return this.cart;
|
106
107
|
};
|
108
|
+
JourneyBooking.prototype.getStorage = function () {
|
109
|
+
if (this.config.ENV !== config_1.MTSEnvs.TEST) {
|
110
|
+
return (0, mtsStorage_1.useMtsBookingState)();
|
111
|
+
}
|
112
|
+
return (0, mtsStorage_1.useTestState)();
|
113
|
+
};
|
107
114
|
JourneyBooking.prototype.resetBooking = function () {
|
108
115
|
this.cart = undefined;
|
109
116
|
this.cartId = undefined;
|
110
117
|
this.bookingStepsToStatus = new Map();
|
111
118
|
this.bookingDueDate = undefined;
|
112
119
|
try {
|
113
|
-
|
120
|
+
this.getStorage().getState().updateCartId(undefined);
|
114
121
|
}
|
115
122
|
catch (e) {
|
116
123
|
if (this.config.ENV !== config_1.MTSEnvs.TEST) {
|
117
|
-
throw new Error("Error while deleting cartId from
|
124
|
+
throw new Error("Error while deleting cartId from storage.");
|
118
125
|
}
|
119
126
|
console.log(e);
|
120
127
|
}
|
@@ -154,7 +161,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
154
161
|
var url;
|
155
162
|
var _this = this;
|
156
163
|
return __generator(this, function (_a) {
|
157
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
164
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
158
165
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
159
166
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
160
167
|
_this.resetBooking();
|
@@ -183,7 +190,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
183
190
|
if (!this.cart || !this.cartId) {
|
184
191
|
throw Error("Cart is not initialized yet");
|
185
192
|
}
|
186
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
193
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: this.cartId.toString() }));
|
187
194
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
188
195
|
// Clear all data
|
189
196
|
_this.resetBooking();
|
@@ -200,7 +207,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
200
207
|
return __awaiter(this, void 0, void 0, function () {
|
201
208
|
var url;
|
202
209
|
return __generator(this, function (_a) {
|
203
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
210
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/departures?");
|
204
211
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
205
212
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
|
206
213
|
})];
|
@@ -217,7 +224,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
217
224
|
var searchParams, url;
|
218
225
|
return __generator(this, function (_a) {
|
219
226
|
searchParams = new URLSearchParams({ departureStopName: departureStopName });
|
220
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
227
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/destinations?").concat(searchParams);
|
221
228
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
222
229
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.stops;
|
223
230
|
})];
|
@@ -239,7 +246,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
239
246
|
throw Error("Fields departureStopName and destinationStopName are required");
|
240
247
|
}
|
241
248
|
searchParams = new URLSearchParams(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), date: request.date, roundTripDate: request.roundTripDate ? request.roundTripDate : "null", currency: request.currency }, (this.cartId && { cartId: this.cartId.toString() })));
|
242
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
249
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys?").concat(searchParams);
|
243
250
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
244
251
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.journeys;
|
245
252
|
})];
|
@@ -251,19 +258,19 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
251
258
|
var url, request;
|
252
259
|
var _this = this;
|
253
260
|
return __generator(this, function (_a) {
|
254
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
261
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/cart");
|
255
262
|
request = __assign(__assign({}, journeyCart), (this.cartId && { cartId: this.cartId.toString() }));
|
256
263
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
257
264
|
// Check for errors
|
258
265
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
259
|
-
// If there was an error, reset cartId and remove it from the
|
266
|
+
// If there was an error, reset cartId and remove it from the mts-storage
|
260
267
|
_this.resetBooking();
|
261
268
|
return response;
|
262
269
|
}
|
263
270
|
_this.cart = response.cart;
|
264
271
|
_this.cartId = response.cart.id;
|
265
|
-
// Save the cartId in the
|
266
|
-
|
272
|
+
// Save the cartId in the storage
|
273
|
+
_this.getStorage().getState().updateCartId(response.cart.id);
|
267
274
|
// Fill the booking process status
|
268
275
|
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
269
276
|
_this.bookingDueDate = new Date(response.cart.bookingDueDate);
|
@@ -291,7 +298,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
291
298
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
292
299
|
throw Error("The status of the cart does not allow to call this API");
|
293
300
|
}
|
294
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
301
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details?");
|
295
302
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
296
303
|
// Check for errors
|
297
304
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -350,7 +357,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
350
357
|
throw Error("At least one of the parameters linkavelCard or phoneNumber must be set");
|
351
358
|
}
|
352
359
|
searchParams = new URLSearchParams(__assign(__assign({}, (linkavelCard && { linkavelCard: linkavelCard })), (phoneNumber && { phoneNumber: phoneNumber })));
|
353
|
-
url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams);
|
360
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_resources/buyers?").concat(searchParams);
|
354
361
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
355
362
|
// Check for errors
|
356
363
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -387,7 +394,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
387
394
|
});
|
388
395
|
request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
|
389
396
|
});
|
390
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
397
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/details");
|
391
398
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
392
399
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
393
400
|
return response;
|
@@ -423,7 +430,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
423
430
|
departureStopId: departureStopId.toString(),
|
424
431
|
destinationStopId: destinationStopId.toString()
|
425
432
|
});
|
426
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
433
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/").concat(tripId, "/seats?").concat(searchParams);
|
427
434
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
428
435
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.busMatrix;
|
429
436
|
})];
|
@@ -448,7 +455,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
448
455
|
throw Error("The status of the cart does not allow to call this API");
|
449
456
|
}
|
450
457
|
searchParams = new URLSearchParams({ tripId: tripId.toString() });
|
451
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
458
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/seats?").concat(searchParams);
|
452
459
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
453
460
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
|
454
461
|
})];
|
@@ -474,7 +481,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
474
481
|
if (!seatSelectionStatus || !seatSelectionStatus[0]) {
|
475
482
|
throw Error("The status of the cart does not allow to call this API");
|
476
483
|
}
|
477
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
484
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/seats");
|
478
485
|
return [2 /*return*/, this.callPostApi(url, { tripId: tripId, newSeatsIds: newSeatsIds }).then(function (response) {
|
479
486
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
480
487
|
return response;
|
@@ -501,7 +508,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
501
508
|
if (!this.cart) {
|
502
509
|
throw Error("Cart is not initialized yet");
|
503
510
|
}
|
504
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
511
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cart.id, "/payment/reduction/trips?");
|
505
512
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
506
513
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
|
507
514
|
})];
|
@@ -514,12 +521,12 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
514
521
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
515
522
|
*/
|
516
523
|
JourneyBooking.prototype.addReduction = function (request) {
|
517
|
-
var _a;
|
518
524
|
return __awaiter(this, void 0, void 0, function () {
|
519
|
-
var discountsStep,
|
525
|
+
var discountsStep, _i, _a, step, url;
|
520
526
|
var _this = this;
|
521
|
-
|
522
|
-
|
527
|
+
var _b;
|
528
|
+
return __generator(this, function (_c) {
|
529
|
+
switch (_c.label) {
|
523
530
|
case 0:
|
524
531
|
// First check that it is possible to call this API
|
525
532
|
if (!this.cartId || this.cartId === 0) {
|
@@ -529,22 +536,16 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
529
536
|
if (!discountsStep)
|
530
537
|
throw Error("Booking step not found!");
|
531
538
|
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
532
|
-
|
533
|
-
_c =
|
534
|
-
for (_d in _b)
|
535
|
-
_c.push(_d);
|
536
|
-
_i = 0;
|
537
|
-
_e.label = 1;
|
539
|
+
_i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
540
|
+
_c.label = 1;
|
538
541
|
case 1:
|
539
|
-
if (!(_i <
|
540
|
-
|
541
|
-
if (
|
542
|
-
step = _d;
|
543
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
542
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
543
|
+
step = _a[_i];
|
544
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
|
544
545
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
545
546
|
case 2:
|
546
|
-
|
547
|
-
|
547
|
+
_c.sent();
|
548
|
+
_c.label = 3;
|
548
549
|
case 3:
|
549
550
|
_i++;
|
550
551
|
return [3 /*break*/, 1];
|
@@ -554,9 +555,9 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
554
555
|
if (!discountsStep || !discountsStep[0]) {
|
555
556
|
throw Error("The status of the cart does not allow to call this API");
|
556
557
|
}
|
557
|
-
|
558
|
+
_c.label = 5;
|
558
559
|
case 5:
|
559
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
560
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction");
|
560
561
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
561
562
|
var _a, _b;
|
562
563
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -593,7 +594,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
593
594
|
throw Error("The status of the cart does not allow to call this API");
|
594
595
|
}
|
595
596
|
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
596
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
597
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
597
598
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
598
599
|
var _a, _b, _c;
|
599
600
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -618,49 +619,43 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
618
619
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
619
620
|
*/
|
620
621
|
JourneyBooking.prototype.useWallet = function () {
|
621
|
-
var _a;
|
622
622
|
return __awaiter(this, void 0, void 0, function () {
|
623
|
-
var
|
623
|
+
var issueStep, _i, _a, step, url;
|
624
624
|
var _this = this;
|
625
|
-
|
626
|
-
|
625
|
+
var _b;
|
626
|
+
return __generator(this, function (_c) {
|
627
|
+
switch (_c.label) {
|
627
628
|
case 0:
|
628
629
|
// First check that it is possible to call this API
|
629
630
|
if (!this.cartId || this.cartId === 0) {
|
630
631
|
throw Error("Cart is not initialized yet");
|
631
632
|
}
|
632
|
-
|
633
|
-
if (!
|
634
|
-
throw Error("Booking step not found!");
|
635
|
-
if (!!
|
636
|
-
|
637
|
-
_c =
|
638
|
-
for (_d in _b)
|
639
|
-
_c.push(_d);
|
640
|
-
_i = 0;
|
641
|
-
_e.label = 1;
|
633
|
+
issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
|
634
|
+
if (!issueStep)
|
635
|
+
throw Error("Booking step: ".concat(booking_1.Booking.BookingSteps.ISSUE, " not found!"));
|
636
|
+
if (!!issueStep[0]) return [3 /*break*/, 5];
|
637
|
+
_i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS, booking_1.Booking.BookingSteps.DISCOUNTS];
|
638
|
+
_c.label = 1;
|
642
639
|
case 1:
|
643
|
-
if (!(_i <
|
644
|
-
|
645
|
-
if (
|
646
|
-
step = _d;
|
647
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
640
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
641
|
+
step = _a[_i];
|
642
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
|
648
643
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
649
644
|
case 2:
|
650
|
-
|
651
|
-
|
645
|
+
_c.sent();
|
646
|
+
_c.label = 3;
|
652
647
|
case 3:
|
653
648
|
_i++;
|
654
649
|
return [3 /*break*/, 1];
|
655
650
|
case 4:
|
656
651
|
// Check again if the discounts step is accessible
|
657
|
-
|
658
|
-
if (!
|
659
|
-
throw Error("The status of the cart does not allow to call
|
652
|
+
issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
|
653
|
+
if (!issueStep || !issueStep[0]) {
|
654
|
+
throw Error("The status of the cart does not allow to call the API: booking/cart/".concat(this.cartId, "/payment/wallet"));
|
660
655
|
}
|
661
|
-
|
656
|
+
_c.label = 5;
|
662
657
|
case 5:
|
663
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
658
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
|
664
659
|
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
665
660
|
var _a, _b;
|
666
661
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -691,7 +686,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
691
686
|
if (!this.cartId || this.cartId === 0) {
|
692
687
|
throw Error("Cart is not initialized yet");
|
693
688
|
}
|
694
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
689
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/wallet");
|
695
690
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
696
691
|
var _a, _b, _c;
|
697
692
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -715,12 +710,12 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
715
710
|
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
716
711
|
*/
|
717
712
|
JourneyBooking.prototype.useVoucher = function (voucherCode) {
|
718
|
-
var _a;
|
719
713
|
return __awaiter(this, void 0, void 0, function () {
|
720
|
-
var discountsStep,
|
714
|
+
var discountsStep, _i, _a, step, url;
|
721
715
|
var _this = this;
|
722
|
-
|
723
|
-
|
716
|
+
var _b;
|
717
|
+
return __generator(this, function (_c) {
|
718
|
+
switch (_c.label) {
|
724
719
|
case 0:
|
725
720
|
// First check that it is possible to call this API
|
726
721
|
if (!this.cartId || this.cartId === 0) {
|
@@ -730,22 +725,16 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
730
725
|
if (!discountsStep)
|
731
726
|
throw Error("Booking step not found!");
|
732
727
|
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
733
|
-
|
734
|
-
_c =
|
735
|
-
for (_d in _b)
|
736
|
-
_c.push(_d);
|
737
|
-
_i = 0;
|
738
|
-
_e.label = 1;
|
728
|
+
_i = 0, _a = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
729
|
+
_c.label = 1;
|
739
730
|
case 1:
|
740
|
-
if (!(_i <
|
741
|
-
|
742
|
-
if (
|
743
|
-
step = _d;
|
744
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
731
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
732
|
+
step = _a[_i];
|
733
|
+
if (!!((_b = this.bookingStepsToStatus.get(step)) !== null && _b !== void 0 ? _b : [false])[0]) return [3 /*break*/, 3];
|
745
734
|
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
746
735
|
case 2:
|
747
|
-
|
748
|
-
|
736
|
+
_c.sent();
|
737
|
+
_c.label = 3;
|
749
738
|
case 3:
|
750
739
|
_i++;
|
751
740
|
return [3 /*break*/, 1];
|
@@ -755,9 +744,9 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
755
744
|
if (!discountsStep || !discountsStep[0]) {
|
756
745
|
throw Error("The status of the cart does not allow to call this API");
|
757
746
|
}
|
758
|
-
|
747
|
+
_c.label = 5;
|
759
748
|
case 5:
|
760
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
749
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/cart/").concat(this.cartId, "/payment/voucher");
|
761
750
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
762
751
|
var _a, _b;
|
763
752
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -796,10 +785,10 @@ exports.JourneyBooking = JourneyBooking;
|
|
796
785
|
case 3: return [2 /*return*/, booking];
|
797
786
|
case 4:
|
798
787
|
error_1 = _a.sent();
|
799
|
-
// Check if the error is due to an expired cart. In this case, delete the cartId from the
|
788
|
+
// Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
|
800
789
|
// This error can occur when the user refreshes the page and the cart has expired
|
801
790
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
|
802
|
-
|
791
|
+
booking.getStorage().getState().updateCartId(undefined);
|
803
792
|
booking.cartId = undefined;
|
804
793
|
return [2 /*return*/, booking];
|
805
794
|
}
|