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
@@ -61,9 +61,20 @@ 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.SubscriptionBooking = void 0;
|
66
75
|
var ErrorResponse_1 = require("../types/ErrorResponse");
|
76
|
+
var Reduction_1 = require("../types/common/Reduction");
|
77
|
+
var processBookingSteps_1 = require("../utils/processBookingSteps");
|
67
78
|
var booking_1 = require("./booking");
|
68
79
|
var SubscriptionBooking = /** @class */ (function (_super) {
|
69
80
|
__extends(SubscriptionBooking, _super);
|
@@ -309,13 +320,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
309
320
|
// Save the cartId in the localStorage
|
310
321
|
localStorage.setItem("cartId", response.cart.id.toString());
|
311
322
|
// Fill the booking process status
|
312
|
-
_this.bookingStepsToStatus =
|
313
|
-
var bookingStep = _a[0], values = _a[1];
|
314
|
-
return [
|
315
|
-
bookingStep,
|
316
|
-
values
|
317
|
-
];
|
318
|
-
}));
|
323
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
|
319
324
|
_this.bookingDueDate = new Date(response.cart.bookingDueDate);
|
320
325
|
_this.createCartTimer(new Date(response.cart.bookingDueDate));
|
321
326
|
return response.cart;
|
@@ -416,11 +421,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
416
421
|
/**
|
417
422
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
418
423
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
419
|
-
* @returns An {@link ErrorResponse} object in case of error,
|
424
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
420
425
|
*/
|
421
426
|
SubscriptionBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
|
422
427
|
return __awaiter(this, void 0, void 0, function () {
|
423
428
|
var buyerPassengersDetails, request, url;
|
429
|
+
var _this = this;
|
424
430
|
return __generator(this, function (_a) {
|
425
431
|
// First check that it is possible to call this API
|
426
432
|
if (!this.cart) {
|
@@ -440,11 +446,283 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
440
446
|
});
|
441
447
|
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
|
442
448
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
443
|
-
|
449
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
450
|
+
return response;
|
451
|
+
}
|
452
|
+
// Update the booking process status
|
453
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.stepsToStatus);
|
454
|
+
return true;
|
455
|
+
})];
|
456
|
+
});
|
457
|
+
});
|
458
|
+
};
|
459
|
+
//#region Reductions APIs
|
460
|
+
/**
|
461
|
+
* @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
|
462
|
+
* @param {AddReductionRequest} request The information about the reduction to add
|
463
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
464
|
+
*/
|
465
|
+
SubscriptionBooking.prototype.addReduction = function (request) {
|
466
|
+
var _a;
|
467
|
+
return __awaiter(this, void 0, void 0, function () {
|
468
|
+
var discountsStep, _b, _c, _d, _i, step, url;
|
469
|
+
var _this = this;
|
470
|
+
return __generator(this, function (_e) {
|
471
|
+
switch (_e.label) {
|
472
|
+
case 0:
|
473
|
+
// First check that it is possible to call this API
|
474
|
+
if (!this.cartId || this.cartId === 0) {
|
475
|
+
throw Error("Cart is not initialized yet");
|
476
|
+
}
|
477
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
478
|
+
if (!discountsStep)
|
479
|
+
throw Error("Booking step not found!");
|
480
|
+
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
481
|
+
_b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
482
|
+
_c = [];
|
483
|
+
for (_d in _b)
|
484
|
+
_c.push(_d);
|
485
|
+
_i = 0;
|
486
|
+
_e.label = 1;
|
487
|
+
case 1:
|
488
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
489
|
+
_d = _c[_i];
|
490
|
+
if (!(_d in _b)) return [3 /*break*/, 3];
|
491
|
+
step = _d;
|
492
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
493
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
494
|
+
case 2:
|
495
|
+
_e.sent();
|
496
|
+
_e.label = 3;
|
497
|
+
case 3:
|
498
|
+
_i++;
|
499
|
+
return [3 /*break*/, 1];
|
500
|
+
case 4:
|
501
|
+
// Check again if the discounts step is accessible
|
502
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
503
|
+
if (!discountsStep || !discountsStep[0]) {
|
504
|
+
throw Error("The status of the cart does not allow to call this API");
|
505
|
+
}
|
506
|
+
_e.label = 5;
|
507
|
+
case 5:
|
508
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction");
|
509
|
+
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
510
|
+
var _a, _b;
|
511
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
512
|
+
return response;
|
513
|
+
}
|
514
|
+
var reductionResponse = response;
|
515
|
+
// Update the booking process status
|
516
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
517
|
+
// Update the cart
|
518
|
+
_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) });
|
519
|
+
return true;
|
520
|
+
})];
|
521
|
+
}
|
522
|
+
});
|
523
|
+
});
|
524
|
+
};
|
525
|
+
/**
|
526
|
+
* @description This method allows to remove a reduction from the whole cart or from a single trip in the cart.
|
527
|
+
* @param tripId The id of the trip from which the reduction should be removed. If the tripId is 0, then the reduction
|
528
|
+
* will be removed from the whole cart.
|
529
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
530
|
+
*/
|
531
|
+
SubscriptionBooking.prototype.removeReduction = function (tripId) {
|
532
|
+
return __awaiter(this, void 0, void 0, function () {
|
533
|
+
var discountsStep, queryParams, url;
|
534
|
+
var _this = this;
|
535
|
+
return __generator(this, function (_a) {
|
536
|
+
// First check that it is possible to call this API
|
537
|
+
if (!this.cartId || this.cartId === 0) {
|
538
|
+
throw Error("Cart is not initialized yet");
|
539
|
+
}
|
540
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
541
|
+
if (!discountsStep || !discountsStep[0]) {
|
542
|
+
throw Error("The status of the cart does not allow to call this API");
|
543
|
+
}
|
544
|
+
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
545
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
546
|
+
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
547
|
+
var _a, _b, _c;
|
548
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
549
|
+
return response;
|
550
|
+
}
|
551
|
+
var reductionResponse = response;
|
552
|
+
// Update the booking process status
|
553
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
554
|
+
// Update the cart
|
555
|
+
_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 ||
|
556
|
+
reduction.type === Reduction_1.ReductionType.VOUCHER ||
|
557
|
+
(reduction.type === Reduction_1.ReductionType.CASH && reduction.tripId !== tripId); })) !== null && _c !== void 0 ? _c : [] });
|
558
|
+
return true;
|
559
|
+
})];
|
560
|
+
});
|
561
|
+
});
|
562
|
+
};
|
563
|
+
/**
|
564
|
+
* @description This method allows the user to use the balance in his wallet to pay the cart. If the balance of
|
565
|
+
* the wallet is enough to pay the cart, the cart will be paid fully. Otherwise, the user will be asked to pay the
|
566
|
+
* remaining amount with another payment method.
|
567
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
568
|
+
*/
|
569
|
+
SubscriptionBooking.prototype.useWallet = function () {
|
570
|
+
var _a;
|
571
|
+
return __awaiter(this, void 0, void 0, function () {
|
572
|
+
var discountsStep, _b, _c, _d, _i, step, url;
|
573
|
+
var _this = this;
|
574
|
+
return __generator(this, function (_e) {
|
575
|
+
switch (_e.label) {
|
576
|
+
case 0:
|
577
|
+
// First check that it is possible to call this API
|
578
|
+
if (!this.cartId || this.cartId === 0) {
|
579
|
+
throw Error("Cart is not initialized yet");
|
580
|
+
}
|
581
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
582
|
+
if (!discountsStep)
|
583
|
+
throw Error("Booking step not found!");
|
584
|
+
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
585
|
+
_b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
586
|
+
_c = [];
|
587
|
+
for (_d in _b)
|
588
|
+
_c.push(_d);
|
589
|
+
_i = 0;
|
590
|
+
_e.label = 1;
|
591
|
+
case 1:
|
592
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
593
|
+
_d = _c[_i];
|
594
|
+
if (!(_d in _b)) return [3 /*break*/, 3];
|
595
|
+
step = _d;
|
596
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
597
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
598
|
+
case 2:
|
599
|
+
_e.sent();
|
600
|
+
_e.label = 3;
|
601
|
+
case 3:
|
602
|
+
_i++;
|
603
|
+
return [3 /*break*/, 1];
|
604
|
+
case 4:
|
605
|
+
// Check again if the discounts step is accessible
|
606
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
607
|
+
if (!discountsStep || !discountsStep[0]) {
|
608
|
+
throw Error("The status of the cart does not allow to call this API");
|
609
|
+
}
|
610
|
+
_e.label = 5;
|
611
|
+
case 5:
|
612
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
|
613
|
+
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
614
|
+
var _a, _b;
|
615
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
616
|
+
return response;
|
617
|
+
}
|
618
|
+
var reductionResponse = response;
|
619
|
+
// Update the booking process status
|
620
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
621
|
+
// Update the cart
|
622
|
+
_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) });
|
623
|
+
return true;
|
624
|
+
})];
|
625
|
+
}
|
626
|
+
});
|
627
|
+
});
|
628
|
+
};
|
629
|
+
/**
|
630
|
+
* @description This method allows to remove a waller reduction from the cart.
|
631
|
+
*
|
632
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise. Also, the cart is updated.
|
633
|
+
*/
|
634
|
+
SubscriptionBooking.prototype.removeWalletReduction = function () {
|
635
|
+
return __awaiter(this, void 0, void 0, function () {
|
636
|
+
var url;
|
637
|
+
var _this = this;
|
638
|
+
return __generator(this, function (_a) {
|
639
|
+
// First check that it is possible to call this API
|
640
|
+
if (!this.cartId || this.cartId === 0) {
|
641
|
+
throw Error("Cart is not initialized yet");
|
642
|
+
}
|
643
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/wallet");
|
644
|
+
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
645
|
+
var _a, _b, _c;
|
646
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
647
|
+
return response;
|
648
|
+
}
|
649
|
+
var reductionResponse = response;
|
650
|
+
// Update the booking process status
|
651
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
652
|
+
// Update the cart
|
653
|
+
_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 : [] });
|
654
|
+
return true;
|
444
655
|
})];
|
445
656
|
});
|
446
657
|
});
|
447
658
|
};
|
659
|
+
/**
|
660
|
+
* @description This method allows the user to use a voucher to pay the cart.
|
661
|
+
* If the balance of the value of the voucher is enough to pay the cart, the cart will be paid fully.
|
662
|
+
* Otherwise, the user will be asked to pay the remaining amount with another payment method.
|
663
|
+
* @param {string} voucherCode The code of the voucher to use
|
664
|
+
* @returns An {@link ErrorResponse} object in case of error, true otherwise.
|
665
|
+
*/
|
666
|
+
SubscriptionBooking.prototype.useVoucher = function (voucherCode) {
|
667
|
+
var _a;
|
668
|
+
return __awaiter(this, void 0, void 0, function () {
|
669
|
+
var discountsStep, _b, _c, _d, _i, step, url;
|
670
|
+
var _this = this;
|
671
|
+
return __generator(this, function (_e) {
|
672
|
+
switch (_e.label) {
|
673
|
+
case 0:
|
674
|
+
// First check that it is possible to call this API
|
675
|
+
if (!this.cartId || this.cartId === 0) {
|
676
|
+
throw Error("Cart is not initialized yet");
|
677
|
+
}
|
678
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
679
|
+
if (!discountsStep)
|
680
|
+
throw Error("Booking step not found!");
|
681
|
+
if (!!discountsStep[0]) return [3 /*break*/, 5];
|
682
|
+
_b = [booking_1.Booking.BookingSteps.SEATS_SELECTION, booking_1.Booking.BookingSteps.EXTRAS];
|
683
|
+
_c = [];
|
684
|
+
for (_d in _b)
|
685
|
+
_c.push(_d);
|
686
|
+
_i = 0;
|
687
|
+
_e.label = 1;
|
688
|
+
case 1:
|
689
|
+
if (!(_i < _c.length)) return [3 /*break*/, 4];
|
690
|
+
_d = _c[_i];
|
691
|
+
if (!(_d in _b)) return [3 /*break*/, 3];
|
692
|
+
step = _d;
|
693
|
+
if (!!((_a = this.bookingStepsToStatus.get(step)) !== null && _a !== void 0 ? _a : [false])[0]) return [3 /*break*/, 3];
|
694
|
+
return [4 /*yield*/, this.markBookingStepCompleted(step)];
|
695
|
+
case 2:
|
696
|
+
_e.sent();
|
697
|
+
_e.label = 3;
|
698
|
+
case 3:
|
699
|
+
_i++;
|
700
|
+
return [3 /*break*/, 1];
|
701
|
+
case 4:
|
702
|
+
// Check again if the discounts step is accessible
|
703
|
+
discountsStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.DISCOUNTS);
|
704
|
+
if (!discountsStep || !discountsStep[0]) {
|
705
|
+
throw Error("The status of the cart does not allow to call this API");
|
706
|
+
}
|
707
|
+
_e.label = 5;
|
708
|
+
case 5:
|
709
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cartId, "/payment/voucher");
|
710
|
+
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
711
|
+
var _a, _b;
|
712
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
713
|
+
return response;
|
714
|
+
}
|
715
|
+
var reductionResponse = response;
|
716
|
+
// Update the booking process status
|
717
|
+
_this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(reductionResponse.stepsToStatus);
|
718
|
+
// Update the cart
|
719
|
+
_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) });
|
720
|
+
return true;
|
721
|
+
})];
|
722
|
+
}
|
723
|
+
});
|
724
|
+
});
|
725
|
+
};
|
448
726
|
return SubscriptionBooking;
|
449
727
|
}(booking_1.Booking));
|
450
728
|
exports.SubscriptionBooking = SubscriptionBooking;
|
@@ -34,3 +34,16 @@ export type Cart = {
|
|
34
34
|
totalAmountToPay: number;
|
35
35
|
extras: Extra[];
|
36
36
|
};
|
37
|
+
/**
|
38
|
+
* Base response type for the booking process. All APIs that update the cart, share this.
|
39
|
+
*
|
40
|
+
* @property {Map<string, boolean[]>} stepsToStatus This data structure describes the steps of the booking process.
|
41
|
+
* The keys of this dictionary represent the booking steps. See ... for the list of possible steps. If the
|
42
|
+
* key is present, then the booking step shall be displayed. The value is a list of 3 booleans:
|
43
|
+
* - The first tells whether it is possible to go to that section. If not, other sections must be completed first.
|
44
|
+
* - The second tells whether the section is completed.
|
45
|
+
* - The third tells whether the section is required.
|
46
|
+
*/
|
47
|
+
export type BaseBookingProcessResponse = {
|
48
|
+
stepsToStatus: Map<string, boolean[]>;
|
49
|
+
};
|
@@ -51,7 +51,14 @@ export declare enum GatewayTypes {
|
|
51
51
|
PAYPAL = "PAYPAL"
|
52
52
|
}
|
53
53
|
/**
|
54
|
-
* @
|
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
|
-
* @
|
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 = {}));
|
@@ -1,6 +1,13 @@
|
|
1
|
+
import { BaseBookingProcessResponse } from "./Cart";
|
2
|
+
export declare enum ReductionType {
|
3
|
+
VOUCHER = "VOUCHER",
|
4
|
+
WALLET = "WALLET",
|
5
|
+
CASH = "CASH"
|
6
|
+
}
|
1
7
|
/**
|
2
8
|
* @description This type represents a reduction applied to the cart. Reductions are applied in the booking step `DISCOUNTS`.
|
3
9
|
*
|
10
|
+
* @property {ReductionType} type The type of the reduction
|
4
11
|
* @property {number} tripId The id of the trip to which the reduction is applied
|
5
12
|
* @property {string} tripName The name of the trip to which the reduction is applied
|
6
13
|
* @property {number} value The value of the reduction
|
@@ -9,6 +16,7 @@
|
|
9
16
|
* @property {string} [voucherCode=undefined] The voucher code used to apply the reduction
|
10
17
|
*/
|
11
18
|
export type Reduction = {
|
19
|
+
type: ReductionType;
|
12
20
|
tripId: number;
|
13
21
|
tripName: string;
|
14
22
|
value: number;
|
@@ -29,3 +37,22 @@ export type AddReductionRequest = {
|
|
29
37
|
reduction: number;
|
30
38
|
isPercentage: boolean;
|
31
39
|
};
|
40
|
+
/**
|
41
|
+
* @description This type represents a response to add a reduction to the cart. It is used in the APIs
|
42
|
+
* {@link Booking.addReduction}, {@link Booking.useVoucher} and {@link Booking.useWallet}
|
43
|
+
*
|
44
|
+
* @property {Reduction} reduction Information about the reduction applied
|
45
|
+
*/
|
46
|
+
export type ReductionResponse = BaseReductionResponse & {
|
47
|
+
reduction: Reduction;
|
48
|
+
};
|
49
|
+
/**
|
50
|
+
* @description This type represents a base response to handle reduction in the cart. It is used in the APIs
|
51
|
+
* {@link Booking.addReduction}, {@link Booking.removeReduction} {@link Booking.useVoucher}, {@link Booking.useWallet}
|
52
|
+
* and {@link Booking.removeWalletReduction}
|
53
|
+
*
|
54
|
+
* @property {number} totalAmountToPay The total amount to pay after the reduction was applied
|
55
|
+
*/
|
56
|
+
export type BaseReductionResponse = BaseBookingProcessResponse & {
|
57
|
+
totalAmountToPay: number;
|
58
|
+
};
|
@@ -1,2 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ReductionType = void 0;
|
4
|
+
var ReductionType;
|
5
|
+
(function (ReductionType) {
|
6
|
+
ReductionType["VOUCHER"] = "VOUCHER";
|
7
|
+
ReductionType["WALLET"] = "WALLET";
|
8
|
+
ReductionType["CASH"] = "CASH";
|
9
|
+
})(ReductionType || (exports.ReductionType = ReductionType = {}));
|
@@ -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
|
+
};
|
package/lib/utils/apiCall.d.ts
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* @module apiCall - This module contains the functions to make the API calls to the MTS API
|
3
|
+
* It contains the following functions:
|
4
|
+
* @method makeGet - Makes a GET request to the MTS API
|
5
|
+
* @method makePost - Makes a POST request to the MTS API
|
6
|
+
* @method makeDelete - Makes a DELETE request to the MTS API
|
7
|
+
*/
|
1
8
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
9
|
export declare const makeGet: (url: string) => Promise<ErrorResponse | any>;
|
3
10
|
export declare const makePost: (url: string, data: any) => Promise<ErrorResponse | any>;
|
11
|
+
export declare const makeDelete: (url: string) => Promise<ErrorResponse | any>;
|
package/lib/utils/apiCall.js
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
"use strict";
|
2
|
+
/**
|
3
|
+
* @module apiCall - This module contains the functions to make the API calls to the MTS API
|
4
|
+
* It contains the following functions:
|
5
|
+
* @method makeGet - Makes a GET request to the MTS API
|
6
|
+
* @method makePost - Makes a POST request to the MTS API
|
7
|
+
* @method makeDelete - Makes a DELETE request to the MTS API
|
8
|
+
*/
|
2
9
|
var __assign = (this && this.__assign) || function () {
|
3
10
|
__assign = Object.assign || function(t) {
|
4
11
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
@@ -47,7 +54,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
47
54
|
}
|
48
55
|
};
|
49
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
50
|
-
exports.makePost = exports.makeGet = void 0;
|
57
|
+
exports.makeDelete = exports.makePost = exports.makeGet = void 0;
|
51
58
|
var axios_1 = require("axios");
|
52
59
|
var config_1 = require("../config");
|
53
60
|
var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
@@ -55,7 +62,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
55
62
|
return __generator(this, function (_a) {
|
56
63
|
debug = (0, config_1.getConfig)().DEBUG;
|
57
64
|
if (debug) {
|
58
|
-
console.log("
|
65
|
+
console.log("GET_RequestData", url);
|
59
66
|
}
|
60
67
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
61
68
|
var response_1, filteredResponse_1, error_1, resError, resError;
|
@@ -76,7 +83,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
76
83
|
return filteredResponse_1 = __assign(__assign({}, filteredResponse_1), (_a = {}, _a[key] = response_1.data[key], _a));
|
77
84
|
});
|
78
85
|
if (debug) {
|
79
|
-
console.log("
|
86
|
+
console.log("GET_ResponseData", url, filteredResponse_1);
|
80
87
|
}
|
81
88
|
resolve(filteredResponse_1);
|
82
89
|
return [3 /*break*/, 3];
|
@@ -89,7 +96,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
89
96
|
message: ((_c = error_1.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
|
90
97
|
};
|
91
98
|
if (debug) {
|
92
|
-
console.log("
|
99
|
+
console.log("GET_ResponseError", url, resError);
|
93
100
|
}
|
94
101
|
reject(resError);
|
95
102
|
}
|
@@ -110,7 +117,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
110
117
|
return __generator(this, function (_a) {
|
111
118
|
debug = (0, config_1.getConfig)().DEBUG;
|
112
119
|
if (debug) {
|
113
|
-
console.log("
|
120
|
+
console.log("POST_RequestData", url, data);
|
114
121
|
}
|
115
122
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
116
123
|
var response, error_2, resError;
|
@@ -125,7 +132,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
125
132
|
case 1:
|
126
133
|
response = _f.sent();
|
127
134
|
if (debug) {
|
128
|
-
console.log("
|
135
|
+
console.log("POST_ResponseData", url, response.data);
|
129
136
|
}
|
130
137
|
resolve(response.data);
|
131
138
|
return [3 /*break*/, 3];
|
@@ -138,7 +145,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
138
145
|
message: ((_e = (_d = error_2.response) === null || _d === void 0 ? void 0 : _d.data.error) === null || _e === void 0 ? void 0 : _e.message) || "Unknown error",
|
139
146
|
};
|
140
147
|
if (debug) {
|
141
|
-
console.log("
|
148
|
+
console.log("POST_ResponseError", url, resError);
|
142
149
|
}
|
143
150
|
reject(resError);
|
144
151
|
}
|
@@ -154,3 +161,52 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
154
161
|
});
|
155
162
|
}); };
|
156
163
|
exports.makePost = makePost;
|
164
|
+
var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
165
|
+
var debug;
|
166
|
+
return __generator(this, function (_a) {
|
167
|
+
debug = (0, config_1.getConfig)().DEBUG;
|
168
|
+
if (debug) {
|
169
|
+
console.log("DELETE_RequestData", url);
|
170
|
+
}
|
171
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
172
|
+
var response, error_3, resError;
|
173
|
+
var _a, _b, _c, _d, _e;
|
174
|
+
return __generator(this, function (_f) {
|
175
|
+
switch (_f.label) {
|
176
|
+
case 0:
|
177
|
+
_f.trys.push([0, 2, , 3]);
|
178
|
+
return [4 /*yield*/, axios_1.default.delete(url, {
|
179
|
+
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
|
180
|
+
})];
|
181
|
+
case 1:
|
182
|
+
response = _f.sent();
|
183
|
+
if (debug) {
|
184
|
+
console.log("DELETE_ResponseData", url, response.data);
|
185
|
+
}
|
186
|
+
resolve(response.data);
|
187
|
+
return [3 /*break*/, 3];
|
188
|
+
case 2:
|
189
|
+
error_3 = _f.sent();
|
190
|
+
if (axios_1.default.isAxiosError(error_3)) {
|
191
|
+
resError = {
|
192
|
+
httpStatus: ((_a = error_3.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
|
193
|
+
mtsCode: ((_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.data.error) === null || _c === void 0 ? void 0 : _c.code) || 500,
|
194
|
+
message: ((_e = (_d = error_3.response) === null || _d === void 0 ? void 0 : _d.data.error) === null || _e === void 0 ? void 0 : _e.message) || "Unknown error",
|
195
|
+
};
|
196
|
+
if (debug) {
|
197
|
+
console.log("DELETE_ResponseError", url, resError);
|
198
|
+
}
|
199
|
+
reject(resError);
|
200
|
+
}
|
201
|
+
else {
|
202
|
+
// Not a axios error, return the error as is
|
203
|
+
reject(error_3);
|
204
|
+
}
|
205
|
+
return [3 /*break*/, 3];
|
206
|
+
case 3: return [2 /*return*/];
|
207
|
+
}
|
208
|
+
});
|
209
|
+
}); })];
|
210
|
+
});
|
211
|
+
}); };
|
212
|
+
exports.makeDelete = makeDelete;
|
@@ -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;
|