Skip to content

Instantly share code, notes, and snippets.

@ianpetzer
Created October 23, 2013 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianpetzer/7115687 to your computer and use it in GitHub Desktop.
Save ianpetzer/7115687 to your computer and use it in GitHub Desktop.
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