bug fixes for payrexx integration (still no good)

This commit is contained in:
2023-09-11 15:10:39 +02:00
parent 171cba0833
commit 9f75aaac99
2 changed files with 56 additions and 42 deletions

View File

@@ -16,6 +16,10 @@ const hmacSHA256 = require( 'crypto-js/hmac-sha256' );
const payrexxConfig = JSON.parse( fs.readFileSync( path.join( __dirname + '/config.payments.secret.json' ) ) ); const payrexxConfig = JSON.parse( fs.readFileSync( path.join( __dirname + '/config.payments.secret.json' ) ) );
const baseUrl = 'https://api.payrexx.com/v1.0/'; const baseUrl = 'https://api.payrexx.com/v1.0/';
if ( !payrexxConfig.APISecret || !payrexxConfig.instance ) {
throw new Error( '[ Payrexx ] No API secret or instance name configured!' );
}
const instance = payrexxConfig.instance; const instance = payrexxConfig.instance;
const secret = payrexxConfig.APISecret; const secret = payrexxConfig.APISecret;
@@ -32,10 +36,12 @@ exports.init = function () {
getGateway: function ( id ) { getGateway: function ( id ) {
const baseUrl = buildBaseUrl( 'Gateway/' + id + '/' ); const baseUrl = buildBaseUrl( 'Gateway/' + id + '/' );
const url = baseUrl + '&ApiSignature=' + buildSignature(); const url = baseUrl + '&ApiSignature=' + buildSignature();
console.error( url );
return axios.get( url ); return axios.get( url );
}, },
createGateway: function ( params ) { createGateway: function ( params ) {
if ( !params.amount ) { if ( !params.amount ) {
// TODO: Think if we really have to throw here
throw new Error( 'Amount required!' ); throw new Error( 'Amount required!' );
} }

View File

@@ -18,6 +18,7 @@ const TicketGenerator = new ticket();
let sessionReference = {}; let sessionReference = {};
let waitingClients = {}; let waitingClients = {};
let pendingPayments = {}; let pendingPayments = {};
let gatewayReference = {};
let paymentOk = {}; let paymentOk = {};
module.exports = ( app, settings ) => { module.exports = ( app, settings ) => {
@@ -33,6 +34,7 @@ module.exports = ( app, settings ) => {
'currency': settings.currency, 'currency': settings.currency,
'basket': [], 'basket': [],
'amount': 0, 'amount': 0,
'referenceId': req.session.id,
}; };
db.getDataSimple( 'temp', 'user_id', req.session.id ).then( dat => { db.getDataSimple( 'temp', 'user_id', req.session.id ).then( dat => {
@@ -55,6 +57,7 @@ module.exports = ( app, settings ) => {
const session = response.data.data[ 0 ]; const session = response.data.data[ 0 ];
sessionReference[ session.id ] = { 'tok': req.session.id, 'email': req.session.username }; sessionReference[ session.id ] = { 'tok': req.session.id, 'email': req.session.username };
pendingPayments[ req.session.id ] = true; pendingPayments[ req.session.id ] = true;
gatewayReference[ req.session.id ] = session.id;
res.send( session.link ); res.send( session.link );
} else { } else {
res.status( 500 ).send( 'ERR_PAYMENT' ); res.status( 500 ).send( 'ERR_PAYMENT' );
@@ -130,9 +133,9 @@ module.exports = ( app, settings ) => {
} }
} ); } );
app.post( '/payments/webhook', bodyParser.raw( { type: 'application/json' } ), async ( req, res ) => { app.post( '/payments/webhook', bodyParser.json(), async ( req, res ) => {
console.error( req.body ); if ( req.body.transaction.status === 'confirmed' ) {
const response = await payrexx.getGateway( req.body.id ); const response = await payrexx.getGateway( gatewayReference[ req.body.transaction.referenceId ] );
if ( response.status === 200 ) { if ( response.status === 200 ) {
const gateway = response.data.data[ 0 ]; const gateway = response.data.data[ 0 ];
@@ -178,6 +181,11 @@ module.exports = ( app, settings ) => {
console.error( err ); console.error( err );
} ); } );
} }
} else {
res.send( 'ok' );
}
} else {
res.send( 'ok' );
} }
} ); } );
}; };