@houlak/plexo-sdk 0.1.0 → 0.1.1-fx

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.
Files changed (139) hide show
  1. package/lib/handler/PlexoHandler.d.ts +21 -10
  2. package/lib/handler/PlexoHandler.js +179 -29
  3. package/lib/index.d.ts +1 -0
  4. package/lib/index.js +4 -1
  5. package/lib/lib/logger.lib.d.ts +1 -6
  6. package/lib/lib/logger.lib.js +10 -6
  7. package/lib/models/Authorization.d.ts +2 -0
  8. package/lib/models/BuiltInPagesOptionsDto.d.ts +4 -0
  9. package/lib/models/BuiltInPagesOptionsDto.js +9 -0
  10. package/lib/models/DisplayOptionsDto.d.ts +7 -0
  11. package/lib/models/DisplayOptionsDto.js +9 -0
  12. package/lib/models/ExpressCheckoutSettingsDto.d.ts +6 -0
  13. package/lib/models/ExpressCheckoutSettingsDto.js +9 -0
  14. package/lib/models/IssuerProcessor.d.ts +4 -4
  15. package/lib/models/IssuerProcessor.js +4 -4
  16. package/lib/models/TokenizationSettingsDto.d.ts +4 -0
  17. package/lib/models/TokenizationSettingsDto.js +9 -0
  18. package/lib/models/UIOptionsDto.d.ts +7 -0
  19. package/lib/models/UIOptionsDto.js +13 -0
  20. package/lib/models/WebFormSettingsDto.d.ts +8 -0
  21. package/lib/models/WebFormSettingsDto.js +9 -0
  22. package/lib/sdk/IPaymentGatewayClient.d.ts +8 -7
  23. package/lib/sdk/PaymentGatewayClient.d.ts +8 -7
  24. package/lib/sdk/PaymentGatewayClient.js +45 -45
  25. package/lib/sdk/PaymentGatewayMock.d.ts +2 -2
  26. package/lib/sdk/PaymentGatewayMock.js +2 -8
  27. package/lib/sdk/enums/plexo-error-enum.d.ts +1 -0
  28. package/lib/sdk/enums/plexo-error-enum.js +1 -0
  29. package/lib/sdk/helpers/signature/signatureHelper.d.ts +3 -7
  30. package/lib/sdk/helpers/signature/signatureHelper.js +71 -201
  31. package/lib/sdk/helpers/signature/signatureUtils.d.ts +10 -0
  32. package/lib/sdk/helpers/signature/signatureUtils.js +155 -0
  33. package/lib/sdk/helpers/signature/stringifyWithFloats.js +2 -0
  34. package/lib/sdk/mocks/mocks.js +2 -0
  35. package/lib/sdk/models/Authorization.d.ts +4 -5
  36. package/lib/sdk/models/Authorization.js +3 -2
  37. package/lib/sdk/models/AuthorizationInfo.d.ts +3 -2
  38. package/lib/sdk/models/AuthorizationInfo.js +24 -5
  39. package/lib/sdk/models/BuiltInPagesOptions.d.ts +5 -0
  40. package/lib/sdk/models/BuiltInPagesOptions.js +11 -0
  41. package/lib/sdk/models/CancelRequest.d.ts +1 -1
  42. package/lib/sdk/models/CancelRequest.js +2 -2
  43. package/lib/sdk/models/CodeRequest.d.ts +4 -2
  44. package/lib/sdk/models/CodeRequest.js +28 -0
  45. package/lib/sdk/models/CommerceIdRequest.d.ts +4 -2
  46. package/lib/sdk/models/CommerceIdRequest.js +27 -0
  47. package/lib/sdk/models/CommerceIssuerIdRequest.d.ts +4 -2
  48. package/lib/sdk/models/CommerceIssuerIdRequest.js +28 -0
  49. package/lib/sdk/models/CommerceModifyRequest.d.ts +4 -2
  50. package/lib/sdk/models/CommerceModifyRequest.js +28 -0
  51. package/lib/sdk/models/CommerceRequest.d.ts +4 -2
  52. package/lib/sdk/models/CommerceRequest.js +27 -0
  53. package/lib/sdk/models/CreateBankInstrumentRequest.d.ts +4 -2
  54. package/lib/sdk/models/CreateBankInstrumentRequest.js +29 -0
  55. package/lib/sdk/models/DeleteInstrumentRequest.d.ts +1 -1
  56. package/lib/sdk/models/DeleteInstrumentRequest.js +2 -2
  57. package/lib/sdk/models/DisplayOptions.d.ts +8 -0
  58. package/lib/sdk/models/DisplayOptions.js +14 -0
  59. package/lib/sdk/models/ExpressCheckoutSettings.d.ts +7 -0
  60. package/lib/sdk/models/ExpressCheckoutSettings.js +11 -0
  61. package/lib/sdk/models/FieldType.d.ts +6 -0
  62. package/lib/sdk/models/FieldType.js +6 -0
  63. package/lib/sdk/models/FixedCustomData.d.ts +5 -0
  64. package/lib/sdk/models/FixedCustomData.js +11 -0
  65. package/lib/sdk/models/IndexSDK.d.ts +8 -6
  66. package/lib/sdk/models/IndexSDK.js +32 -14
  67. package/lib/sdk/models/IssuerData.d.ts +6 -2
  68. package/lib/sdk/models/IssuerData.js +31 -0
  69. package/lib/sdk/models/PaymentRequest.d.ts +3 -2
  70. package/lib/sdk/models/PaymentRequest.js +33 -14
  71. package/lib/sdk/models/Reference.d.ts +4 -2
  72. package/lib/sdk/models/Reference.js +25 -5
  73. package/lib/sdk/models/Reserve.d.ts +1 -1
  74. package/lib/sdk/models/Reserve.js +2 -2
  75. package/lib/sdk/models/ReserveRequest.d.ts +1 -1
  76. package/lib/sdk/models/ReserveRequest.js +2 -2
  77. package/lib/sdk/models/TokenizationSettings.d.ts +5 -0
  78. package/lib/sdk/models/TokenizationSettings.js +10 -0
  79. package/lib/sdk/models/TransactionQuery.d.ts +4 -2
  80. package/lib/sdk/models/TransactionQuery.js +30 -1
  81. package/lib/sdk/models/TransactionsCSV.d.ts +3 -0
  82. package/lib/sdk/models/TransactionsCSV.js +2 -0
  83. package/lib/sdk/models/UIOptions.d.ts +8 -0
  84. package/lib/sdk/models/UIOptions.js +13 -0
  85. package/lib/sdk/models/WebFormSettings.d.ts +9 -0
  86. package/lib/sdk/models/WebFormSettings.js +12 -0
  87. package/lib/sdk/models/webhook/Address.d.ts +9 -0
  88. package/lib/sdk/models/webhook/Address.js +15 -0
  89. package/lib/sdk/models/webhook/CancellationInfo.d.ts +11 -0
  90. package/lib/sdk/models/webhook/CancellationInfo.js +17 -0
  91. package/lib/sdk/models/webhook/Client.d.ts +9 -0
  92. package/lib/sdk/models/webhook/Client.js +14 -0
  93. package/lib/sdk/models/webhook/Commerce.d.ts +6 -0
  94. package/lib/sdk/models/webhook/Commerce.js +12 -0
  95. package/lib/sdk/models/webhook/Currency.d.ts +8 -0
  96. package/lib/sdk/models/webhook/Currency.js +14 -0
  97. package/lib/sdk/models/webhook/Customer.d.ts +17 -0
  98. package/lib/sdk/models/webhook/Customer.js +22 -0
  99. package/lib/sdk/models/webhook/Document.d.ts +5 -0
  100. package/lib/sdk/models/webhook/Document.js +11 -0
  101. package/lib/sdk/models/webhook/IndexWebhook.d.ts +21 -0
  102. package/lib/sdk/models/webhook/IndexWebhook.js +45 -0
  103. package/lib/sdk/models/webhook/Instrument.d.ts +17 -0
  104. package/lib/sdk/models/webhook/Instrument.js +21 -0
  105. package/lib/sdk/models/webhook/Issuer.d.ts +8 -0
  106. package/lib/sdk/models/webhook/Issuer.js +14 -0
  107. package/lib/sdk/models/webhook/IssuerData.d.ts +8 -0
  108. package/lib/sdk/models/webhook/IssuerData.js +13 -0
  109. package/lib/sdk/models/webhook/IssuerDto.d.ts +5 -0
  110. package/lib/sdk/models/webhook/IssuerDto.js +11 -0
  111. package/lib/sdk/models/webhook/Item.d.ts +14 -0
  112. package/lib/sdk/models/webhook/Item.js +19 -0
  113. package/lib/sdk/models/webhook/PartialRefundsInfo.d.ts +12 -0
  114. package/lib/sdk/models/webhook/PartialRefundsInfo.js +18 -0
  115. package/lib/sdk/models/webhook/PaymentFacilitator.d.ts +8 -0
  116. package/lib/sdk/models/webhook/PaymentFacilitator.js +13 -0
  117. package/lib/sdk/models/webhook/PaymentProcessor.d.ts +5 -0
  118. package/lib/sdk/models/webhook/PaymentProcessor.js +11 -0
  119. package/lib/sdk/models/webhook/PurchaseInfo.d.ts +16 -0
  120. package/lib/sdk/models/webhook/PurchaseInfo.js +22 -0
  121. package/lib/sdk/models/webhook/RefundInfo.d.ts +12 -0
  122. package/lib/sdk/models/webhook/RefundInfo.js +18 -0
  123. package/lib/sdk/models/webhook/ReserveInfo.d.ts +13 -0
  124. package/lib/sdk/models/webhook/ReserveInfo.js +19 -0
  125. package/lib/sdk/models/webhook/Shipping.d.ts +7 -0
  126. package/lib/sdk/models/webhook/Shipping.js +12 -0
  127. package/lib/sdk/models/webhook/Transaction.d.ts +31 -0
  128. package/lib/sdk/models/webhook/Transaction.js +36 -0
  129. package/lib/sdk/models/webhook/TransactionResult.d.ts +5 -0
  130. package/lib/sdk/models/webhook/TransactionResult.js +10 -0
  131. package/lib/sdk/models/webhook/index.d.ts +21 -0
  132. package/lib/sdk/models/webhook/index.js +45 -0
  133. package/lib/utils/boolean.utils.d.ts +4 -0
  134. package/lib/utils/boolean.utils.js +53 -0
  135. package/lib/utils/case.util.d.ts +4 -0
  136. package/lib/utils/case.util.js +61 -0
  137. package/lib/utils/index.d.ts +1 -0
  138. package/lib/utils/index.js +5 -0
  139. package/package.json +3 -3
