refs #5174 TpvTransaction.confirm code refator to improve debugging
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2023-03-03 18:55:58 +01:00
parent 5984d6820b
commit 99f8bc6bac
1 changed files with 19 additions and 19 deletions

View File

@ -32,23 +32,24 @@ module.exports = Self => {
Self.confirm = async(signatureVersion, merchantParameters, signature) => {
const $ = Self.app.models;
const decodedParams = JSON.parse(
base64url.decode(merchantParameters, 'utf8'));
const params = {};
for (const param in decodedParams)
params[param] = decodeURIComponent(decodedParams[param]);
const orderId = params['Ds_Order'];
if (!orderId)
throw new UserError('Order id not provided');
const transaction = await Self.findById(orderId, {fields: ['id']});
if (!transaction)
throw new UserError('Order not found');
let transaction;
try {
const decodedParams = JSON.parse(
base64url.decode(merchantParameters, 'utf8'));
const params = {};
for (const param in decodedParams)
params[param] = decodeURIComponent(decodedParams[param]);
const orderId = params['Ds_Order'];
if (!orderId)
throw new UserError('Order id not provided');
transaction = await Self.findById(orderId, {fields: ['id']});
if (!transaction)
throw new UserError('Order not found');
await transaction.updateAttributes({
merchantParameters,
signature,
@ -86,11 +87,10 @@ module.exports = Self => {
return true;
} catch (err) {
try {
if (transaction)
await transaction.updateAttribute('responseError', err.message);
} catch (e) {
console.error(e);
}
else
console.error(err);
throw err;
}
};