@houlak/plexo-sdk 1.0.23 → 1.0.24
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.
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -67,6 +78,85 @@ var getTransactionStatus = function (transaction, transactionType) {
|
|
|
67
78
|
};
|
|
68
79
|
}
|
|
69
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* This function validates the response format to unify the response structure
|
|
83
|
+
* and to avoid errors when accessing the response properties.
|
|
84
|
+
*/
|
|
85
|
+
var validateTransactionResponse = function (request, response, transactionName) {
|
|
86
|
+
var _a;
|
|
87
|
+
var parsedResponse = response;
|
|
88
|
+
var mockString = 'nan-nananan-nana-nanana';
|
|
89
|
+
var isPurchase = transactionName === 'Purchase';
|
|
90
|
+
// This is a list of result codes that are considered incomplete responses
|
|
91
|
+
// and should be handled differently.
|
|
92
|
+
// 9: The Payment instrument is disabled.
|
|
93
|
+
// 10: The Payment instrument is expired.
|
|
94
|
+
// 15: The Payment instrument does not exist.
|
|
95
|
+
var resultCodesWithIncompleteResponse = [9, 10, 15];
|
|
96
|
+
var isIncompleteResponse = resultCodesWithIncompleteResponse.includes(response.resultCode);
|
|
97
|
+
if (isPurchase && isIncompleteResponse) {
|
|
98
|
+
var paymentRequest = request;
|
|
99
|
+
var currencyMap = {
|
|
100
|
+
1: { currencyId: 1, name: 'Peso', plural: 'Pesos', symbol: '$' },
|
|
101
|
+
2: { currencyId: 2, name: 'Dólar', plural: 'Dólares', symbol: 'USD' },
|
|
102
|
+
};
|
|
103
|
+
var currencyData = currencyMap[paymentRequest.currencyId] || {
|
|
104
|
+
currencyId: paymentRequest.currencyId,
|
|
105
|
+
name: 'Unknown',
|
|
106
|
+
plural: 'Unknown',
|
|
107
|
+
symbol: '?',
|
|
108
|
+
};
|
|
109
|
+
parsedResponse = __assign(__assign({}, response), { response: {
|
|
110
|
+
currentState: index_1.TransactionType.Purchase,
|
|
111
|
+
amount: paymentRequest.items[0].amount,
|
|
112
|
+
commerce: {
|
|
113
|
+
commerceId: (_a = paymentRequest.optionalCommerceId) !== null && _a !== void 0 ? _a : 0,
|
|
114
|
+
name: mockString,
|
|
115
|
+
},
|
|
116
|
+
currency: currencyData,
|
|
117
|
+
fieldInformation: {
|
|
118
|
+
address: mockString,
|
|
119
|
+
aggregatorId: mockString,
|
|
120
|
+
birthDate: mockString,
|
|
121
|
+
cardIssuer: mockString,
|
|
122
|
+
city: mockString,
|
|
123
|
+
commerceCity: mockString,
|
|
124
|
+
commerceCountry: mockString,
|
|
125
|
+
commerceRut: mockString,
|
|
126
|
+
cybersourceDeviceFingerprint: mockString,
|
|
127
|
+
email: mockString,
|
|
128
|
+
expiration: mockString,
|
|
129
|
+
firstName: mockString,
|
|
130
|
+
lastName: mockString,
|
|
131
|
+
mcc: mockString,
|
|
132
|
+
name: mockString,
|
|
133
|
+
paymentFacilitatorIntegratorId: mockString,
|
|
134
|
+
paymentProcessorId: mockString,
|
|
135
|
+
provider: mockString,
|
|
136
|
+
providerCommerceNumber: mockString,
|
|
137
|
+
softDescriptor: mockString,
|
|
138
|
+
subCommerceAddress: mockString,
|
|
139
|
+
subMerchantId: mockString,
|
|
140
|
+
},
|
|
141
|
+
instrumentToken: paymentRequest.paymentInstrumentInput.instrumentToken,
|
|
142
|
+
instrumentName: mockString,
|
|
143
|
+
installments: paymentRequest.installments,
|
|
144
|
+
transactionId: mockString,
|
|
145
|
+
isAnonymous: false,
|
|
146
|
+
isAsyncPayment: false,
|
|
147
|
+
transactions: {
|
|
148
|
+
purchase: {
|
|
149
|
+
clientReferenceId: paymentRequest.clientReferenceId,
|
|
150
|
+
clientMetadata: paymentRequest.optionalMetadata,
|
|
151
|
+
status: index_1.TransactionResult.Denied,
|
|
152
|
+
transactionCode: response.resultCode,
|
|
153
|
+
transactionResultText: response.errorMessage,
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
} });
|
|
157
|
+
}
|
|
158
|
+
return parsedResponse;
|
|
159
|
+
};
|
|
70
160
|
var genericEvaluator = function (request, response, withoutParams) {
|
|
71
161
|
if (withoutParams === void 0) { withoutParams = false; }
|
|
72
162
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -88,14 +178,20 @@ var genericEvaluator = function (request, response, withoutParams) {
|
|
|
88
178
|
});
|
|
89
179
|
};
|
|
90
180
|
var transactionEvaluator = function (request, response, transactionName, transactionType) {
|
|
181
|
+
logger_lib_1.default.info({ request: request, response: response, transactionName: transactionName }, '[PX-SDK] Transaction Evaluator');
|
|
182
|
+
if (!response) {
|
|
183
|
+
return new BaseResponse_1.BaseResponse(plexo_error_enum_1.PlexoErrorEnum.PlexoUnknownError, false, "Plexo unknown error on: ".concat(transactionName), response);
|
|
184
|
+
}
|
|
185
|
+
// Validate the response format to unify the response structure
|
|
186
|
+
var parsedResponse = validateTransactionResponse(request, response, transactionName);
|
|
91
187
|
var errorCode = plexo_error_enum_1.PlexoErrorEnum.Generic;
|
|
92
188
|
var errorMessage = '';
|
|
93
189
|
var plexoOrTransactionError = '';
|
|
94
190
|
var resultCode = response.resultCode;
|
|
95
|
-
var transactionStatus = getTransactionStatus(
|
|
191
|
+
var transactionStatus = getTransactionStatus(parsedResponse.response, transactionType);
|
|
96
192
|
if (resultCode !== index_1.ResultCodes.Ok) {
|
|
97
|
-
errorCode =
|
|
98
|
-
errorMessage =
|
|
193
|
+
errorCode = parsedResponse.resultCode;
|
|
194
|
+
errorMessage = parsedResponse.errorMessage;
|
|
99
195
|
plexoOrTransactionError = 'PLEXO ERROR';
|
|
100
196
|
}
|
|
101
197
|
if (transactionStatus.status !== index_1.TransactionResult[index_1.TransactionResult.Ok] &&
|
|
@@ -109,7 +205,7 @@ var transactionEvaluator = function (request, response, transactionName, transac
|
|
|
109
205
|
transactionStatus.status === index_1.TransactionResult[index_1.TransactionResult.Pending]) {
|
|
110
206
|
// Maybe we should add some project configuration to define
|
|
111
207
|
// wether or not we want to log successful transactions 🤔
|
|
112
|
-
return new BaseResponse_1.BaseResponse(undefined, true, 'Success',
|
|
208
|
+
return new BaseResponse_1.BaseResponse(undefined, true, 'Success', parsedResponse.response);
|
|
113
209
|
}
|
|
114
210
|
logger_lib_1.default.info({
|
|
115
211
|
transactionName: transactionName,
|
|
@@ -117,8 +213,6 @@ var transactionEvaluator = function (request, response, transactionName, transac
|
|
|
117
213
|
errorCode: errorCode,
|
|
118
214
|
errorMessage: errorMessage,
|
|
119
215
|
});
|
|
120
|
-
|
|
121
|
-
logger_lib_1.default.info({ response: response }, 'Response --> ');
|
|
122
|
-
return new BaseResponse_1.BaseResponse(errorCode, false, errorMessage, response.response);
|
|
216
|
+
return new BaseResponse_1.BaseResponse(errorCode, false, errorMessage, parsedResponse.response);
|
|
123
217
|
};
|
|
124
218
|
exports.Evaluator = { genericEvaluator: genericEvaluator, transactionEvaluator: transactionEvaluator };
|
package/lib/lib/logger.lib.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
declare const logger: import("pino").Logger<
|
|
2
|
-
level: string;
|
|
3
|
-
base: null;
|
|
4
|
-
nestedKey: string;
|
|
5
|
-
transport: any;
|
|
6
|
-
serializers: {
|
|
7
|
-
data: (data: any | Error) => any;
|
|
8
|
-
};
|
|
9
|
-
}>;
|
|
1
|
+
declare const logger: import("pino").Logger<never>;
|
|
10
2
|
export default logger;
|