mts-booking-library 1.2.10 → 1.2.12
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +23 -24
- package/lib/booking/booking.js +149 -98
- package/lib/booking/journeyBooking.d.ts +47 -4
- package/lib/booking/journeyBooking.js +317 -18
- package/lib/booking/serviceBooking.d.ts +37 -2
- package/lib/booking/serviceBooking.js +289 -16
- package/lib/booking/subscriptionBooking.d.ts +37 -2
- package/lib/booking/subscriptionBooking.js +287 -9
- package/lib/types/common/Cart.d.ts +13 -0
- package/lib/types/common/Payment.d.ts +10 -2
- package/lib/types/common/Payment.js +9 -1
- package/lib/types/common/Reduction.d.ts +27 -0
- package/lib/types/common/Reduction.js +7 -0
- package/lib/types/journeys/Trip.d.ts +10 -0
- package/lib/utils/apiCall.d.ts +8 -0
- package/lib/utils/apiCall.js +63 -7
- package/lib/utils/processBookingSteps.d.ts +7 -0
- package/lib/utils/processBookingSteps.js +24 -0
- package/package.json +1 -1
package/lib/booking/booking.d.ts
CHANGED
@@ -4,7 +4,7 @@ import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, Pa
|
|
4
4
|
import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
5
5
|
import { AddReductionRequest } from "../types/common/Reduction";
|
6
6
|
export declare abstract class Booking {
|
7
|
-
|
7
|
+
private sellerId?;
|
8
8
|
readonly resellerId?: number | undefined;
|
9
9
|
readonly bookingType: Booking.BookingTypes;
|
10
10
|
readonly config: MTSConfig;
|
@@ -35,6 +35,12 @@ export declare abstract class Booking {
|
|
35
35
|
* @param {number} [resellerId=undefined] The id of the reseller.
|
36
36
|
*/
|
37
37
|
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, bookingType: Booking.BookingTypes, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
38
|
+
/**
|
39
|
+
* This method allows to update the sellerId. It is mostly important for Linkavel, as we start with sellerId = 0
|
40
|
+
* but then it changes to the actual sellerId once the cart is created.
|
41
|
+
* @param sellerId The id of the seller.
|
42
|
+
*/
|
43
|
+
updateSellerId(sellerId: number): void;
|
38
44
|
/**
|
39
45
|
* This method allows to renew the access token for calling MTS APIs
|
40
46
|
* @param {string} access_token The new access token
|
@@ -42,35 +48,26 @@ export declare abstract class Booking {
|
|
42
48
|
renewAccessToken(access_token: string): void;
|
43
49
|
callGetApi(url: string): Promise<ErrorResponse | any>;
|
44
50
|
callPostApi(url: string, body: any): Promise<any>;
|
51
|
+
callDeleteApi(url: string): Promise<ErrorResponse | any>;
|
45
52
|
getBookingStepsToStatus(): Map<string, boolean[]>;
|
46
53
|
changeCurrency(currency: Booking.Currencies): void;
|
47
54
|
changeLanguage(language: string): void;
|
48
55
|
getCartExpirationTimeInMs(): Promise<number>;
|
56
|
+
/**
|
57
|
+
* This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
|
58
|
+
* @param bookingStep The booking step to mark as completed
|
59
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
60
|
+
*/
|
61
|
+
markBookingStepCompleted(bookingStep: Booking.BookingSteps): Promise<ErrorResponse | boolean>;
|
49
62
|
abstract deleteCart(): Promise<ErrorResponse | any>;
|
50
63
|
abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
51
64
|
abstract getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
|
52
|
-
abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse |
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
addReduction(request: AddReductionRequest): Promise<ErrorResponse | any>;
|
59
|
-
/**
|
60
|
-
* @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
|
61
|
-
* the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
|
62
|
-
* remaining amount with another payment method.
|
63
|
-
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
64
|
-
*/
|
65
|
-
useWallet(): Promise<ErrorResponse | any>;
|
66
|
-
/**
|
67
|
-
* @description This method allows the user to use a voucher to pay the cart.
|
68
|
-
* If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
|
69
|
-
* Otherwise, the user will be asked to pay the remaining amount with another payment method.
|
70
|
-
* @param {string} voucherCode The code of the voucher to use
|
71
|
-
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
72
|
-
*/
|
73
|
-
useVoucher(voucherCode: string): Promise<ErrorResponse | any>;
|
65
|
+
abstract updateBuyerPassengersDetails(request: any): 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>;
|
74
71
|
/**
|
75
72
|
* @description This method shall be used to get the available payment methods for the cart. They depend on the seller configuration.
|
76
73
|
* @returns An {@link ErrorResponse} object in case of error, a {@link GetSellerGatewaysResponse} object otherwise.
|
@@ -86,9 +83,11 @@ export declare abstract class Booking {
|
|
86
83
|
getPaymentInformationFromGateway(gatewayId: number, returnUrl?: string): Promise<ErrorResponse | GetPaymentInformationFromGatewayResponse>;
|
87
84
|
/**
|
88
85
|
* @description This method shall be used to issue the tickets. It must be called after the payment was successful.
|
86
|
+
* @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
|
87
|
+
* first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
|
89
88
|
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
90
89
|
*/
|
91
|
-
issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse |
|
90
|
+
issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse | boolean>;
|
92
91
|
}
|
93
92
|
export declare namespace Booking {
|
94
93
|
enum Currencies {
|
package/lib/booking/booking.js
CHANGED
@@ -52,6 +52,7 @@ var config_1 = require("../config");
|
|
52
52
|
var ErrorResponse_1 = require("../types/ErrorResponse");
|
53
53
|
var Payment_1 = require("../types/common/Payment");
|
54
54
|
var apiCall_1 = require("../utils/apiCall");
|
55
|
+
var processBookingSteps_1 = require("../utils/processBookingSteps");
|
55
56
|
var Booking = /** @class */ (function () {
|
56
57
|
/**
|
57
58
|
* This is the constructor of the Booking class.
|
@@ -86,6 +87,14 @@ var Booking = /** @class */ (function () {
|
|
86
87
|
this.onCartExpiration = onCartExpiration;
|
87
88
|
this.changeLanguage(language);
|
88
89
|
}
|
90
|
+
/**
|
91
|
+
* This method allows to update the sellerId. It is mostly important for Linkavel, as we start with sellerId = 0
|
92
|
+
* but then it changes to the actual sellerId once the cart is created.
|
93
|
+
* @param sellerId The id of the seller.
|
94
|
+
*/
|
95
|
+
Booking.prototype.updateSellerId = function (sellerId) {
|
96
|
+
this.sellerId = sellerId;
|
97
|
+
};
|
89
98
|
/**
|
90
99
|
* This method allows to renew the access token for calling MTS APIs
|
91
100
|
* @param {string} access_token The new access token
|
@@ -105,6 +114,13 @@ var Booking = /** @class */ (function () {
|
|
105
114
|
var completeBody = __assign(__assign(__assign(__assign({}, body), (this.sellerId && { sellerId: this.sellerId.toString() })), (this.resellerId && { resellerId: this.resellerId.toString() })), { language: this.language });
|
106
115
|
return (0, apiCall_1.makePost)(url, completeBody);
|
107
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
|
+
};
|
108
124
|
Booking.prototype.getBookingStepsToStatus = function () {
|
109
125
|
return this.bookingStepsToStatus;
|
110
126
|
};
|
@@ -134,79 +150,35 @@ var Booking = /** @class */ (function () {
|
|
134
150
|
});
|
135
151
|
});
|
136
152
|
};
|
137
|
-
//#endregion
|
138
|
-
//#region Reductions APIs
|
139
|
-
/**
|
140
|
-
* @description This method allows to add a reduction to the cart
|
141
|
-
* @param {AddReductionRequest} request The information about the reduction to add
|
142
|
-
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
143
|
-
*/
|
144
|
-
Booking.prototype.addReduction = function (request) {
|
145
|
-
return __awaiter(this, void 0, void 0, function () {
|
146
|
-
var discountsStep, url;
|
147
|
-
return __generator(this, function (_a) {
|
148
|
-
// First check that it is possible to call this API
|
149
|
-
if (!this.cartId || this.cartId === 0) {
|
150
|
-
throw Error("Cart is not initialized yet");
|
151
|
-
}
|
152
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
153
|
-
if (!discountsStep || !discountsStep[0]) {
|
154
|
-
throw Error("The status of the cart does not allow to call this API");
|
155
|
-
}
|
156
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/reduction");
|
157
|
-
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
158
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
159
|
-
})];
|
160
|
-
});
|
161
|
-
});
|
162
|
-
};
|
163
|
-
/**
|
164
|
-
* @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
|
165
|
-
* the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
|
166
|
-
* remaining amount with another payment method.
|
167
|
-
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
168
|
-
*/
|
169
|
-
Booking.prototype.useWallet = function () {
|
170
|
-
return __awaiter(this, void 0, void 0, function () {
|
171
|
-
var discountsStep, url;
|
172
|
-
return __generator(this, function (_a) {
|
173
|
-
// First check that it is possible to call this API
|
174
|
-
if (!this.cartId || this.cartId === 0) {
|
175
|
-
throw Error("Cart is not initialized yet");
|
176
|
-
}
|
177
|
-
discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
178
|
-
if (!discountsStep || !discountsStep[0]) {
|
179
|
-
throw Error("The status of the cart does not allow to call this API");
|
180
|
-
}
|
181
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
|
182
|
-
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
183
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
184
|
-
})];
|
185
|
-
});
|
186
|
-
});
|
187
|
-
};
|
188
153
|
/**
|
189
|
-
*
|
190
|
-
*
|
191
|
-
*
|
192
|
-
* @param {string} voucherCode The code of the voucher to use
|
193
|
-
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
154
|
+
* This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
|
155
|
+
* @param bookingStep The booking step to mark as completed
|
156
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
194
157
|
*/
|
195
|
-
Booking.prototype.
|
158
|
+
Booking.prototype.markBookingStepCompleted = function (bookingStep) {
|
196
159
|
return __awaiter(this, void 0, void 0, function () {
|
197
|
-
var
|
160
|
+
var currentStepStatus, url;
|
161
|
+
var _this = this;
|
198
162
|
return __generator(this, function (_a) {
|
199
163
|
// First check that it is possible to call this API
|
200
164
|
if (!this.cartId || this.cartId === 0) {
|
201
165
|
throw Error("Cart is not initialized yet");
|
202
166
|
}
|
203
|
-
|
204
|
-
if (!
|
205
|
-
throw Error("The
|
167
|
+
currentStepStatus = this.bookingStepsToStatus.get(bookingStep);
|
168
|
+
if (!currentStepStatus || currentStepStatus[2]) {
|
169
|
+
throw Error("The step ".concat(bookingStep, " cannot be marked as completed because it is required"));
|
206
170
|
}
|
207
|
-
|
208
|
-
|
209
|
-
|
171
|
+
// Booking step is already completedm, no need to call the API
|
172
|
+
if (currentStepStatus[0])
|
173
|
+
return [2 /*return*/, true];
|
174
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/bookingSteps");
|
175
|
+
return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep }).then(function (response) {
|
176
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
177
|
+
return response;
|
178
|
+
}
|
179
|
+
// Update the booking process status
|
180
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
181
|
+
return true;
|
210
182
|
})];
|
211
183
|
});
|
212
184
|
});
|
@@ -218,21 +190,52 @@ var Booking = /** @class */ (function () {
|
|
218
190
|
* @returns An {@link ErrorResponse} object in case of error, a {@link GetSellerGatewaysResponse} object otherwise.
|
219
191
|
*/
|
220
192
|
Booking.prototype.getSellerGateways = function () {
|
193
|
+
var _a;
|
221
194
|
return __awaiter(this, void 0, void 0, function () {
|
222
|
-
var issueStep, url;
|
223
|
-
return __generator(this, function (
|
224
|
-
|
225
|
-
|
226
|
-
|
195
|
+
var issueStep, _b, _c, _d, _i, step, url;
|
196
|
+
return __generator(this, function (_e) {
|
197
|
+
switch (_e.label) {
|
198
|
+
case 0:
|
199
|
+
// First check that it is possible to call this API
|
200
|
+
if (!this.cartId || this.cartId === 0) {
|
201
|
+
throw Error("Cart is not initialized yet");
|
202
|
+
}
|
203
|
+
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
|
204
|
+
if (!issueStep)
|
205
|
+
throw Error("Booking step not found!");
|
206
|
+
if (!!issueStep[0]) return [3 /*break*/, 5];
|
207
|
+
_b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
|
208
|
+
_c = [];
|
209
|
+
for (_d in _b)
|
210
|
+
_c.push(_d);
|
211
|
+
_i = 0;
|
212
|
+
_e.label = 1;
|
213
|
+
case 1:
|
214
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
215
|
+
_d = _c[_i];
|
216
|
+
if (!(_d in _b)) return [3 /*break*/, 3];
|
217
|
+
step = _d;
|
218
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
219
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
220
|
+
case 2:
|
221
|
+
_e.sent();
|
222
|
+
_e.label = 3;
|
223
|
+
case 3:
|
224
|
+
_i++;
|
225
|
+
return [3 /*break*/, 1];
|
226
|
+
case 4:
|
227
|
+
// Check again if the issue step is accessible
|
228
|
+
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
229
|
+
if (!issueStep || !issueStep[0]) {
|
230
|
+
throw Error("The status of the cart does not allow to call this API");
|
231
|
+
}
|
232
|
+
_e.label = 5;
|
233
|
+
case 5:
|
234
|
+
url = "".concat(this.config.API_ENDPOINT, "/sellers/").concat(this.sellerId, "/gateways");
|
235
|
+
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
236
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
237
|
+
})];
|
227
238
|
}
|
228
|
-
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
|
229
|
-
if (!issueStep || !issueStep[0]) {
|
230
|
-
throw Error("The status of the cart does not allow to call this API");
|
231
|
-
}
|
232
|
-
url = "".concat(this.config.API_ENDPOINT, "/sellers/").concat(this.sellerId, "/gateways");
|
233
|
-
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
234
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
235
|
-
})];
|
236
239
|
});
|
237
240
|
});
|
238
241
|
};
|
@@ -245,7 +248,7 @@ var Booking = /** @class */ (function () {
|
|
245
248
|
*/
|
246
249
|
Booking.prototype.getPaymentInformationFromGateway = function (gatewayId, returnUrl) {
|
247
250
|
return __awaiter(this, void 0, void 0, function () {
|
248
|
-
var issueStep,
|
251
|
+
var issueStep, searchParams, url;
|
249
252
|
return __generator(this, function (_a) {
|
250
253
|
// First check that it is possible to call this API
|
251
254
|
if (!this.cartId || this.cartId === 0) {
|
@@ -255,9 +258,9 @@ var Booking = /** @class */ (function () {
|
|
255
258
|
if (!issueStep || !issueStep[0]) {
|
256
259
|
throw Error("The status of the cart does not allow to call this API");
|
257
260
|
}
|
258
|
-
|
259
|
-
|
260
|
-
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) {
|
261
264
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
262
265
|
})];
|
263
266
|
});
|
@@ -265,28 +268,76 @@ var Booking = /** @class */ (function () {
|
|
265
268
|
};
|
266
269
|
/**
|
267
270
|
* @description This method shall be used to issue the tickets. It must be called after the payment was successful.
|
271
|
+
* @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
|
272
|
+
* first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
|
268
273
|
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
269
274
|
*/
|
270
275
|
Booking.prototype.issueTickets = function (paymentMethod) {
|
276
|
+
var _a;
|
271
277
|
return __awaiter(this, void 0, void 0, function () {
|
272
|
-
var issueStep, url, body;
|
273
|
-
return __generator(this, function (
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
278
|
+
var paymentMethodToSet, issueStep, _b, _c, _d, _i, step, url, body;
|
279
|
+
return __generator(this, function (_e) {
|
280
|
+
switch (_e.label) {
|
281
|
+
case 0:
|
282
|
+
// First check that it is possible to call this API
|
283
|
+
if (!this.cartId || this.cartId === 0) {
|
284
|
+
throw Error("Cart is not initialized yet");
|
285
|
+
}
|
286
|
+
paymentMethodToSet = paymentMethod;
|
287
|
+
if (!(paymentMethod === Payment_1.PaymentMethods.ZERO_COST)) return [3 /*break*/, 2];
|
288
|
+
return [4 /*yield*/, this.addReduction({ tripId: 0, reduction: 1, isPercentage: true }).then(function (response) {
|
289
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
290
|
+
return response;
|
291
|
+
}
|
292
|
+
else {
|
293
|
+
// Request was successful. Set payment method to CASH
|
294
|
+
paymentMethodToSet = Payment_1.PaymentMethods.CASH;
|
295
|
+
}
|
296
|
+
})];
|
297
|
+
case 1:
|
298
|
+
_e.sent();
|
299
|
+
_e.label = 2;
|
300
|
+
case 2:
|
301
|
+
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
|
302
|
+
if (!issueStep)
|
303
|
+
throw Error("Booking step not found!");
|
304
|
+
if (!!issueStep[0]) return [3 /*break*/, 7];
|
305
|
+
_b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
|
306
|
+
_c = [];
|
307
|
+
for (_d in _b)
|
308
|
+
_c.push(_d);
|
309
|
+
_i = 0;
|
310
|
+
_e.label = 3;
|
311
|
+
case 3:
|
312
|
+
if (!(_i < _c.length)) return [3 /*break*/, 6];
|
313
|
+
_d = _c[_i];
|
314
|
+
if (!(_d in _b)) return [3 /*break*/, 5];
|
315
|
+
step = _d;
|
316
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 5];
|
317
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
318
|
+
case 4:
|
319
|
+
_e.sent();
|
320
|
+
_e.label = 5;
|
321
|
+
case 5:
|
322
|
+
_i++;
|
323
|
+
return [3 /*break*/, 3];
|
324
|
+
case 6:
|
325
|
+
// Check again if the issue step is accessible
|
326
|
+
issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
|
327
|
+
if (!issueStep || !issueStep[0]) {
|
328
|
+
throw Error("The status of the cart does not allow to call this API");
|
329
|
+
}
|
330
|
+
_e.label = 7;
|
331
|
+
case 7:
|
332
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/issue");
|
333
|
+
body = {
|
334
|
+
cartId: this.cartId,
|
335
|
+
paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
|
336
|
+
};
|
337
|
+
return [2 /*return*/, this.callPostApi(url, body).then(function (response) {
|
338
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : true;
|
339
|
+
})];
|
281
340
|
}
|
282
|
-
url = "".concat(this.config.API_ENDPOINT, "/issueTickets");
|
283
|
-
body = {
|
284
|
-
cartId: this.cartId,
|
285
|
-
paymentMethod: paymentMethod === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethod,
|
286
|
-
};
|
287
|
-
return [2 /*return*/, this.callPostApi(url, body).then(function (response) {
|
288
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
289
|
-
})];
|
290
341
|
});
|
291
342
|
});
|
292
343
|
};
|
@@ -1,9 +1,11 @@
|
|
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";
|
8
|
+
import { ReductionTrip } from "../types/journeys/Trip";
|
7
9
|
import { Booking } from "./booking";
|
8
10
|
export declare class JourneyBooking extends Booking {
|
9
11
|
private cart?;
|
@@ -68,9 +70,9 @@ export declare class JourneyBooking extends Booking {
|
|
68
70
|
/**
|
69
71
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
70
72
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
71
|
-
* @returns An {@link ErrorResponse} object in case of error,
|
73
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
72
74
|
*/
|
73
|
-
updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse |
|
75
|
+
updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | boolean>;
|
74
76
|
/**
|
75
77
|
* @description This method shall be used when the user wants to retrieve the bus matrix for a trip. The bus matrix shows
|
76
78
|
* the seats that are available and the ones that are already taken, as well as how the bus is made.
|
@@ -90,9 +92,50 @@ export declare class JourneyBooking extends Booking {
|
|
90
92
|
* @description This method shall be called when the user wants to change the assigned seats of a trip.
|
91
93
|
* @param {number} tripId The id of the trip for which the seats should be changed
|
92
94
|
* @param {number[]} newSeatsIds The ids of the new seats, as found the {@link BusMatrix}
|
93
|
-
* @returns An {@link ErrorResponse} object in case of error,
|
95
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
94
96
|
*/
|
95
|
-
changeSeatsOfTrip(tripId: number, newSeatsIds: number[]): Promise<ErrorResponse |
|
97
|
+
changeSeatsOfTrip(tripId: number, newSeatsIds: number[]): Promise<ErrorResponse | boolean>;
|
98
|
+
/**
|
99
|
+
* @description This method shall be called when the user wants to retrieve the trips in the cart, for adding a available reduction
|
100
|
+
* to a specific trip (rather than to the whole cart).
|
101
|
+
* @see {@link Booking.addReduction} for detailed info on how to add a reduction.
|
102
|
+
* @returns An {@link ErrorResponse} object in case of error, a list of {@link ReductionTrip} otherwise, representing the trips in the cart.
|
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>;
|
96
139
|
}
|
97
140
|
export declare namespace JourneyBooking {
|
98
141
|
const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
|