mts-booking-library 1.3.25 → 2.0.0

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.
@@ -1,8 +1,9 @@
1
1
  import { MTSConfig, MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
- import { processedStepsToStatus } from "../types/common/Cart";
4
- import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueTicketsResponse } from "../types/common/Payment";
5
- import { Buyer, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
3
+ import { Cart, processedStepsToStatus } from "../types/common/Cart";
4
+ import { GetExtrasForBookingResponse, GetExtrasResponse } from "../types/common/Extra";
5
+ import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueCartResponse } from "../types/common/Payment";
6
+ import { PersonDetails, GetBuyerPassengersDetailsResponse, GetPersonRequest } from "../types/common/Person";
6
7
  import { AddReductionRequest } from "../types/common/Reduction";
7
8
  export declare abstract class Booking {
8
9
  private sellerId?;
@@ -20,8 +21,6 @@ export declare abstract class Booking {
20
21
  * - The third tells whether the section is required. <br/>
21
22
  */
22
23
  bookingStepsToStatus: processedStepsToStatus;
23
- /** @deprecated Please use {@link cartGuid} instead */
24
- cartId: number | undefined;
25
24
  cartGuid: string | undefined;
26
25
  bookingDueDate: Date | undefined;
27
26
  /**
@@ -42,6 +41,7 @@ export declare abstract class Booking {
42
41
  renewAccessToken(access_token: string): void;
43
42
  callGetApi(url: string): Promise<ErrorResponse | any>;
44
43
  callPostApi(url: string, body: any): Promise<any>;
44
+ callPutApi(url: string, body: any): Promise<any>;
45
45
  callDeleteApi(url: string): Promise<ErrorResponse | any>;
46
46
  getBookingStepsToStatus(): processedStepsToStatus;
47
47
  changeCurrency(currency: Booking.Currencies): void;
@@ -55,8 +55,13 @@ 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 getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
59
58
  abstract updateBuyerPassengersDetails(request: any): Promise<ErrorResponse | boolean>;
59
+ /**
60
+ * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
61
+ * @param {GetPersonRequest} request The object containing the parameters to search the buyer.
62
+ * @returns An object of type {@link PersonDetails} containing the buyer information, or an {@link ErrorResponse} object in case of error.
63
+ */
64
+ getPerson(request: GetPersonRequest): Promise<ErrorResponse | PersonDetails>;
60
65
  abstract addReduction(request: AddReductionRequest): Promise<ErrorResponse | boolean>;
61
66
  abstract removeReduction(tripId: number): Promise<ErrorResponse | boolean>;
62
67
  abstract useWallet(): Promise<ErrorResponse | boolean>;
@@ -79,9 +84,31 @@ export declare abstract class Booking {
79
84
  * @description This method shall be used to issue the tickets. It must be called after the payment was successful.
80
85
  * @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
81
86
  * first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
82
- * @returns An {@link IssueTicketsResponse} object.
87
+ * @returns An {@link IssueCartResponse} object.
88
+ */
89
+ issueCart(paymentMethod: PaymentMethods): Promise<ErrorResponse | IssueCartResponse>;
90
+ getExtras({ extraId, tariffPlanId }?: {
91
+ /** The extra object identifier. By default, all the extras of the seller are returned. */
92
+ extraId?: number;
93
+ /** If present, the extras that are part of that tariff plan are returned. */
94
+ tariffPlanId?: number;
95
+ }): Promise<ErrorResponse | GetExtrasResponse>;
96
+ /**
97
+ * Fetches extras tariffs for the given cart
98
+ * @param cartGuid The guid of the cart
99
+ * @param tripId The ID of the trip for which the extras are requested. Please note that this
100
+ * parameter is required when adding extras to a MLP or services cart.
101
+ */
102
+ getExtrasForBooking(cartGuid: string, tripId?: number): Promise<ErrorResponse | GetExtrasForBookingResponse>;
103
+ /**
104
+ * Updates the extras associated with a cart, removing all previous ones.
105
+ * @param cartGuid The guid of the cart
106
+ * @param tariffIdToQuantity A map of tariff ids to the quantity of tickets to add for that tariff
83
107
  */
84
- issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse | IssueTicketsResponse>;
108
+ updateExtrasForCart(cartGuid: string, tariffIdToQuantity: Record<number, number>): Promise<ErrorResponse | {}>;
109
+ abstract getCart(): Cart | undefined;
110
+ abstract fetchAndSetCart(cartGuid: string): Promise<void>;
111
+ abstract fetchCart(cartGuid: string): Promise<Cart>;
85
112
  }
86
113
  export declare namespace Booking {
87
114
  enum Currencies {
@@ -122,8 +149,8 @@ export declare namespace Booking {
122
149
  /** The language in which the app is running. Can be "it", "en", "fr", "de" */
123
150
  language: Booking.Languages;
124
151
  /**
125
- * If true, the app will try to restore the state of the booking, reading the cartId from the mts-storage.
126
- * After reading the cartId, the BE will be called to retrieve the status of the cart.
152
+ * If true, the app will try to restore the state of the booking, reading the cartGuid from the mts-storage.
153
+ * After reading the cartGuid, the BE will be called to retrieve the status of the cart.
127
154
  * E.g. set this to `true` if you want your booking to be preserved after a page refresh.
128
155
  */
129
156
  restoreState: boolean;
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  });
21
21
  };
22
22
  var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
@@ -125,6 +125,13 @@ var Booking = /** @class */ (function () {
125
125
  (0, config_1.getConfig)().DB_TYPE && { databaseType: (0, config_1.getConfig)().DB_TYPE }));
126
126
  return (0, apiCall_1.makePost)(url, completeBody);
127
127
  };
128
+ Booking.prototype.callPutApi = function (url, body) {
129
+ var _a, _b, _c, _d;
130
+ // Add sellerId, resellerId and language to the query string
131
+ var completeBody = __assign(__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 }), ((0, config_1.getConfig)().ENV === config_1.MTSEnvs.DEV &&
132
+ (0, config_1.getConfig)().DB_TYPE && { databaseType: (0, config_1.getConfig)().DB_TYPE }));
133
+ return (0, apiCall_1.makePut)(url, completeBody);
134
+ };
128
135
  Booking.prototype.callDeleteApi = function (url) {
129
136
  var _a, _b, _c, _d;
130
137
  // Add sellerId, resellerId and language to the query string.
@@ -150,6 +157,7 @@ var Booking = /** @class */ (function () {
150
157
  this.language = Booking.Languages.EN;
151
158
  }
152
159
  };
160
+ // TODO: Add a test for this API once Extras are available on LinkAvel
153
161
  /**
154
162
  * This API allows to mark a non-required booking step as completed. It is useful for example for the seats selection step.
155
163
  * @param bookingStep The booking step to mark as completed
@@ -173,10 +181,10 @@ var Booking = /** @class */ (function () {
173
181
  throw Error("The step ".concat(bookingStep, " cannot be marked as completed because it is required"));
174
182
  }
175
183
  // Booking step is already completed, no need to call the API
176
- if (currentStepStatus[0])
184
+ if (currentStepStatus[1])
177
185
  return [2 /*return*/, true];
178
186
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/bookingSteps");
179
- return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep }).then(function (response) {
187
+ return [2 /*return*/, this.callPostApi(url, { bookingStep: bookingStep, cartGuid: this.cartGuid }).then(function (response) {
180
188
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
181
189
  return response;
182
190
  }
@@ -187,6 +195,41 @@ var Booking = /** @class */ (function () {
187
195
  });
188
196
  });
189
197
  };
198
+ /**
199
+ * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
200
+ * @param {GetPersonRequest} request The object containing the parameters to search the buyer.
201
+ * @returns An object of type {@link PersonDetails} containing the buyer information, or an {@link ErrorResponse} object in case of error.
202
+ */
203
+ Booking.prototype.getPerson = function (request) {
204
+ return __awaiter(this, void 0, void 0, function () {
205
+ var buyerPassengersDetails, searchParams, url;
206
+ var _a;
207
+ return __generator(this, function (_b) {
208
+ // First check that it is possible to call this API
209
+ if ((0, utils_1.isNullOrWhiteSpace)(this.cartGuid)) {
210
+ throw Error("Cart is not initialized yet");
211
+ }
212
+ buyerPassengersDetails = this.bookingStepsToStatus.get(Booking.BookingSteps.BUYER_PASSENGERS);
213
+ if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
214
+ throw Error("The status of the cart does not allow to call this API");
215
+ }
216
+ if (!request.personId && !request.personCode && !request.phoneNumber) {
217
+ throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
218
+ }
219
+ searchParams = new URLSearchParams(__assign(__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 })), { includeSSN: "true" }));
220
+ url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
221
+ return [2 /*return*/, this.callGetApi(url).then(function (response) {
222
+ // Check for errors
223
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
224
+ return response;
225
+ }
226
+ // Return the person details
227
+ var person = __assign(__assign({}, response.persons[0]), { socialSecurityNumber: response.persons[0].personDetails.socialSecurityNumber });
228
+ return person;
229
+ })];
230
+ });
231
+ });
232
+ };
190
233
  //#endregion
