This toolkit exposes 3 utilities:
- Parameter Signer (to sign and send)
- Parameter Authenticator (to unsign and read signed parameters)
- Express webhook (to process notification events)
The signer is to sign form parameters to send to eMerchantPay
app.get('/payment/', function (req, res) {
var ParamSigner = require('node-emerchantpay').ParamSigner;
// initialize it from the constructor
var ps = new ParamSigner({
// secret, url, lifetime, signatureType
secret: 'xxxxxxxx',
url: 'https://payment-xxxxxxxxx.emerchantpay.com/payment/form/post'
}, {
// key/value params
'client_id': 'xxxxxxxxxx',
'form_id': 'xxxxxxxxx'
});
// or initialize it using setters
var ps = new ParamSigner();
ps.setURL('https://payment-xxxxxxxxx.emerchantpay.com/payment/form/post');
ps.setSecret('xxxxxxxx');
ps.setParam('client_id', 'xxxxxxxx');
ps.setParam('form_id', 'xxxxx');
ps.setParam('test_transaction', 1);
ps.setParam('item_1_code', 'premium');
ps.setParam('item_1_predefined', 1);
ps.setParam('customer_email', req.user.email);
var url = ps.getUrlWithQueryString();
return res.render('payment', {
url: url
});
});
extends ../layouts/default
block body
iframe(src='#{url}', frameborder='0', scrolling='0', border='0', style='width: 100%; height:100%; min-height:1600px;')
The authenticator is to check the validity of incoming notifications from eMerchantPay
app.get('/payment/', function (req, res) {
var ParamAuthenticator = require('node-emerchantpay').ParamAuthenticator;
var pa = new ParamAuthenticator({
secret: 'xxxxxxx'
}, req.body); // returs true or false or throws an error
});
The webhook is there to hook into express and also to provide you with means to process notification events
app.post('/payment/', function (req, res, next) {
var EmpWebhook = require('node-emerchantpay').WebHook;
empWebhook = new EmpWebhook({
secret: 'xxxxxxxxx',
notifications: {
'order': function (notification, response) {
trace.log('processed order: ' + notification.notification_type);
response.status(200).send('OK');
}
}
})
return empWebhook(req, res, next);
});
DEBUG=node-emerchantpay:* node .
DEBUG=node-emerchantpay:signer node .
DEBUG=node-emerchantpay:authenticator node .
DEBUG=node-emerchantpay:webhook node .