Coder Social home page Coder Social logo

payfort-node's Introduction

Payfort Payment API

There seems to be some changes to payfort api which breaks the below method and forces to run the payments via client side. I am yet to find a fix, when I will i'll update the repo.

Basic useful feature list:

  • Allows you to make Payfort Credit/Debit card Payment API
  • PayAtHome method not yet supported
  • If you have experience with SOAP Client on Node.JS then please contact me we can do payfort-PayAtHOme API for this module.

Install

npm install payfort-node --save

And here's some code! ๐Ÿ‘

// initialize the client
var payfort = require("payfort-node");
// create client
var client = payfort.create_client("development", {
  access_code : "your_access_code",
  merchant_identifier : "your_merchant_identifier",
  passphrase : "your_passphrase"
  purchase_url : "send this only to override default urls"
});
// default URLs
// Authorization/Purchase URLs
// Test Environment URL: https://sbcheckout.payfort.com/FortAPI/paymentPage
// Production Environment URL: https://checkout.payfort.com/FortAPI/paymentPage
// purchase data to be sent to payfort
var purchaseData = {
  "amount": data.amount,
  "command" : "PURCHASE", // PURCHASE OR AUTHORIZATION
  "currency": data.currency,
  "customer_email": data.email,
  "customer_name": data.name,
  "language": "ar",
  "return_url": "https://your_website.com/packages/v1/callback",
  "merchant_reference": data.order_id
};
//call payfort API
payfort.send_request(client, purchaseData, function(err, response){
  if(err){
      //error stuff
    }
    //handle response
})

When you get the callback from payfort you can use the following code to validate the data sent by payfort.

// Callback will be a get request so below valiable 'get_request' will the decoded Query Parameters

var get_request = {
  // decoded query params
};
var original_signature = get_request.signature;
delete response.signature;
var new_signature = payfort.create_signature("your_passphrase", get_request);

if(original_signature == new_signature){
  // valid data
}else{
  // invalid data
}

payfort-node's People

Contributors

rohithzr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.