@houlak/plexo-sdk 0.1.11 → 0.1.12-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 +29 -18
- package/lib/handler/PlexoHandler.js +199 -49
- package/lib/handler/services/evaluator.service.js +3 -3
- 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 +28 -27
- package/lib/sdk/PaymentGatewayClient.d.ts +28 -27
- package/lib/sdk/PaymentGatewayClient.js +66 -68
- package/lib/sdk/PaymentGatewayMock.d.ts +2 -2
- package/lib/sdk/PaymentGatewayMock.js +5 -11
- 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 +78 -210
- 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 +19 -19
- 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 +7 -0
- package/lib/sdk/models/FixedCustomData.js +13 -0
- package/lib/sdk/models/GenericSignedObject.d.ts +3 -3
- 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 +5 -5
- package/lib/sdk/models/InstrumentCallback.js +5 -5
- package/lib/sdk/models/InstrumentWithMetadata.d.ts +3 -3
- package/lib/sdk/models/InstrumentWithMetadata.js +3 -3
- package/lib/sdk/models/IssuerData.d.ts +5 -2
- package/lib/sdk/models/IssuerData.js +12 -0
- package/lib/sdk/models/PaymentInstrument.d.ts +11 -11
- package/lib/sdk/models/StateObject.d.ts +2 -2
- package/lib/sdk/models/StateObject.js +2 -2
- package/lib/sdk/models/TokenizationSettings.d.ts +5 -0
- package/lib/sdk/models/TokenizationSettings.js +10 -0
- package/lib/sdk/models/TransactionCallback.d.ts +4 -4
- 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,21 @@ 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
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
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, plexoCertificatePassword, 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, plexoCertificatePassword)];
|
|
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()
|
|
@@ -197,65 +59,35 @@ var getSignatureFromPlexo = function (objectToSign) { return __awaiter(void 0, v
|
|
|
197
59
|
.map(function (line) { return line.trim(); })
|
|
198
60
|
.join('');
|
|
199
61
|
signedObject = {
|
|
200
|
-
|
|
201
|
-
|
|
62
|
+
object: objectToSign,
|
|
63
|
+
signature: '',
|
|
202
64
|
};
|
|
203
|
-
thumbnail =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
65
|
+
thumbnail = signatureUtils_1.signatureUtils
|
|
66
|
+
.getFingerprint(stringifiedCert, 'sha1', 'base64', 'hex')
|
|
67
|
+
.toUpperCase();
|
|
68
|
+
objectToSign.fingerprint = thumbnail;
|
|
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');
|
|
74
|
+
signedObject.signature = signKey;
|
|
75
|
+
signedObject.object = objectWithStringBooleans;
|
|
210
76
|
return [2 /*return*/, signedObject];
|
|
211
77
|
}
|
|
212
78
|
});
|
|
213
79
|
}); };
|
|
214
|
-
var
|
|
215
|
-
var
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
logger_lib_1.default.debug("GET PLEXO KEY RESPONSE --> ".concat(JSON.stringify(plexoResponse)));
|
|
259
91
|
if (plexoResponse.status !== 200) {
|
|
260
92
|
throw new Error("Invalid or outdated Fingerprint, server returns: ".concat(plexoResponse.data.Object.Object.ErrorMessage));
|
|
261
93
|
}
|
|
@@ -263,14 +95,13 @@ var getPlexoKey = function (fingerprint) { return __awaiter(void 0, void 0, void
|
|
|
263
95
|
}
|
|
264
96
|
});
|
|
265
97
|
}); };
|
|
266
|
-
var
|
|
267
|
-
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;
|
|
268
100
|
return __generator(this, function (_a) {
|
|
269
101
|
switch (_a.label) {
|
|
270
102
|
case 0:
|
|
271
103
|
_a.trys.push([0, 2, , 3]);
|
|
272
|
-
|
|
273
|
-
return [4 /*yield*/, getPlexoKey(fingerprint)];
|
|
104
|
+
return [4 /*yield*/, getPlexoKey(fingerprint, plexoUrl)];
|
|
274
105
|
case 1:
|
|
275
106
|
plexoResponse = _a.sent();
|
|
276
107
|
return [3 /*break*/, 3];
|
|
@@ -278,30 +109,67 @@ var getPlexoSignature = function (fingerprint, response) { return __awaiter(void
|
|
|
278
109
|
err_1 = _a.sent();
|
|
279
110
|
logger_lib_1.default.error({ err: err_1 }, 'Error getting plexo certificate');
|
|
280
111
|
serverResponse = {
|
|
281
|
-
response: response.
|
|
112
|
+
response: response.object.object,
|
|
282
113
|
resultCode: __1.ResultCodes.InvalidFingerprint,
|
|
283
114
|
errorMessage: err_1,
|
|
284
115
|
};
|
|
285
116
|
return [2 /*return*/, serverResponse];
|
|
286
117
|
case 3:
|
|
287
|
-
|
|
288
|
-
|
|
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));
|
|
289
128
|
verifySignature = (0, crypto_1.createVerify)('SHA512')
|
|
290
129
|
.update(objectBuffer)
|
|
291
|
-
.verify(key, response.
|
|
130
|
+
.verify(key, response.signature, 'base64');
|
|
292
131
|
serverResponse = {
|
|
293
|
-
response: response.
|
|
132
|
+
response: response.object.object,
|
|
294
133
|
resultCode: verifySignature ? __1.ResultCodes.Ok : __1.ResultCodes.InvalidSignature,
|
|
295
|
-
errorMessage: verifySignature ?
|
|
134
|
+
errorMessage: verifySignature ? 'Success' : 'Signature do not match',
|
|
296
135
|
};
|
|
297
136
|
return [2 /*return*/, serverResponse];
|
|
298
137
|
}
|
|
299
138
|
});
|
|
300
139
|
}); };
|
|
140
|
+
var signCallback = function (response, plexoCertificatePath, plexoCertificatePassword) { 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, plexoCertificatePassword, 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
|
+
}); };
|
|
301
171
|
exports.SignatureHelper = {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
getPlexoSignature: getPlexoSignature,
|
|
306
|
-
toCamelKeys: toCamelKeys,
|
|
172
|
+
signRequest: signRequest,
|
|
173
|
+
unwrapCallback: unwrapCallback,
|
|
174
|
+
signCallback: signCallback,
|
|
307
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, 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
|
@@ -49,16 +49,16 @@ var issuerMock = {
|
|
|
49
49
|
fields: [fieldMock],
|
|
50
50
|
};
|
|
51
51
|
var paymentInstrumentMock = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
instrumentToken: 'token',
|
|
53
|
+
name: 'mockedInstrument',
|
|
54
|
+
issuer: issuerMock,
|
|
55
|
+
supportedCurrencies: [currencyMock],
|
|
56
|
+
status: IndexSDK_1.CardStatus.Ok,
|
|
57
|
+
instrumentExpirationUTC: 1919276061,
|
|
58
|
+
creditLimits: [amountLimitMock],
|
|
59
|
+
additionalRequirements: [timeLimitMock],
|
|
60
|
+
instrumentInformation: null,
|
|
61
|
+
sessionCreationId: 'MockedId',
|
|
62
62
|
};
|
|
63
63
|
var financialInclusionMock = {
|
|
64
64
|
isApplied: true,
|
|
@@ -138,9 +138,9 @@ var issuerProcessorMock = {
|
|
|
138
138
|
paymentProcessors: [paymentProcessorMock],
|
|
139
139
|
};
|
|
140
140
|
var clientSignedResponseMock = {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
signature: 'signature',
|
|
142
|
+
object: {
|
|
143
|
+
fingerprint: 'fingerprint',
|
|
144
144
|
utcUnixTimeExpiration: 1919276061,
|
|
145
145
|
object: {
|
|
146
146
|
client: 'PlexoMock',
|
|
@@ -148,13 +148,13 @@ var clientSignedResponseMock = {
|
|
|
148
148
|
},
|
|
149
149
|
},
|
|
150
150
|
};
|
|
151
|
-
var transactionCallbackMock = __assign(__assign({}, transactionMock), {
|
|
151
|
+
var transactionCallbackMock = __assign(__assign({}, transactionMock), { client: 'PlexoMock' });
|
|
152
152
|
var instrumentCallbackMock = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
153
|
+
action: IndexSDK_1.ActionType.RegisterInstrument,
|
|
154
|
+
client: 'PlexoMock',
|
|
155
|
+
sessionId: (0, crypto_1.randomUUID)(),
|
|
156
|
+
optionalMetadata: 'metadata',
|
|
157
|
+
paymentInstrument: paymentInstrumentMock,
|
|
158
158
|
};
|
|
159
159
|
exports.mocks = {
|
|
160
160
|
currencyMock: currencyMock,
|
|
@@ -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;
|