mts-booking-library 3.0.14 → 3.2.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.
@@ -78,11 +78,13 @@ export declare abstract class Booking {
78
78
  /**
79
79
  * @description This method shall be used to get all necessary informations to initialize a payment with a certain gateway.
80
80
  * @param gatewayId The id of the gateway to use. Its value shall be taken from the response of the {@link Booking.getSellerGateways} API
81
- * @param returnUrl The url to which the user will be redirected after the payment. This value shall be set only if the
82
- * chosen gateway is {@link GatewayTypes.PAYPAL} or {@link GatewayTypes.WORLDLINE}
81
+ * @param returnOrigin The FE origin (scheme+host+port, e.g. `window.location.origin`) that the gateway should redirect
82
+ * back to after the payment. The BE validates this against a per-app allowlist and stitches the canonical
83
+ * `/booking?step=BOOKING_STEP_PAYMENT_PROCESSING&cartGuid={guid}` path on top. Pass `window.location.origin` from the
84
+ * caller — the BE owns the rest. Replaces the legacy full-URL `returnUrl` parameter (BE 3.2.0+).
83
85
  * @returns An {@link ErrorResponse} object in case of error, a {@link GetPaymentInformationFromGatewayResponse} object otherwise.
84
86
  */
85
- getPaymentInformationFromGateway(gatewayId: number, returnUrl?: string, options?: ApiCallOptions): Promise<ErrorResponse | GetPaymentInformationFromGatewayResponse>;
87
+ getPaymentInformationFromGateway(gatewayId: number, returnOrigin: string, options?: ApiCallOptions): Promise<ErrorResponse | GetPaymentInformationFromGatewayResponse>;
86
88
  /**
87
89
  * @description This method shall be used to issue the tickets. It must be called after the payment was successful.
88
90
  * @param paymentMethod The payment method used to pay the cart. If the chosen method is {@link PaymentMethods.ZERO_COST},
@@ -285,11 +285,13 @@ var Booking = /** @class */ (function () {
285
285
  /**
286
286
  * @description This method shall be used to get all necessary informations to initialize a payment with a certain gateway.
287
287
  * @param gatewayId The id of the gateway to use. Its value shall be taken from the response of the {@link Booking.getSellerGateways} API
288
- * @param returnUrl The url to which the user will be redirected after the payment. This value shall be set only if the
289
- * chosen gateway is {@link GatewayTypes.PAYPAL} or {@link GatewayTypes.WORLDLINE}
288
+ * @param returnOrigin The FE origin (scheme+host+port, e.g. `window.location.origin`) that the gateway should redirect
289
+ * back to after the payment. The BE validates this against a per-app allowlist and stitches the canonical
290
+ * `/booking?step=BOOKING_STEP_PAYMENT_PROCESSING&cartGuid={guid}` path on top. Pass `window.location.origin` from the
291
+ * caller — the BE owns the rest. Replaces the legacy full-URL `returnUrl` parameter (BE 3.2.0+).
290
292
  * @returns An {@link ErrorResponse} object in case of error, a {@link GetPaymentInformationFromGatewayResponse} object otherwise.
291
293
  */
292
- Booking.prototype.getPaymentInformationFromGateway = function (gatewayId, returnUrl, options) {
294
+ Booking.prototype.getPaymentInformationFromGateway = function (gatewayId, returnOrigin, options) {
293
295
  return __awaiter(this, void 0, void 0, function () {
294
296
  var issueStep, searchParams, url;
295
297
  return __generator(this, function (_a) {
@@ -301,7 +303,7 @@ var Booking = /** @class */ (function () {
301
303
  if (!issueStep || !issueStep[0]) {
302
304
  throw Error("The status of the cart does not allow to call this API");
303
305
  }
304
- searchParams = new URLSearchParams(__assign({ gatewayId: gatewayId.toString(), cartGuid: this.cartGuid }, (returnUrl && { returnUrl: returnUrl })));
306
+ searchParams = new URLSearchParams(__assign({ gatewayId: gatewayId.toString(), cartGuid: this.cartGuid }, (returnOrigin && { returnOrigin: returnOrigin })));
305
307
  url = "".concat(this.config.API_ENDPOINT, "/v3_payment/paymentInformation?").concat(searchParams);
306
308
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
307
309
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
@@ -134,17 +134,20 @@ var JourneyBooking = /** @class */ (function (_super) {
134
134
  };
135
135
  JourneyBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
136
136
  return __awaiter(this, void 0, void 0, function () {
137
- var cart;
138
- return __generator(this, function (_a) {
139
- switch (_a.label) {
137
+ var cart, isDeadCart;
138
+ var _a, _b;
139
+ return __generator(this, function (_c) {
140
+ switch (_c.label) {
140
141
  case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
141
142
  case 1:
142
- cart = _a.sent();
143
+ cart = _c.sent();
143
144
  if (!cart)
144
145
  return [2 /*return*/];
146
+ isDeadCart = cart.hasCanceledTickets === true && ((_b = (_a = cart.bookings) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0;
145
147
  if (cart.bookingDueDateTime &&
146
148
  new Date(cart.bookingDueDateTime.dateTime) > new Date() &&
147
- !cart.hasIssuedTickets) {
149
+ !cart.hasIssuedTickets &&
150
+ !isDeadCart) {
148
151
  this.cart = cart;
149
152
  this.cartGuid = cart.guid;
150
153
  this.bookingDueDateTime = cart.bookingDueDateTime; // See Booking class
@@ -134,17 +134,20 @@ var ServiceBooking = /** @class */ (function (_super) {
134
134
  };
135
135
  ServiceBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
136
136
  return __awaiter(this, void 0, void 0, function () {
137
- var cart;
138
- return __generator(this, function (_a) {
139
- switch (_a.label) {
137
+ var cart, isDeadCart;
138
+ var _a, _b;
139
+ return __generator(this, function (_c) {
140
+ switch (_c.label) {
140
141
  case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
141
142
  case 1:
142
- cart = _a.sent();
143
+ cart = _c.sent();
143
144
  if (!cart)
144
145
  return [2 /*return*/];
146
+ isDeadCart = cart.hasCanceledTickets === true && ((_b = (_a = cart.bookings) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0;
145
147
  if (cart.bookingDueDateTime &&
146
148
  new Date(cart.bookingDueDateTime.dateTime) > new Date() &&
147
- !cart.hasIssuedTickets) {
149
+ !cart.hasIssuedTickets &&
150
+ !isDeadCart) {
148
151
  this.cart = cart;
149
152
  this.cartGuid = cart.guid;
150
153
  this.bookingDueDateTime = cart.bookingDueDateTime; // See Booking class
@@ -134,17 +134,20 @@ var SubscriptionBooking = /** @class */ (function (_super) {
134
134
  };
135
135
  SubscriptionBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
136
136
  return __awaiter(this, void 0, void 0, function () {
137
- var cart;
138
- return __generator(this, function (_a) {
139
- switch (_a.label) {
137
+ var cart, isDeadCart;
138
+ var _a, _b;
139
+ return __generator(this, function (_c) {
140
+ switch (_c.label) {
140
141
  case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
141
142
  case 1:
142
- cart = _a.sent();
143
+ cart = _c.sent();
143
144
  if (!cart)
144
145
  return [2 /*return*/];
146
+ isDeadCart = cart.hasCanceledTickets === true && ((_b = (_a = cart.bookings) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0;
145
147
  if (cart.bookingDueDateTime &&
146
148
  new Date(cart.bookingDueDateTime.dateTime) > new Date() &&
147
- !cart.hasIssuedTickets) {
149
+ !cart.hasIssuedTickets &&
150
+ !isDeadCart) {
148
151
  this.cart = cart;
149
152
  this.cartGuid = cart.guid;
150
153
  this.bookingDueDateTime = cart.bookingDueDateTime; // See Booking class
@@ -141,17 +141,20 @@ var TplBooking = /** @class */ (function (_super) {
141
141
  };
142
142
  TplBooking.prototype.fetchAndSetCart = function (cartGuid, options) {
143
143
  return __awaiter(this, void 0, void 0, function () {
144
- var cart;
145
- return __generator(this, function (_a) {
146
- switch (_a.label) {
144
+ var cart, isDeadCart;
145
+ var _a, _b;
146
+ return __generator(this, function (_c) {
147
+ switch (_c.label) {
147
148
  case 0: return [4 /*yield*/, this.fetchCart(cartGuid, options)];
148
149
  case 1:
149
- cart = _a.sent();
150
+ cart = _c.sent();
150
151
  if (!cart)
151
152
  return [2 /*return*/];
153
+ isDeadCart = cart.hasCanceledTickets === true && ((_b = (_a = cart.bookings) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) === 0;
152
154
  if (cart.bookingDueDateTime &&
153
155
  new Date(cart.bookingDueDateTime.dateTime) > new Date() &&
154
- !cart.hasIssuedTickets) {
156
+ !cart.hasIssuedTickets &&
157
+ !isDeadCart) {
155
158
  this.cart = cart;
156
159
  this.cartGuid = cart.guid;
157
160
  this.bookingDueDateTime = cart.bookingDueDateTime; // See Booking class
@@ -113,6 +113,14 @@ export type Cart = {
113
113
  * possible to add tickets to an issued cart. Thus, all data should be reset.
114
114
  */
115
115
  hasIssuedTickets: boolean;
116
+ /**
117
+ * True when at least one ticket attached to the cart has been canceled (e.g. all
118
+ * gateway transactions expired before capture and the parent service transaction
119
+ * also expired, auto-canceling the ticket). Combined with an empty `bookings`
120
+ * list this flags a dead cart that the library will drop from persisted state.
121
+ * Optional for forward compatibility against backends that pre-date the field.
122
+ */
123
+ hasCanceledTickets?: boolean;
116
124
  /** The booking due date as ISO string */
117
125
  bookingDueDateTime: DateWithTimeZone;
118
126
  /** The ids of the tickets in the cart */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "3.0.14",
3
+ "version": "3.2.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",