mts-booking-library 1.2.11 → 1.2.13
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +6 -21
- package/lib/booking/booking.js +16 -197
- package/lib/booking/journeyBooking.d.ts +35 -0
- package/lib/booking/journeyBooking.js +277 -0
- package/lib/booking/serviceBooking.d.ts +35 -0
- package/lib/booking/serviceBooking.js +278 -0
- package/lib/booking/subscriptionBooking.d.ts +35 -0
- package/lib/booking/subscriptionBooking.js +277 -0
- package/lib/types/common/Cart.d.ts +13 -0
- package/lib/types/common/Reduction.d.ts +27 -0
- package/lib/types/common/Reduction.js +7 -0
- package/lib/utils/apiCall.d.ts +8 -0
- package/lib/utils/apiCall.js +63 -7
- package/package.json +1 -1
package/lib/booking/booking.d.ts
CHANGED
@@ -48,6 +48,7 @@ export declare abstract class Booking {
|
|
48
48
|
renewAccessToken(access_token: string): void;
|
49
49
|
callGetApi(url: string): Promise<ErrorResponse | any>;
|
50
50
|
callPostApi(url: string, body: any): Promise<any>;
|
51
|
+
callDeleteApi(url: string): Promise<ErrorResponse | any>;
|
51
52
|
getBookingStepsToStatus(): Map<string, boolean[]>;
|
52
53
|
changeCurrency(currency: Booking.Currencies): void;
|
53
54
|
changeLanguage(language: string): void;
|
@@ -62,27 +63,11 @@ export declare abstract class Booking {
|
|
62
63
|
abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
63
64
|
abstract getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
|
64
65
|
abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | boolean>;
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
|
71
|
-
/**
|
72
|
-
* @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
|
73
|
-
* the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
|
74
|
-
* remaining amount with another payment method.
|
75
|
-
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
76
|
-
*/
|
77
|
-
useWallet(): Promise<ErrorResponse | boolean>;
|
78
|
-
/**
|
79
|
-
* @description This method allows the user to use a voucher to pay the cart.
|
80
|
-
* If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
|
81
|
-
* Otherwise, the user will be asked to pay the remaining amount with another payment method.
|
82
|
-
* @param {string} voucherCode The code of the voucher to use
|
83
|
-
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
84
|
-
*/
|
85
|
-
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
66
|
+
abstract addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
|
67
|
+
abstract removeReduction(tripId: number): Promise<ErrorResponse | boolean>;
|
68
|
+
abstract useWallet(): Promise<ErrorResponse | boolean>;
|
69
|
+
abstract removeWalletReduction(): Promise<ErrorResponse | boolean>;
|
70
|
+
abstract useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
86
71
|
/**
|
87
72
|
* @description This method shall be used to get the available payment methods for the cart. They depend on the seller configuration.
|
88
73
|
* @returns An {@link ErrorResponse} object in case of error, a {@link GetSellerGatewaysResponse} object otherwise.
|
package/lib/booking/booking.js
CHANGED
@@ -114,6 +114,13 @@ var Booking = /** @class */ (function () {
|
|
114
114
|
var completeBody = __assign(__assign(__assign(__assign({}, body), (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language });
|
115
115
|
return (0, apiCall_1.makePost)(url, completeBody);
|
116
116
|
};
|
117
|
+
Booking.prototype.callDeleteApi = function (url) {
|
118
|
+
// Add sellerId, resellerId and language to the query string.
|
119
|
+
// If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
|
120
|
+
// Otherwise, add it (as we are adding some parameters to the query string)
|
121
|
+
var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(__assign(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language })));
|
122
|
+
return (0, apiCall_1.makeDelete)(completeUrl);
|
123
|
+
};
|
117
124
|
Booking.prototype.getBookingStepsToStatus = function () {
|
118
125
|
return this.bookingStepsToStatus;
|
119
126
|
};
|
@@ -177,194 +184,6 @@ var Booking = /** @class */ (function () {
|
|
177
184
|
});
|
178
185
|
};
|
179
186
|
//#endregion
|
180
|
-
//#region Reductions APIs
|
181
|
-
/**
|
182
|
-
* @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
|
183
|
-
* @param {AddReductionRequest} request The information about the reduction to add
|
184
|
-
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
185
|
-
*/
|
186
|
-
Booking.prototype.addReduction = function (request) {
|
187
|
-
var _a;
|
188
|
-
return __awaiter(this, void 0, void 0, function () {
|
189
|
-
var discountsStep, _b, _c, _d, _i, step, url;
|
190
|
-
var _this = this;
|
191
|
-
return __generator(this, function (_e) {
|
192
|
-
switch (_e.label) {
|
193
|
-
case 0:
|
194
|
-
// First check that it is possible to call this API
|
195
|
-
if (!this.cartId || this.cartId === 0) {
|
196
|
-
throw Error("Cart is not initialized yet");
|
197
|
-
}
|
198
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
199
|
-
if (!discountsStep)
|
200
|
-
throw Error("Booking step not found!");
|
201
|
-
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
202
|
-
_b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS];
|
203
|
-
_c = [];
|
204
|
-
for (_d in _b)
|
205
|
-
_c.push(_d);
|
206
|
-
_i = 0;
|
207
|
-
_e.label = 1;
|
208
|
-
case 1:
|
209
|
-
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
210
|
-
_d = _c[_i];
|
211
|
-
if (!(_d in _b)) return [3 /*break*/, 3];
|
212
|
-
step = _d;
|
213
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
214
|
-
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
215
|
-
case 2:
|
216
|
-
_e.sent();
|
217
|
-
_e.label = 3;
|
218
|
-
case 3:
|
219
|
-
_i++;
|
220
|
-
return [3 /*break*/, 1];
|
221
|
-
case 4:
|
222
|
-
// Check again if the discounts step is accessible
|
223
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
224
|
-
if (!discountsStep || !discountsStep[0]) {
|
225
|
-
throw Error("The status of the cart does not allow to call this API");
|
226
|
-
}
|
227
|
-
_e.label = 5;
|
228
|
-
case 5:
|
229
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/reduction");
|
230
|
-
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
231
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
232
|
-
return response;
|
233
|
-
}
|
234
|
-
// Update the booking process status
|
235
|
-
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
236
|
-
return true;
|
237
|
-
})];
|
238
|
-
}
|
239
|
-
});
|
240
|
-
});
|
241
|
-
};
|
242
|
-
/**
|
243
|
-
* @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
|
244
|
-
* the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
|
245
|
-
* remaining amount with another payment method.
|
246
|
-
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
247
|
-
*/
|
248
|
-
Booking.prototype.useWallet = function () {
|
249
|
-
var _a;
|
250
|
-
return __awaiter(this, void 0, void 0, function () {
|
251
|
-
var discountsStep, _b, _c, _d, _i, step, url;
|
252
|
-
var _this = this;
|
253
|
-
return __generator(this, function (_e) {
|
254
|
-
switch (_e.label) {
|
255
|
-
case 0:
|
256
|
-
// First check that it is possible to call this API
|
257
|
-
if (!this.cartId || this.cartId === 0) {
|
258
|
-
throw Error("Cart is not initialized yet");
|
259
|
-
}
|
260
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
261
|
-
if (!discountsStep)
|
262
|
-
throw Error("Booking step not found!");
|
263
|
-
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
264
|
-
_b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS];
|
265
|
-
_c = [];
|
266
|
-
for (_d in _b)
|
267
|
-
_c.push(_d);
|
268
|
-
_i = 0;
|
269
|
-
_e.label = 1;
|
270
|
-
case 1:
|
271
|
-
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
272
|
-
_d = _c[_i];
|
273
|
-
if (!(_d in _b)) return [3 /*break*/, 3];
|
274
|
-
step = _d;
|
275
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
276
|
-
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
277
|
-
case 2:
|
278
|
-
_e.sent();
|
279
|
-
_e.label = 3;
|
280
|
-
case 3:
|
281
|
-
_i++;
|
282
|
-
return [3 /*break*/, 1];
|
283
|
-
case 4:
|
284
|
-
// Check again if the discounts step is accessible
|
285
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
286
|
-
if (!discountsStep || !discountsStep[0]) {
|
287
|
-
throw Error("The status of the cart does not allow to call this API");
|
288
|
-
}
|
289
|
-
_e.label = 5;
|
290
|
-
case 5:
|
291
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
|
292
|
-
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
293
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
294
|
-
return response;
|
295
|
-
}
|
296
|
-
// Update the booking process status
|
297
|
-
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
298
|
-
return true;
|
299
|
-
})];
|
300
|
-
}
|
301
|
-
});
|
302
|
-
});
|
303
|
-
};
|
304
|
-
/**
|
305
|
-
* @description This method allows the user to use a voucher to pay the cart.
|
306
|
-
* If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
|
307
|
-
* Otherwise, the user will be asked to pay the remaining amount with another payment method.
|
308
|
-
* @param {string} voucherCode The code of the voucher to use
|
309
|
-
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
310
|
-
*/
|
311
|
-
Booking.prototype.useVoucher = function (voucherCode) {
|
312
|
-
var _a;
|
313
|
-
return __awaiter(this, void 0, void 0, function () {
|
314
|
-
var discountsStep, _b, _c, _d, _i, step, url;
|
315
|
-
var _this = this;
|
316
|
-
return __generator(this, function (_e) {
|
317
|
-
switch (_e.label) {
|
318
|
-
case 0:
|
319
|
-
// First check that it is possible to call this API
|
320
|
-
if (!this.cartId || this.cartId === 0) {
|
321
|
-
throw Error("Cart is not initialized yet");
|
322
|
-
}
|
323
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
324
|
-
if (!discountsStep)
|
325
|
-
throw Error("Booking step not found!");
|
326
|
-
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
327
|
-
_b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS];
|
328
|
-
_c = [];
|
329
|
-
for (_d in _b)
|
330
|
-
_c.push(_d);
|
331
|
-
_i = 0;
|
332
|
-
_e.label = 1;
|
333
|
-
case 1:
|
334
|
-
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
335
|
-
_d = _c[_i];
|
336
|
-
if (!(_d in _b)) return [3 /*break*/, 3];
|
337
|
-
step = _d;
|
338
|
-
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
339
|
-
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
340
|
-
case 2:
|
341
|
-
_e.sent();
|
342
|
-
_e.label = 3;
|
343
|
-
case 3:
|
344
|
-
_i++;
|
345
|
-
return [3 /*break*/, 1];
|
346
|
-
case 4:
|
347
|
-
// Check again if the discounts step is accessible
|
348
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
349
|
-
if (!discountsStep || !discountsStep[0]) {
|
350
|
-
throw Error("The status of the cart does not allow to call this API");
|
351
|
-
}
|
352
|
-
_e.label = 5;
|
353
|
-
case 5:
|
354
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/voucher");
|
355
|
-
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
356
|
-
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
357
|
-
return response;
|
358
|
-
}
|
359
|
-
// Update the booking process status
|
360
|
-
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
361
|
-
return true;
|
362
|
-
})];
|
363
|
-
}
|
364
|
-
});
|
365
|
-
});
|
366
|
-
};
|
367
|
-
//#endregion
|
368
187
|
//#region Payment APIs
|
369
188
|
/**
|
370
189
|
* @description This method shall be used to get the available payment methods for the cart. They depend on the seller configuration.
|
@@ -429,7 +248,7 @@ var Booking = /** @class */ (function () {
|
|
429
248
|
*/
|
430
249
|
Booking.prototype.getPaymentInformationFromGateway = function (gatewayId, returnUrl) {
|
431
250
|
return __awaiter(this, void 0, void 0, function () {
|
432
|
-
var issueStep,
|
251
|
+
var issueStep, searchParams, url;
|
433
252
|
return __generator(this, function (_a) {
|
434
253
|
// First check that it is possible to call this API
|
435
254
|
if (!this.cartId || this.cartId === 0) {
|
@@ -439,9 +258,9 @@ var Booking = /** @class */ (function () {
|
|
439
258
|
if (!issueStep || !issueStep[0]) {
|
440
259
|
throw Error("The status of the cart does not allow to call this API");
|
441
260
|
}
|
442
|
-
|
443
|
-
|
444
|
-
return [2 /*return*/, this.
|
261
|
+
searchParams = new URLSearchParams(__assign({ gatewayId: gatewayId.toString() }, (returnUrl && { returnUrl: returnUrl })));
|
262
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment?").concat(searchParams);
|
263
|
+
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
445
264
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
446
265
|
})];
|
447
266
|
});
|
@@ -467,13 +286,13 @@ var Booking = /** @class */ (function () {
|
|
467
286
|
paymentMethodToSet = paymentMethod;
|
468
287
|
if (!(paymentMethod === Payment_1.PaymentMethods.ZERO_COST)) return [3 /*break*/, 2];
|
469
288
|
return [4 /*yield*/, this.addReduction({ tripId: 0, reduction: 1, isPercentage: true }).then(function (response) {
|
289
|
+
if (typeof response === "boolean" && response) {
|
290
|
+
// Reduction was successfully added. Set payment method to CASH
|
291
|
+
paymentMethodToSet = Payment_1.PaymentMethods.CASH;
|
292
|
+
}
|
470
293
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
471
294
|
return response;
|
472
295
|
}
|
473
|
-
else {
|
474
|
-
// Request was successful. Set payment method to CASH
|
475
|
-
paymentMethodToSet = Payment_1.PaymentMethods.CASH;
|
476
|
-
}
|
477
296
|
})];
|
478
297
|
case 1:
|
479
298
|
_e.sent();
|
@@ -510,7 +329,7 @@ var Booking = /** @class */ (function () {
|
|
510
329
|
}
|
511
330
|
_e.label = 7;
|
512
331
|
case 7:
|
513
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
332
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/issue");
|
514
333
|
body = {
|
515
334
|
cartId: this.cartId,
|
516
335
|
paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { MTSEnvs } from "../config";
|
2
2
|
import { ErrorResponse } from "../types/ErrorResponse";
|
3
3
|
import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
4
|
+
import { AddReductionRequest } from "../types/common/Reduction";
|
4
5
|
import { BusMatrix } from "../types/journeys/BusMatrix";
|
5
6
|
import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
|
6
7
|
import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
|
@@ -101,6 +102,40 @@ export declare class JourneyBooking extends Booking {
|
|
101
102
|
* @returns An {@link ErrorResponse} object in case of error, a list of {@link ReductionTrip} otherwise, representing the trips in the cart.
|
102
103
|
*/
|
103
104
|
getCartTrips(): Promise<ErrorResponse | ReductionTrip[]>;
|
105
|
+
/**
|
106
|
+
* @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
|
107
|
+
* @param {AddReductionRequest} request The information about the reduction to add
|
108
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
109
|
+
*/
|
110
|
+
addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
|
111
|
+
/**
|
112
|
+
* @description This method allows to remove a reduction from the whole cart or from a single trip in the cart.
|
113
|
+
* @param tripId The id of the trip from which the reduction should be removed. If the tripId is 0, then the reduction
|
114
|
+
* will be removed from the whole cart.
|
115
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
116
|
+
*/
|
117
|
+
removeReduction(tripId: number): Promise<ErrorResponse | boolean>;
|
118
|
+
/**
|
119
|
+
* @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
|
120
|
+
* the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
|
121
|
+
* remaining amount with another payment method.
|
122
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
123
|
+
*/
|
124
|
+
useWallet(): Promise<ErrorResponse | boolean>;
|
125
|
+
/**
|
126
|
+
* @description This method allows to remove a waller reduction from the cart.
|
127
|
+
*
|
128
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
129
|
+
*/
|
130
|
+
removeWalletReduction(): Promise<ErrorResponse | boolean>;
|
131
|
+
/**
|
132
|
+
* @description This method allows the user to use a voucher to pay the cart.
|
133
|
+
* If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
|
134
|
+
* Otherwise, the user will be asked to pay the remaining amount with another payment method.
|
135
|
+
* @param {string} voucherCode The code of the voucher to use
|
136
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
137
|
+
*/
|
138
|
+
useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
|
104
139
|
}
|
105
140
|
export declare namespace JourneyBooking {
|
106
141
|
const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
|
@@ -61,9 +61,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
61
61
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
62
62
|
}
|
63
63
|
};
|
64
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
65
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
66
|
+
if (ar || !(i in from)) {
|
67
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
68
|
+
ar[i] = from[i];
|
69
|
+
}
|
70
|
+
}
|
71
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
72
|
+
};
|
64
73
|
Object.defineProperty(exports, "__esModule", { value: true });
|
65
74
|
exports.JourneyBooking = void 0;
|
66
75
|
var ErrorResponse_1 = require("../types/ErrorResponse");
|
76
|
+
var Reduction_1 = require("../types/common/Reduction");
|
67
77
|
var processBookingSteps_1 = require("../utils/processBookingSteps");
|
68
78
|
var booking_1 = require("./booking");
|
69
79
|
var JourneyBooking = /** @class */ (function (_super) {
|
@@ -478,6 +488,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
478
488
|
});
|
479
489
|
});
|
480
490
|
};
|
491
|
+
//#region Reductions APIs
|
481
492
|
/**
|
482
493
|
* @description This method shall be called when the user wants to retrieve the trips in the cart, for adding a available reduction
|
483
494
|
* to a specific trip (rather than to the whole cart).
|
@@ -499,6 +510,272 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
499
510
|
});
|
500
511
|
});
|
501
512
|
};
|
513
|
+
/**
|
514
|
+
* @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
|
515
|
+
* @param {AddReductionRequest} request The information about the reduction to add
|
516
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
517
|
+
*/
|
518
|
+
JourneyBooking.prototype.addReduction = function (request) {
|
519
|
+
var _a;
|
520
|
+
return __awaiter(this, void 0, void 0, function () {
|
521
|
+
var discountsStep, _b, _c, _d, _i, step, url;
|
522
|
+
var _this = this;
|
523
|
+
return __generator(this, function (_e) {
|
524
|
+
switch (_e.label) {
|
525
|
+
case 0:
|
526
|
+
// First check that it is possible to call this API
|
527
|
+
if (!this.cartId || this.cartId === 0) {
|
528
|
+
throw Error("Cart is not initialized yet");
|
529
|
+
}
|
530
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
531
|
+
if (!discountsStep)
|
532
|
+
throw Error("Booking step not found!");
|
533
|
+
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
534
|
+
_b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
535
|
+
_c = [];
|
536
|
+
for (_d in _b)
|
537
|
+
_c.push(_d);
|
538
|
+
_i = 0;
|
539
|
+
_e.label = 1;
|
540
|
+
case 1:
|
541
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
542
|
+
_d = _c[_i];
|
543
|
+
if (!(_d in _b)) return [3 /*break*/, 3];
|
544
|
+
step = _d;
|
545
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
546
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
547
|
+
case 2:
|
548
|
+
_e.sent();
|
549
|
+
_e.label = 3;
|
550
|
+
case 3:
|
551
|
+
_i++;
|
552
|
+
return [3 /*break*/, 1];
|
553
|
+
case 4:
|
554
|
+
// Check again if the discounts step is accessible
|
555
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
556
|
+
if (!discountsStep || !discountsStep[0]) {
|
557
|
+
throw Error("The status of the cart does not allow to call this API");
|
558
|
+
}
|
559
|
+
_e.label = 5;
|
560
|
+
case 5:
|
561
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction");
|
562
|
+
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
563
|
+
var _a, _b;
|
564
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
565
|
+
return response;
|
566
|
+
}
|
567
|
+
var reductionResponse = response;
|
568
|
+
// Update the booking process status
|
569
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
570
|
+
// Update the cart
|
571
|
+
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: __spreadArray(__spreadArray([], ((_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) !== null && _b !== void 0 ? _b : []), true), [reductionResponse.reduction], false) });
|
572
|
+
return true;
|
573
|
+
})];
|
574
|
+
}
|
575
|
+
});
|
576
|
+
});
|
577
|
+
};
|
578
|
+
/**
|
579
|
+
* @description This method allows to remove a reduction from the whole cart or from a single trip in the cart.
|
580
|
+
* @param tripId The id of the trip from which the reduction should be removed. If the tripId is 0, then the reduction
|
581
|
+
* will be removed from the whole cart.
|
582
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
583
|
+
*/
|
584
|
+
JourneyBooking.prototype.removeReduction = function (tripId) {
|
585
|
+
return __awaiter(this, void 0, void 0, function () {
|
586
|
+
var discountsStep, queryParams, url;
|
587
|
+
var _this = this;
|
588
|
+
return __generator(this, function (_a) {
|
589
|
+
// First check that it is possible to call this API
|
590
|
+
if (!this.cartId || this.cartId === 0) {
|
591
|
+
throw Error("Cart is not initialized yet");
|
592
|
+
}
|
593
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
594
|
+
if (!discountsStep || !discountsStep[0]) {
|
595
|
+
throw Error("The status of the cart does not allow to call this API");
|
596
|
+
}
|
597
|
+
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
598
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
599
|
+
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
600
|
+
var _a, _b, _c;
|
601
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
602
|
+
return response;
|
603
|
+
}
|
604
|
+
var reductionResponse = response;
|
605
|
+
// Update the booking process status
|
606
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
607
|
+
// Update the cart
|
608
|
+
_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) { return reduction.type === Reduction_1.ReductionType.WALLET ||
|
609
|
+
reduction.type === Reduction_1.ReductionType.VOUCHER ||
|
610
|
+
(reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId); })) !== null && _c !== void 0 ? _c : [] });
|
611
|
+
return true;
|
612
|
+
})];
|
613
|
+
});
|
614
|
+
});
|
615
|
+
};
|
616
|
+
/**
|
617
|
+
* @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
|
618
|
+
* the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
|
619
|
+
* remaining amount with another payment method.
|
620
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
621
|
+
*/
|
622
|
+
JourneyBooking.prototype.useWallet = function () {
|
623
|
+
var _a;
|
624
|
+
return __awaiter(this, void 0, void 0, function () {
|
625
|
+
var discountsStep, _b, _c, _d, _i, step, url;
|
626
|
+
var _this = this;
|
627
|
+
return __generator(this, function (_e) {
|
628
|
+
switch (_e.label) {
|
629
|
+
case 0:
|
630
|
+
// First check that it is possible to call this API
|
631
|
+
if (!this.cartId || this.cartId === 0) {
|
632
|
+
throw Error("Cart is not initialized yet");
|
633
|
+
}
|
634
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
635
|
+
if (!discountsStep)
|
636
|
+
throw Error("Booking step not found!");
|
637
|
+
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
638
|
+
_b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
639
|
+
_c = [];
|
640
|
+
for (_d in _b)
|
641
|
+
_c.push(_d);
|
642
|
+
_i = 0;
|
643
|
+
_e.label = 1;
|
644
|
+
case 1:
|
645
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
646
|
+
_d = _c[_i];
|
647
|
+
if (!(_d in _b)) return [3 /*break*/, 3];
|
648
|
+
step = _d;
|
649
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
650
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
651
|
+
case 2:
|
652
|
+
_e.sent();
|
653
|
+
_e.label = 3;
|
654
|
+
case 3:
|
655
|
+
_i++;
|
656
|
+
return [3 /*break*/, 1];
|
657
|
+
case 4:
|
658
|
+
// Check again if the discounts step is accessible
|
659
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
660
|
+
if (!discountsStep || !discountsStep[0]) {
|
661
|
+
throw Error("The status of the cart does not allow to call this API");
|
662
|
+
}
|
663
|
+
_e.label = 5;
|
664
|
+
case 5:
|
665
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
|
666
|
+
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
667
|
+
var _a, _b;
|
668
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
669
|
+
return response;
|
670
|
+
}
|
671
|
+
var reductionResponse = response;
|
672
|
+
// Update the booking process status
|
673
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
674
|
+
// Update the cart
|
675
|
+
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: __spreadArray(__spreadArray([], ((_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) !== null && _b !== void 0 ? _b : []), true), [reductionResponse.reduction], false) });
|
676
|
+
return true;
|
677
|
+
})];
|
678
|
+
}
|
679
|
+
});
|
680
|
+
});
|
681
|
+
};
|
682
|
+
/**
|
683
|
+
* @description This method allows to remove a waller reduction from the cart.
|
684
|
+
*
|
685
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
686
|
+
*/
|
687
|
+
JourneyBooking.prototype.removeWalletReduction = function () {
|
688
|
+
return __awaiter(this, void 0, void 0, function () {
|
689
|
+
var url;
|
690
|
+
var _this = this;
|
691
|
+
return __generator(this, function (_a) {
|
692
|
+
// First check that it is possible to call this API
|
693
|
+
if (!this.cartId || this.cartId === 0) {
|
694
|
+
throw Error("Cart is not initialized yet");
|
695
|
+
}
|
696
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
|
697
|
+
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
698
|
+
var _a, _b, _c;
|
699
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
700
|
+
return response;
|
701
|
+
}
|
702
|
+
var reductionResponse = response;
|
703
|
+
// Update the booking process status
|
704
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
705
|
+
// Update the cart
|
706
|
+
_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) { return reduction.type !== Reduction_1.ReductionType.WALLET; })) !== null && _c !== void 0 ? _c : [] });
|
707
|
+
return true;
|
708
|
+
})];
|
709
|
+
});
|
710
|
+
});
|
711
|
+
};
|
712
|
+
/**
|
713
|
+
* @description This method allows the user to use a voucher to pay the cart.
|
714
|
+
* If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
|
715
|
+
* Otherwise, the user will be asked to pay the remaining amount with another payment method.
|
716
|
+
* @param {string} voucherCode The code of the voucher to use
|
717
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
718
|
+
*/
|
719
|
+
JourneyBooking.prototype.useVoucher = function (voucherCode) {
|
720
|
+
var _a;
|
721
|
+
return __awaiter(this, void 0, void 0, function () {
|
722
|
+
var discountsStep, _b, _c, _d, _i, step, url;
|
723
|
+
var _this = this;
|
724
|
+
return __generator(this, function (_e) {
|
725
|
+
switch (_e.label) {
|
726
|
+
case 0:
|
727
|
+
// First check that it is possible to call this API
|
728
|
+
if (!this.cartId || this.cartId === 0) {
|
729
|
+
throw Error("Cart is not initialized yet");
|
730
|
+
}
|
731
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
732
|
+
if (!discountsStep)
|
733
|
+
throw Error("Booking step not found!");
|
734
|
+
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
735
|
+
_b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
736
|
+
_c = [];
|
737
|
+
for (_d in _b)
|
738
|
+
_c.push(_d);
|
739
|
+
_i = 0;
|
740
|
+
_e.label = 1;
|
741
|
+
case 1:
|
742
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
743
|
+
_d = _c[_i];
|
744
|
+
if (!(_d in _b)) return [3 /*break*/, 3];
|
745
|
+
step = _d;
|
746
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
747
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
748
|
+
case 2:
|
749
|
+
_e.sent();
|
750
|
+
_e.label = 3;
|
751
|
+
case 3:
|
752
|
+
_i++;
|
753
|
+
return [3 /*break*/, 1];
|
754
|
+
case 4:
|
755
|
+
// Check again if the discounts step is accessible
|
756
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
757
|
+
if (!discountsStep || !discountsStep[0]) {
|
758
|
+
throw Error("The status of the cart does not allow to call this API");
|
759
|
+
}
|
760
|
+
_e.label = 5;
|
761
|
+
case 5:
|
762
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/voucher");
|
763
|
+
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
764
|
+
var _a, _b;
|
765
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
766
|
+
return response;
|
767
|
+
}
|
768
|
+
var reductionResponse = response;
|
769
|
+
// Update the booking process status
|
770
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
771
|
+
// Update the cart
|
772
|
+
_this.cart = __assign(__assign({}, _this.cart), { totalAmountToPay: reductionResponse.totalAmountToPay, reductions: __spreadArray(__spreadArray([], ((_b = (_a = _this.cart) === null || _a === void 0 ? void 0 : _a.reductions) !== null && _b !== void 0 ? _b : []), true), [reductionResponse.reduction], false) });
|
773
|
+
return true;
|
774
|
+
})];
|
775
|
+
}
|
776
|
+
});
|
777
|
+
});
|
778
|
+
};
|
502
779
|
return JourneyBooking;
|
503
780
|
}(booking_1.Booking));
|
504
781
|
exports.JourneyBooking = JourneyBooking;
|