mts-booking-library 1.3.1 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/SubscriptionBooking.d.ts +0 -0
- package/lib/SubscriptionBooking.js +139 -0
- package/lib/booking/booking.d.ts +0 -1
- package/lib/booking/booking.js +17 -19
- package/lib/booking/journeyBooking.js +17 -16
- package/lib/booking/serviceBooking.d.ts +3 -3
- package/lib/booking/serviceBooking.js +16 -15
- package/lib/booking/subscriptionBooking.js +14 -13
- package/lib/booking/tplBooking.js +14 -13
- package/lib/types/common/Cart.d.ts +2 -0
- package/lib/types/services/Service.d.ts +10 -0
- package/lib/types/services/ServiceCart.d.ts +2 -2
- package/lib/utils/utils.d.ts +14 -0
- package/lib/utils/utils.js +26 -0
- package/package.json +3 -2
File without changes
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"use strict";
|
2
|
+
// import { MTSEnvs } from "../config";
|
3
|
+
// import { ServiceBooking } from "../booking/serviceBooking";
|
4
|
+
// import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
|
5
|
+
// import { Service, ServiceTripsResponse } from "../types/services/Service";
|
6
|
+
// import { GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
7
|
+
// import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
|
8
|
+
// import { useTestState } from "../mtsStorage";
|
9
|
+
// import { SubscriptionBooking } from "../booking/subscriptionBooking";
|
10
|
+
// // Load .env file
|
11
|
+
// require('dotenv').config();
|
12
|
+
// // How to run the test: npm run test -- SubscriptionBooking.test.ts
|
13
|
+
// describe("SubscriptionBooking", () => {
|
14
|
+
// const timeOut = 120000;
|
15
|
+
// const sub_key = process.env.OCP_SUB_KEY_MTS;
|
16
|
+
// const access_token = process.env.ACCESS_TOKEN;
|
17
|
+
// const sellerId = 8; // ATV
|
18
|
+
// // Define localStorage for local testing
|
19
|
+
// if (typeof localStorage === "undefined" || localStorage === null) {
|
20
|
+
// var LocalStorage = require("node-localstorage").LocalStorage;
|
21
|
+
// global.localStorage = new LocalStorage("./scratch");
|
22
|
+
// }
|
23
|
+
// test("search_tpl", async () => {
|
24
|
+
// const booking = new SubscriptionBooking(MTSEnvs.TEST, sub_key!, true, SubscriptionBooking.Languages.EN, access_token, sellerId);
|
25
|
+
// // First, get the departures
|
26
|
+
// const departures = await booking.getSubscriptionsDepartures() as string[];
|
27
|
+
// expect(departures.length).toBeGreaterThan(0);
|
28
|
+
// expect(departures).toContain("APT TREVISO CANOVA");
|
29
|
+
// const selectedDeparture = "APT TREVISO CANOVA";
|
30
|
+
// const destinations = await booking.getJourneysDestinations(selectedDeparture);
|
31
|
+
// expect(destinations).toContain("MESTRE FFSS");
|
32
|
+
// }, timeOut);
|
33
|
+
// const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
|
34
|
+
// const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
|
35
|
+
// const services = servicesResponse as Service[];
|
36
|
+
// // Build create cart request
|
37
|
+
// let tariffsMatrix = services[0].tariffsMatrix;
|
38
|
+
// tariffsMatrix[0][0].quantity = 1;
|
39
|
+
// const createServiceCartRequest: CreateServiceCartRequest = {
|
40
|
+
// currency: ServiceBooking.Currencies.EUR,
|
41
|
+
// service: {
|
42
|
+
// serviceId: services[0].id,
|
43
|
+
// tariffsMatrix: tariffsMatrix
|
44
|
+
// }
|
45
|
+
// };
|
46
|
+
// // Create cart
|
47
|
+
// const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
|
48
|
+
// return cart;
|
49
|
+
// }
|
50
|
+
// test("create_service_cart", async () => {
|
51
|
+
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
52
|
+
// const cart = await createCart(booking);
|
53
|
+
// // Check that the cartId was saved to the local storage
|
54
|
+
// expect(useTestState().getState().cartId).toBe(cart.id);
|
55
|
+
// expect(booking.cartId).toBe(cart.id);
|
56
|
+
// // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
|
57
|
+
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
|
58
|
+
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
|
59
|
+
// // Test booking due date
|
60
|
+
// expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
|
61
|
+
// // Test expired tickets
|
62
|
+
// expect(cart.hasIssuedTickets).toBe(false);
|
63
|
+
// // Test seller data
|
64
|
+
// expect(booking.getSellerId()).toBe(cart.sellerId);
|
65
|
+
// expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
|
66
|
+
// expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
|
67
|
+
// // Now try to get the cart
|
68
|
+
// const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
69
|
+
// expect(newBooking.cartId).toBe(cart.id);
|
70
|
+
// expect(newBooking.getCart()?.id).toBe(cart.id)
|
71
|
+
// expect(newBooking.getSellerId()).toBe(cart.sellerId);
|
72
|
+
// // Finally try to delete the cart
|
73
|
+
// await booking.deleteCart();
|
74
|
+
// expect(booking.getCart()).toBe(undefined);
|
75
|
+
// expect(useTestState().getState().cartId).toBe(undefined);
|
76
|
+
// }, timeOut);
|
77
|
+
// test("get_edit_buyer_data", async () => {
|
78
|
+
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
79
|
+
// const cart = await createCart(booking);
|
80
|
+
// // First, try to get the buyer data
|
81
|
+
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
82
|
+
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
83
|
+
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
84
|
+
// expect(buyer).toBe(null);
|
85
|
+
// // Now try to edit the buyer data
|
86
|
+
// buyer = {
|
87
|
+
// id: 0,
|
88
|
+
// name: "TestName",
|
89
|
+
// lastName: "TestSurname",
|
90
|
+
// email: "testBookingLib@infos.it",
|
91
|
+
// phoneNumber: "+391234567890"
|
92
|
+
// }
|
93
|
+
// await booking.updateBuyerPassengersDetails(buyer);
|
94
|
+
// // Finally, get the buyer data again and check that the data was updated
|
95
|
+
// buyerDataResponse = await booking.getBuyerPassengersDetails();
|
96
|
+
// const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
97
|
+
// expect(updatedBuyer.id).toBeGreaterThan(0);
|
98
|
+
// expect(updatedBuyer.name).toBe(buyer.name);
|
99
|
+
// expect(updatedBuyer.lastName).toBe(buyer.lastName);
|
100
|
+
// expect(updatedBuyer.email).toBe(buyer.email);
|
101
|
+
// expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
|
102
|
+
// // Finally try to delete the cart
|
103
|
+
// await booking.deleteCart();
|
104
|
+
// expect(booking.getCart()).toBe(undefined);
|
105
|
+
// expect(useTestState().getState().cartId).toBe(undefined);
|
106
|
+
// }, timeOut);
|
107
|
+
// test("get_gateway_info", async () => {
|
108
|
+
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
109
|
+
// const cart = await createCart(booking);
|
110
|
+
// booking.updateSellerId(cart.sellerId);
|
111
|
+
// // First, try to get the buyer data
|
112
|
+
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
113
|
+
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
114
|
+
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
115
|
+
// expect(buyer).toBe(null);
|
116
|
+
// // Now try to edit the buyer data
|
117
|
+
// buyer = {
|
118
|
+
// id: 0,
|
119
|
+
// name: "TestName",
|
120
|
+
// lastName: "TestSurname",
|
121
|
+
// email: "testBookingLib@infos.it",
|
122
|
+
// phoneNumber: "+391234567890"
|
123
|
+
// }
|
124
|
+
// await booking.updateBuyerPassengersDetails(buyer);
|
125
|
+
// // Try to get the gateways
|
126
|
+
// const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
|
127
|
+
// if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
|
128
|
+
// throw new Error("No gateways found");
|
129
|
+
// }
|
130
|
+
// const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
|
131
|
+
// expect(gateway?.id).toBeGreaterThan(0);
|
132
|
+
// // Now try to get the info
|
133
|
+
// const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
|
134
|
+
// // Finally try to delete the cart
|
135
|
+
// await booking.deleteCart();
|
136
|
+
// expect(booking.getCart()).toBe(undefined);
|
137
|
+
// expect(useTestState().getState().cartId).toBe(undefined);
|
138
|
+
// }, timeOut);
|
139
|
+
// });
|
package/lib/booking/booking.d.ts
CHANGED
@@ -51,7 +51,6 @@ export declare abstract class Booking {
|
|
51
51
|
getBookingStepsToStatus(): Map<string, boolean[]>;
|
52
52
|
changeCurrency(currency: Booking.Currencies): void;
|
53
53
|
changeLanguage(language: string): void;
|
54
|
-
getCartExpirationTimeInMs(): Promise<number>;
|
55
54
|
/**
|
56
55
|
* This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
|
57
56
|
* @param bookingStep The booking step to mark as completed
|
package/lib/booking/booking.js
CHANGED
@@ -104,22 +104,33 @@ var Booking = /** @class */ (function () {
|
|
104
104
|
(0, config_1.setConfig)(this.config.ENV, this.config.OCP_SUBSCRIPTION_KEY, this.config.DEBUG, access_token);
|
105
105
|
};
|
106
106
|
Booking.prototype.callGetApi = function (url) {
|
107
|
+
var _a, _b, _c, _d;
|
107
108
|
// Add sellerId, resellerId and language to the query string.
|
108
109
|
// If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
|
109
110
|
// Otherwise, add it (as we are adding some parameters to the query string)
|
110
|
-
var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(
|
111
|
+
var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams({
|
112
|
+
sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0",
|
113
|
+
resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0",
|
114
|
+
language: this.language
|
115
|
+
}));
|
111
116
|
return (0, apiCall_1.makeGet)(completeUrl);
|
112
117
|
};
|
113
118
|
Booking.prototype.callPostApi = function (url, body) {
|
119
|
+
var _a, _b, _c, _d;
|
114
120
|
// Add sellerId, resellerId and language to the query string
|
115
|
-
var completeBody = __assign(__assign(
|
121
|
+
var completeBody = __assign(__assign({}, body), { sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 0, resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : 0, language: this.language });
|
116
122
|
return (0, apiCall_1.makePost)(url, completeBody);
|
117
123
|
};
|
118
124
|
Booking.prototype.callDeleteApi = function (url) {
|
125
|
+
var _a, _b, _c, _d;
|
119
126
|
// Add sellerId, resellerId and language to the query string.
|
120
127
|
// If the last character of the url is a question mark (meaning that the query string is empty), don't add the "&" character.
|
121
128
|
// Otherwise, add it (as we are adding some parameters to the query string)
|
122
|
-
var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams(
|
129
|
+
var completeUrl = "".concat(url).concat(url.slice(-1) === "?" ? "" : "&").concat(new URLSearchParams({
|
130
|
+
sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "0",
|
131
|
+
resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : "0",
|
132
|
+
language: this.language
|
133
|
+
}));
|
123
134
|
return (0, apiCall_1.makeDelete)(completeUrl);
|
124
135
|
};
|
125
136
|
Booking.prototype.getBookingStepsToStatus = function () {
|
@@ -138,19 +149,6 @@ var Booking = /** @class */ (function () {
|
|
138
149
|
this.language = Booking.Languages.EN;
|
139
150
|
}
|
140
151
|
};
|
141
|
-
Booking.prototype.getCartExpirationTimeInMs = function () {
|
142
|
-
return __awaiter(this, void 0, void 0, function () {
|
143
|
-
return __generator(this, function (_a) {
|
144
|
-
// If cart is initialized, return the time in ms until the cart expires.
|
145
|
-
// Note that bookingDueDate is initialized only when the cart is created.
|
146
|
-
if (this.bookingDueDate) {
|
147
|
-
return [2 /*return*/, (new Date(this.bookingDueDate).valueOf() - new Date().valueOf())];
|
148
|
-
}
|
149
|
-
// Cart is not initialized
|
150
|
-
throw Error("Cart is not initialized yet");
|
151
|
-
});
|
152
|
-
});
|
153
|
-
};
|
154
152
|
/**
|
155
153
|
* This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
|
156
154
|
* @param bookingStep The booking step to mark as completed
|
@@ -176,7 +174,7 @@ var Booking = /** @class */ (function () {
|
|
176
174
|
// Booking step is already completed, no need to call the API
|
177
175
|
if (currentStepStatus[0])
|
178
176
|
return [2 /*return*/, true];
|
179
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
177
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/bookingSteps");
|
180
178
|
return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep }).then(function (response) {
|
181
179
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
182
180
|
return response;
|
@@ -259,7 +257,7 @@ var Booking = /** @class */ (function () {
|
|
259
257
|
throw Error("The status of the cart does not allow to call this API");
|
260
258
|
}
|
261
259
|
searchParams = new URLSearchParams(__assign({ gatewayId: gatewayId.toString() }, (returnUrl && { returnUrl: returnUrl })));
|
262
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
260
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment?").concat(searchParams);
|
263
261
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
264
262
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
265
263
|
})];
|
@@ -324,7 +322,7 @@ var Booking = /** @class */ (function () {
|
|
324
322
|
}
|
325
323
|
_c.label = 7;
|
326
324
|
case 7:
|
327
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
325
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/issue");
|
328
326
|
body = {
|
329
327
|
cartId: this.cartId,
|
330
328
|
paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
|
@@ -133,11 +133,12 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
133
133
|
switch (_a.label) {
|
134
134
|
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
|
135
135
|
if (cart) {
|
136
|
-
var
|
137
|
-
|
136
|
+
var cartDueDate = new Date();
|
137
|
+
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
138
|
+
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
138
139
|
_this.cart = cart;
|
139
140
|
_this.cartId = cart.id;
|
140
|
-
_this.bookingDueDate =
|
141
|
+
_this.bookingDueDate = cartDueDate; // See Booking class
|
141
142
|
// Update the sellerId. This is particularly important in Linkavel
|
142
143
|
_this.updateSellerId(cart.sellerId);
|
143
144
|
// Fill the booking process status
|
@@ -161,7 +162,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
161
162
|
var url;
|
162
163
|
var _this = this;
|
163
164
|
return __generator(this, function (_a) {
|
164
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
165
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
165
166
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
166
167
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
167
168
|
_this.resetBooking();
|
@@ -258,7 +259,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
258
259
|
var url, request;
|
259
260
|
var _this = this;
|
260
261
|
return __generator(this, function (_a) {
|
261
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/
|
262
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/carts");
|
262
263
|
request = __assign(__assign({}, journeyCart), (this.cartId && { cartId: this.cartId.toString() }));
|
263
264
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
264
265
|
// Check for errors
|
@@ -298,7 +299,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
298
299
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
299
300
|
throw Error("The status of the cart does not allow to call this API");
|
300
301
|
}
|
301
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
302
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
|
302
303
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
303
304
|
// Check for errors
|
304
305
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -394,7 +395,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
394
395
|
});
|
395
396
|
request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
|
396
397
|
});
|
397
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
398
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
|
398
399
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
399
400
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
400
401
|
return response;
|
@@ -455,7 +456,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
455
456
|
throw Error("The status of the cart does not allow to call this API");
|
456
457
|
}
|
457
458
|
searchParams = new URLSearchParams({ tripId: tripId.toString() });
|
458
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
459
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/seats?").concat(searchParams);
|
459
460
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
460
461
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.assignedSeats;
|
461
462
|
})];
|
@@ -481,7 +482,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
481
482
|
if (!seatSelectionStatus || !seatSelectionStatus[0]) {
|
482
483
|
throw Error("The status of the cart does not allow to call this API");
|
483
484
|
}
|
484
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
485
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/seats");
|
485
486
|
return [2 /*return*/, this.callPostApi(url, { tripId: tripId, newSeatsIds: newSeatsIds }).then(function (response) {
|
486
487
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
487
488
|
return response;
|
@@ -508,7 +509,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
508
509
|
if (!this.cart) {
|
509
510
|
throw Error("Cart is not initialized yet");
|
510
511
|
}
|
511
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
512
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/payment/reduction/trips?");
|
512
513
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
513
514
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
|
514
515
|
})];
|
@@ -557,7 +558,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
557
558
|
}
|
558
559
|
_c.label = 5;
|
559
560
|
case 5:
|
560
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
561
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
|
561
562
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
562
563
|
var _a, _b;
|
563
564
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -594,7 +595,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
594
595
|
throw Error("The status of the cart does not allow to call this API");
|
595
596
|
}
|
596
597
|
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
597
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
598
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
598
599
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
599
600
|
var _a, _b, _c;
|
600
601
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -651,11 +652,11 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
651
652
|
// Check again if the discounts step is accessible
|
652
653
|
issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
|
653
654
|
if (!issueStep || !issueStep[0]) {
|
654
|
-
throw Error("The status of the cart does not allow to call the API: booking/
|
655
|
+
throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
|
655
656
|
}
|
656
657
|
_c.label = 5;
|
657
658
|
case 5:
|
658
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
659
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
659
660
|
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
660
661
|
var _a, _b;
|
661
662
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -686,7 +687,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
686
687
|
if (!this.cartId || this.cartId === 0) {
|
687
688
|
throw Error("Cart is not initialized yet");
|
688
689
|
}
|
689
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
690
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
690
691
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
691
692
|
var _a, _b, _c;
|
692
693
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -746,7 +747,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
746
747
|
}
|
747
748
|
_c.label = 5;
|
748
749
|
case 5:
|
749
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
750
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
|
750
751
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
751
752
|
var _a, _b;
|
752
753
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -2,7 +2,7 @@ import { MTSEnvs } from "../config";
|
|
2
2
|
import { ErrorResponse } from "../types/ErrorResponse";
|
3
3
|
import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
4
4
|
import { AddReductionRequest } from "../types/common/Reduction";
|
5
|
-
import { Service,
|
5
|
+
import { Service, ServiceTripsResponse } from "../types/services/Service";
|
6
6
|
import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
|
7
7
|
import { Booking } from "./booking";
|
8
8
|
export declare class ServiceBooking extends Booking {
|
@@ -94,9 +94,9 @@ export declare class ServiceBooking extends Booking {
|
|
94
94
|
* You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
|
95
95
|
* @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
|
96
96
|
* @param {string} date The date on which to get the tours, in ISO string format
|
97
|
-
* @returns {
|
97
|
+
* @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
|
98
98
|
*/
|
99
|
-
getServiceTrips(serviceId: number, date: string): Promise<ErrorResponse |
|
99
|
+
getServiceTrips(serviceId: number, date: string): Promise<ErrorResponse | ServiceTripsResponse>;
|
100
100
|
createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
|
101
101
|
/**
|
102
102
|
* @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
|
@@ -133,11 +133,12 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
133
133
|
switch (_a.label) {
|
134
134
|
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
|
135
135
|
if (cart) {
|
136
|
-
var
|
137
|
-
|
136
|
+
var cartDueDate = new Date();
|
137
|
+
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
138
|
+
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
138
139
|
_this.cart = cart;
|
139
140
|
_this.cartId = cart.id;
|
140
|
-
_this.bookingDueDate =
|
141
|
+
_this.bookingDueDate = cartDueDate; // See Booking class
|
141
142
|
// Update the sellerId. This is particularly important in Linkavel
|
142
143
|
_this.updateSellerId(cart.sellerId);
|
143
144
|
// Fill the booking process status
|
@@ -161,7 +162,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
161
162
|
var url;
|
162
163
|
var _this = this;
|
163
164
|
return __generator(this, function (_a) {
|
164
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
165
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
165
166
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
166
167
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
167
168
|
_this.resetBooking();
|
@@ -240,7 +241,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
240
241
|
* You should call this method only if {@link Service.isDateOptional} or {@link Service.isDateRequired} is true for the selected tour.
|
241
242
|
* @param {number} serviceId The id of the selected tour (can be retrieved in the object {@link Service} returned by {@link getTours})
|
242
243
|
* @param {string} date The date on which to get the tours, in ISO string format
|
243
|
-
* @returns {
|
244
|
+
* @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
|
244
245
|
*/
|
245
246
|
ServiceBooking.prototype.getServiceTrips = function (serviceId, date) {
|
246
247
|
return __awaiter(this, void 0, void 0, function () {
|
@@ -249,7 +250,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
249
250
|
searchParams = new URLSearchParams({ date: date });
|
250
251
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/").concat(serviceId, "/trips?").concat(searchParams);
|
251
252
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
252
|
-
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response
|
253
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
253
254
|
})];
|
254
255
|
});
|
255
256
|
});
|
@@ -259,7 +260,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
259
260
|
var url;
|
260
261
|
var _this = this;
|
261
262
|
return __generator(this, function (_a) {
|
262
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/
|
263
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/services/carts");
|
263
264
|
return [2 /*return*/, this.callPostApi(url, serviceCart).then(function (response) {
|
264
265
|
// Check for errors
|
265
266
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -300,7 +301,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
300
301
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
301
302
|
throw Error("The status of the cart does not allow to call this API");
|
302
303
|
}
|
303
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
304
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
|
304
305
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
305
306
|
// Check for errors
|
306
307
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -373,7 +374,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
373
374
|
buyer: buyerDetails,
|
374
375
|
passengers: [],
|
375
376
|
};
|
376
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
377
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
|
377
378
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
378
379
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
379
380
|
return response;
|
@@ -429,7 +430,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
429
430
|
}
|
430
431
|
_c.label = 5;
|
431
432
|
case 5:
|
432
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
433
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
|
433
434
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
434
435
|
var _a, _b;
|
435
436
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -466,7 +467,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
466
467
|
throw Error("The status of the cart does not allow to call this API");
|
467
468
|
}
|
468
469
|
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
469
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
470
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
470
471
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
471
472
|
var _a, _b, _c;
|
472
473
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -523,11 +524,11 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
523
524
|
// Check again if the discounts step is accessible
|
524
525
|
issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
|
525
526
|
if (!issueStep || !issueStep[0]) {
|
526
|
-
throw Error("The status of the cart does not allow to call the API: booking/
|
527
|
+
throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
|
527
528
|
}
|
528
529
|
_c.label = 5;
|
529
530
|
case 5:
|
530
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
531
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
531
532
|
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
532
533
|
var _a, _b;
|
533
534
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -558,7 +559,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
558
559
|
if (!this.cartId || this.cartId === 0) {
|
559
560
|
throw Error("Cart is not initialized yet");
|
560
561
|
}
|
561
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
562
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
562
563
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
563
564
|
var _a, _b, _c;
|
564
565
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -618,7 +619,7 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
618
619
|
}
|
619
620
|
_c.label = 5;
|
620
621
|
case 5:
|
621
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
622
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
|
622
623
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
623
624
|
var _a, _b;
|
624
625
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -133,11 +133,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
133
133
|
switch (_a.label) {
|
134
134
|
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
|
135
135
|
if (cart) {
|
136
|
-
var
|
137
|
-
|
136
|
+
var cartDueDate = new Date();
|
137
|
+
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
138
|
+
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
138
139
|
_this.cart = cart;
|
139
140
|
_this.cartId = cart.id;
|
140
|
-
_this.bookingDueDate =
|
141
|
+
_this.bookingDueDate = cartDueDate; // See Booking class
|
141
142
|
// Update the sellerId. This is particularly important in Linkavel
|
142
143
|
_this.updateSellerId(cart.sellerId);
|
143
144
|
// Fill the booking process status
|
@@ -161,7 +162,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
161
162
|
var url;
|
162
163
|
var _this = this;
|
163
164
|
return __generator(this, function (_a) {
|
164
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
165
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
165
166
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
166
167
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
167
168
|
_this.resetBooking();
|
@@ -314,7 +315,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
314
315
|
var url;
|
315
316
|
var _this = this;
|
316
317
|
return __generator(this, function (_a) {
|
317
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/
|
318
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/subscriptions/carts");
|
318
319
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
319
320
|
// Check for errors
|
320
321
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -353,7 +354,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
353
354
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
354
355
|
throw Error("The status of the cart does not allow to call this API");
|
355
356
|
}
|
356
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
357
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
|
357
358
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
358
359
|
// Check for errors
|
359
360
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -449,7 +450,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
449
450
|
});
|
450
451
|
request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
|
451
452
|
});
|
452
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
453
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
|
453
454
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
454
455
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
455
456
|
return response;
|
@@ -504,7 +505,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
504
505
|
}
|
505
506
|
_c.label = 5;
|
506
507
|
case 5:
|
507
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
508
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
|
508
509
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
509
510
|
var _a, _b;
|
510
511
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -541,7 +542,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
541
542
|
throw Error("The status of the cart does not allow to call this API");
|
542
543
|
}
|
543
544
|
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
544
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
545
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
545
546
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
546
547
|
var _a, _b, _c;
|
547
548
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -598,11 +599,11 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
598
599
|
// Check again if the discounts step is accessible
|
599
600
|
issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
|
600
601
|
if (!issueStep || !issueStep[0]) {
|
601
|
-
throw Error("The status of the cart does not allow to call the API: booking/
|
602
|
+
throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
|
602
603
|
}
|
603
604
|
_c.label = 5;
|
604
605
|
case 5:
|
605
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
606
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
606
607
|
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
607
608
|
var _a, _b;
|
608
609
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -633,7 +634,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
633
634
|
if (!this.cartId || this.cartId === 0) {
|
634
635
|
throw Error("Cart is not initialized yet");
|
635
636
|
}
|
636
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
637
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
637
638
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
638
639
|
var _a, _b, _c;
|
639
640
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -693,7 +694,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
693
694
|
}
|
694
695
|
_c.label = 5;
|
695
696
|
case 5:
|
696
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
697
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
|
697
698
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
698
699
|
var _a, _b;
|
699
700
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -133,11 +133,12 @@ var TplBooking = /** @class */ (function (_super) {
|
|
133
133
|
switch (_a.label) {
|
134
134
|
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
|
135
135
|
if (cart) {
|
136
|
-
var
|
137
|
-
|
136
|
+
var cartDueDate = new Date();
|
137
|
+
cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
|
138
|
+
if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
|
138
139
|
_this.cart = cart;
|
139
140
|
_this.cartId = cart.id;
|
140
|
-
_this.bookingDueDate =
|
141
|
+
_this.bookingDueDate = cartDueDate; // See Booking class
|
141
142
|
// Update the sellerId. This is particularly important in Linkavel
|
142
143
|
_this.updateSellerId(cart.sellerId);
|
143
144
|
// Fill the booking process status
|
@@ -161,7 +162,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
161
162
|
var url;
|
162
163
|
var _this = this;
|
163
164
|
return __generator(this, function (_a) {
|
164
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
165
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts?").concat(new URLSearchParams({ cartId: cartId.toString() }));
|
165
166
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
166
167
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
167
168
|
_this.resetBooking();
|
@@ -287,7 +288,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
287
288
|
var url, processedTariffIdToQuantity, request;
|
288
289
|
var _this = this;
|
289
290
|
return __generator(this, function (_a) {
|
290
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/
|
291
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/carts");
|
291
292
|
processedTariffIdToQuantity = {};
|
292
293
|
tariffIdToQuantity.forEach(function (value, key) {
|
293
294
|
processedTariffIdToQuantity[key] = value;
|
@@ -333,7 +334,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
333
334
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
334
335
|
throw Error("The status of the cart does not allow to call this API");
|
335
336
|
}
|
336
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
337
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details?");
|
337
338
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
338
339
|
// Check for errors
|
339
340
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -406,7 +407,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
406
407
|
buyer: buyerDetails,
|
407
408
|
passengers: [],
|
408
409
|
};
|
409
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
410
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cart.id, "/details");
|
410
411
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
411
412
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
412
413
|
return response;
|
@@ -462,7 +463,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
462
463
|
}
|
463
464
|
_c.label = 5;
|
464
465
|
case 5:
|
465
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
466
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction");
|
466
467
|
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
467
468
|
var _a, _b;
|
468
469
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -499,7 +500,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
499
500
|
throw Error("The status of the cart does not allow to call this API");
|
500
501
|
}
|
501
502
|
queryParams = new URLSearchParams({ tripId: tripId.toString() });
|
502
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
503
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/reduction?").concat(queryParams);
|
503
504
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
504
505
|
var _a, _b, _c;
|
505
506
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -556,11 +557,11 @@ var TplBooking = /** @class */ (function (_super) {
|
|
556
557
|
// Check again if the discounts step is accessible
|
557
558
|
issueStep = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.ISSUE);
|
558
559
|
if (!issueStep || !issueStep[0]) {
|
559
|
-
throw Error("The status of the cart does not allow to call the API: booking/
|
560
|
+
throw Error("The status of the cart does not allow to call the API: booking/carts/".concat(this.cartId, "/payment/wallet"));
|
560
561
|
}
|
561
562
|
_c.label = 5;
|
562
563
|
case 5:
|
563
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
564
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
564
565
|
return [2 /*return*/, this.callPostApi(url, {}).then(function (response) {
|
565
566
|
var _a, _b;
|
566
567
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -591,7 +592,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
591
592
|
if (!this.cartId || this.cartId === 0) {
|
592
593
|
throw Error("Cart is not initialized yet");
|
593
594
|
}
|
594
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
595
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/wallet");
|
595
596
|
return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
|
596
597
|
var _a, _b, _c;
|
597
598
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -651,7 +652,7 @@ var TplBooking = /** @class */ (function (_super) {
|
|
651
652
|
}
|
652
653
|
_c.label = 5;
|
653
654
|
case 5:
|
654
|
-
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/
|
655
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/").concat(this.cartId, "/payment/voucher");
|
655
656
|
return [2 /*return*/, this.callPostApi(url, { voucherCode: voucherCode }).then(function (response) {
|
656
657
|
var _a, _b;
|
657
658
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
@@ -21,6 +21,7 @@ import { Extra } from "./Extra";
|
|
21
21
|
* - The second tells whether the section is completed.
|
22
22
|
* - The third tells whether the section is required.
|
23
23
|
* @property {Booking.Currencies} currency The currency of the cart. See {@link Booking.Currencies}
|
24
|
+
* @property {number} bookingDueDateRemainingSeconds The number of seconds remaining before the cart expires. This should be equivalent `bookingDueDate`
|
24
25
|
* @property {string} bookingDueDate The date and time when the cart expires
|
25
26
|
* @property {Reduction[]} reductions The list of reductions applied to the cart
|
26
27
|
* @property {Extra[]} extras The list of extras services of the cart
|
@@ -42,6 +43,7 @@ export type Cart = {
|
|
42
43
|
stepsToStatus: Map<string, boolean[]>;
|
43
44
|
currency: Booking.Currencies;
|
44
45
|
bookingDueDate: string;
|
46
|
+
bookingDueDateRemainingSeconds: number;
|
45
47
|
reductions: Reduction[];
|
46
48
|
extras: Extra[];
|
47
49
|
sellingMethod: string;
|
@@ -31,3 +31,13 @@ export type ServiceTrip = {
|
|
31
31
|
date: Date;
|
32
32
|
name: string;
|
33
33
|
};
|
34
|
+
/**
|
35
|
+
* @description Represents a response from the service trips endpoint
|
36
|
+
* @param {boolean} areThereTrips - Indicates whether there are trips available for the service.
|
37
|
+
* @param {ServiceTrip[]} trips - An array of {@link ServiceTrip} objects representing the available trips. This can be empty
|
38
|
+
* even if `areThereTrips` is true, as the user might be not allowed to select a specific trip.
|
39
|
+
*/
|
40
|
+
export type ServiceTripsResponse = {
|
41
|
+
areThereTrips: boolean;
|
42
|
+
trips: ServiceTrip[];
|
43
|
+
};
|
@@ -9,7 +9,7 @@ import { ServiceTrip } from "./Service";
|
|
9
9
|
* @property {Object} service - Information about the selected service.
|
10
10
|
* @property {number} service.serviceId - The unique identifier for the service.
|
11
11
|
* @property {TariffsMatrix} service.tariffsMatrix - The tariff matrix for pricing the service.
|
12
|
-
* @property {
|
12
|
+
* @property {string|undefined} [service.date] - The date for the service in ISO string format (optional).
|
13
13
|
* @property {number|undefined} [service.tripId] - The unique identifier for the trip (optional).
|
14
14
|
*/
|
15
15
|
export type CreateServiceCartRequest = {
|
@@ -17,7 +17,7 @@ export type CreateServiceCartRequest = {
|
|
17
17
|
service: {
|
18
18
|
serviceId: number;
|
19
19
|
tariffsMatrix: TariffsMatrix;
|
20
|
-
date?:
|
20
|
+
date?: string;
|
21
21
|
tripId?: number;
|
22
22
|
};
|
23
23
|
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
|
3
|
+
* @param {Date | string} date the date to convert
|
4
|
+
* @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
|
5
|
+
* that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
|
6
|
+
* @returns {string} the ISO string
|
7
|
+
*/
|
8
|
+
export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
|
9
|
+
/**
|
10
|
+
* This method check where a variable is null or undefined
|
11
|
+
* @param value The value to check
|
12
|
+
* @returns True if the value is null or undefined, false otherwise
|
13
|
+
*/
|
14
|
+
export declare const isNullOrUndefined: (value: any) => boolean;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isNullOrUndefined = exports.getISOStringWithoutGMT = void 0;
|
4
|
+
/**
|
5
|
+
* This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
|
6
|
+
* @param {Date | string} date the date to convert
|
7
|
+
* @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
|
8
|
+
* that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
|
9
|
+
* @returns {string} the ISO string
|
10
|
+
*/
|
11
|
+
var getISOStringWithoutGMT = function (date, removeTimezone) {
|
12
|
+
if (removeTimezone === void 0) { removeTimezone = true; }
|
13
|
+
if (!date)
|
14
|
+
return null;
|
15
|
+
var newDate = new Date(date);
|
16
|
+
var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
|
17
|
+
return removeTimezone ? isoString.slice(0, -1) : isoString;
|
18
|
+
};
|
19
|
+
exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
|
20
|
+
/**
|
21
|
+
* This method check where a variable is null or undefined
|
22
|
+
* @param value The value to check
|
23
|
+
* @returns True if the value is null or undefined, false otherwise
|
24
|
+
*/
|
25
|
+
var isNullOrUndefined = function (value) { return value === null || value === undefined; };
|
26
|
+
exports.isNullOrUndefined = isNullOrUndefined;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mts-booking-library",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.3",
|
4
4
|
"description": "Library for using MyTicketSolution Booking API",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -17,7 +17,7 @@
|
|
17
17
|
"@types/jest": "^29.5.12",
|
18
18
|
"jest": "^29.7.0",
|
19
19
|
"ts-jest": "^29.1.2",
|
20
|
-
"typescript": "^5.4.
|
20
|
+
"typescript": "^5.4.3"
|
21
21
|
},
|
22
22
|
"files": [
|
23
23
|
"lib/**/*"
|
@@ -30,6 +30,7 @@
|
|
30
30
|
"dependencies": {
|
31
31
|
"@react-native-async-storage/async-storage": "^1.23.1",
|
32
32
|
"axios": "^1.6.8",
|
33
|
+
"dotenv": "^16.4.5",
|
33
34
|
"node-localstorage": "^3.0.5",
|
34
35
|
"zustand": "^4.5.2"
|
35
36
|
}
|