mts-booking-library 1.2.7 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
- getBuyer(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
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.
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -71,9 +82,8 @@ var JourneyBooking = /** @class */ (function (_super) {
71
82
  function JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) {
72
83
  if (debug === void 0) { debug = false; }
73
84
  if (language === void 0) { language = booking_1.Booking.Languages.EN; }
74
- var _this =
75
85
  // Call Booking constructor
76
- _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;
77
87
  // Set cartId
78
88
  var cartId = localStorage.getItem("cartId");
79
89
  if (cartId) {
@@ -145,6 +155,33 @@ var JourneyBooking = /** @class */ (function (_super) {
145
155
  });
146
156
  });
147
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
+ };
148
185
  /**
149
186
  * This method returns the possible departures for all journeys (MLP) sold by this seller.
150
187
  * @returns {string[]} The list of possible departures
@@ -297,7 +334,7 @@ var JourneyBooking = /** @class */ (function (_super) {
297
334
  * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
298
335
  * as well as a list of the available tariffs for each trip.
299
336
  */
300
- JourneyBooking.prototype.getBuyer = function (linkavelCardNumber, linkavelCardPhoneNumber) {
337
+ JourneyBooking.prototype.getBuyerFromLinkavelCard = function (linkavelCardNumber, linkavelCardPhoneNumber) {
301
338
  return __awaiter(this, void 0, void 0, function () {
302
339
  var buyerPassengersDetails, searchParams, url;
303
340
  return __generator(this, function (_a) {
@@ -334,7 +371,7 @@ var JourneyBooking = /** @class */ (function (_super) {
334
371
  */
335
372
  JourneyBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
336
373
  return __awaiter(this, void 0, void 0, function () {
337
- var buyerPassengersDetails, url;
374
+ var buyerPassengersDetails, request, url;
338
375
  return __generator(this, function (_a) {
339
376
  // First check that it is possible to call this API
340
377
  if (!this.cart) {
@@ -344,8 +381,16 @@ var JourneyBooking = /** @class */ (function (_super) {
344
381
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
345
382
  throw Error("The status of the cart does not allow to call this API");
346
383
  }
384
+ request = __assign({}, passengersDetails);
385
+ passengersDetails.passengers.map(function (passenger, passengerIndex) {
386
+ var tripsToTariffsToJson = {};
387
+ passenger.tripsToTariffs.forEach(function (value, key) {
388
+ tripsToTariffsToJson[key] = value;
389
+ });
390
+ request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
391
+ });
347
392
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
348
- return [2 /*return*/, this.callPostApi(url, passengersDetails).then(function (response) {
393
+ return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
349
394
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
350
395
  })];
351
396
  });
@@ -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
- getBuyer(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
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.
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -71,9 +82,8 @@ var SubscriptionBooking = /** @class */ (function (_super) {
71
82
  function SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) {
72
83
  if (debug === void 0) { debug = false; }
73
84
  if (language === void 0) { language = booking_1.Booking.Languages.EN; }
74
- var _this =
75
85
  // Call Booking constructor
76
- _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;
77
87
  // Set cartId
78
88
  var cartId = localStorage.getItem("cartId");
79
89
  if (cartId) {
@@ -146,6 +156,33 @@ var SubscriptionBooking = /** @class */ (function (_super) {
146
156
  });
147
157
  };
148
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
+ /**
149
186
  * This method returns the possible departures for all subscriptions sold by this seller.
150
187
  * @returns {string[]} The list of possible departures
151
188
  */
@@ -346,7 +383,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
346
383
  * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
347
384
  * as well as a list of the available tariffs for each trip.
348
385
  */
349
- SubscriptionBooking.prototype.getBuyer = function (linkavelCardNumber, linkavelCardPhoneNumber) {
386
+ SubscriptionBooking.prototype.getBuyerFromLinkavelCard = function (linkavelCardNumber, linkavelCardPhoneNumber) {
350
387
  return __awaiter(this, void 0, void 0, function () {
351
388
  var buyerPassengersDetails, searchParams, url;
352
389
  return __generator(this, function (_a) {
@@ -383,7 +420,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
383
420
  */
384
421
  SubscriptionBooking.prototype.updateBuyerPassengersDetails = function (passengersDetails) {
385
422
  return __awaiter(this, void 0, void 0, function () {
386
- var buyerPassengersDetails, url;
423
+ var buyerPassengersDetails, request, url;
387
424
  return __generator(this, function (_a) {
388
425
  // First check that it is possible to call this API
389
426
  if (!this.cart) {
@@ -393,8 +430,16 @@ var SubscriptionBooking = /** @class */ (function (_super) {
393
430
  if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
394
431
  throw Error("The status of the cart does not allow to call this API");
395
432
  }
433
+ request = __assign({}, passengersDetails);
434
+ passengersDetails.passengers.map(function (passenger, passengerIndex) {
435
+ var tripsToTariffsToJson = {};
436
+ passenger.tripsToTariffs.forEach(function (value, key) {
437
+ tripsToTariffsToJson[key] = value;
438
+ });
439
+ request.passengers[passengerIndex].tripsToTariffs = tripsToTariffsToJson;
440
+ });
396
441
  url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/details");
397
- return [2 /*return*/, this.callPostApi(url, passengersDetails).then(function (response) {
442
+ return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
398
443
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
399
444
  })];
400
445
  });
@@ -54,11 +54,10 @@ export type GetBuyerPassengersDetailsResponse = {
54
54
  };
55
55
  /**
56
56
  * @description Represents the type of the passengers array in {@link EditPassengersDetailsRequest}.
57
+ * Note that in the `tripsToTariffs` map, the key is the trip id and the value is the chosen tariff id.
57
58
  */
58
59
  export type EditPassengerRequestType = Person & {
59
- tripsToTariffs: {
60
- [tripId: number]: number;
61
- };
60
+ tripsToTariffs: Map<number, number>;
62
61
  };
63
62
  /**
64
63
  * @description Represents the passengers details.
@@ -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 (_d) {
119
- switch (_d.label) {
117
+ var _a, _b, _c, _d, _e;
118
+ return __generator(this, function (_f) {
119
+ switch (_f.label) {
120
120
  case 0:
121
- _d.trys.push([0, 2, , 3]);
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 = _d.sent();
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 = _d.sent();
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: ((_c = error_2.response) === null || _c === void 0 ? void 0 : _c.data.error.message) || "Unknown error",
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.7",
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.7",
17
+ "@types/jest": "^29.5.10",
18
18
  "jest": "^29.7.0",
19
19
  "ts-jest": "^29.1.1",
20
- "typescript": "^5.2.2"
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.0",
31
+ "axios": "^1.6.2",
32
32
  "node-localstorage": "^3.0.5"
33
33
  }
34
34
  }