191
234
  //#region Payment APIs
192
235
  /**
@@ -233,9 +276,9 @@ var Booking = /** @class */ (function () {
233
276
  }
234
277
  _c.label = 5;
235
278
  case 5:
236
- url = "".concat(this.config.API_ENDPOINT, "/v3_resources/sellers/").concat(this.sellerId, "/gateways?");
279
+ url = "".concat(this.config.API_ENDPOINT, "/v3_resources/sellers/gateways?");
237
280
  // We use directly makeGet because we don't want to add sellerId to the query string (it is already present in the url)
238
- return [2 /*return*/, (0, apiCall_1.makeGet)(url).then(function (response) {
281
+ return [2 /*return*/, this.callGetApi(url).then(function (response) {
239
282
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
240
283
  ? response
241
284
  : response;
@@ -273,14 +316,13 @@ var Booking = /** @class */ (function () {
273
316
  });
274
317
  });
275
318
  };
276
- // TODO: Rename this as issueCart
277
319
  /**
278
320
  * @description This method shall be used to issue the tickets. It must be called after the payment was successful.
279
321
  * @param {PaymentMethods} paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
280
322
  * first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
281
- * @returns An {@link IssueTicketsResponse} object.
323
+ * @returns An {@link IssueCartResponse} object.
282
324
  */
283
- Booking.prototype.issueTickets = function (paymentMethod) {
325
+ Booking.prototype.issueCart = function (paymentMethod) {
284
326
  return __awaiter(this, void 0, void 0, function () {
285
327
  var paymentMethodToSet, issueStep, _i, _a, step, url, body;
286
328
  var _b;
@@ -350,6 +392,65 @@ var Booking = /** @class */ (function () {
350
392
  });
351
393
  });
352
394
  };
395
+ //#endregion
396
+ // #region Extras
397
+ Booking.prototype.getExtras = function () {
398
+ return __awaiter(this, arguments, void 0, function (_a) {
399
+ var searchParams, url;
400
+ var _b = _a === void 0 ? {} : _a, extraId = _b.extraId, tariffPlanId = _b.tariffPlanId;
401
+ return __generator(this, function (_c) {
402
+ searchParams = new URLSearchParams(__assign(__assign({}, (extraId && { extraId: extraId.toString() })), (tariffPlanId && { tariffPlanId: tariffPlanId.toString() })));
403
+ url = "".concat(this.config.API_ENDPOINT, "/v3_resources/extras?").concat(searchParams);
404
+ return [2 /*return*/, this.callGetApi(url)];
405
+ });
406
+ });
407
+ };
408
+ /**
409
+ * Fetches extras tariffs for the given cart
410
+ * @param cartGuid The guid of the cart
411
+ * @param tripId The ID of the trip for which the extras are requested. Please note that this
412
+ * parameter is required when adding extras to a MLP or services cart.
413
+ */
414
+ Booking.prototype.getExtrasForBooking = function (cartGuid, tripId) {
415
+ return __awaiter(this, void 0, void 0, function () {
416
+ var searchParams, url;
417
+ return __generator(this, function (_a) {
418
+ searchParams = new URLSearchParams(__assign({ cartGuid: cartGuid }, (tripId && { tripId: tripId.toString() })));
419
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/extras?").concat(searchParams);
420
+ return [2 /*return*/, this.callGetApi(url)];
421
+ });
422
+ });
423
+ };
424
+ /**
425
+ * Updates the extras associated with a cart, removing all previous ones.
426
+ * @param cartGuid The guid of the cart
427
+ * @param tariffIdToQuantity A map of tariff ids to the quantity of tickets to add for that tariff
428
+ */
429
+ Booking.prototype.updateExtrasForCart = function (cartGuid, tariffIdToQuantity) {
430
+ return __awaiter(this, void 0, void 0, function () {
431
+ var body, url, res;
432
+ return __generator(this, function (_a) {
433
+ switch (_a.label) {
434
+ case 0:
435
+ body = {
436
+ cartGuid: cartGuid,
437
+ tariffIdToQuantity: tariffIdToQuantity
438
+ };
439
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/extras");
440
+ return [4 /*yield*/, this.callPutApi(url, body)];
441
+ case 1:
442
+ res = _a.sent();
443
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(res)) {
444
+ return [2 /*return*/, res];
445
+ }
446
+ return [4 /*yield*/, this.fetchAndSetCart(cartGuid)];
447
+ case 2:
448
+ _a.sent();
449
+ return [2 /*return*/, res];
450
+ }
451
+ });
452
+ });
453
+ };
353
454
  return Booking;
354
455
  }());
355
456
  exports.Booking = Booking;
@@ -1,5 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
- import { Buyer, EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
2
+ import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } 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";
@@ -14,54 +14,47 @@ export declare class JourneyBooking extends Booking {
14
14
  constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
15
15
  getCart(): JourneyCart | undefined;
16
16
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
17
- cartId: number | undefined;
18
17
  cartGuid: string | undefined;
19
18
  } & {
20
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
19
+ updateCartGuid: (cartGuid: string | undefined) => void;
21
20
  resetState: () => void;
22
21
  }>, "persist"> & {
23
22
  persist: {
24
23
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
25
- cartId: number | undefined;
26
24
  cartGuid: string | undefined;
27
25
  } & {
28
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
26
+ updateCartGuid: (cartGuid: string | undefined) => void;
29
27
  resetState: () => void;
30
28
  }, {
31
- cartId: number | undefined;
32
29
  cartGuid: string | undefined;
33
30
  } & {
34
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
31
+ updateCartGuid: (cartGuid: string | undefined) => void;
35
32
  resetState: () => void;
36
33
  }>>) => void;
37
34
  clearStorage: () => void;
38
35
  rehydrate: () => Promise<void> | void;
39
36
  hasHydrated: () => boolean;
40
37
  onHydrate: (fn: (state: {
41
- cartId: number | undefined;
42
38
  cartGuid: string | undefined;
43
39
  } & {
44
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
40
+ updateCartGuid: (cartGuid: string | undefined) => void;
45
41
  resetState: () => void;
46
42
  }) => void) => () => void;
47
43
  onFinishHydration: (fn: (state: {
48
- cartId: number | undefined;
49
44
  cartGuid: string | undefined;
50
45
  } & {
51
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
46
+ updateCartGuid: (cartGuid: string | undefined) => void;
52
47
  resetState: () => void;
53
48
  }) => void) => () => void;
54
49
  getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
55
- cartId: number | undefined;
56
50
  cartGuid: string | undefined;
57
51
  } & {
58
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
52
+ updateCartGuid: (cartGuid: string | undefined) => void;
59
53
  resetState: () => void;
60
54
  }, {
61
- cartId: number | undefined;
62
55
  cartGuid: string | undefined;
63
56
  } & {
64
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
57
+ updateCartGuid: (cartGuid: string | undefined) => void;
65
58
  resetState: () => void;
66
59
  }>>;
67
60
  };
