Create a gist now

Instantly share code, notes, and snippets.

Using node.js to make payment using a stored card in Peach Payments
var request = require('request'),
Config = require('./config'),
config = new Config();
//Simple config to hold environment specific values
exports.makePayment = function(data, callback) {
var params = {
'SECURITY.SENDER': config.securitySender,
'USER.LOGIN': config.userLogin,
'USER.PWD': config.userPwd,
'TRANSACTION.CHANNEL': config.transactionChannel,
'TRANSACTION.MODE': config.transactionMode,
'REQUEST.VERSION': "1.0",
'IDENTIFICATION.TRANSACTIONID': data.transactionId, //Your own transactionId here
'FRONTEND.ENABLED': "false",
'ACCOUNT.REGISTRATION': data.uniqueId, //This is the IDENTIFICATION.UNIQUEID supplied by Peach after card registration
'PAYMENT.CODE': data.transactionType, //CC.RG for card registration ... CC.DB for payment
'NAME.GIVEN': data.user.name,
'NAME.FAMILY': data.user.surname,
'CONTACT.EMAIL': data.user.email,
'PRESENTATION.AMOUNT': data.price,
'PRESENTATION.CURRENCY': "ZAR"
}
var url = config.peachUrl;
request.post(url, {form: params}, function (err, res, body) {
if (err) callback(err);
var payload = {};
body.split("&").forEach(function (responseParts) {
console.log(responseParts);
var keyValues = responseParts.split('=');
payload[keyValues[0]] = decodeURIComponent(keyValues[1]);
});
callback(null);
})
}
var data = {
transactionId: 'IanTransaction2',
price: '250.00',
transactionType: 'CC.DB',
uniqueId: 'xxx', //This is the IDENTIFICATION.UNIQUEID supplied by Peach after card registration
user: {
name: 'Ian',
surname: 'Petzer',
email: 'ian@mailinator.com'
}
}
exports.makePayment(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment