mts-booking-library 1.3.22 → 1.3.24
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/SubscriptionBooking.d.ts +0 -0
- package/lib/SubscriptionBooking.js +148 -0
- package/lib/booking/booking.d.ts +2 -2
- package/lib/booking/journeyBooking.d.ts +4 -6
- package/lib/booking/journeyBooking.js +11 -19
- package/lib/booking/serviceBooking.d.ts +4 -6
- package/lib/booking/serviceBooking.js +10 -11
- package/lib/booking/subscriptionBooking.d.ts +4 -6
- package/lib/booking/subscriptionBooking.js +10 -11
- package/lib/booking/tplBooking.d.ts +4 -6
- package/lib/booking/tplBooking.js +10 -11
- package/lib/index.d.ts +2 -3
- package/lib/types/common/Person.d.ts +12 -1
- package/lib/utils/testUtils.d.ts +8 -0
- package/lib/utils/testUtils.js +19 -0
- package/package.json +5 -5
File without changes
|
@@ -0,0 +1,148 @@
|
|
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 and destinations
|
26
|
+
// const departures = await booking.getSubscriptionsDepartures() as string[];
|
27
|
+
// expect(departures.length).toBeGreaterThan(0);
|
28
|
+
// expect(departures).toContain("BARDOLINO AUTOSTAZIONE");
|
29
|
+
// const selectedDeparture = "BARDOLINO AUTOSTAZIONE";
|
30
|
+
// const destinations = await booking.getSubscriptionsDestinations(selectedDeparture) as string[];
|
31
|
+
// expect(destinations.length).toBeGreaterThan(0);
|
32
|
+
// expect(destinations).toContain("GARDA AUTOSTAZIONE");
|
33
|
+
// const selectedDestination = "GARDA AUTOSTAZIONE";
|
34
|
+
// // Then get the validity types
|
35
|
+
// const validityTypes = await booking.getSubscriptionsValidityTypes(selectedDeparture, selectedDestination) as SubscriptionBooking.ValidityTypes[];
|
36
|
+
// expect(validityTypes.length).toBeGreaterThan(0);
|
37
|
+
// for (const validityType of validityTypes) {
|
38
|
+
// // Check that all returned validity types are valid
|
39
|
+
// expect(Object.values(SubscriptionBooking.ValidityTypes).includes(validityType)).toBe(true);
|
40
|
+
// }
|
41
|
+
// }, timeOut);
|
42
|
+
// const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
|
43
|
+
// const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
|
44
|
+
// const services = servicesResponse as Service[];
|
45
|
+
// // Build create cart request
|
46
|
+
// let tariffsMatrix = services[0].tariffsMatrix;
|
47
|
+
// tariffsMatrix[0][0].quantity = 1;
|
48
|
+
// const createServiceCartRequest: CreateServiceCartRequest = {
|
49
|
+
// currency: ServiceBooking.Currencies.EUR,
|
50
|
+
// service: {
|
51
|
+
// serviceId: services[0].id,
|
52
|
+
// tariffsMatrix: tariffsMatrix
|
53
|
+
// }
|
54
|
+
// };
|
55
|
+
// // Create cart
|
56
|
+
// const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
|
57
|
+
// return cart;
|
58
|
+
// }
|
59
|
+
// test("create_service_cart", async () => {
|
60
|
+
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
61
|
+
// const cart = await createCart(booking);
|
62
|
+
// // Check that the cartId was saved to the local storage
|
63
|
+
// expect(useTestState().getState().cartId).toBe(cart.id);
|
64
|
+
// expect(booking.cartId).toBe(cart.id);
|
65
|
+
// // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
|
66
|
+
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
|
67
|
+
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
|
68
|
+
// // Test booking due date
|
69
|
+
// expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
|
70
|
+
// // Test expired tickets
|
71
|
+
// expect(cart.hasIssuedTickets).toBe(false);
|
72
|
+
// // Test seller data
|
73
|
+
// expect(booking.getSellerId()).toBe(cart.sellerId);
|
74
|
+
// expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
|
75
|
+
// expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
|
76
|
+
// // Now try to get the cart
|
77
|
+
// const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
78
|
+
// expect(newBooking.cartId).toBe(cart.id);
|
79
|
+
// expect(newBooking.getCart()?.id).toBe(cart.id)
|
80
|
+
// expect(newBooking.getSellerId()).toBe(cart.sellerId);
|
81
|
+
// // Finally try to delete the cart
|
82
|
+
// await booking.deleteCart();
|
83
|
+
// expect(booking.getCart()).toBe(undefined);
|
84
|
+
// expect(useTestState().getState().cartId).toBe(undefined);
|
85
|
+
// }, timeOut);
|
86
|
+
// test("get_edit_buyer_data", async () => {
|
87
|
+
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
88
|
+
// const cart = await createCart(booking);
|
89
|
+
// // First, try to get the buyer data
|
90
|
+
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
91
|
+
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
92
|
+
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
93
|
+
// expect(buyer).toBe(null);
|
94
|
+
// // Now try to edit the buyer data
|
95
|
+
// buyer = {
|
96
|
+
// id: 0,
|
97
|
+
// name: "TestName",
|
98
|
+
// lastName: "TestSurname",
|
99
|
+
// email: "testBookingLib@infos.it",
|
100
|
+
// phoneNumber: "+391234567890"
|
101
|
+
// }
|
102
|
+
// await booking.updateBuyerPassengersDetails(buyer);
|
103
|
+
// // Finally, get the buyer data again and check that the data was updated
|
104
|
+
// buyerDataResponse = await booking.getBuyerPassengersDetails();
|
105
|
+
// const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
106
|
+
// expect(updatedBuyer.id).toBeGreaterThan(0);
|
107
|
+
// expect(updatedBuyer.name).toBe(buyer.name);
|
108
|
+
// expect(updatedBuyer.lastName).toBe(buyer.lastName);
|
109
|
+
// expect(updatedBuyer.email).toBe(buyer.email);
|
110
|
+
// expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
|
111
|
+
// // Finally try to delete the cart
|
112
|
+
// await booking.deleteCart();
|
113
|
+
// expect(booking.getCart()).toBe(undefined);
|
114
|
+
// expect(useTestState().getState().cartId).toBe(undefined);
|
115
|
+
// }, timeOut);
|
116
|
+
// test("get_gateway_info", async () => {
|
117
|
+
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
118
|
+
// const cart = await createCart(booking);
|
119
|
+
// booking.updateSellerId(cart.sellerId);
|
120
|
+
// // First, try to get the buyer data
|
121
|
+
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
122
|
+
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
123
|
+
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
124
|
+
// expect(buyer).toBe(null);
|
125
|
+
// // Now try to edit the buyer data
|
126
|
+
// buyer = {
|
127
|
+
// id: 0,
|
128
|
+
// name: "TestName",
|
129
|
+
// lastName: "TestSurname",
|
130
|
+
// email: "testBookingLib@infos.it",
|
131
|
+
// phoneNumber: "+391234567890"
|
132
|
+
// }
|
133
|
+
// await booking.updateBuyerPassengersDetails(buyer);
|
134
|
+
// // Try to get the gateways
|
135
|
+
// const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
|
136
|
+
// if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
|
137
|
+
// throw new Error("No gateways found");
|
138
|
+
// }
|
139
|
+
// const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
|
140
|
+
// expect(gateway?.id).toBeGreaterThan(0);
|
141
|
+
// // Now try to get the info
|
142
|
+
// const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
|
143
|
+
// // Finally try to delete the cart
|
144
|
+
// await booking.deleteCart();
|
145
|
+
// expect(booking.getCart()).toBe(undefined);
|
146
|
+
// expect(useTestState().getState().cartId).toBe(undefined);
|
147
|
+
// }, timeOut);
|
148
|
+
// });
|
package/lib/booking/booking.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { MTSConfig, MTSEnvs } from "../config";
|
|
2
2
|
import { ErrorResponse } from "../types/ErrorResponse";
|
3
3
|
import { processedStepsToStatus } from "../types/common/Cart";
|
4
4
|
import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueTicketsResponse } from "../types/common/Payment";
|
5
|
-
import { GetBuyerPassengersDetailsResponse,
|
5
|
+
import { Buyer, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
|
6
6
|
import { AddReductionRequest } from "../types/common/Reduction";
|
7
7
|
export declare abstract class Booking {
|
8
8
|
private sellerId?;
|
@@ -55,7 +55,7 @@ export declare abstract class Booking {
|
|
55
55
|
abstract deleteCart(): Promise<ErrorResponse | any>;
|
56
56
|
abstract resetBooking(): void;
|
57
57
|
abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
58
|
-
abstract
|
58
|
+
abstract getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
59
59
|
abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | boolean>;
|
60
60
|
abstract addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
|
61
61
|
abstract removeReduction(tripId: number): Promise<ErrorResponse | boolean>;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
|
-
import { Buyer, EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
2
|
+
import { Buyer, EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
|
3
3
|
import { AddReductionRequest } from "../types/common/Reduction";
|
4
4
|
import { BusMatrix } from "../types/journeys/BusMatrix";
|
5
5
|
import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
|
@@ -103,12 +103,10 @@ export declare class JourneyBooking extends Booking {
|
|
103
103
|
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
104
104
|
/**
|
105
105
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
106
|
-
* @param
|
107
|
-
* @
|
108
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
109
|
-
* as well as a list of the available tariffs for each trip.
|
106
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
107
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
110
108
|
*/
|
111
|
-
|
109
|
+
getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
112
110
|
/**
|
113
111
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
114
112
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
@@ -258,14 +258,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
258
258
|
if (request.departureStopName === undefined || request.destinationStopName === undefined) {
|
259
259
|
throw Error("Fields departureStopName and destinationStopName are required");
|
260
260
|
}
|
261
|
-
searchParams = new URLSearchParams({
|
262
|
-
departureStopName: request.departureStopName,
|
263
|
-
destinationStopName: request.destinationStopName,
|
264
|
-
passengersNumber: request.passengersNumber.toString(),
|
265
|
-
date: request.date,
|
266
|
-
roundTripDate: request.roundTripDate ? request.roundTripDate : "null",
|
267
|
-
currency: request.currency
|
268
|
-
});
|
261
|
+
searchParams = new URLSearchParams(__assign(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), date: request.date, roundTripDate: request.roundTripDate ? request.roundTripDate : "null", currency: request.currency }, (this.cartId && { cartId: this.cartId.toString() })), (this.cartGuid && { cartGuid: this.cartGuid })));
|
269
262
|
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys?").concat(searchParams);
|
270
263
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
271
264
|
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
|
@@ -363,15 +356,14 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
363
356
|
};
|
364
357
|
/**
|
365
358
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
366
|
-
* @param
|
367
|
-
* @
|
368
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
369
|
-
* as well as a list of the available tariffs for each trip.
|
359
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
360
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
370
361
|
*/
|
371
|
-
JourneyBooking.prototype.
|
362
|
+
JourneyBooking.prototype.getBuyer = function (request) {
|
372
363
|
return __awaiter(this, void 0, void 0, function () {
|
373
364
|
var buyerPassengersDetails, searchParams, url;
|
374
|
-
|
365
|
+
var _a;
|
366
|
+
return __generator(this, function (_b) {
|
375
367
|
// First check that it is possible to call this API
|
376
368
|
if (!this.cart) {
|
377
369
|
throw Error("Cart is not initialized yet");
|
@@ -380,17 +372,17 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
380
372
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
381
373
|
throw Error("The status of the cart does not allow to call this API");
|
382
374
|
}
|
383
|
-
if (!
|
384
|
-
throw Error("At least one of the parameters
|
375
|
+
if (!request.personId && !request.personCode && !request.phoneNumber) {
|
376
|
+
throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
|
385
377
|
}
|
386
|
-
searchParams = new URLSearchParams(__assign(__assign({}, (
|
387
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
378
|
+
searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
|
379
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
|
388
380
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
389
381
|
// Check for errors
|
390
382
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
391
383
|
return response;
|
392
384
|
}
|
393
|
-
return response.
|
385
|
+
return response.persons[0];
|
394
386
|
})];
|
395
387
|
});
|
396
388
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
|
-
import { Buyer, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
2
|
+
import { Buyer, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
|
3
3
|
import { AddReductionRequest } from "../types/common/Reduction";
|
4
4
|
import { Service, ServiceTripsResponse } from "../types/services/Service";
|
5
5
|
import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
|
@@ -105,12 +105,10 @@ export declare class ServiceBooking extends Booking {
|
|
105
105
|
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
106
106
|
/**
|
107
107
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
108
|
-
* @param
|
109
|
-
* @
|
110
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
111
|
-
* as well as a list of the available tariffs for each trip.
|
108
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
109
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
112
110
|
*/
|
113
|
-
|
111
|
+
getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
114
112
|
/**
|
115
113
|
* @description This method shall be called when the user wants to update the buyer information.
|
116
114
|
* @param buyerDetails The object containing the buyer information.
|
@@ -336,15 +336,14 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
336
336
|
};
|
337
337
|
/**
|
338
338
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
339
|
-
* @param
|
340
|
-
* @
|
341
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
342
|
-
* as well as a list of the available tariffs for each trip.
|
339
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
340
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
343
341
|
*/
|
344
|
-
ServiceBooking.prototype.
|
342
|
+
ServiceBooking.prototype.getBuyer = function (request) {
|
345
343
|
return __awaiter(this, void 0, void 0, function () {
|
346
344
|
var buyerPassengersDetails, searchParams, url;
|
347
|
-
|
345
|
+
var _a;
|
346
|
+
return __generator(this, function (_b) {
|
348
347
|
// First check that it is possible to call this API
|
349
348
|
if (!this.cart) {
|
350
349
|
throw Error("Cart is not initialized yet");
|
@@ -353,17 +352,17 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
353
352
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
354
353
|
throw Error("The status of the cart does not allow to call this API");
|
355
354
|
}
|
356
|
-
if (!
|
357
|
-
throw Error("At least one of the parameters
|
355
|
+
if (!request.personId && !request.personCode && !request.phoneNumber) {
|
356
|
+
throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
|
358
357
|
}
|
359
|
-
searchParams = new URLSearchParams(__assign(__assign({}, (
|
360
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
358
|
+
searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
|
359
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
|
361
360
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
362
361
|
// Check for errors
|
363
362
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
364
363
|
return response;
|
365
364
|
}
|
366
|
-
return response.
|
365
|
+
return response.persons[0];
|
367
366
|
})];
|
368
367
|
});
|
369
368
|
});
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
|
-
import { Buyer, EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
2
|
+
import { Buyer, EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
|
3
3
|
import { AddReductionRequest } from "../types/common/Reduction";
|
4
4
|
import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
|
5
5
|
import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
|
@@ -124,12 +124,10 @@ export declare class SubscriptionBooking extends Booking {
|
|
124
124
|
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
125
125
|
/**
|
126
126
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
127
|
-
* @param
|
128
|
-
* @
|
129
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
130
|
-
* as well as a list of the available tariffs for each trip.
|
127
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
128
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
131
129
|
*/
|
132
|
-
|
130
|
+
getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
133
131
|
/**
|
134
132
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
135
133
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
@@ -415,15 +415,14 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
415
415
|
};
|
416
416
|
/**
|
417
417
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
418
|
-
* @param
|
419
|
-
* @
|
420
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
421
|
-
* as well as a list of the available tariffs for each trip.
|
418
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
419
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
422
420
|
*/
|
423
|
-
SubscriptionBooking.prototype.
|
421
|
+
SubscriptionBooking.prototype.getBuyer = function (request) {
|
424
422
|
return __awaiter(this, void 0, void 0, function () {
|
425
423
|
var buyerPassengersDetails, searchParams, url;
|
426
|
-
|
424
|
+
var _a;
|
425
|
+
return __generator(this, function (_b) {
|
427
426
|
// First check that it is possible to call this API
|
428
427
|
if (!this.cart) {
|
429
428
|
throw Error("Cart is not initialized yet");
|
@@ -432,17 +431,17 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
432
431
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
433
432
|
throw Error("The status of the cart does not allow to call this API");
|
434
433
|
}
|
435
|
-
if (!
|
436
|
-
throw Error("At least one of the parameters
|
434
|
+
if (!request.personId && !request.personCode && !request.phoneNumber) {
|
435
|
+
throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
|
437
436
|
}
|
438
|
-
searchParams = new URLSearchParams(__assign(__assign({}, (
|
439
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
437
|
+
searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
|
438
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
|
440
439
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
441
440
|
// Check for errors
|
442
441
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
443
442
|
return response;
|
444
443
|
}
|
445
|
-
return response.
|
444
|
+
return response.persons[0];
|
446
445
|
})];
|
447
446
|
});
|
448
447
|
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ErrorResponse } from "../types/ErrorResponse";
|
2
2
|
import { City } from "../types/common/City";
|
3
|
-
import { Buyer, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
|
3
|
+
import { Buyer, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
|
4
4
|
import { AddReductionRequest } from "../types/common/Reduction";
|
5
5
|
import { TariffType, TermsType } from "../types/common/Tariffs";
|
6
6
|
import { GetTariffsResponse } from "../types/tpl/GetTariffsResponse";
|
@@ -125,12 +125,10 @@ export declare class TplBooking extends Booking {
|
|
125
125
|
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
126
126
|
/**
|
127
127
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
128
|
-
* @param
|
129
|
-
* @
|
130
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
131
|
-
* as well as a list of the available tariffs for each trip.
|
128
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
129
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
132
130
|
*/
|
133
|
-
|
131
|
+
getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
|
134
132
|
/**
|
135
133
|
* @description This method shall be called when the user wants to update the buyer information.
|
136
134
|
* @param buyerDetails The object containing the buyer information.
|
@@ -396,15 +396,14 @@ var TplBooking = /** @class */ (function (_super) {
|
|
396
396
|
};
|
397
397
|
/**
|
398
398
|
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
399
|
-
* @param
|
400
|
-
* @
|
401
|
-
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
402
|
-
* as well as a list of the available tariffs for each trip.
|
399
|
+
* @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
|
400
|
+
* @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
|
403
401
|
*/
|
404
|
-
TplBooking.prototype.
|
402
|
+
TplBooking.prototype.getBuyer = function (request) {
|
405
403
|
return __awaiter(this, void 0, void 0, function () {
|
406
404
|
var buyerPassengersDetails, searchParams, url;
|
407
|
-
|
405
|
+
var _a;
|
406
|
+
return __generator(this, function (_b) {
|
408
407
|
// First check that it is possible to call this API
|
409
408
|
if (!this.cart) {
|
410
409
|
throw Error("Cart is not initialized yet");
|
@@ -413,17 +412,17 @@ var TplBooking = /** @class */ (function (_super) {
|
|
413
412
|
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
414
413
|
throw Error("The status of the cart does not allow to call this API");
|
415
414
|
}
|
416
|
-
if (!
|
417
|
-
throw Error("At least one of the parameters
|
415
|
+
if (!request.personId && !request.personCode && !request.phoneNumber) {
|
416
|
+
throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
|
418
417
|
}
|
419
|
-
searchParams = new URLSearchParams(__assign(__assign({}, (
|
420
|
-
url = "".concat(this.config.API_ENDPOINT, "/
|
418
|
+
searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
|
419
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
|
421
420
|
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
422
421
|
// Check for errors
|
423
422
|
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
424
423
|
return response;
|
425
424
|
}
|
426
|
-
return response.
|
425
|
+
return response.persons[0];
|
427
426
|
})];
|
428
427
|
});
|
429
428
|
});
|
package/lib/index.d.ts
CHANGED
@@ -4,9 +4,8 @@ export { ServiceBooking } from "./booking/serviceBooking";
|
|
4
4
|
export { SubscriptionBooking } from "./booking/subscriptionBooking";
|
5
5
|
export { TplBooking } from "./booking/tplBooking";
|
6
6
|
export { useMtsBookingState } from "./mtsStorage";
|
7
|
-
export { Person, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
|
8
|
-
export { GetBuyerPassengersDetailsResponse, GetPassenger, BuyerDataStatus } from "./types/common/Person";
|
9
|
-
export { EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
|
7
|
+
export { Person, Buyer, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
|
8
|
+
export { GetBuyerPassengersDetailsResponse, GetBuyerRequest, GetPassenger, BuyerDataStatus, EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
|
10
9
|
export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType, PassengerTariff, ExtraTariff } from "./types/common/Tariffs";
|
11
10
|
export { Reduction, AddReductionRequest } from "./types/common/Reduction";
|
12
11
|
export { Gateway, GetSellerGatewaysResponse, GetPaymentInformationFromGatewayResponse, IssueTicketsResponse, GatewayTypes, PaymentMethods } from "./types/common/Payment";
|
@@ -25,7 +25,18 @@ export type Buyer = Person & {
|
|
25
25
|
export declare const DEFAULT_PERSON: Person;
|
26
26
|
export declare const initializePerson: (person?: Person | undefined | null) => Person;
|
27
27
|
/**
|
28
|
-
* @description Represents
|
28
|
+
* @description Represents the request for the {@link Booking.getBuyerFromLinkavelCard} method.
|
29
|
+
* @property {number} personId - The unique identifier of the buyer.
|
30
|
+
* @property {string} personCode - The person code of the person (the old linkAvelCardNumber)
|
31
|
+
* @property {string} phoneNumber - The phone number of the person.
|
32
|
+
*/
|
33
|
+
export type GetBuyerRequest = {
|
34
|
+
personId?: number;
|
35
|
+
personCode?: string;
|
36
|
+
phoneNumber?: string;
|
37
|
+
};
|
38
|
+
/**
|
39
|
+
* @description Represents a passenger in the response of the {@link Booking.getPassengersDetails} method. This type extends the {@link Person} type
|
29
40
|
* with the `outboundTariffs` and `returnTariffs` properties.
|
30
41
|
*
|
31
42
|
* @property {string} outboundNotes - The notes for the outbound trip.
|
@@ -0,0 +1,8 @@
|
|
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;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
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;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mts-booking-library",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.24",
|
4
4
|
"description": "Library for using MyTicketSolution Booking API",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"@types/jest": "^29.5.12",
|
20
20
|
"jest": "^29.7.0",
|
21
21
|
"prettier": "^3.3.3",
|
22
|
-
"ts-jest": "^29.2.
|
22
|
+
"ts-jest": "^29.2.4",
|
23
23
|
"typescript": "^5.5.4"
|
24
24
|
},
|
25
25
|
"files": [
|
@@ -31,10 +31,10 @@
|
|
31
31
|
],
|
32
32
|
"author": "Infoservice s.r.l.",
|
33
33
|
"dependencies": {
|
34
|
-
"@react-native-async-storage/async-storage": "^1.
|
35
|
-
"axios": "^1.7.
|
34
|
+
"@react-native-async-storage/async-storage": "^1.24.0",
|
35
|
+
"axios": "^1.7.4",
|
36
36
|
"dotenv": "^16.4.5",
|
37
37
|
"node-localstorage": "^3.0.5",
|
38
|
-
"zustand": "^4.5.
|
38
|
+
"zustand": "^4.5.5"
|
39
39
|
}
|
40
40
|
}
|