mts-booking-library 1.2.13 → 1.2.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { MTSConfig, MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
- import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
3
+ import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, Wallet } from "../types/common/Payment";
4
4
  import { GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
5
5
  import { AddReductionRequest } from "../types/common/Reduction";
6
6
  export declare abstract class Booking {
@@ -77,7 +77,7 @@ export declare abstract class Booking {
77
77
  * @description This method shall be used to get all necessary informations to initialize a payment with a certain gateway.
78
78
  * @param {number} gatewayId The id of the gateway to use. Its value shall be taken from the response of the {@link Booking.getSellerGateways} API
79
79
  * @param {string} [returnUrl=undefined] The url to which the user will be redirected after the payment. This value shall be set only if the
80
- * chosen gateway is {@link GatewayTypes.PAYPAL}
80
+ * chosen gateway is {@link GatewayTypes.PAYPAL} or {@link GatewayTypes.WORLDLINE}
81
81
  * @returns An {@link ErrorResponse} object in case of error, a {@link GetPaymentInformationFromGatewayResponse} object otherwise.
82
82
  */
83
83
  getPaymentInformationFromGateway(gatewayId: number, returnUrl?: string): Promise<ErrorResponse | GetPaymentInformationFromGatewayResponse>;
@@ -87,7 +87,10 @@ export declare abstract class Booking {
87
87
  * first the {@link Booking.addReduction} API is called with a 100% discount, then tickets are issued with the {@link PaymentMethods.CASH} method.
88
88
  * @returns An {@link ErrorResponse} object in case of error, nothing otherwise.
89
89
  */
90
- issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse | boolean>;
90
+ issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse | {
91
+ wallet: Wallet;
92
+ result: boolean;
93
+ }>;
91
94
  }
92
95
  export declare namespace Booking {
93
96
  enum Currencies {
@@ -231,7 +231,7 @@ var Booking = /** @class */ (function () {
231
231
  }
232
232
  _e.label = 5;
233
233
  case 5:
234
- url = "".concat(this.config.API_ENDPOINT, "/sellers/").concat(this.sellerId, "/gateways");
234
+ url = "".concat(this.config.API_ENDPOINT, "/sellers/").concat(this.sellerId, "/gateways?");
235
235
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
236
236
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response;
237
237
  })];
@@ -243,7 +243,7 @@ var Booking = /** @class */ (function () {
243
243
  * @description This method shall be used to get all necessary informations to initialize a payment with a certain gateway.
244
244
  * @param {number} gatewayId The id of the gateway to use. Its value shall be taken from the response of the {@link Booking.getSellerGateways} API
245
245
  * @param {string} [returnUrl=undefined] The url to which the user will be redirected after the payment. This value shall be set only if the
246
- * chosen gateway is {@link GatewayTypes.PAYPAL}
246
+ * chosen gateway is {@link GatewayTypes.PAYPAL} or {@link GatewayTypes.WORLDLINE}
247
247
  * @returns An {@link ErrorResponse} object in case of error, a {@link GetPaymentInformationFromGatewayResponse} object otherwise.
248
248
  */
249
249
  Booking.prototype.getPaymentInformationFromGateway = function (gatewayId, returnUrl) {
@@ -289,6 +289,7 @@ var Booking = /** @class */ (function () {
289
289
  if (typeof response === "boolean" && response) {
290
290
  // Reduction was successfully added. Set payment method to CASH
291
291
  paymentMethodToSet = Payment_1.PaymentMethods.CASH;
292
+ return true;
292
293
  }
293
294
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
294
295
  return response;
@@ -335,7 +336,7 @@ var Booking = /** @class */ (function () {
335
336
  paymentMethod: paymentMethodToSet === Payment_1.PaymentMethods.PAY_LATER ? null : paymentMethodToSet,
336
337
  };
337
338
  return [2 /*return*/, this.callPostApi(url, body).then(function (response) {
338
- return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : true;
339
+ return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : { wallet: response.wallet, result: true };
339
340
  })];
340
341
  }
341
342
  });
@@ -503,7 +503,7 @@ var JourneyBooking = /** @class */ (function (_super) {
503
503
  if (!this.cart) {
504
504
  throw Error("Cart is not initialized yet");
505
505
  }
506
- url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/payment/reduction/trips");
506
+ url = "".concat(this.config.API_ENDPOINT, "/booking/cart/").concat(this.cart.id, "/payment/reduction/trips?");
507
507
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
508
508
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response) ? response : response.trips;
509
509
  })];
@@ -47,6 +47,7 @@ export type GetPaymentInformationFromGatewayResponse = {
47
47
  */
48
48
  export declare enum GatewayTypes {
49
49
  AXEPTA_BNL = "AXEPTA_BNL",
50
+ WORLDLINE = "WORLDLINE",
50
51
  AXERVE_BANCASELLA = "AXERVE_BANCASELLA",
51
52
  PAYPAL = "PAYPAL"
52
53
  }
@@ -69,3 +70,10 @@ export declare enum PaymentMethods {
69
70
  WALLET = "WALLET",
70
71
  ZERO_COST = "ZERO_COST"
71
72
  }
73
+ export type Wallet = {
74
+ id: number;
75
+ sellerId: number;
76
+ resellerId: number;
77
+ balance: any;
78
+ walletTransactions: any[];
79
+ };
@@ -7,6 +7,7 @@ exports.PaymentMethods = exports.GatewayTypes = void 0;
7
7
  var GatewayTypes;
8
8
  (function (GatewayTypes) {
9
9
  GatewayTypes["AXEPTA_BNL"] = "AXEPTA_BNL";
10
+ GatewayTypes["WORLDLINE"] = "WORLDLINE";
10
11
  GatewayTypes["AXERVE_BANCASELLA"] = "AXERVE_BANCASELLA";
11
12
  GatewayTypes["PAYPAL"] = "PAYPAL";
12
13
  })(GatewayTypes || (exports.GatewayTypes = GatewayTypes = {}));
@@ -57,6 +57,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
57
57
  exports.makeDelete = exports.makePost = exports.makeGet = void 0;
58
58
  var axios_1 = require("axios");
59
59
  var config_1 = require("../config");
60
+ var removeNullError = function (resData) {
61
+ var filteredResponse = {};
62
+ Object.keys(resData).filter(function (key) { return key !== "error"; })
63
+ .map(function (key) {
64
+ var _a;
65
+ return filteredResponse = __assign(__assign({}, filteredResponse), (_a = {}, _a[key] = resData[key], _a));
66
+ });
67
+ return filteredResponse;
68
+ };
60
69
  var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function () {
61
70
  var debug;
62
71
  return __generator(this, function (_a) {
@@ -65,7 +74,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
65
74
  console.log("GET_RequestData", url);
66
75
  }
67
76
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
68
- var response_1, filteredResponse_1, error_1, resError, resError;
77
+ var response, filteredResponse, error_1, resError, resError;
69
78
  var _a, _b, _c;
70
79
  return __generator(this, function (_d) {
71
80
  switch (_d.label) {
@@ -75,17 +84,12 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
75
84
  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) })),
76
85
  })];
77
86
  case 1:
78
- response_1 = _d.sent();
79
- filteredResponse_1 = {};
80
- Object.keys(response_1.data).filter(function (key) { return key !== "error"; })
81
- .map(function (key) {
82
- var _a;
83
- return filteredResponse_1 = __assign(__assign({}, filteredResponse_1), (_a = {}, _a[key] = response_1.data[key], _a));
84
- });
87
+ response = _d.sent();
88
+ filteredResponse = removeNullError(response.data);
85
89
  if (debug) {
86
- console.log("GET_ResponseData", url, filteredResponse_1);
90
+ console.log("GET_ResponseData", url, filteredResponse);
87
91
  }
88
- resolve(filteredResponse_1);
92
+ resolve(filteredResponse);
89
93
  return [3 /*break*/, 3];
90
94
  case 2:
91
95
  error_1 = _d.sent();
@@ -120,7 +124,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
120
124
  console.log("POST_RequestData", url, data);
121
125
  }
122
126
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
123
- var response, error_2, resError;
127
+ var response, filteredResponse, error_2, resError;
124
128
  var _a, _b, _c, _d, _e;
125
129
  return __generator(this, function (_f) {
126
130
  switch (_f.label) {
@@ -131,10 +135,11 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
131
135
  })];
132
136
  case 1:
133
137
  response = _f.sent();
138
+ filteredResponse = removeNullError(response.data);
134
139
  if (debug) {
135
- console.log("POST_ResponseData", url, response.data);
140
+ console.log("POST_ResponseData", url, filteredResponse);
136
141
  }
137
- resolve(response.data);
142
+ resolve(filteredResponse);
138
143
  return [3 /*break*/, 3];
139
144
  case 2:
140
145
  error_2 = _f.sent();
@@ -169,7 +174,7 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
169
174
  console.log("DELETE_RequestData", url);
170
175
  }
171
176
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
172
- var response, error_3, resError;
177
+ var response, filteredResponse, error_3, resError;
173
178
  var _a, _b, _c, _d, _e;
174
179
  return __generator(this, function (_f) {
175
180
  switch (_f.label) {
@@ -180,10 +185,11 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
180
185
  })];
181
186
  case 1:
182
187
  response = _f.sent();
188
+ filteredResponse = removeNullError(response.data);
183
189
  if (debug) {
184
- console.log("DELETE_ResponseData", url, response.data);
190
+ console.log("DELETE_ResponseData", url, filteredResponse);
185
191
  }
186
- resolve(response.data);
192
+ resolve(filteredResponse);
187
193
  return [3 /*break*/, 3];
188
194
  case 2:
189
195
  error_3 = _f.sent();
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
3
+ * @param {Date | string} date the date to convert
4
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
5
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
6
+ * @returns {string} the ISO string
7
+ */
8
+ export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getISOStringWithoutGMT = void 0;
4
+ /**
5
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
6
+ * @param {Date | string} date the date to convert
7
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
8
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
9
+ * @returns {string} the ISO string
10
+ */
11
+ var getISOStringWithoutGMT = function (date, removeTimezone) {
12
+ if (removeTimezone === void 0) { removeTimezone = true; }
13
+ if (!date)
14
+ return null;
15
+ var newDate = new Date(date);
16
+ var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
17
+ return removeTimezone ? isoString.slice(0, -1) : isoString;
18
+ };
19
+ exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.13",
3
+ "version": "1.2.15",
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.10",
17
+ "@types/jest": "^29.5.11",
18
18
  "jest": "^29.7.0",
19
19
  "ts-jest": "^29.1.1",
20
- "typescript": "^5.3.2"
20
+ "typescript": "^5.3.3"
21
21
  },
22
22
  "files": [
23
23
  "lib/**/*"