@@ -36,159 +36,21 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.SignatureHelper = exports.canonizeJson = void 0;
39
+ exports.SignatureHelper = void 0;
40
40
  var axios_1 = require("axios");
41
- var fs = require("fs");
42
- var pem = require("pem");
43
41
  var crypto_1 = require("crypto");
44
- var js_convert_case_1 = require("js-convert-case");
45
- var util_1 = require("util");
46
- var logger_lib_1 = require("../../../lib/logger.lib");
47
- var config_1 = require("../../../config/config");
48
42
  var __1 = require("../..");
49
- var stringifyWithFloats_1 = require("./stringifyWithFloats");
50
- var client = axios_1.default.create({
51
- baseURL: config_1.config.plexoUrl,
52
- });
53
- var specialWords = [
54
- { word: 'UtcUnixTimeExpiration', substitute: 'UTCUnixTimeExpiration' },
55
- { word: 'VatAmount', substitute: 'VATAmount' },
56
- ];
57
- var canonizeJson = function (object) {
58
- var cleanObject = deleteObjectUndefined(object);
59
- return sort(cleanObject);
60
- };
61
- exports.canonizeJson = canonizeJson;
62
- var toCamelKeys = function (object) {
63
- var parsedObject = (0, js_convert_case_1.camelKeys)(object, { recursive: true, recursiveInArray: true });
64
- return parsedObject;
65
- };
66
- function substituteWordRecursively(theParsedObject, word, substitute) {
67
- var deleteObject = function (obj, key) {
68
- delete obj[key];
69
- };
70
- if (typeof theParsedObject === 'object') {
71
- Object.keys(theParsedObject).map(function (key) {
72
- if (key === word) {
73
- Object.defineProperty(theParsedObject, substitute, Object.getOwnPropertyDescriptor(theParsedObject, word) || '');
74
- deleteObject(theParsedObject, word);
75
- }
76
- if (typeof theParsedObject[key] === 'object') {
77
- substituteWordRecursively(theParsedObject[key], word, substitute);
78
- }
79
- });
80
- }
81
- }
82
- var toPascalKeys = function (object) {
83
- var parsedObject = (0, js_convert_case_1.pascalKeys)(object, { recursive: true, recursiveInArray: true });
84
- specialWords.forEach(function (specialWord) {
85
- if (JSON.stringify(parsedObject).includes(specialWord.word)) {
86
- substituteWordRecursively(parsedObject, specialWord.word, specialWord.substitute);
87
- }
88
- });
89
- return parsedObject;
90
- };
91
- var sort = function (object) {
92
- if (Array.isArray(object)) {
93
- var newArray_1 = [];
94
- object.map(function (item) { return newArray_1.push(sort(item)); });
95
- return newArray_1;
96
- }
97
- if (typeof object === 'object') {
98
- var newObject_1 = {};
99
- Object.keys(object)
100
- .sort()
101
- .map(function (key) { return (newObject_1[key] = sort(object[key])); });
102
- return newObject_1;
103
- }
104
- return object;
105
- };
106
- // TODO:
107
- // const parseDateToISO = (object: any) => {}
108
- var deleteObjectUndefined = function (object) {
109
- if (Array.isArray(object)) {
110
- object = object
111
- .filter(function (item) { return item !== undefined || !item.length; })
112
- .map(function (item) {
113
- return typeof item === 'object' || Array.isArray(item) ? deleteObjectUndefined(item) : null;
114
- });
115
- return;
116
- }
117
- if (typeof object === 'object') {
118
- Object.keys(object).map(function (key) {
119
- if (typeof object[key] === 'object') {
120
- if (Object.entries(object[key]).length === 0) {
121
- delete object[key];
122
- }
123
- deleteObjectUndefined(object[key]);
124
- }
125
- if ((!object[key] && object[key] !== 0 && typeof object[key] !== 'boolean') ||
126
- (!object[key].length && Array.isArray(object[key]))) {
127
- delete object[key];
128
- return;
129
- }
130
- if (Array.isArray(object[key]) && object[key].length) {
131
- deleteObjectUndefined(object[key]);
132
- }
133
- });
134
- }
135
- return object;
136
- };
137
- var getFingerprint = function (content, algorithm, inputEncoding, outputEncoding) {
138
- if (algorithm === void 0) { algorithm = 'sha1'; }
139
- if (inputEncoding === void 0) { inputEncoding = 'utf8'; }
140
- if (outputEncoding === void 0) { outputEncoding = 'base64'; }
141
- var shaSum = (0, crypto_1.createHash)(algorithm);
142
- shaSum.update(content, inputEncoding);
143
- var res = shaSum.digest(outputEncoding);
144
- return res;
145
- };
146
- var getCertificate = function () { return __awaiter(void 0, void 0, void 0, function () {
147
- var pathPfx, pfx, certs;
148
- return __generator(this, function (_a) {
149
- switch (_a.label) {
150
- case 0:
151
- pathPfx = config_1.config.plexoClient.certificatePath;
152
- pfx = fs.readFileSync(pathPfx);
153
- return [4 /*yield*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
154
- return __generator(this, function (_a) {
155
- switch (_a.label) {
156
- case 0: return [4 /*yield*/, pem.readPkcs12(pfx, { p12Password: config_1.config.plexoClient.certificatePassword }, function (_err, cert) { return __awaiter(void 0, void 0, void 0, function () {
157
- var privateKey, stringifiedCert;
158
- return __generator(this, function (_a) {
159
- privateKey = cert.key;
160
- stringifiedCert = cert.cert;
161
- resolve({ privateKey: privateKey, cert: stringifiedCert });
162
- return [2 /*return*/];
163
- });
164
- }); })];
165
- case 1:
166
- _a.sent();
167
- return [2 /*return*/];
168
- }
169
- });
170
- }); })];
171
- case 1:
172
- certs = _a.sent();
173
- return [2 /*return*/, certs];
174
- }
175
- });
176
- }); };
177
- var generateSignature = function (object, privateKey) {
178
- var canonizedString = (0, stringifyWithFloats_1.stringifyAmountsWithFloats)(object);
179
- logger_lib_1.default.debug('STRING TO SIGN --> ' + canonizedString);
180
- var canonizedStringEncoded = new util_1.TextEncoder().encode(canonizedString);
181
- var signKey = (0, crypto_1.sign)('SHA512', canonizedStringEncoded, privateKey).toString('base64');
182
- return signKey;
183
- };
184
- var getSignatureFromPlexo = function (objectToSign) { return __awaiter(void 0, void 0, void 0, function () {
185
- var cert, privateKey, stringifiedCert, signedObject, thumbnail, canonizedObject, objectoToPascalKeys, signKey;
43
+ var logger_lib_1 = require("../../../lib/logger.lib");
44
+ var utils_1 = require("../../../utils");
45
+ var boolean_utils_1 = require("../../../utils/boolean.utils");
46
+ var signatureUtils_1 = require("./signatureUtils");
47
+ var signRequest = function (objectToSign, plexoCertificatePath) { return __awaiter(void 0, void 0, void 0, function () {
48
+ var cert, privateKey, stringifiedCert, signedObject, thumbnail, canonizedObject, objectoToPascalKeys, objectWithStringBooleans, signKey;
186
49
  return __generator(this, function (_a) {
187
50
  switch (_a.label) {
188
- case 0: return [4 /*yield*/, getCertificate()];
51
+ case 0: return [4 /*yield*/, signatureUtils_1.signatureUtils.getCertificate(plexoCertificatePath)];
189
52
  case 1:
190
53
  cert = _a.sent();
191
- logger_lib_1.default.debug({ cert: cert });
192
54
  privateKey = cert.privateKey;
193
55
  stringifiedCert = cert.cert
194
56
  .toString()
@@ -200,59 +62,30 @@ var getSignatureFromPlexo = function (objectToSign) { return __awaiter(void 0, v
200
62
  object: objectToSign,
201
63
  signature: '',
202
64
  };
203
- thumbnail = getFingerprint(stringifiedCert, 'sha1', 'base64', 'hex').toUpperCase();
65
+ thumbnail = signatureUtils_1.signatureUtils
66
+ .getFingerprint(stringifiedCert, 'sha1', 'base64', 'hex')
67
+ .toUpperCase();
204
68
  objectToSign.fingerprint = thumbnail;
205
- canonizedObject = (0, exports.canonizeJson)(objectToSign);
206
- objectoToPascalKeys = toPascalKeys(canonizedObject);
207
- signKey = generateSignature(objectoToPascalKeys, privateKey);
69
+ canonizedObject = signatureUtils_1.signatureUtils.canonizeJson(objectToSign);
70
+ objectoToPascalKeys = utils_1.caseUtils.toPascalKeys(canonizedObject);
71
+ objectWithStringBooleans = boolean_utils_1.booleanUtils.stringifyBooleans(objectoToPascalKeys);
72
+ signKey = signatureUtils_1.signatureUtils.generateSignature(objectWithStringBooleans, privateKey);
73
+ logger_lib_1.default.debug(objectWithStringBooleans, 'Object to sign');
208
74
  signedObject.signature = signKey;
209
- signedObject.object = canonizedObject;
75
+ signedObject.object = objectWithStringBooleans;
210
76
  return [2 /*return*/, signedObject];
211
77
  }
212
78
  });
213
79
  }); };
214
- var getSignatureFromCallback = function (response) { return __awaiter(void 0, void 0, void 0, function () {
215
- var object, stateObject, objectSignature, serverResponse;
80
+ var getPlexoKey = function (fingerprint, plexoUrl) { return __awaiter(void 0, void 0, void 0, function () {
81
+ var client, plexoResponse;
216
82
  return __generator(this, function (_a) {
217
83
  switch (_a.label) {
218
84
  case 0:
219
- object = {
220
- client: response.response.client,
221
- request: response,
222
- };
223
- stateObject = {
224
- fingerprint: '',
225
- utcUnixTimeExpiration: Date.parse(new Date().toString()),
226
- object: object,
227
- };
228
- return [4 /*yield*/, getSignatureFromPlexo(stateObject)];
229
- case 1:
230
- objectSignature = _a.sent();
231
- serverResponse = {
232
- response: {
233
- object: {
234
- object: {
235
- client: objectSignature.object.object.client,
236
- resultCode: response.resultCode,
237
- },
238
- fingerprint: objectSignature.object.fingerprint,
239
- utcUnixTimeExpiration: objectSignature.object.utcUnixTimeExpiration,
240
- },
241
- signature: objectSignature.signature,
242
- },
243
- resultCode: response.resultCode,
244
- errorMessage: response.errorMessage,
245
- i18ErrorMessages: response.i18ErrorMessages,
246
- };
247
- return [2 /*return*/, serverResponse];
248
- }
249
- });
250
- }); };
251
- var getPlexoKey = function (fingerprint) { return __awaiter(void 0, void 0, void 0, function () {
252
- var plexoResponse;
253
- return __generator(this, function (_a) {
254
- switch (_a.label) {
255
- case 0: return [4 /*yield*/, client.get("/Key/".concat(fingerprint))];
85
+ client = axios_1.default.create({
86
+ baseURL: plexoUrl,
87
+ });
88
+ return [4 /*yield*/, client.get("/Key/".concat(fingerprint))];
256
89
  case 1:
257
90
  plexoResponse = _a.sent();
258
91
  if (plexoResponse.status !== 200) {
@@ -262,13 +95,13 @@ var getPlexoKey = function (fingerprint) { return __awaiter(void 0, void 0, void
262
95
  }
263
96
  });
264
97
  }); };
265
- var getPlexoSignature = function (fingerprint, response) { return __awaiter(void 0, void 0, void 0, function () {
266
- var serverResponse, plexoResponse, err_1, key, objectBuffer, verifySignature;
98
+ var unwrapCallback = function (fingerprint, response, plexoUrl) { return __awaiter(void 0, void 0, void 0, function () {
99
+ var serverResponse, plexoResponse, err_1, certificate, key, canonizedObject, objectInPascalCase, objectWithStringBooleans, objectSorted, objectBuffer, verifySignature;
267
100
  return __generator(this, function (_a) {
268
101
  switch (_a.label) {
269
102
  case 0:
270
103
  _a.trys.push([0, 2, , 3]);
271
- return [4 /*yield*/, getPlexoKey(fingerprint)];
104
+ return [4 /*yield*/, getPlexoKey(fingerprint, plexoUrl)];
272
105
  case 1:
273
106
  plexoResponse = _a.sent();
274
107
  return [3 /*break*/, 3];
@@ -282,24 +115,61 @@ var getPlexoSignature = function (fingerprint, response) { return __awaiter(void
282
115
  };
283
116
  return [2 /*return*/, serverResponse];
284
117
  case 3:
285
- key = "-----BEGIN CERTIFICATE-----\n".concat(plexoResponse.Object.Object.Response.Key, "\n-----END CERTIFICATE-----");
286
- objectBuffer = new util_1.TextEncoder().encode((0, stringifyWithFloats_1.stringifyAmountsWithFloats)(response.object));
118
+ certificate = new crypto_1.X509Certificate(Buffer.from(plexoResponse.Object.Object.Response.Key, 'base64'));
119
+ key = certificate.publicKey.export({ format: 'pem', type: 'pkcs1' });
120
+ canonizedObject = signatureUtils_1.signatureUtils.canonizeJson(response.object, [
121
+ 'CreditLimits',
122
+ 'creditLimits',
123
+ ]);
124
+ objectInPascalCase = utils_1.caseUtils.toPascalKeys(canonizedObject);
125
+ objectWithStringBooleans = boolean_utils_1.booleanUtils.stringifyBooleans(objectInPascalCase);
126
+ objectSorted = signatureUtils_1.signatureUtils.sortObject(objectWithStringBooleans);
127
+ objectBuffer = Buffer.from(JSON.stringify(objectSorted));
287
128
  verifySignature = (0, crypto_1.createVerify)('SHA512')
288
129
  .update(objectBuffer)
289
130
  .verify(key, response.signature, 'base64');
290
131
  serverResponse = {
291
132
  response: response.object.object,
292
133
  resultCode: verifySignature ? __1.ResultCodes.Ok : __1.ResultCodes.InvalidSignature,
293
- errorMessage: verifySignature ? "Signature do not match" : 'Success',
134
+ errorMessage: verifySignature ? 'Success' : 'Signature do not match',
294
135
  };
295
136
  return [2 /*return*/, serverResponse];
296
137
  }
297
138
  });
298
139
  }); };
140
+ var signCallback = function (response, plexoCertificatePath) { return __awaiter(void 0, void 0, void 0, function () {
141
+ var clientResponse, stateObject, signedObject, clientSignedResponse;
142
+ return __generator(this, function (_a) {
143
+ switch (_a.label) {
144
+ case 0:
145
+ clientResponse = {
146
+ resultCode: response.resultCode,
147
+ errorMessage: response.errorMessage,
148
+ client: response.response.client,
149
+ i18ErrorMessages: response.i18ErrorMessages,
150
+ };
151
+ stateObject = {
152
+ fingerprint: '',
153
+ object: clientResponse,
154
+ utcUnixTimeExpiration: Date.parse(new Date().toString()),
155
+ };
156
+ return [4 /*yield*/, signRequest(stateObject, plexoCertificatePath)];
157
+ case 1:
158
+ signedObject = _a.sent();
159
+ clientSignedResponse = {
160
+ signature: signedObject.signature,
161
+ object: {
162
+ fingerprint: signedObject.object.fingerprint,
163
+ utcUnixTimeExpiration: signedObject.object.utcUnixTimeExpiration,
164
+ object: clientResponse,
165
+ },
166
+ };
167
+ return [2 /*return*/, clientSignedResponse];
168
+ }
169
+ });
170
+ }); };
299
171
  exports.SignatureHelper = {
300
- getCertificate: getCertificate,
301
- getSignatureFromPlexo: getSignatureFromPlexo,
302
- getSignatureFromCallback: getSignatureFromCallback,
303
- getPlexoSignature: getPlexoSignature,
304
- toCamelKeys: toCamelKeys,
172
+ signRequest: signRequest,
173
+ unwrapCallback: unwrapCallback,
174
+ signCallback: signCallback,
305
175
  };
@@ -0,0 +1,10 @@
1
+ import { BinaryToTextEncoding, Encoding } from 'crypto';
2
+ import { Certificate } from '../../types/signatureHelper.type';
3
+ export declare const signatureUtils: {
4
+ canonizeJson: <T>(object: T, keysToSkip?: string[]) => T;
5
+ sortObject: (object: any | any[]) => any | any[];
6
+ deleteObjectUndefined: (object: any, keysToSkip?: string[]) => any;
7
+ getFingerprint: (content: string, algorithm?: string, inputEncoding?: Encoding, outputEncoding?: BinaryToTextEncoding) => string;
8
+ getCertificate: (plexoCertificatePath: string) => Promise<Certificate>;
9
+ generateSignature: <T_1 extends object>(object: T_1, privateKey: string) => string;
10
+ };
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.signatureUtils = void 0;
40
+ var crypto_1 = require("crypto");
41
+ var fs = require("fs");
42
+ var pem = require("pem");
43
+ var util_1 = require("util");
44
+ var logger_lib_1 = require("../../../lib/logger.lib");
45
+ var stringifyWithFloats_1 = require("./stringifyWithFloats");
46
+ var canonizeJson = function (object, keysToSkip) {
47
+ var cleanObject = deleteObjectUndefined(object, keysToSkip);
48
+ return sortObject(cleanObject);
49
+ };
50
+ var sortObject = function (object) {
51
+ if (Array.isArray(object)) {
52
+ var newArray_1 = [];
53
+ object.map(function (item) { return newArray_1.push(sortObject(item)); });
54
+ return newArray_1;
55
+ }
56
+ if (object && typeof object === 'object') {
57
+ var newObject_1 = {};
58
+ Object.keys(object)
59
+ .sort()
60
+ .map(function (key) { return (newObject_1[key] = sortObject(object[key])); });
61
+ return newObject_1;
62
+ }
63
+ return object;
64
+ };
65
+ var deleteObjectUndefined = function (object, keysToSkip) {
66
+ if (Array.isArray(object)) {
67
+ object = object
68
+ .filter(function (item) { return item !== undefined || !item.length; })
69
+ .map(function (item) {
70
+ return (item && typeof item === 'object') || Array.isArray(item)
71
+ ? deleteObjectUndefined(item, keysToSkip)
72
+ : null;
73
+ });
74
+ return;
75
+ }
76
+ if (object && typeof object === 'object') {
77
+ Object.keys(object).map(function (key) {
78
+ if (keysToSkip === null || keysToSkip === void 0 ? void 0 : keysToSkip.includes(key)) {
79
+ return;
80
+ }
81
+ if (object[key] && typeof object[key] === 'object') {
82
+ if (Object.entries(object[key]).length === 0) {
83
+ delete object[key];
84
+ }
85
+ deleteObjectUndefined(object[key], keysToSkip);
86
+ }
87
+ if ((!object[key] && object[key] !== 0 && typeof object[key] !== 'boolean') ||
88
+ (!object[key].length && Array.isArray(object[key]))) {
89
+ delete object[key];
90
+ return;
91
+ }
92
+ if (Array.isArray(object[key]) && object[key].length) {
93
+ deleteObjectUndefined(object[key], keysToSkip);
94
+ }
95
+ });
96
+ }
97
+ return object;
98
+ };
99
+ var getFingerprint = function (content, algorithm, inputEncoding, outputEncoding) {
100
+ if (algorithm === void 0) { algorithm = 'sha1'; }
101
+ if (inputEncoding === void 0) { inputEncoding = 'utf8'; }
102
+ if (outputEncoding === void 0) { outputEncoding = 'base64'; }
103
+ var shaSum = (0, crypto_1.createHash)(algorithm);
104
+ shaSum.update(content, inputEncoding);
105
+ var res = shaSum.digest(outputEncoding);
106
+ return res;
107
+ };
108
+ var getCertificate = function (plexoCertificatePath) { return __awaiter(void 0, void 0, void 0, function () {
109
+ var pfx, certs;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ pfx = fs.readFileSync(plexoCertificatePath);
114
+ return [4 /*yield*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0: return [4 /*yield*/, pem.readPkcs12(pfx, { p12Password: plexoCertificatePath }, function (_err, cert) { return __awaiter(void 0, void 0, void 0, function () {
118
+ var privateKey, stringifiedCert;
119
+ return __generator(this, function (_a) {
120
+ if (_err) {
121
+ return [2 /*return*/, reject(_err)];
122
+ }
123
+ privateKey = cert.key;
124
+ stringifiedCert = cert.cert;
125
+ resolve({ privateKey: privateKey, cert: stringifiedCert });
126
+ return [2 /*return*/];
127
+ });
128
+ }); })];
129
+ case 1:
130
+ _a.sent();
131
+ return [2 /*return*/];
132
+ }
133
+ });
134
+ }); })];
135
+ case 1:
136
+ certs = _a.sent();
137
+ return [2 /*return*/, certs];
138
+ }
139
+ });
140
+ }); };
141
+ var generateSignature = function (object, privateKey) {
142
+ var canonizedString = (0, stringifyWithFloats_1.stringifyAmountsWithFloats)(object);
143
+ logger_lib_1.default.debug(canonizedString, 'String to sign');
144
+ var canonizedStringEncoded = new util_1.TextEncoder().encode(canonizedString);
145
+ var signKey = (0, crypto_1.sign)('SHA512', canonizedStringEncoded, privateKey).toString('base64');
146
+ return signKey;
147
+ };
148
+ exports.signatureUtils = {
149
+ canonizeJson: canonizeJson,
150
+ sortObject: sortObject,
151
+ deleteObjectUndefined: deleteObjectUndefined,
152
+ getFingerprint: getFingerprint,
153
+ getCertificate: getCertificate,
154
+ generateSignature: generateSignature,
155
+ };
@@ -62,10 +62,12 @@ var stringifyAmountsWithFloats = function (object) {
62
62
  billedAmount: 'float',
63
63
  taxedAmount: 'float',
64
64
  vatAmount: 'float',
65
+ tipAmount: 'float',
65
66
  Amount: 'float',
66
67
  BilledAmount: 'float',
67
68
  TaxedAmount: 'float',
68
69
  VATAmount: 'float',
70
+ TipAmount: 'float',
69
71
  }, 1)(object, null, 0);
70
72
  };
71
73
  exports.stringifyAmountsWithFloats = stringifyAmountsWithFloats;
@@ -86,6 +86,8 @@ var paymentCodeMock = {
86
86
  var issuerDataMock = {
87
87
  commerceId: 1891,
88
88
  issuerId: 4,
89
+ plexoCertificatePath: './certificates',
90
+ plexoClientName: 'fixed',
89
91
  metadata: {
90
92
  providerCommerceNumber: '12345',
91
93
  terminalNumber: '12345',
@@ -1,18 +1,17 @@
1
- import { ESMap } from 'typescript';
2
1
  import { AuthorizationType } from '..';
3
2
  import { ActionType } from './ActionType';
4
3
  import { AuthorizationInfo } from './AuthorizationInfo';
5
- import { WebFormSettingsDto } from './WebFormSettingsDto';
4
+ import { WebFormSettings } from './WebFormSettings';
6
5
  export declare class Authorization extends AuthorizationInfo {
7
6
  action: ActionType;
8
7
  redirectUri: string;
9
8
  limitIssuers: string[];
10
9
  optionalCommerceId: number;
10
+ webFormSettings?: WebFormSettings;
11
11
  doNotUseCallback?: boolean;
12
12
  clientInformation?: any;
13
13
  optionalMetadata?: string;
14
- promotionInfoIssuers?: ESMap<string, string>;
14
+ promotionInfoIssuers?: Record<string, string>;
15
15
  extendableInstrumentToken?: string;
16
- webFormSettings?: WebFormSettingsDto;
17
- constructor(action: ActionType, redirectUri: string, limitIssuers: string[], optionalCommerceId: number, type: AuthorizationType, metaReference: string);
16
+ constructor(action: ActionType, redirectUri: string, limitIssuers: string[], optionalCommerceId: number, type: AuthorizationType, metaReference: string, webFormSettings: WebFormSettings, plexoClientName: string, plexoCertificatePath: string);
18
17
  }
@@ -19,12 +19,13 @@ exports.Authorization = void 0;
19
19
  var AuthorizationInfo_1 = require("./AuthorizationInfo");
20
20
  var Authorization = /** @class */ (function (_super) {
21
21
  __extends(Authorization, _super);
22
- function Authorization(action, redirectUri, limitIssuers, optionalCommerceId, type, metaReference) {
23
- var _this = _super.call(this, type, metaReference) || this;
22
+ function Authorization(action, redirectUri, limitIssuers, optionalCommerceId, type, metaReference, webFormSettings, plexoClientName, plexoCertificatePath) {
23
+ var _this = _super.call(this, type, metaReference, plexoClientName, plexoCertificatePath) || this;
24
24
  _this.action = action;
25
25
  _this.redirectUri = redirectUri;
26
26
  _this.limitIssuers = limitIssuers;
27
27
  _this.optionalCommerceId = optionalCommerceId;
28
+ _this.webFormSettings = webFormSettings || null;
28
29
  return _this;
29
30
  }
30
31
  return Authorization;
@@ -1,6 +1,7 @@
1
1
  import { AuthorizationType } from './AuthorizationType';
2
- export declare class AuthorizationInfo {
2
+ import { FixedCustomData } from './FixedCustomData';
3
+ export declare class AuthorizationInfo extends FixedCustomData {
3
4
  type: AuthorizationType;
4
5
  metaReference: string;
5
- constructor(type: AuthorizationType, metaReference: string);
6
+ constructor(type: AuthorizationType, metaReference: string, plexoClientName: string, plexoCertificatePath: string);
6
7
  }
@@ -1,11 +1,30 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.AuthorizationInfo = void 0;
4
- var AuthorizationInfo = /** @class */ (function () {
5
- function AuthorizationInfo(type, metaReference) {
6
- this.type = type;
7
- this.metaReference = metaReference;
19
+ var FixedCustomData_1 = require("./FixedCustomData");
20
+ var AuthorizationInfo = /** @class */ (function (_super) {
21
+ __extends(AuthorizationInfo, _super);
22
+ function AuthorizationInfo(type, metaReference, plexoClientName, plexoCertificatePath) {
23
+ var _this = _super.call(this, plexoClientName, plexoCertificatePath) || this;
24
+ _this.type = type;
25
+ _this.metaReference = metaReference;
26
+ return _this;
8
27
  }
9
28
  return AuthorizationInfo;
10
- }());
29
+ }(FixedCustomData_1.FixedCustomData));
11
30
  exports.AuthorizationInfo = AuthorizationInfo;
@@ -0,0 +1,5 @@
1
+ export declare class BuiltInPagesOptions {
2
+ checkoutSuccessPage: boolean;
3
+ checkoutErrorPage: boolean;
4
+ constructor(checkoutSuccessPage: boolean, checkoutErrorPage: boolean);
5
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuiltInPagesOptions = void 0;
4
+ var BuiltInPagesOptions = /** @class */ (function () {
5
+ function BuiltInPagesOptions(checkoutSuccessPage, checkoutErrorPage) {
6
+ this.checkoutSuccessPage = checkoutSuccessPage;
7
+ this.checkoutErrorPage = checkoutErrorPage;
8
+ }
9
+ return BuiltInPagesOptions;
10
+ }());
11
+ exports.BuiltInPagesOptions = BuiltInPagesOptions;
@@ -2,5 +2,5 @@ import { ReferenceType } from '..';
2
2
  import { Reference } from './Reference';
3
3
  export declare class CancelRequest extends Reference {
4
4
  clientReferenceId: string;
5
- constructor(clientReferenceId: string, type: ReferenceType, metaReference: string);
5
+ constructor(clientReferenceId: string, plexoClientName: string, plexoCertificatePath: string, type: ReferenceType, metaReference: string);
6
6
  }
@@ -19,8 +19,8 @@ exports.CancelRequest = void 0;
19
19
  var Reference_1 = require("./Reference");
20
20
  var CancelRequest = /** @class */ (function (_super) {
21
21
  __extends(CancelRequest, _super);
22
- function CancelRequest(clientReferenceId, type, metaReference) {
23
- var _this = _super.call(this, type, metaReference) || this;
22
+ function CancelRequest(clientReferenceId, plexoClientName, plexoCertificatePath, type, metaReference) {
23
+ var _this = _super.call(this, type, metaReference, plexoClientName, plexoCertificatePath) || this;
24
24
  _this.clientReferenceId = clientReferenceId;
25
25
  return _this;
26
26
  }
@@ -1,5 +1,7 @@
1
1
  import { CodeAction } from './CodeAction';
2
- export declare type CodeRequest = {
2
+ import { FixedCustomData } from './FixedCustomData';
3
+ export declare class CodeRequest extends FixedCustomData {
3
4
  code: string;
4
5
  action: CodeAction;
5
- };
6
+ constructor(code: string, action: CodeAction, plexoClientName: string, plexoCertificatePath: string);
7
+ }