48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
|
|
||
|
module.exports = Self => {
|
||
|
Self.remoteMethod('confirm', {
|
||
|
description: 'Confirms electronic payment transaction',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [
|
||
|
{
|
||
|
arg: 'Ds_SignatureVersion',
|
||
|
type: 'string',
|
||
|
required: true,
|
||
|
}, {
|
||
|
arg: 'Ds_MerchantParameters',
|
||
|
type: 'string',
|
||
|
required: true,
|
||
|
}, {
|
||
|
arg: 'Ds_Signature',
|
||
|
type: 'string',
|
||
|
required: true,
|
||
|
}
|
||
|
],
|
||
|
returns: {
|
||
|
type: 'Boolean',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/confirm`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.confirm = async(signatureVersion, merchantParameters, signature) => {
|
||
|
const buffer = Buffer.from(merchantParameters, 'base64');
|
||
|
const params = JSON.parse(buffer.toString());
|
||
|
console.debug('Payment confirmation received:', params);
|
||
|
await Self.rawSql(
|
||
|
'CALL hedera.tpvTransaction_confirm(?, ?, ?, ?, ?, ?)', [
|
||
|
params['Ds_Amount'],
|
||
|
params['Ds_Order'],
|
||
|
params['Ds_MerchantCode'],
|
||
|
params['Ds_Currency'],
|
||
|
params['Ds_Response'],
|
||
|
params['Ds_ErrorCode']
|
||
|
]
|
||
|
);
|
||
|
return true;
|
||
|
};
|
||
|
};
|