@houlak/plexo-sdk 0.1.9 → 0.1.10-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.
- package/lib/handler/PlexoHandler.d.ts +23 -12
- package/lib/handler/PlexoHandler.js +183 -33
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -1
- package/lib/lib/logger.lib.js +3 -3
- package/lib/sdk/IPaymentGatewayClient.d.ts +10 -9
- package/lib/sdk/PaymentGatewayClient.d.ts +13 -12
- package/lib/sdk/PaymentGatewayClient.js +275 -196
- package/lib/sdk/PaymentGatewayMock.d.ts +2 -2
- package/lib/sdk/PaymentGatewayMock.js +2 -8
- package/lib/sdk/enums/plexo-error-enum.d.ts +1 -0
- package/lib/sdk/enums/plexo-error-enum.js +1 -0
- package/lib/sdk/helpers/signature/signatureHelper.d.ts +3 -7
- package/lib/sdk/helpers/signature/signatureHelper.js +67 -200
- package/lib/sdk/helpers/signature/signatureUtils.d.ts +10 -0
- package/lib/sdk/helpers/signature/signatureUtils.js +155 -0
- package/lib/sdk/helpers/signature/stringifyWithFloats.js +2 -0
- package/lib/sdk/mocks/mocks.js +3 -0
- package/lib/sdk/models/Authorization.d.ts +4 -5
- package/lib/sdk/models/Authorization.js +7 -1
- package/lib/sdk/models/BuiltInPagesOptions.d.ts +5 -0
- package/lib/sdk/models/BuiltInPagesOptions.js +11 -0
- package/lib/sdk/models/CodeRequest.d.ts +3 -2
- package/lib/sdk/models/CodeRequest.js +9 -0
- package/lib/sdk/models/CommerceIdRequest.d.ts +3 -2
- package/lib/sdk/models/CommerceIdRequest.js +8 -0
- package/lib/sdk/models/CommerceIssuerIdRequest.d.ts +3 -2
- package/lib/sdk/models/CommerceIssuerIdRequest.js +9 -0
- package/lib/sdk/models/CommerceModifyRequest.d.ts +3 -2
- package/lib/sdk/models/CommerceModifyRequest.js +9 -0
- package/lib/sdk/models/CommerceRequest.d.ts +3 -2
- package/lib/sdk/models/CommerceRequest.js +8 -0
- package/lib/sdk/models/CreateBankInstrumentRequest.d.ts +3 -2
- package/lib/sdk/models/CreateBankInstrumentRequest.js +10 -0
- package/lib/sdk/models/DisplayOptions.d.ts +8 -0
- package/lib/sdk/models/DisplayOptions.js +14 -0
- package/lib/sdk/models/ExpressCheckoutSettings.d.ts +7 -0
- package/lib/sdk/models/ExpressCheckoutSettings.js +11 -0
- package/lib/sdk/models/FieldType.d.ts +6 -0
- package/lib/sdk/models/FieldType.js +6 -0
- package/lib/sdk/models/FixedCustomData.d.ts +6 -0
- package/lib/sdk/models/FixedCustomData.js +12 -0
- package/lib/sdk/models/GenericSignedObject.d.ts +1 -1
- package/lib/sdk/models/GenericSignedObject.js +3 -3
- package/lib/sdk/models/GenericStateObject.d.ts +1 -1
- package/lib/sdk/models/GenericStateObject.js +3 -3
- package/lib/sdk/models/IndexSDK.d.ts +8 -6
- package/lib/sdk/models/IndexSDK.js +32 -14
- package/lib/sdk/models/InstrumentCallback.d.ts +2 -2
- package/lib/sdk/models/InstrumentCallback.js +5 -5
- package/lib/sdk/models/IssuerData.d.ts +6 -2
- package/lib/sdk/models/IssuerData.js +31 -0
- package/lib/sdk/models/TokenizationSettings.d.ts +5 -0
- package/lib/sdk/models/TokenizationSettings.js +10 -0
- package/lib/sdk/models/TransactionCallback.d.ts +3 -3
- package/lib/sdk/models/TransactionCallback.js +3 -3
- package/lib/sdk/models/TransactionQuery.d.ts +3 -2
- package/lib/sdk/models/TransactionQuery.js +11 -1
- package/lib/sdk/models/TransactionsCSV.d.ts +3 -0
- package/lib/sdk/models/TransactionsCSV.js +2 -0
- package/lib/sdk/models/UIOptions.d.ts +8 -0
- package/lib/sdk/models/UIOptions.js +13 -0
- package/lib/sdk/models/WebFormSettings.d.ts +9 -0
- package/lib/sdk/models/WebFormSettings.js +12 -0
- package/lib/sdk/models/webhook/Address.d.ts +9 -0
- package/lib/sdk/models/webhook/Address.js +15 -0
- package/lib/sdk/models/webhook/CancellationInfo.d.ts +11 -0
- package/lib/sdk/models/webhook/CancellationInfo.js +17 -0
- package/lib/sdk/models/webhook/Client.d.ts +9 -0
- package/lib/sdk/models/webhook/Client.js +14 -0
- package/lib/sdk/models/webhook/Commerce.d.ts +6 -0
- package/lib/sdk/models/webhook/Commerce.js +12 -0
- package/lib/sdk/models/webhook/Currency.d.ts +8 -0
- package/lib/sdk/models/webhook/Currency.js +14 -0
- package/lib/sdk/models/webhook/Customer.d.ts +17 -0
- package/lib/sdk/models/webhook/Customer.js +22 -0
- package/lib/sdk/models/webhook/Document.d.ts +5 -0
- package/lib/sdk/models/webhook/Document.js +11 -0
- package/lib/sdk/models/webhook/IndexWebhook.d.ts +21 -0
- package/lib/sdk/models/webhook/IndexWebhook.js +45 -0
- package/lib/sdk/models/webhook/Instrument.d.ts +17 -0
- package/lib/sdk/models/webhook/Instrument.js +21 -0
- package/lib/sdk/models/webhook/Issuer.d.ts +8 -0
- package/lib/sdk/models/webhook/Issuer.js +14 -0
- package/lib/sdk/models/webhook/IssuerData.d.ts +8 -0
- package/lib/sdk/models/webhook/IssuerData.js +13 -0
- package/lib/sdk/models/webhook/IssuerDto.d.ts +5 -0
- package/lib/sdk/models/webhook/IssuerDto.js +11 -0
- package/lib/sdk/models/webhook/Item.d.ts +14 -0
- package/lib/sdk/models/webhook/Item.js +19 -0
- package/lib/sdk/models/webhook/PartialRefundsInfo.d.ts +12 -0
- package/lib/sdk/models/webhook/PartialRefundsInfo.js +18 -0
- package/lib/sdk/models/webhook/PaymentFacilitator.d.ts +8 -0
- package/lib/sdk/models/webhook/PaymentFacilitator.js +13 -0
- package/lib/sdk/models/webhook/PaymentProcessor.d.ts +5 -0
- package/lib/sdk/models/webhook/PaymentProcessor.js +11 -0
- package/lib/sdk/models/webhook/PurchaseInfo.d.ts +16 -0
- package/lib/sdk/models/webhook/PurchaseInfo.js +22 -0
- package/lib/sdk/models/webhook/RefundInfo.d.ts +12 -0
- package/lib/sdk/models/webhook/RefundInfo.js +18 -0
- package/lib/sdk/models/webhook/ReserveInfo.d.ts +13 -0
- package/lib/sdk/models/webhook/ReserveInfo.js +19 -0
- package/lib/sdk/models/webhook/Shipping.d.ts +7 -0
- package/lib/sdk/models/webhook/Shipping.js +12 -0
- package/lib/sdk/models/webhook/Transaction.d.ts +31 -0
- package/lib/sdk/models/webhook/Transaction.js +36 -0
- package/lib/sdk/models/webhook/TransactionResult.d.ts +5 -0
- package/lib/sdk/models/webhook/TransactionResult.js +10 -0
- package/lib/sdk/models/webhook/index.d.ts +21 -0
- package/lib/sdk/models/webhook/index.js +45 -0
- package/lib/utils/boolean.utils.d.ts +4 -0
- package/lib/utils/boolean.utils.js +53 -0
- package/lib/utils/case.util.d.ts +4 -0
- package/lib/utils/case.util.js +61 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +5 -0
- package/package.json +3 -3
|
@@ -36,159 +36,24 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.SignatureHelper =
|
|
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
|
|
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");
|
|
50
47
|
var client = axios_1.default.create({
|
|
51
|
-
baseURL:
|
|
48
|
+
baseURL: 'https://testing.plexo.com.uy:4043/SecurePaymentGateway.svc',
|
|
52
49
|
});
|
|
53
|
-
var
|
|
54
|
-
|
|
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;
|
|
50
|
+
var signRequest = function (objectToSign, plexoCertificatePassword, plexoCertificatePath) { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
+
var cert, privateKey, stringifiedCert, signedObject, thumbnail, canonizedObject, objectoToPascalKeys, objectWithStringBooleans, signKey;
|
|
148
52
|
return __generator(this, function (_a) {
|
|
149
53
|
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;
|
|
186
|
-
return __generator(this, function (_a) {
|
|
187
|
-
switch (_a.label) {
|
|
188
|
-
case 0: return [4 /*yield*/, getCertificate()];
|
|
54
|
+
case 0: return [4 /*yield*/, signatureUtils_1.signatureUtils.getCertificate(plexoCertificatePath, plexoCertificatePassword)];
|
|
189
55
|
case 1:
|
|
190
56
|
cert = _a.sent();
|
|
191
|
-
logger_lib_1.default.debug({ cert: cert });
|
|
192
57
|
privateKey = cert.privateKey;
|
|
193
58
|
stringifiedCert = cert.cert
|
|
194
59
|
.toString()
|
|
@@ -200,62 +65,28 @@ var getSignatureFromPlexo = function (objectToSign) { return __awaiter(void 0, v
|
|
|
200
65
|
object: objectToSign,
|
|
201
66
|
signature: '',
|
|
202
67
|
};
|
|
203
|
-
thumbnail =
|
|
68
|
+
thumbnail = signatureUtils_1.signatureUtils
|
|
69
|
+
.getFingerprint(stringifiedCert, 'sha1', 'base64', 'hex')
|
|
70
|
+
.toUpperCase();
|
|
204
71
|
objectToSign.fingerprint = thumbnail;
|
|
205
|
-
canonizedObject =
|
|
206
|
-
objectoToPascalKeys = toPascalKeys(canonizedObject);
|
|
207
|
-
|
|
72
|
+
canonizedObject = signatureUtils_1.signatureUtils.canonizeJson(objectToSign);
|
|
73
|
+
objectoToPascalKeys = utils_1.caseUtils.toPascalKeys(canonizedObject);
|
|
74
|
+
objectWithStringBooleans = boolean_utils_1.booleanUtils.stringifyBooleans(objectoToPascalKeys);
|
|
75
|
+
signKey = signatureUtils_1.signatureUtils.generateSignature(objectWithStringBooleans, privateKey);
|
|
76
|
+
logger_lib_1.default.debug(objectWithStringBooleans, 'Object to sign');
|
|
208
77
|
signedObject.signature = signKey;
|
|
209
|
-
signedObject.object =
|
|
78
|
+
signedObject.object = objectWithStringBooleans;
|
|
210
79
|
return [2 /*return*/, signedObject];
|
|
211
80
|
}
|
|
212
81
|
});
|
|
213
82
|
}); };
|
|
214
|
-
var
|
|
215
|
-
var object, stateObject, objectSignature, serverResponse;
|
|
216
|
-
return __generator(this, function (_a) {
|
|
217
|
-
switch (_a.label) {
|
|
218
|
-
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 () {
|
|
83
|
+
var getPlexoKey = function (fingerprint, plexoUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
252
84
|
var plexoResponse;
|
|
253
85
|
return __generator(this, function (_a) {
|
|
254
86
|
switch (_a.label) {
|
|
255
87
|
case 0: return [4 /*yield*/, client.get("/Key/".concat(fingerprint))];
|
|
256
88
|
case 1:
|
|
257
89
|
plexoResponse = _a.sent();
|
|
258
|
-
logger_lib_1.default.info("GET PLEXO KEY RESPONSE --> ".concat(JSON.stringify(plexoResponse)));
|
|
259
90
|
if (plexoResponse.status !== 200) {
|
|
260
91
|
throw new Error("Invalid or outdated Fingerprint, server returns: ".concat(plexoResponse.data.Object.Object.ErrorMessage));
|
|
261
92
|
}
|
|
@@ -263,14 +94,13 @@ var getPlexoKey = function (fingerprint) { return __awaiter(void 0, void 0, void
|
|
|
263
94
|
}
|
|
264
95
|
});
|
|
265
96
|
}); };
|
|
266
|
-
var
|
|
267
|
-
var serverResponse, plexoResponse, err_1, key, objectBuffer, verifySignature;
|
|
97
|
+
var unwrapCallback = function (fingerprint, response, plexoUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
98
|
+
var serverResponse, plexoResponse, err_1, certificate, key, canonizedObject, objectInPascalCase, objectWithStringBooleans, objectSorted, objectBuffer, verifySignature;
|
|
268
99
|
return __generator(this, function (_a) {
|
|
269
100
|
switch (_a.label) {
|
|
270
101
|
case 0:
|
|
271
102
|
_a.trys.push([0, 2, , 3]);
|
|
272
|
-
|
|
273
|
-
return [4 /*yield*/, getPlexoKey(fingerprint)];
|
|
103
|
+
return [4 /*yield*/, getPlexoKey(fingerprint, plexoUrl)];
|
|
274
104
|
case 1:
|
|
275
105
|
plexoResponse = _a.sent();
|
|
276
106
|
return [3 /*break*/, 3];
|
|
@@ -284,24 +114,61 @@ var getPlexoSignature = function (fingerprint, response) { return __awaiter(void
|
|
|
284
114
|
};
|
|
285
115
|
return [2 /*return*/, serverResponse];
|
|
286
116
|
case 3:
|
|
287
|
-
|
|
288
|
-
|
|
117
|
+
certificate = new crypto_1.X509Certificate(Buffer.from(plexoResponse.Object.Object.Response.Key, 'base64'));
|
|
118
|
+
key = certificate.publicKey.export({ format: 'pem', type: 'pkcs1' });
|
|
119
|
+
canonizedObject = signatureUtils_1.signatureUtils.canonizeJson(response.object, [
|
|
120
|
+
'CreditLimits',
|
|
121
|
+
'creditLimits',
|
|
122
|
+
]);
|
|
123
|
+
objectInPascalCase = utils_1.caseUtils.toPascalKeys(canonizedObject);
|
|
124
|
+
objectWithStringBooleans = boolean_utils_1.booleanUtils.stringifyBooleans(objectInPascalCase);
|
|
125
|
+
objectSorted = signatureUtils_1.signatureUtils.sortObject(objectWithStringBooleans);
|
|
126
|
+
objectBuffer = Buffer.from(JSON.stringify(objectSorted));
|
|
289
127
|
verifySignature = (0, crypto_1.createVerify)('SHA512')
|
|
290
128
|
.update(objectBuffer)
|
|
291
129
|
.verify(key, response.signature, 'base64');
|
|
292
130
|
serverResponse = {
|
|
293
131
|
response: response.object.object,
|
|
294
132
|
resultCode: verifySignature ? __1.ResultCodes.Ok : __1.ResultCodes.InvalidSignature,
|
|
295
|
-
errorMessage: verifySignature ?
|
|
133
|
+
errorMessage: verifySignature ? 'Success' : 'Signature do not match',
|
|
296
134
|
};
|
|
297
135
|
return [2 /*return*/, serverResponse];
|
|
298
136
|
}
|
|
299
137
|
});
|
|
300
138
|
}); };
|
|
139
|
+
var signCallback = function (response, plexoCertificatePath, plexoCertificatePassword) { return __awaiter(void 0, void 0, void 0, function () {
|
|
140
|
+
var clientResponse, stateObject, signedObject, clientSignedResponse;
|
|
141
|
+
return __generator(this, function (_a) {
|
|
142
|
+
switch (_a.label) {
|
|
143
|
+
case 0:
|
|
144
|
+
clientResponse = {
|
|
145
|
+
resultCode: response.resultCode,
|
|
146
|
+
errorMessage: response.errorMessage,
|
|
147
|
+
client: response.response.client,
|
|
148
|
+
i18ErrorMessages: response.i18ErrorMessages,
|
|
149
|
+
};
|
|
150
|
+
stateObject = {
|
|
151
|
+
fingerprint: '',
|
|
152
|
+
object: clientResponse,
|
|
153
|
+
utcUnixTimeExpiration: Date.parse(new Date().toString()),
|
|
154
|
+
};
|
|
155
|
+
return [4 /*yield*/, signRequest(stateObject, plexoCertificatePassword, plexoCertificatePath)];
|
|
156
|
+
case 1:
|
|
157
|
+
signedObject = _a.sent();
|
|
158
|
+
clientSignedResponse = {
|
|
159
|
+
signature: signedObject.signature,
|
|
160
|
+
object: {
|
|
161
|
+
fingerprint: signedObject.object.fingerprint,
|
|
162
|
+
utcUnixTimeExpiration: signedObject.object.utcUnixTimeExpiration,
|
|
163
|
+
object: clientResponse,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
return [2 /*return*/, clientSignedResponse];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}); };
|
|
301
170
|
exports.SignatureHelper = {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
getPlexoSignature: getPlexoSignature,
|
|
306
|
-
toCamelKeys: toCamelKeys,
|
|
171
|
+
signRequest: signRequest,
|
|
172
|
+
unwrapCallback: unwrapCallback,
|
|
173
|
+
signCallback: signCallback,
|
|
307
174
|
};
|
|
@@ -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, plexoCertificatePassword: 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, plexoCertificatePassword) { 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: plexoCertificatePassword }, 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;
|
package/lib/sdk/mocks/mocks.js
CHANGED
|
@@ -86,6 +86,9 @@ var paymentCodeMock = {
|
|
|
86
86
|
var issuerDataMock = {
|
|
87
87
|
commerceId: 1891,
|
|
88
88
|
issuerId: 4,
|
|
89
|
+
plexoCertificatePassword: '2LlCCZSF04LgtJuWge',
|
|
90
|
+
plexoClientName: 'fixed',
|
|
91
|
+
plexoCertificatePath: './certificates',
|
|
89
92
|
metadata: {
|
|
90
93
|
providerCommerceNumber: '12345',
|
|
91
94
|
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 {
|
|
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?:
|
|
14
|
+
promotionInfoIssuers?: Record<string, string>;
|
|
15
15
|
extendableInstrumentToken?: string;
|
|
16
|
-
webFormSettings?:
|
|
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, doNotUseCallback?: boolean, clientInformation?: any, optionalMetadata?: string, promotionInfoIssuers?: Record<string, string>, extendableInstrumentToken?: string);
|
|
18
17
|
}
|
|
@@ -19,12 +19,18 @@ 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) {
|
|
22
|
+
function Authorization(action, redirectUri, limitIssuers, optionalCommerceId, type, metaReference, webFormSettings, doNotUseCallback, clientInformation, optionalMetadata, promotionInfoIssuers, extendableInstrumentToken) {
|
|
23
23
|
var _this = _super.call(this, type, metaReference) || 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;
|
|
29
|
+
_this.doNotUseCallback = doNotUseCallback;
|
|
30
|
+
_this.clientInformation = clientInformation;
|
|
31
|
+
_this.optionalMetadata = optionalMetadata;
|
|
32
|
+
_this.promotionInfoIssuers = promotionInfoIssuers;
|
|
33
|
+
_this.extendableInstrumentToken = extendableInstrumentToken;
|
|
28
34
|
return _this;
|
|
29
35
|
}
|
|
30
36
|
return Authorization;
|
|
@@ -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;
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeRequest = void 0;
|
|
4
|
+
var CodeRequest = /** @class */ (function () {
|
|
5
|
+
function CodeRequest(code, action) {
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.action = action;
|
|
8
|
+
}
|
|
9
|
+
return CodeRequest;
|
|
10
|
+
}());
|
|
11
|
+
exports.CodeRequest = CodeRequest;
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommerceIdRequest = void 0;
|
|
4
|
+
var CommerceIdRequest = /** @class */ (function () {
|
|
5
|
+
function CommerceIdRequest(commerceId) {
|
|
6
|
+
this.commerceId = commerceId;
|
|
7
|
+
}
|
|
8
|
+
return CommerceIdRequest;
|
|
9
|
+
}());
|
|
10
|
+
exports.CommerceIdRequest = CommerceIdRequest;
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommerceIssuerIdRequest = void 0;
|
|
4
|
+
var CommerceIssuerIdRequest = /** @class */ (function () {
|
|
5
|
+
function CommerceIssuerIdRequest(commerceId, issuerId) {
|
|
6
|
+
this.commerceId = commerceId;
|
|
7
|
+
this.issuerId = issuerId;
|
|
8
|
+
}
|
|
9
|
+
return CommerceIssuerIdRequest;
|
|
10
|
+
}());
|
|
11
|
+
exports.CommerceIssuerIdRequest = CommerceIssuerIdRequest;
|