Skip to content

Instantly share code, notes, and snippets.

@alovak
Created April 13, 2016 16:27
Show Gist options
  • Save alovak/c75b4f99a08282c939c1c64a0bb2ee24 to your computer and use it in GitHub Desktop.
Save alovak/c75b4f99a08282c939c1c64a0bb2ee24 to your computer and use it in GitHub Desktop.
// Install library before:
// > npm install node-rest-client
//
// More information about rest client: https://www.npmjs.com/package/node-rest-client
var Client = require('node-rest-client').Client;
var client = new Client({ user: "YOUR SECRET API KEY GOES HERE" });
var args = {
data: {
amount: 100, // in cents, so it's actually 1.00 AED
currency: "AED",
email: "customer@address.com",
// token should be received using Beautiful.js library https://docs.start.payfort.com/guides/beautiful.js
card: "CARD TOKEN SHOULD GO HERE",
description: "Charge description",
metadata: {
reference_id: "ORDER ID IN YOUR SYSTEM"
}
// other parameters can be found here: https://docs.start.payfort.com/references/api/
},
headers: { "Content-Type": "application/json" }
};
client.post("http://remote.site/rest/xml/method", args, function (data, response) {
// parsed response body as js object
console.log(data);
// raw response
console.log(response);
});
client.on('error', function (err) {
console.error('Something went wrong on the client', err);
});
@Humphrey2641405
Copy link

Great!
"remote.site" means the server site that has an account payfort?
If so, would you show me the code for refunding from the server to the client?

@kpsdeveloper
Copy link

I have problem with generate token with nodejs who can advice me thanks
{
"error": {
"type": "request",
"code": "unprocessable_entity",
"message": "Request params are invalid.",
"extras": {
"card": [
"card (or token) has to be authenticated with 3-D Secure"
]
}
}
}

@kpsdeveloper
Copy link

How to receive token using Beautiful.js with node? appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment