mts-booking-library 1.2.9 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- readonly sellerId?: number | undefined;
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
@@ -46,31 +52,37 @@ export declare abstract class Booking {
46
52
  changeCurrency(currency: Booking.Currencies): void;
47
53
  changeLanguage(language: string): void;
48
54
  getCartExpirationTimeInMs(): Promise<number>;
55
+ /**
56
+ * This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
57
+ * @param bookingStep The booking step to mark as completed
58
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
59
+ */
60
+ markBookingStepCompleted(bookingStep: Booking.BookingSteps): Promise<ErrorResponse | boolean>;
49
61
  abstract deleteCart(): Promise<ErrorResponse | any>;
50
62
  abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
51
63
  abstract getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
52
- abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | any>;
64
+ abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | boolean>;
53
65
  /**
54
- * @description This method allows to add a reduction to the cart
66
+ * @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
55
67
  * @param {AddReductionRequest} request The information about the reduction to add
56
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
68
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
57
69
  */
58
- addReduction(request: AddReductionRequest): Promise<ErrorResponse | any>;
70
+ addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
59
71
  /**
60
72
  * @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
61
73
  * the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
62
74
  * remaining amount with another payment method.
63
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
75
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
64
76
  */
65
- useWallet(): Promise<ErrorResponse | any>;
77
+ useWallet(): Promise<ErrorResponse | boolean>;
66
78
  /**
67
79
  * @description This method allows the user to use a voucher to pay the cart.
68
80
  * If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
69
81
  * Otherwise, the user will be asked to pay the remaining amount with another payment method.
70
82
  * @param {string} voucherCode The code of the voucher to use
71
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
83
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
72
84
  */
73
- useVoucher(voucherCode: string): Promise<ErrorResponse | any>;
85
+ useVoucher(voucherCode: string): Promise<ErrorResponse | boolean>;
74
86
  /**
75
87
  * @description This method shall be used to get the available payment methods for the cart. They depend on the seller configuration.
76
88
  * @returns An {@link ErrorResponse} object in case of error, a {@link GetSellerGatewaysResponse} object otherwise.
@@ -86,9 +98,11 @@ export declare abstract class Booking {
86
98
  getPaymentInformationFromGateway(gatewayId: number, returnUrl?: string): Promise<ErrorResponse | GetPaymentInformationFromGatewayResponse>;
87
99
  /**
88
100
  * @description This method shall be used to issue the tickets. It must be called after the payment was successful.
101
+ * @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
102
+ * first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
89
103
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
90
104
  */
91
- issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse | any>;
105
+ issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse | boolean>;
92
106
  }
93
107
  export declare namespace Booking {
94
108
  enum Currencies {
@@ -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
@@ -134,54 +143,161 @@ var Booking = /** @class */ (function () {
134
143
  });
135
144
  });
136
145
  };
137
- //#endregion
138
- //#region Reductions APIs
139
146
  /**
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.
147
+ * This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
148
+ * @param bookingStep The booking step to mark as completed
149
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
143
150
  */
144
- Booking.prototype.addReduction = function (request) {
151
+ Booking.prototype.markBookingStepCompleted = function (bookingStep) {
145
152
  return __awaiter(this, void 0, void 0, function () {
146
- var discountsStep, url;
153
+ var currentStepStatus, url;
154
+ var _this = this;
147
155
  return __generator(this, function (_a) {
148
156
  // First check that it is possible to call this API
149
157
  if (!this.cartId || this.cartId === 0) {
150
158
  throw Error("Cart is not initialized yet");
151
159
  }
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");
160
+ currentStepStatus = this.bookingStepsToStatus.get(bookingStep);
161
+ if (!currentStepStatus || currentStepStatus[2]) {
162
+ throw Error("The step ".concat(bookingStep, " cannot be marked as completed because it is required"));
155
163
  }
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;
164
+ // Booking step is already completedm, no need to call the API
165
+ if (currentStepStatus[0])
166
+ return [2 /*return*/, true];
167
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/bookingSteps");
168
+ return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep }).then(function (response) {
169
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
170
+ return response;
171
+ }
172
+ // Update the booking process status
173
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
174
+ return true;
159
175
  })];
160
176
  });
161
177
  });
162
178
  };
179
+ //#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
+ };
163
242
  /**
164
243
  * @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
165
244
  * the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
166
245
  * remaining amount with another payment method.
167
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
246
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
168
247
  */
169
248
  Booking.prototype.useWallet = function () {
249
+ var _a;
170
250
  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");
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
+ })];
180
300
  }
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
301
  });
186
302
  });
187
303
  };
@@ -190,24 +306,61 @@ var Booking = /** @class */ (function () {
190
306
  * If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
191
307
  * Otherwise, the user will be asked to pay the remaining amount with another payment method.
192
308
  * @param {string} voucherCode The code of the voucher to use
193
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
309
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
194
310
  */
195
311
  Booking.prototype.useVoucher = function (voucherCode) {
312
+ var _a;
196
313
  return __awaiter(this, void 0, void 0, function () {
197
- var discountsStep, url;
198
- return __generator(this, function (_a) {
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");
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
+ })];
202
363
  }
203
- discountsStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
204
- if (!discountsStep || !discountsStep[0]) {
205
- throw Error("The status of the cart does not allow to call this API");
206
- }
207
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/voucher");
208
- return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
209
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
210
- })];
211
364
  });
212
365
  });
213
366
  };
@@ -218,21 +371,52 @@ var Booking = /** @class */ (function () {
218
371
  * @returns An {@link ErrorResponse} object in case of error, a {@link GetSellerGatewaysResponse} object otherwise.
219
372
  */
220
373
  Booking.prototype.getSellerGateways = function () {
374
+ var _a;
221
375
  return __awaiter(this, void 0, void 0, function () {
222
- var issueStep, url;
223
- return __generator(this, function (_a) {
224
- // First check that it is possible to call this API
225
- if (!this.cartId || this.cartId === 0) {
226
- throw Error("Cart is not initialized yet");
227
- }
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");
376
+ var issueStep, _b, _c, _d, _i, step, url;
377
+ return __generator(this, function (_e) {
378
+ switch (_e.label) {
379
+ case 0:
380
+ // First check that it is possible to call this API
381
+ if (!this.cartId || this.cartId === 0) {
382
+ throw Error("Cart is not initialized yet");
383
+ }
384
+ issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
385
+ if (!issueStep)
386
+ throw Error("Booking step not found!");
387
+ if (!!issueStep[0]) return [3 /*break*/, 5];
388
+ _b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
389
+ _c = [];
390
+ for (_d in _b)
391
+ _c.push(_d);
392
+ _i = 0;
393
+ _e.label = 1;
394
+ case 1:
395
+ if (!(_i < _c.length)) return [3 /*break*/, 4];
396
+ _d = _c[_i];
397
+ if (!(_d in _b)) return [3 /*break*/, 3];
398
+ step = _d;
399
+ if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
400
+ return [4 /*yield*/, this.markBookingStepCompleted(step)];
401
+ case 2:
402
+ _e.sent();
403
+ _e.label = 3;
404
+ case 3:
405
+ _i++;
406
+ return [3 /*break*/, 1];
407
+ case 4:
408
+ // Check again if the issue step is accessible
409
+ issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
410
+ if (!issueStep || !issueStep[0]) {
411
+ throw Error("The status of the cart does not allow to call this API");
412
+ }
413
+ _e.label = 5;
414
+ case 5:
415
+ url = "".concat(this.config.API_ENDPOINT, "/sellers/").concat(this.sellerId, "/gateways");
416
+ return [2 /*return*/, this.callGetApi(url).then(function (response) {
417
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
418
+ })];
231
419
  }
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
420
  });
237
421
  });
238
422
  };
@@ -265,28 +449,76 @@ var Booking = /** @class */ (function () {
265
449
  };
266
450
  /**
267
451
  * @description This method shall be used to issue the tickets. It must be called after the payment was successful.
452
+ * @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
453
+ * first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
268
454
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
269
455
  */
270
456
  Booking.prototype.issueTickets = function (paymentMethod) {
457
+ var _a;
271
458
  return __awaiter(this, void 0, void 0, function () {
272
- var issueStep, url, body;
273
- return __generator(this, function (_a) {
274
- // First check that it is possible to call this API
275
- if (!this.cartId || this.cartId === 0) {
276
- throw Error("Cart is not initialized yet");
459
+ var paymentMethodToSet, issueStep, _b, _c, _d, _i, step, url, body;
460
+ return __generator(this, function (_e) {
461
+ switch (_e.label) {
462
+ case 0:
463
+ // First check that it is possible to call this API
464
+ if (!this.cartId || this.cartId === 0) {
465
+ throw Error("Cart is not initialized yet");
466
+ }
467
+ paymentMethodToSet = paymentMethod;
468
+ if (!(paymentMethod === Payment_1.PaymentMethods.ZERO_COST)) return [3 /*break*/, 2];
469
+ return [4 /*yield*/, this.addReduction({ tripId: 0, reduction: 1, isPercentage: true }).then(function (response) {
470
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
471
+ return response;
472
+ }
473
+ else {
474
+ // Request was successful. Set payment method to CASH
475
+ paymentMethodToSet = Payment_1.PaymentMethods.CASH;
476
+ }
477
+ })];
478
+ case 1:
479
+ _e.sent();
480
+ _e.label = 2;
481
+ case 2:
482
+ issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
483
+ if (!issueStep)
484
+ throw Error("Booking step not found!");
485
+ if (!!issueStep[0]) return [3 /*break*/, 7];
486
+ _b = [Booking.BookingSteps.SEATS_SELECTION, Booking.BookingSteps.EXTRAS, Booking.BookingSteps.DISCOUNTS];
487
+ _c = [];
488
+ for (_d in _b)
489
+ _c.push(_d);
490
+ _i = 0;
491
+ _e.label = 3;
492
+ case 3:
493
+ if (!(_i < _c.length)) return [3 /*break*/, 6];
494
+ _d = _c[_i];
495
+ if (!(_d in _b)) return [3 /*break*/, 5];
496
+ step = _d;
497
+ if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 5];
498
+ return [4 /*yield*/, this.markBookingStepCompleted(step)];
499
+ case 4:
500
+ _e.sent();
501
+ _e.label = 5;
502
+ case 5:
503
+ _i++;
504
+ return [3 /*break*/, 3];
505
+ case 6:
506
+ // Check again if the issue step is accessible
507
+ issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.DISCOUNTS);
508
+ if (!issueStep || !issueStep[0]) {
509
+ throw Error("The status of the cart does not allow to call this API");
510
+ }
511
+ _e.label = 7;
512
+ case 7:
513
+ url = "".concat(this.config.API_ENDPOINT, "/issueTickets");
514
+ body = {
515
+ cartId: this.cartId,
516
+ paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
517
+ };
518
+ return [2 /*return*/, this.callPostApi(url, body).then(function (response) {
519
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : true;
520
+ })];
277
521
  }
278
- issueStep = this.bookingStepsToStatus.get(Booking.BookingSteps.ISSUE);
279
- if (!issueStep || !issueStep[0]) {
280
- throw Error("The status of the cart does not allow to call this API");
281
- }
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
522
  });
291
523
  });
292
524
  };
@@ -4,6 +4,7 @@ import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person
4
4
  import { BusMatrix } from "../types/journeys/BusMatrix";
5
5
  import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
6
6
  import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
7
+ import { ReductionTrip } from "../types/journeys/Trip";
7
8
  import { Booking } from "./booking";
8
9
  export declare class JourneyBooking extends Booking {
9
10
  private cart?;
@@ -68,9 +69,9 @@ export declare class JourneyBooking extends Booking {
68
69
  /**
69
70
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
70
71
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
71
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
72
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
72
73
  */
73
- updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | any>;
74
+ updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | boolean>;
74
75
  /**
75
76
  * @description This method shall be used when the user wants to retrieve the bus matrix for a trip. The bus matrix shows
76
77
  * the seats that are available and the ones that are already taken, as well as how the bus is made.
@@ -90,9 +91,16 @@ export declare class JourneyBooking extends Booking {
90
91
  * @description This method shall be called when the user wants to change the assigned seats of a trip.
91
92
  * @param {number} tripId The id of the trip for which the seats should be changed
92
93
  * @param {number[]} newSeatsIds The ids of the new seats, as found the {@link BusMatrix}
93
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
94
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
94
95
  */
95
- changeSeatsOfTrip(tripId: number, newSeatsIds: number[]): Promise<ErrorResponse | any>;
96
+ changeSeatsOfTrip(tripId: number, newSeatsIds: number[]): Promise<ErrorResponse | boolean>;
97
+ /**
98
+ * @description This method shall be called when the user wants to retrieve the trips in the cart, for adding a available reduction
99
+ * to a specific trip (rather than to the whole cart).
100
+ * @see {@link Booking.addReduction} for detailed info on how to add a reduction.
101
+ * @returns An {@link ErrorResponse} object in case of error, a list of {@link ReductionTrip} otherwise, representing the trips in the cart.
102
+ */
103
+ getCartTrips(): Promise<ErrorResponse | ReductionTrip[]>;
96
104
  }
97
105
  export declare namespace JourneyBooking {
98
106
  const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
@@ -64,6 +64,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
64
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
65
  exports.JourneyBooking = void 0;
66
66
  var ErrorResponse_1 = require("../types/ErrorResponse");
67
+ var processBookingSteps_1 = require("../utils/processBookingSteps");
67
68
  var booking_1 = require("./booking");
68
69
  var JourneyBooking = /** @class */ (function (_super) {
69
70
  __extends(JourneyBooking, _super);
@@ -106,13 +107,7 @@ var JourneyBooking = /** @class */ (function (_super) {
106
107
  _this.cartId = cart.id;
107
108
  _this.bookingDueDate = cartDate; // See Booking class
108
109
  // Fill the booking process status
109
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
110
- var bookingStep = _a[0], values = _a[1];
111
- return [
112
- bookingStep,
113
- values
114
- ];
115
- }));
110
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
116
111
  _this.createCartTimer(cartDate);
117
112
  }
118
113
  })];
@@ -260,13 +255,7 @@ var JourneyBooking = /** @class */ (function (_super) {
260
255
  // Save the cartId in the localStorage
261
256
  localStorage.setItem("cartId", response.cart.id.toString());
262
257
  // Fill the booking process status
263
- _this.bookingStepsToStatus = new Map(Object.entries(response.cart.stepsToStatus).map(function (_a) {
264
- var bookingStep = _a[0], values = _a[1];
265
- return [
266
- bookingStep,
267
- values
268
- ];
269
- }));
258
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
270
259
  _this.bookingDueDate = new Date(response.cart.bookingDueDate);
271
260
  _this.createCartTimer(new Date(response.cart.bookingDueDate));
272
261
  return response.cart;
@@ -367,11 +356,12 @@ var JourneyBooking = /** @class */ (function (_super) {
367
356
  /**
368
357
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
369
358
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
370
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
359
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
371
360
  */
372
361
  JourneyBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
373
362
  return __awaiter(this, void 0, void 0, function () {
374
363
  var buyerPassengersDetails, request, url;
364
+ var _this = this;
375
365
  return __generator(this, function (_a) {
376
366
  // First check that it is possible to call this API
377
367
  if (!this.cart) {
@@ -391,7 +381,12 @@ var JourneyBooking = /** @class */ (function (_super) {
391
381
  });
392
382
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
393
383
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
394
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
384
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
385
+ return response;
386
+ }
387
+ // Update the booking process status
388
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
389
+ return true;
395
390
  })];
396
391
  });
397
392
  });
@@ -456,11 +451,12 @@ var JourneyBooking = /** @class */ (function (_super) {
456
451
  * @description This method shall be called when the user wants to change the assigned seats of a trip.
457
452
  * @param {number} tripId The id of the trip for which the seats should be changed
458
453
  * @param {number[]} newSeatsIds The ids of the new seats, as found the {@link BusMatrix}
459
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
454
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
460
455
  */
461
456
  JourneyBooking.prototype.changeSeatsOfTrip = function (tripId, newSeatsIds) {
462
457
  return __awaiter(this, void 0, void 0, function () {
463
458
  var seatSelectionStatus, url;
459
+ var _this = this;
464
460
  return __generator(this, function (_a) {
465
461
  // First check that it is possible to call this API
466
462
  if (!this.cart) {
@@ -472,7 +468,33 @@ var JourneyBooking = /** @class */ (function (_super) {
472
468
  }
473
469
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/seats");
474
470
  return [2 /*return*/, this.callPostApi(url, { tripId: tripId, seatsIds: newSeatsIds }).then(function (response) {
475
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
471
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
472
+ return response;
473
+ }
474
+ // Update the booking process status
475
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
476
+ return true;
477
+ })];
478
+ });
479
+ });
480
+ };
481
+ /**
482
+ * @description This method shall be called when the user wants to retrieve the trips in the cart, for adding a available reduction
483
+ * to a specific trip (rather than to the whole cart).
484
+ * @see {@link Booking.addReduction} for detailed info on how to add a reduction.
485
+ * @returns An {@link ErrorResponse} object in case of error, a list of {@link ReductionTrip} otherwise, representing the trips in the cart.
486
+ */
487
+ JourneyBooking.prototype.getCartTrips = function () {
488
+ return __awaiter(this, void 0, void 0, function () {
489
+ var url;
490
+ return __generator(this, function (_a) {
491
+ // First check that it is possible to call this API
492
+ if (!this.cart) {
493
+ throw Error("Cart is not initialized yet");
494
+ }
495
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/payment/reduction/trips");
496
+ return [2 /*return*/, this.callGetApi(url).then(function (response) {
497
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
476
498
  })];
477
499
  });
478
500
  });
@@ -71,9 +71,9 @@ export declare class ServiceBooking extends Booking {
71
71
  /**
72
72
  * @description This method shall be called when the user wants to update the buyer information.
73
73
  * @param {Person} buyerDetails The object containing the buyer information.
74
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
74
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
75
75
  */
76
- updateBuyerPassengersDetails(buyerDetails: Person): Promise<ErrorResponse | any>;
76
+ updateBuyerPassengersDetails(buyerDetails: Person): Promise<ErrorResponse | boolean>;
77
77
  }
78
78
  export declare namespace ServiceBooking {
79
79
  const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
@@ -64,6 +64,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
64
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
65
  exports.ServiceBooking = void 0;
66
66
  var ErrorResponse_1 = require("../types/ErrorResponse");
67
+ var processBookingSteps_1 = require("../utils/processBookingSteps");
67
68
  var booking_1 = require("./booking");
68
69
  var ServiceBooking = /** @class */ (function (_super) {
69
70
  __extends(ServiceBooking, _super);
@@ -106,13 +107,7 @@ var ServiceBooking = /** @class */ (function (_super) {
106
107
  _this.cartId = cart.id;
107
108
  _this.bookingDueDate = cartDate; // See Booking class
108
109
  // Fill the booking process status
109
- _this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
110
- var bookingStep = _a[0], values = _a[1];
111
- return [
112
- bookingStep,
113
- values
114
- ];
115
- }));
110
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(cart.stepsToStatus);
116
111
  _this.createCartTimer(cartDate);
117
112
  }
118
113
  })];
@@ -253,13 +248,7 @@ var ServiceBooking = /** @class */ (function (_super) {
253
248
  // Save the cartId in the localStorage
254
249
  localStorage.setItem("cartId", response.cart.id.toString());
255
250
  // Fill the booking process status
256
- _this.bookingStepsToStatus = new Map(Object.entries(response.cart.stepsToStatus).map(function (_a) {
257
- var bookingStep = _a[0], values = _a[1];
258
- return [
259
- bookingStep,
260
- values
261
- ];
262
- }));
251
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
263
252
  _this.bookingDueDate = new Date(response.cart.bookingDueDate);
264
253
  _this.createCartTimer(new Date(response.cart.bookingDueDate));
265
254
  return response.cart;
@@ -341,11 +330,12 @@ var ServiceBooking = /** @class */ (function (_super) {
341
330
  /**
342
331
  * @description This method shall be called when the user wants to update the buyer information.
343
332
  * @param {Person} buyerDetails The object containing the buyer information.
344
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
333
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
345
334
  */
346
335
  ServiceBooking.prototype.updateBuyerPassengersDetails = function (buyerDetails) {
347
336
  return __awaiter(this, void 0, void 0, function () {
348
337
  var buyerPassengersDetails, request, url;
338
+ var _this = this;
349
339
  return __generator(this, function (_a) {
350
340
  // First check that it is possible to call this API
351
341
  if (!this.cart) {
@@ -361,7 +351,12 @@ var ServiceBooking = /** @class */ (function (_super) {
361
351
  };
362
352
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
363
353
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
364
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
354
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
355
+ return response;
356
+ }
357
+ // Update the booking process status
358
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
359
+ return true;
365
360
  })];
366
361
  });
367
362
  });
@@ -1,6 +1,5 @@
1
1
  import { MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
- import { Cart } from "../types/common/Cart";
4
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
5
4
  import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
6
5
  import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
@@ -21,10 +20,10 @@ export declare class SubscriptionBooking extends Booking {
21
20
  * @param {number} [resellerId=undefined] The id of the reseller.
22
21
  */
23
22
  constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
24
- getCart(): Cart | undefined;
23
+ getCart(): SubscriptionCart | undefined;
25
24
  fetchAndSetCart(cartId: number): Promise<void>;
26
25
  private createCartTimer;
27
- fetchCart(cartId: number): Promise<Cart>;
26
+ fetchCart(cartId: number): Promise<SubscriptionCart>;
28
27
  /**
29
28
  * This method allows to delete a cart, thus allowing the user to exit from the booking process.
30
29
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
@@ -91,9 +90,9 @@ export declare class SubscriptionBooking extends Booking {
91
90
  /**
92
91
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
93
92
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
94
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
93
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
95
94
  */
96
- updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | any>;
95
+ updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | boolean>;
97
96
  }
98
97
  export declare namespace SubscriptionBooking {
99
98
  const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
@@ -64,6 +64,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
64
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
65
  exports.SubscriptionBooking = void 0;
66
66
  var ErrorResponse_1 = require("../types/ErrorResponse");
67
+ var processBookingSteps_1 = require("../utils/processBookingSteps");
67
68
  var booking_1 = require("./booking");
68
69
  var SubscriptionBooking = /** @class */ (function (_super) {
69
70
  __extends(SubscriptionBooking, _super);
@@ -309,13 +310,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
309
310
  // Save the cartId in the localStorage
310
311
  localStorage.setItem("cartId", response.cart.id.toString());
311
312
  // Fill the booking process status
312
- _this.bookingStepsToStatus = new Map(Object.entries(response.cart.stepsToStatus).map(function (_a) {
313
- var bookingStep = _a[0], values = _a[1];
314
- return [
315
- bookingStep,
316
- values
317
- ];
318
- }));
313
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
319
314
  _this.bookingDueDate = new Date(response.cart.bookingDueDate);
320
315
  _this.createCartTimer(new Date(response.cart.bookingDueDate));
321
316
  return response.cart;
@@ -416,11 +411,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
416
411
  /**
417
412
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
418
413
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
419
- * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
414
+ * @returns An {@link ErrorResponse} object in case of error, true otherwise.
420
415
  */
421
416
  SubscriptionBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
422
417
  return __awaiter(this, void 0, void 0, function () {
423
418
  var buyerPassengersDetails, request, url;
419
+ var _this = this;
424
420
  return __generator(this, function (_a) {
425
421
  // First check that it is possible to call this API
426
422
  if (!this.cart) {
@@ -440,7 +436,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
440
436
  });
441
437
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
442
438
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
443
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
439
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
440
+ return response;
441
+ }
442
+ // Update the booking process status
443
+ _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
444
+ return true;
444
445
  })];
445
446
  });
446
447
  });
package/lib/index.d.ts CHANGED
@@ -21,4 +21,4 @@ export { ServiceCart, ServiceBookingType, CreateServiceCartRequest } from "./typ
21
21
  export { ServiceInfo } from "./types/services/ServiceInfo";
22
22
  export { Subscription } from "./types/subscriptions/Subscriptions";
23
23
  export { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse, SubscriptionCalendarDayPeriodInfo } from "./types/subscriptions/SubscriptionAvailabilities";
24
- export { CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
24
+ export { SubscriptionCart, SubscriptionBookingType, CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
@@ -51,7 +51,14 @@ export declare enum GatewayTypes {
51
51
  PAYPAL = "PAYPAL"
52
52
  }
53
53
  /**
54
- * @description This enum contains the possible values for the `paymentMethod` parameter of the {@link Booking.issueTickets} function.
54
+ * @enum {string} This enum contains the possible values for the `paymentMethod` parameter of the {@link Booking.issueTickets} function.
55
+ *
56
+ * @property {string} ZERO_COST: Only for Sellers: 100% discount
57
+ * @property {string} PAY_LATER: Only for Sellers: Ticket will be paid at the counter/bus
58
+ * @property {string} WALLET: Only for Resellers: the ticket will be paid with the wallet balance
59
+ * @property {string} CARD: Pay with card at the Seller/Reseller counter
60
+ * @property {string} CASH: Pay with cash at the Seller/Reseller counter
61
+ * @property {string} ONLINE: Pay online using payment gateways
55
62
  */
56
63
  export declare enum PaymentMethods {
57
64
  CARD = "CARD",
@@ -59,5 +66,6 @@ export declare enum PaymentMethods {
59
66
  CREDIT_FROM_CHANGE = "CREDIT_FROM_CHANGE",
60
67
  PAY_LATER = "PAY_LATER",
61
68
  ONLINE_CARD = "ONLINE CARD",
62
- WALLET = "WALLET"
69
+ WALLET = "WALLET",
70
+ ZERO_COST = "ZERO_COST"
63
71
  }
@@ -11,7 +11,14 @@ var GatewayTypes;
11
11
  GatewayTypes["PAYPAL"] = "PAYPAL";
12
12
  })(GatewayTypes || (exports.GatewayTypes = GatewayTypes = {}));
13
13
  /**
14
- * @description This enum contains the possible values for the `paymentMethod` parameter of the {@link Booking.issueTickets} function.
14
+ * @enum {string} This enum contains the possible values for the `paymentMethod` parameter of the {@link Booking.issueTickets} function.
15
+ *
16
+ * @property {string} ZERO_COST: Only for Sellers: 100% discount
17
+ * @property {string} PAY_LATER: Only for Sellers: Ticket will be paid at the counter/bus
18
+ * @property {string} WALLET: Only for Resellers: the ticket will be paid with the wallet balance
19
+ * @property {string} CARD: Pay with card at the Seller/Reseller counter
20
+ * @property {string} CASH: Pay with cash at the Seller/Reseller counter
21
+ * @property {string} ONLINE: Pay online using payment gateways
15
22
  */
16
23
  var PaymentMethods;
17
24
  (function (PaymentMethods) {
@@ -21,4 +28,5 @@ var PaymentMethods;
21
28
  PaymentMethods["PAY_LATER"] = "PAY_LATER";
22
29
  PaymentMethods["ONLINE_CARD"] = "ONLINE CARD";
23
30
  PaymentMethods["WALLET"] = "WALLET";
31
+ PaymentMethods["ZERO_COST"] = "ZERO_COST";
24
32
  })(PaymentMethods || (exports.PaymentMethods = PaymentMethods = {}));
@@ -8,3 +8,13 @@ export type Trip = {
8
8
  tariffTypes: TariffType[];
9
9
  termsTypes: TermsType[];
10
10
  };
11
+ /**
12
+ * This type is used to represent a trip for the reduction page. This only makes sense for a JourneyBooking,
13
+ * and it allows to add a reduction to a specific trip (rather than to the whole cart).
14
+ * @property { number } id - The id of the trip
15
+ * @property { string } name - The name of the trip
16
+ */
17
+ export type ReductionTrip = {
18
+ id: number;
19
+ name: string;
20
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This function process the stepsToStatus object returned by the BE in several APIs and returns the processed Map.
3
+ * This is necessary because Typescript does not treat the jsonized map as an actual Map making it impossible to use.
4
+ * @param stepsToStatus the stepsToStatus object returned by the BE
5
+ * @returns The processed Map
6
+ */
7
+ export declare const processBookingSteps: (stepsToStatus: any) => Map<string, boolean[]>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processBookingSteps = void 0;
4
+ /**
5
+ * This function process the stepsToStatus object returned by the BE in several APIs and returns the processed Map.
6
+ * This is necessary because Typescript does not treat the jsonized map as an actual Map making it impossible to use.
7
+ * @param stepsToStatus the stepsToStatus object returned by the BE
8
+ * @returns The processed Map
9
+ */
10
+ var processBookingSteps = function (stepsToStatus) {
11
+ try {
12
+ return new Map(Object.entries(stepsToStatus).map(function (_a) {
13
+ var bookingStep = _a[0], values = _a[1];
14
+ return [
15
+ bookingStep,
16
+ values
17
+ ];
18
+ }));
19
+ }
20
+ catch (error) {
21
+ throw new Error("Error while processing booking steps");
22
+ }
23
+ };
24
+ exports.processBookingSteps = processBookingSteps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",