@@ -101,12 +94,6 @@ export declare class JourneyBooking extends Booking {
101
94
  * as well as a list of the available tariffs for each trip.
102
95
  */
103
96
  getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
104
- /**
105
- * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
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.
108
- */
109
- getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
110
97
  /**
111
98
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
112
99
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
@@ -35,8 +35,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
35
35
  });
36
36
  };
37
37
  var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
39
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
40
  function verb(n) { return function (v) { return step([n, v]); }; }
41
41
  function step(op) {
42
42
  if (f) throw new TypeError("Generator is already executing.");
@@ -99,11 +99,8 @@ var JourneyBooking = /** @class */ (function (_super) {
99
99
  resellerId: resellerId,
100
100
  dbType: dbType
101
101
  }) || this;
102
- // Set cartId & cartGuid
103
- var _b = _this.getStorage().getState(), cartId = _b.cartId, cartGuid = _b.cartGuid;
104
- if (cartId && restoreState) {
105
- _this.cartId = cartId;
106
- }
102
+ // Set cartGuid
103
+ var cartGuid = _this.getStorage().getState().cartGuid;
107
104
  if (cartGuid && restoreState) {
108
105
  _this.cartGuid = cartGuid;
109
106
  }
@@ -120,16 +117,15 @@ var JourneyBooking = /** @class */ (function (_super) {
120
117
  };
121
118
  JourneyBooking.prototype.resetBooking = function () {
122
119
  this.cart = undefined;
123
- this.cartId = undefined;
124
120
  this.cartGuid = undefined;
125
121
  this.bookingStepsToStatus = new Map();
126
122
  this.bookingDueDate = undefined;
127
123
  try {
128
- this.getStorage().getState().updateCartId(undefined, undefined);
124
+ this.getStorage().getState().updateCartGuid(undefined);
129
125
  }
130
126
  catch (e) {
131
127
  if (this.config.ENV !== config_1.MTSEnvs.TEST) {
132
- throw new Error("Error while deleting cartId from storage.");
128
+ throw new Error("Error while deleting cartGuid from storage.");
133
129
  }
134
130
  console.log(e);
135
131
  }
@@ -145,7 +141,6 @@ var JourneyBooking = /** @class */ (function (_super) {
145
141
  cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
146
142
  if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
147
143
  _this.cart = cart;
148
- _this.cartId = cart.id;
149
144
  _this.cartGuid = cart.guid;
150
145
  _this.bookingDueDate = cartDueDate; // See Booking class
151
146
  // Update the sellerId. This is particularly important in Linkavel
@@ -259,7 +254,7 @@ var JourneyBooking = /** @class */ (function (_super) {
259
254
  if (request.departureStopName === undefined || request.destinationStopName === undefined) {
260
255
  throw Error("Fields departureStopName and destinationStopName are required");
261
256
  }
262
- 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 })));
257
+ searchParams = new URLSearchParams(__assign({ departureStopName: request.departureStopName, destinationStopName: request.destinationStopName, passengersNumber: request.passengersNumber.toString(), date: request.date, roundTripDate: request.roundTripDate ? request.roundTripDate : "null", currency: request.currency }, (this.cartGuid && { cartGuid: this.cartGuid })));
263
258
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys?").concat(searchParams);
264
259
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
265
260
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
@@ -279,15 +274,14 @@ var JourneyBooking = /** @class */ (function (_super) {
279
274
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
280
275
  // Check for errors
281
276
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
282
- // If there was an error, reset cartId and remove it from the mts-storage
277
+ // If there was an error, reset cartGuid and remove it from the mts-storage
283
278
  _this.resetBooking();
284
279
  return response;
285
280
  }
286
281
  _this.cart = response.cart;
287
- _this.cartId = response.cart.id;
288
282
  _this.cartGuid = response.cart.guid;
289
- // Save the cartId in the storage
290
- _this.getStorage().getState().updateCartId(response.cart.id, response.cart.guid);
283
+ // Save the cartGuid in the storage
284
+ _this.getStorage().getState().updateCartGuid(response.cart.guid);
291
285
  // Fill the booking process status
292
286
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
293
287
  var cartDueDate = new Date();
@@ -355,40 +349,6 @@ var JourneyBooking = /** @class */ (function (_super) {
355
349
  });
356
350
  });
357
351
  };
358
- // TODO: rename this as getPerson and use personDetails as return type
359
- /**
360
- * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
361
- * @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
362
- * @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
363
- */
364
- JourneyBooking.prototype.getBuyer = function (request) {
365
- return __awaiter(this, void 0, void 0, function () {
366
- var buyerPassengersDetails, searchParams, url;
367
- var _a;
368
- return __generator(this, function (_b) {
369
- // First check that it is possible to call this API
370
- if (!this.cart) {
371
- throw Error("Cart is not initialized yet");
372
- }
373
- buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
374
- if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
375
- throw Error("The status of the cart does not allow to call this API");
376
- }
377
- if (!request.personId && !request.personCode && !request.phoneNumber) {
378
- throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
379
- }
380
- 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 })));
381
- url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
382
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
383
- // Check for errors
384
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
385
- return response;
386
- }
387
- return response.persons[0];
388
- })];
389
- });
390
- });
391
- };
392
352
  /**
393
353
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
394
354
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
@@ -448,10 +408,11 @@ var JourneyBooking = /** @class */ (function (_super) {
448
408
  throw Error("The status of the cart does not allow to call this API");
449
409
  }
450
410
  searchParams = new URLSearchParams({
411
+ tripId: tripId.toString(),
451
412
  departureStopId: departureStopId.toString(),
452
413
  destinationStopId: destinationStopId.toString()
453
414
  });
454
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/").concat(tripId, "/seats?").concat(searchParams);
415
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/journeys/trips/seats?").concat(searchParams);
455
416
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
456
417
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
457
418
  ? response
@@ -593,7 +554,7 @@ var JourneyBooking = /** @class */ (function (_super) {
593
554
  _c.label = 5;
594
555
  case 5:
595
556
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
596
- return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartId: this.cartId, cartGuid: this.cartGuid })).then(function (response) {
557
+ return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid })).then(function (response) {
597
558
  var _a, _b;
598
559
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
599
560
  return response;
@@ -628,7 +589,10 @@ var JourneyBooking = /** @class */ (function (_super) {
628
589
  if (!discountsStep || !discountsStep[0]) {
629
590
  throw Error("The status of the cart does not allow to call this API");
630
591
  }
631
- queryParams = new URLSearchParams({ tripId: tripId.toString(), cartId: this.cartId.toString(), cartGuid: this.cartGuid });
592
+ queryParams = new URLSearchParams({
593
+ tripId: tripId.toString(),
594
+ cartGuid: this.cartGuid
595
+ });
632
596
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
633
597
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
634
598
  var _a, _b, _c;
@@ -697,7 +661,7 @@ var JourneyBooking = /** @class */ (function (_super) {
697
661
  _c.label = 5;
698
662
  case 5:
699
663
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
700
- return [2 /*return*/, this.callPostApi(url, { cartId: this.cartId, cartGuid: this.cartGuid }).then(function (response) {
664
+ return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }).then(function (response) {
701
665
  var _a, _b;
702
666
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
703
667
  return response;
@@ -727,7 +691,7 @@ var JourneyBooking = /** @class */ (function (_super) {
727
691
  if ((0, utils_1.isNullOrWhiteSpace)(this.cartGuid)) {
728
692
  throw Error("Cart is not initialized yet");
729
693
  }
730
- queryParams = new URLSearchParams({ cartId: this.cartId.toString(), cartGuid: this.cartGuid });
694
+ queryParams = new URLSearchParams({ cartGuid: this.cartGuid });
731
695
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
732
696
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
733
697
  var _a, _b, _c;
@@ -839,11 +803,10 @@ exports.JourneyBooking = JourneyBooking;
839
803
  case 3: return [2 /*return*/, booking];
840
804
  case 4:
841
805
  error_1 = _c.sent();
842
- // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
806
+ // Check if the error is due to an expired cart. In this case, delete the cartGuid from the mts-storage
843
807
  // This error can occur when the user refreshes the page and the cart has expired
844
808
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
845
- booking.getStorage().getState().updateCartId(undefined, undefined);
846
- booking.cartId = undefined;
809
+ booking.getStorage().getState().updateCartGuid(undefined);
847
810
  booking.cartGuid = undefined;
848
811
  return [2 /*return*/, booking];
849
812
  }
@@ -1,5 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
- import { Buyer, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
2
+ import { PersonDetails, GetBuyerPassengersDetailsResponse } 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";
@@ -11,54 +11,47 @@ export declare class ServiceBooking extends Booking {
11
11
  */
12
12
  constructor({ env, subKey, debug, language, sessionId, restoreState, accessToken, sellerId, resellerId, dbType }: Omit<Booking.BookingConfig, "bookingType">);
13
13
  getStorage(): import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
14
- cartId: number | undefined;
15
14
  cartGuid: string | undefined;
16
15
  } & {
17
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
16
+ updateCartGuid: (cartGuid: string | undefined) => void;
18
17
  resetState: () => void;
19
18
  }>, "persist"> & {
20
19
  persist: {
21
20
  setOptions: (options: Partial<import("zustand/middleware").PersistOptions<{
22
- cartId: number | undefined;
23
21
  cartGuid: string | undefined;
24
22
  } & {
25
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
23
+ updateCartGuid: (cartGuid: string | undefined) => void;
26
24
  resetState: () => void;
27
25
  }, {
28
- cartId: number | undefined;
29
26
  cartGuid: string | undefined;
30
27
  } & {
31
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
28
+ updateCartGuid: (cartGuid: string | undefined) => void;
32
29
  resetState: () => void;
33
30
  }>>) => void;
34
31
  clearStorage: () => void;
35
32
  rehydrate: () => Promise<void> | void;
36
33
  hasHydrated: () => boolean;
37
34
  onHydrate: (fn: (state: {
38
- cartId: number | undefined;
39
35
  cartGuid: string | undefined;
40
36
  } & {
41
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
37
+ updateCartGuid: (cartGuid: string | undefined) => void;
42
38
  resetState: () => void;
43
39
  }) => void) => () => void;
44
40
  onFinishHydration: (fn: (state: {
45
- cartId: number | undefined;
46
41
  cartGuid: string | undefined;
47
42
  } & {
48
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
43
+ updateCartGuid: (cartGuid: string | undefined) => void;
49
44
  resetState: () => void;
50
45
  }) => void) => () => void;
51
46
  getOptions: () => Partial<import("zustand/middleware").PersistOptions<{
52
- cartId: number | undefined;
53
47
  cartGuid: string | undefined;
54
48
  } & {
55
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
49
+ updateCartGuid: (cartGuid: string | undefined) => void;
56
50
  resetState: () => void;
57
51
  }, {
58
- cartId: number | undefined;
59
52
  cartGuid: string | undefined;
60
53
  } & {
61
- updateCartId: (cartId: number | undefined, cartGuid: string | undefined) => void;
54
+ updateCartGuid: (cartGuid: string | undefined) => void;
62
55
  resetState: () => void;
63
56
  }>>;
64
57
  };
@@ -103,19 +96,13 @@ export declare class ServiceBooking extends Booking {
103
96
  * as well as a list of the available tariffs for each trip.
104
97
  */
105
98
  getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
106
- /**
107
- * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
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.
110
- */
111
- getBuyer(request: GetBuyerRequest): Promise<ErrorResponse | Buyer>;
112
99
  /**
113
100
  * @description This method shall be called when the user wants to update the buyer information.
114
101
  * @param buyerDetails The object containing the buyer information.
115
102
  * It should be null if the buyer data cannot be specified (see {@link GetBuyerPassengersDetailsResponse.buyerDataStatus}).
116
103
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
117
104
  */
118
- updateBuyerPassengersDetails(buyerDetails: Buyer | null): Promise<ErrorResponse | boolean>;
105
+ updateBuyerPassengersDetails(buyerDetails: PersonDetails | null): Promise<ErrorResponse | boolean>;
119
106
  /**
120
107
  * @description This method allows to add a reduction to the whole cart or to a single trip in the cart.
121
108
  * @param {AddReductionRequest} request The information about the reduction to add