From 109556ae2eb647efb2e688305e4d69bc0cf2ea70 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 30 Jan 2023 12:39:47 +0100 Subject: [PATCH] refs #5122 Hotfix: Basic implementation for payment confirmation --- .../back/methods/tpv-transaction/confirm.js | 47 +++++++++++++++++++ modules/client/back/models/tpv-transaction.js | 3 ++ 2 files changed, 50 insertions(+) create mode 100644 modules/client/back/methods/tpv-transaction/confirm.js create mode 100644 modules/client/back/models/tpv-transaction.js diff --git a/modules/client/back/methods/tpv-transaction/confirm.js b/modules/client/back/methods/tpv-transaction/confirm.js new file mode 100644 index 000000000..21484b220 --- /dev/null +++ b/modules/client/back/methods/tpv-transaction/confirm.js @@ -0,0 +1,47 @@ + +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; + }; +}; diff --git a/modules/client/back/models/tpv-transaction.js b/modules/client/back/models/tpv-transaction.js new file mode 100644 index 000000000..b511ae52e --- /dev/null +++ b/modules/client/back/models/tpv-transaction.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/tpv-transaction/confirm')(Self); +};