mts-booking-library 1.2.8 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +5 -0
- package/lib/booking/booking.js +4 -0
- package/lib/booking/journeyBooking.d.ts +7 -1
- package/lib/booking/journeyBooking.js +29 -3
- package/lib/booking/serviceBooking.d.ts +28 -0
- package/lib/booking/serviceBooking.js +127 -2
- package/lib/booking/subscriptionBooking.d.ts +7 -1
- package/lib/booking/subscriptionBooking.js +29 -3
- package/lib/utils/apiCall.js +8 -8
- package/package.json +4 -4
package/lib/booking/booking.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { MTSConfig, MTSEnvs } from "../config";
|
2
2
|
import { ErrorResponse } from "../types/ErrorResponse";
|
3
3
|
import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
|
4
|
+
import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
4
5
|
import { AddReductionRequest } from "../types/common/Reduction";
|
5
6
|
export declare abstract class Booking {
|
6
7
|
readonly sellerId?: number | undefined;
|
@@ -45,6 +46,10 @@ export declare abstract class Booking {
|
|
45
46
|
changeCurrency(currency: Booking.Currencies): void;
|
46
47
|
changeLanguage(language: string): void;
|
47
48
|
getCartExpirationTimeInMs(): Promise<number>;
|
49
|
+
abstract deleteCart(): Promise<ErrorResponse | any>;
|
50
|
+
abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
51
|
+
abstract getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
|
52
|
+
abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | any>;
|
48
53
|
/**
|
49
54
|
* @description This method allows to add a reduction to the cart
|
50
55
|
* @param {AddReductionRequest} request The information about the reduction to add
|
package/lib/booking/booking.js
CHANGED
@@ -134,6 +134,8 @@ var Booking = /** @class */ (function () {
|
|
134
134
|
});
|
135
135
|
});
|
136
136
|
};
|
137
|
+
//#endregion
|
138
|
+
//#region Reductions APIs
|
137
139
|
/**
|
138
140
|
* @description This method allows to add a reduction to the cart
|
139
141
|
* @param {AddReductionRequest} request The information about the reduction to add
|
@@ -209,6 +211,8 @@ var Booking = /** @class */ (function () {
|
|
209
211
|
});
|
210
212
|
});
|
211
213
|
};
|
214
|
+
//#endregion
|
215
|
+
//#region Payment APIs
|
212
216
|
/**
|
213
217
|
* @description This method shall be used to get the available payment methods for the cart. They depend on the seller configuration.
|
214
218
|
* @returns An {@link ErrorResponse} object in case of error, a {@link GetSellerGatewaysResponse} object otherwise.
|
@@ -24,6 +24,12 @@ export declare class JourneyBooking extends Booking {
|
|
24
24
|
fetchAndSetCart(cartId: number): Promise<void>;
|
25
25
|
private createCartTimer;
|
26
26
|
fetchCart(cartId: number): Promise<JourneyCart>;
|
27
|
+
/**
|
28
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
29
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
30
|
+
* data will be deleted.
|
31
|
+
*/
|
32
|
+
deleteCart(): Promise<ErrorResponse | any>;
|
27
33
|
/**
|
28
34
|
* This method returns the possible departures for all journeys (MLP) sold by this seller.
|
29
35
|
* @returns {string[]} The list of possible departures
|
@@ -58,7 +64,7 @@ export declare class JourneyBooking extends Booking {
|
|
58
64
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
59
65
|
* as well as a list of the available tariffs for each trip.
|
60
66
|
*/
|
61
|
-
|
67
|
+
getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
|
62
68
|
/**
|
63
69
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
64
70
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
@@ -82,9 +82,8 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
82
82
|
function JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) {
|
83
83
|
if (debug === void 0) { debug = false; }
|
84
84
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
85
|
-
var _this =
|
86
85
|
// Call Booking constructor
|
87
|
-
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
|
86
|
+
var _this = _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
|
88
87
|
// Set cartId
|
89
88
|
var cartId = localStorage.getItem("cartId");
|
90
89
|
if (cartId) {
|
@@ -156,6 +155,33 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
156
155
|
});
|
157
156
|
});
|
158
157
|
};
|
158
|
+
/**
|
159
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
160
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
161
|
+
* data will be deleted.
|
162
|
+
*/
|
163
|
+
JourneyBooking.prototype.deleteCart = function () {
|
164
|
+
return __awaiter(this, void 0, void 0, function () {
|
165
|
+
var url;
|
166
|
+
var _this = this;
|
167
|
+
return __generator(this, function (_a) {
|
168
|
+
// First check that it is possible to call this API
|
169
|
+
if (!this.cart) {
|
170
|
+
throw Error("Cart is not initialized yet");
|
171
|
+
}
|
172
|
+
url = "".concat(this.config.API_ENDPOINT, "/removeBookingFromCart");
|
173
|
+
return [2 /*return*/, this.callPostApi(url, { cartId: this.cart.id }).then(function (response) {
|
174
|
+
// Clear all data
|
175
|
+
localStorage.removeItem("cartId");
|
176
|
+
_this.bookingStepsToStatus = new Map();
|
177
|
+
_this.cart = undefined;
|
178
|
+
_this.cartId = undefined;
|
179
|
+
_this.bookingDueDate = undefined; // See Booking class
|
180
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
181
|
+
})];
|
182
|
+
});
|
183
|
+
});
|
184
|
+
};
|
159
185
|
/**
|
160
186
|
* This method returns the possible departures for all journeys (MLP) sold by this seller.
|
161
187
|
* @returns {string[]} The list of possible departures
|
@@ -308,7 +334,7 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
308
334
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
309
335
|
* as well as a list of the available tariffs for each trip.
|
310
336
|
*/
|
311
|
-
JourneyBooking.prototype.
|
337
|
+
JourneyBooking.prototype.getBuyerFromLinkavelCard = function (linkavelCardNumber, linkavelCardPhoneNumber) {
|
312
338
|
return __awaiter(this, void 0, void 0, function () {
|
313
339
|
var buyerPassengersDetails, searchParams, url;
|
314
340
|
return __generator(this, function (_a) {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { MTSEnvs } from "../config";
|
2
2
|
import { ErrorResponse } from "../types/ErrorResponse";
|
3
|
+
import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
|
3
4
|
import { Service, ServiceTrip } from "../types/services/Service";
|
4
5
|
import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
|
5
6
|
import { Booking } from "./booking";
|
@@ -23,6 +24,12 @@ export declare class ServiceBooking extends Booking {
|
|
23
24
|
private createCartTimer;
|
24
25
|
fetchCart(cartId: number): Promise<ServiceCart>;
|
25
26
|
/**
|
27
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
28
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
29
|
+
* data will be deleted.
|
30
|
+
*/
|
31
|
+
deleteCart(): Promise<ErrorResponse | any>;
|
32
|
+
/**
|
26
33
|
* This method returns the list of cities in which the seller offers tours.
|
27
34
|
* If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
|
28
35
|
* @returns {string[]} The list of possible cities
|
@@ -46,6 +53,27 @@ export declare class ServiceBooking extends Booking {
|
|
46
53
|
*/
|
47
54
|
getServiceTrips(serviceId: number, date: Date): Promise<ErrorResponse | ServiceTrip[]>;
|
48
55
|
createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
|
56
|
+
/**
|
57
|
+
* @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
|
58
|
+
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
59
|
+
* as well as a list of the available tariffs for each trip.
|
60
|
+
*/
|
61
|
+
getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
|
62
|
+
/**
|
63
|
+
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
64
|
+
* @param {string} [linkavelCardNumber=undefined] The linkavel card number of the buyer. This parameter is required if linkavelCardPhoneNumber is not set.
|
65
|
+
* A linkavelCardNumber is a string of 9 digits.
|
66
|
+
* @param {string} [linkavelCardPhoneNumber=undefined] The linkavel card phone number of the buyer. This parameter is required if linkavelCardNumber is not set.
|
67
|
+
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
68
|
+
* as well as a list of the available tariffs for each trip.
|
69
|
+
*/
|
70
|
+
getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
|
71
|
+
/**
|
72
|
+
* @description This method shall be called when the user wants to update the buyer information.
|
73
|
+
* @param {Person} buyerDetails The object containing the buyer information.
|
74
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
75
|
+
*/
|
76
|
+
updateBuyerPassengersDetails(buyerDetails: Person): Promise<ErrorResponse | any>;
|
49
77
|
}
|
50
78
|
export declare namespace ServiceBooking {
|
51
79
|
const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
|
@@ -82,9 +82,8 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
82
82
|
function ServiceBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) {
|
83
83
|
if (debug === void 0) { debug = false; }
|
84
84
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
85
|
-
var _this =
|
86
85
|
// Call Booking constructor
|
87
|
-
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
|
86
|
+
var _this = _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
|
88
87
|
// Set cartId
|
89
88
|
var cartId = localStorage.getItem("cartId");
|
90
89
|
if (cartId) {
|
@@ -156,6 +155,33 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
156
155
|
});
|
157
156
|
};
|
158
157
|
/**
|
158
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
159
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
160
|
+
* data will be deleted.
|
161
|
+
*/
|
162
|
+
ServiceBooking.prototype.deleteCart = function () {
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
164
|
+
var url;
|
165
|
+
var _this = this;
|
166
|
+
return __generator(this, function (_a) {
|
167
|
+
// First check that it is possible to call this API
|
168
|
+
if (!this.cart) {
|
169
|
+
throw Error("Cart is not initialized yet");
|
170
|
+
}
|
171
|
+
url = "".concat(this.config.API_ENDPOINT, "/removeBookingFromCart");
|
172
|
+
return [2 /*return*/, this.callPostApi(url, { cartId: this.cart.id }).then(function (response) {
|
173
|
+
// Clear all data
|
174
|
+
localStorage.removeItem("cartId");
|
175
|
+
_this.bookingStepsToStatus = new Map();
|
176
|
+
_this.cart = undefined;
|
177
|
+
_this.cartId = undefined;
|
178
|
+
_this.bookingDueDate = undefined; // See Booking class
|
179
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
180
|
+
})];
|
181
|
+
});
|
182
|
+
});
|
183
|
+
};
|
184
|
+
/**
|
159
185
|
* This method returns the list of cities in which the seller offers tours.
|
160
186
|
* If the sellerId is not set or it is 0, it will return the list of cities for all sellers.
|
161
187
|
* @returns {string[]} The list of possible cities
|
@@ -241,6 +267,105 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
241
267
|
});
|
242
268
|
});
|
243
269
|
};
|
270
|
+
//#region Buyer data API
|
271
|
+
/**
|
272
|
+
* @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
|
273
|
+
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
274
|
+
* as well as a list of the available tariffs for each trip.
|
275
|
+
*/
|
276
|
+
ServiceBooking.prototype.getBuyerPassengersDetails = function () {
|
277
|
+
return __awaiter(this, void 0, void 0, function () {
|
278
|
+
var buyerPassengersDetails, url;
|
279
|
+
return __generator(this, function (_a) {
|
280
|
+
// First check that it is possible to call this API
|
281
|
+
if (!this.cart) {
|
282
|
+
throw Error("Cart is not initialized yet");
|
283
|
+
}
|
284
|
+
buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
|
285
|
+
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
286
|
+
throw Error("The status of the cart does not allow to call this API");
|
287
|
+
}
|
288
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details?");
|
289
|
+
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
290
|
+
// Check for errors
|
291
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
292
|
+
return response;
|
293
|
+
}
|
294
|
+
return {
|
295
|
+
buyerDataStatus: response.buyerDataStatus,
|
296
|
+
buyer: response.buyer,
|
297
|
+
passengers: [],
|
298
|
+
};
|
299
|
+
})];
|
300
|
+
});
|
301
|
+
});
|
302
|
+
};
|
303
|
+
/**
|
304
|
+
* @description This method shall be called when the user wants to retrieve information about an esisting buyer.
|
305
|
+
* @param {string} [linkavelCardNumber=undefined] The linkavel card number of the buyer. This parameter is required if linkavelCardPhoneNumber is not set.
|
306
|
+
* A linkavelCardNumber is a string of 9 digits.
|
307
|
+
* @param {string} [linkavelCardPhoneNumber=undefined] The linkavel card phone number of the buyer. This parameter is required if linkavelCardNumber is not set.
|
308
|
+
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
309
|
+
* as well as a list of the available tariffs for each trip.
|
310
|
+
*/
|
311
|
+
ServiceBooking.prototype.getBuyerFromLinkavelCard = function (linkavelCardNumber, linkavelCardPhoneNumber) {
|
312
|
+
return __awaiter(this, void 0, void 0, function () {
|
313
|
+
var buyerPassengersDetails, searchParams, url;
|
314
|
+
return __generator(this, function (_a) {
|
315
|
+
// First check that it is possible to call this API
|
316
|
+
if (!this.cart) {
|
317
|
+
throw Error("Cart is not initialized yet");
|
318
|
+
}
|
319
|
+
buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
|
320
|
+
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
321
|
+
throw Error("The status of the cart does not allow to call this API");
|
322
|
+
}
|
323
|
+
if (!linkavelCardNumber && !linkavelCardPhoneNumber) {
|
324
|
+
throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
|
325
|
+
}
|
326
|
+
searchParams = new URLSearchParams({
|
327
|
+
linkavelCardNumber: linkavelCardNumber !== null && linkavelCardNumber !== void 0 ? linkavelCardNumber : "",
|
328
|
+
linkavelCardPhoneNumber: linkavelCardPhoneNumber !== null && linkavelCardPhoneNumber !== void 0 ? linkavelCardPhoneNumber : "",
|
329
|
+
});
|
330
|
+
url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams, "}");
|
331
|
+
return [2 /*return*/, this.callGetApi(url).then(function (response) {
|
332
|
+
// Check for errors
|
333
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
|
334
|
+
return response;
|
335
|
+
}
|
336
|
+
return response.buyers[0];
|
337
|
+
})];
|
338
|
+
});
|
339
|
+
});
|
340
|
+
};
|
341
|
+
/**
|
342
|
+
* @description This method shall be called when the user wants to update the buyer information.
|
343
|
+
* @param {Person} buyerDetails The object containing the buyer information.
|
344
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
|
345
|
+
*/
|
346
|
+
ServiceBooking.prototype.updateBuyerPassengersDetails = function (buyerDetails) {
|
347
|
+
return __awaiter(this, void 0, void 0, function () {
|
348
|
+
var buyerPassengersDetails, request, url;
|
349
|
+
return __generator(this, function (_a) {
|
350
|
+
// First check that it is possible to call this API
|
351
|
+
if (!this.cart) {
|
352
|
+
throw Error("Cart is not initialized yet");
|
353
|
+
}
|
354
|
+
buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
|
355
|
+
if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
|
356
|
+
throw Error("The status of the cart does not allow to call this API");
|
357
|
+
}
|
358
|
+
request = {
|
359
|
+
buyer: buyerDetails,
|
360
|
+
passengers: [],
|
361
|
+
};
|
362
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
|
363
|
+
return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
|
364
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
365
|
+
})];
|
366
|
+
});
|
367
|
+
});
|
368
|
+
};
|
244
369
|
return ServiceBooking;
|
245
370
|
}(booking_1.Booking));
|
246
371
|
exports.ServiceBooking = ServiceBooking;
|
@@ -26,6 +26,12 @@ export declare class SubscriptionBooking extends Booking {
|
|
26
26
|
private createCartTimer;
|
27
27
|
fetchCart(cartId: number): Promise<Cart>;
|
28
28
|
/**
|
29
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
30
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
31
|
+
* data will be deleted.
|
32
|
+
*/
|
33
|
+
deleteCart(): Promise<ErrorResponse | any>;
|
34
|
+
/**
|
29
35
|
* This method returns the possible departures for all subscriptions sold by this seller.
|
30
36
|
* @returns {string[]} The list of possible departures
|
31
37
|
*/
|
@@ -81,7 +87,7 @@ export declare class SubscriptionBooking extends Booking {
|
|
81
87
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
82
88
|
* as well as a list of the available tariffs for each trip.
|
83
89
|
*/
|
84
|
-
|
90
|
+
getBuyerFromLinkavelCard(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
|
85
91
|
/**
|
86
92
|
* @description This methosd shall be called when the user wants to update the buyer and the passengers information.
|
87
93
|
* @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
|
@@ -82,9 +82,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
82
82
|
function SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) {
|
83
83
|
if (debug === void 0) { debug = false; }
|
84
84
|
if (language === void 0) { language = booking_1.Booking.Languages.EN; }
|
85
|
-
var _this =
|
86
85
|
// Call Booking constructor
|
87
|
-
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
|
86
|
+
var _this = _super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
|
88
87
|
// Set cartId
|
89
88
|
var cartId = localStorage.getItem("cartId");
|
90
89
|
if (cartId) {
|
@@ -157,6 +156,33 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
157
156
|
});
|
158
157
|
};
|
159
158
|
/**
|
159
|
+
* This method allows to delete a cart, thus allowing the user to exit from the booking process.
|
160
|
+
* @returns An {@link ErrorResponse} object in case of error, nothing otherwise. Note that also in case of error, all
|
161
|
+
* data will be deleted.
|
162
|
+
*/
|
163
|
+
SubscriptionBooking.prototype.deleteCart = function () {
|
164
|
+
return __awaiter(this, void 0, void 0, function () {
|
165
|
+
var url;
|
166
|
+
var _this = this;
|
167
|
+
return __generator(this, function (_a) {
|
168
|
+
// First check that it is possible to call this API
|
169
|
+
if (!this.cart) {
|
170
|
+
throw Error("Cart is not initialized yet");
|
171
|
+
}
|
172
|
+
url = "".concat(this.config.API_ENDPOINT, "/removeBookingFromCart");
|
173
|
+
return [2 /*return*/, this.callPostApi(url, { cartId: this.cart.id }).then(function (response) {
|
174
|
+
// Clear all data
|
175
|
+
localStorage.removeItem("cartId");
|
176
|
+
_this.bookingStepsToStatus = new Map();
|
177
|
+
_this.cart = undefined;
|
178
|
+
_this.cartId = undefined;
|
179
|
+
_this.bookingDueDate = undefined; // See Booking class
|
180
|
+
return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
|
181
|
+
})];
|
182
|
+
});
|
183
|
+
});
|
184
|
+
};
|
185
|
+
/**
|
160
186
|
* This method returns the possible departures for all subscriptions sold by this seller.
|
161
187
|
* @returns {string[]} The list of possible departures
|
162
188
|
*/
|
@@ -357,7 +383,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
357
383
|
* @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
|
358
384
|
* as well as a list of the available tariffs for each trip.
|
359
385
|
*/
|
360
|
-
SubscriptionBooking.prototype.
|
386
|
+
SubscriptionBooking.prototype.getBuyerFromLinkavelCard = function (linkavelCardNumber, linkavelCardPhoneNumber) {
|
361
387
|
return __awaiter(this, void 0, void 0, function () {
|
362
388
|
var buyerPassengersDetails, searchParams, url;
|
363
389
|
return __generator(this, function (_a) {
|
package/lib/utils/apiCall.js
CHANGED
@@ -114,28 +114,28 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
114
114
|
}
|
115
115
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
116
116
|
var response, error_2, resError;
|
117
|
-
var _a, _b, _c;
|
118
|
-
return __generator(this, function (
|
119
|
-
switch (
|
117
|
+
var _a, _b, _c, _d, _e;
|
118
|
+
return __generator(this, function (_f) {
|
119
|
+
switch (_f.label) {
|
120
120
|
case 0:
|
121
|
-
|
121
|
+
_f.trys.push([0, 2, , 3]);
|
122
122
|
return [4 /*yield*/, axios_1.default.post(url, data, {
|
123
123
|
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) })),
|
124
124
|
})];
|
125
125
|
case 1:
|
126
|
-
response =
|
126
|
+
response = _f.sent();
|
127
127
|
if (debug) {
|
128
128
|
console.log("PostResponseData", url, response.data);
|
129
129
|
}
|
130
130
|
resolve(response.data);
|
131
131
|
return [3 /*break*/, 3];
|
132
132
|
case 2:
|
133
|
-
error_2 =
|
133
|
+
error_2 = _f.sent();
|
134
134
|
if (axios_1.default.isAxiosError(error_2)) {
|
135
135
|
resError = {
|
136
136
|
httpStatus: ((_a = error_2.response) === null || _a === void 0 ? void 0 : _a.status) || 500,
|
137
|
-
mtsCode: ((_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data.error.code) || 500,
|
138
|
-
message: ((
|
137
|
+
mtsCode: ((_c = (_b = error_2.response) === null || _b === void 0 ? void 0 : _b.data.error) === null || _c === void 0 ? void 0 : _c.code) || 500,
|
138
|
+
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
139
|
};
|
140
140
|
if (debug) {
|
141
141
|
console.log("GetResponseError", url, resError);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mts-booking-library",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.9",
|
4
4
|
"description": "Library for use MyTicketSolution Booking API",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -14,10 +14,10 @@
|
|
14
14
|
},
|
15
15
|
"license": "ISC",
|
16
16
|
"devDependencies": {
|
17
|
-
"@types/jest": "^29.5.
|
17
|
+
"@types/jest": "^29.5.10",
|
18
18
|
"jest": "^29.7.0",
|
19
19
|
"ts-jest": "^29.1.1",
|
20
|
-
"typescript": "^5.
|
20
|
+
"typescript": "^5.3.2"
|
21
21
|
},
|
22
22
|
"files": [
|
23
23
|
"lib/**/*"
|
@@ -28,7 +28,7 @@
|
|
28
28
|
],
|
29
29
|
"author": "M",
|
30
30
|
"dependencies": {
|
31
|
-
"axios": "^1.6.
|
31
|
+
"axios": "^1.6.2",
|
32
32
|
"node-localstorage": "^3.0.5"
|
33
33
|
}
|
34
34
|
}
|