@houlak/plexo-sdk 0.1.43 → 0.1.45
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.
|
@@ -44,6 +44,7 @@ var config_1 = require("../../../config/config");
|
|
|
44
44
|
var __1 = require("../..");
|
|
45
45
|
var utils_1 = require("../../../utils");
|
|
46
46
|
var signatureUtils_1 = require("./signatureUtils");
|
|
47
|
+
var stringifyWithFloats_1 = require("./stringifyWithFloats");
|
|
47
48
|
var client = axios_1.default.create({
|
|
48
49
|
baseURL: config_1.config.plexoUrl,
|
|
49
50
|
});
|
|
@@ -93,7 +94,7 @@ var getPlexoKey = function (fingerprint) { return __awaiter(void 0, void 0, void
|
|
|
93
94
|
});
|
|
94
95
|
}); };
|
|
95
96
|
var unwrapCallback = function (fingerprint, response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
-
var serverResponse, plexoResponse, err_1, certificate, key, canonizedObject, objectInPascalCase, objectSorted, objectBuffer, verifySignature;
|
|
97
|
+
var serverResponse, plexoResponse, err_1, certificate, key, canonizedObject, objectInPascalCase, objectSorted, objectWithAmounts, objectBuffer, verifySignature;
|
|
97
98
|
return __generator(this, function (_a) {
|
|
98
99
|
switch (_a.label) {
|
|
99
100
|
case 0:
|
|
@@ -114,7 +115,7 @@ var unwrapCallback = function (fingerprint, response) { return __awaiter(void 0,
|
|
|
114
115
|
case 3:
|
|
115
116
|
certificate = new crypto_1.X509Certificate(Buffer.from(plexoResponse.Object.Object.Response.Key, 'base64'));
|
|
116
117
|
key = certificate.publicKey.export({ format: 'pem', type: 'pkcs1' });
|
|
117
|
-
logger_lib_1.default.info(response
|
|
118
|
+
logger_lib_1.default.info(response, 'Callback de Plexo');
|
|
118
119
|
canonizedObject = signatureUtils_1.signatureUtils.canonizeJson(response.object, [
|
|
119
120
|
'CreditLimits',
|
|
120
121
|
'creditLimits',
|
|
@@ -122,8 +123,9 @@ var unwrapCallback = function (fingerprint, response) { return __awaiter(void 0,
|
|
|
122
123
|
logger_lib_1.default.info(canonizedObject, 'Objeto canonizado');
|
|
123
124
|
objectInPascalCase = utils_1.caseUtils.toPascalKeys(canonizedObject);
|
|
124
125
|
objectSorted = signatureUtils_1.signatureUtils.sortObject(objectInPascalCase);
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
objectWithAmounts = (0, stringifyWithFloats_1.stringifyAmountsWithFloats)(objectSorted);
|
|
127
|
+
logger_lib_1.default.info(objectWithAmounts, 'Objeto a verificar');
|
|
128
|
+
objectBuffer = Buffer.from(JSON.stringify(objectWithAmounts));
|
|
127
129
|
verifySignature = (0, crypto_1.createVerify)('SHA512')
|
|
128
130
|
.update(objectBuffer)
|
|
129
131
|
.verify(key, response.signature, 'base64');
|
|
@@ -133,6 +135,7 @@ var unwrapCallback = function (fingerprint, response) { return __awaiter(void 0,
|
|
|
133
135
|
resultCode: verifySignature ? __1.ResultCodes.Ok : __1.ResultCodes.InvalidSignature,
|
|
134
136
|
errorMessage: verifySignature ? 'Success' : 'Signature do not match',
|
|
135
137
|
};
|
|
138
|
+
logger_lib_1.default.info(serverResponse, 'Server response, end of unwrap');
|
|
136
139
|
return [2 /*return*/, serverResponse];
|
|
137
140
|
}
|
|
138
141
|
});
|
|
@@ -62,10 +62,12 @@ var stringifyAmountsWithFloats = function (object) {
|
|
|
62
62
|
billedAmount: 'float',
|
|
63
63
|
taxedAmount: 'float',
|
|
64
64
|
vatAmount: 'float',
|
|
65
|
+
returnAmount: 'float',
|
|
65
66
|
Amount: 'float',
|
|
66
67
|
BilledAmount: 'float',
|
|
67
68
|
TaxedAmount: 'float',
|
|
68
69
|
VATAmount: 'float',
|
|
69
|
-
|
|
70
|
+
ReturnAmount: 'float',
|
|
71
|
+
}, 2)(object, null, 0);
|
|
70
72
|
};
|
|
71
73
|
exports.stringifyAmountsWithFloats = stringifyAmountsWithFloats;
|