Integrate CardConnect Payment with Node.js

    Sep 10, 2019       by Pankaj Kumar
integrate-cardConnect-with-nodejs.jpg

There are many payment gateways available today for our application. Today, I am going to create a sample application to integrate Node.js application with CardConnect Payment gateway. 

 

CardConnect is a payments platform of Fiserv, focused on helping businesses of all sizes grow through the seamless integration of secure payment processing.

NPM package required

We will use here Axios package of NPM to connect with CardConnect API.

 

Let's Get Started

Create new project folder and create a file named server.js, Have a look on code inside server.js below:

 
const axios = require('axios');
 
const paymentCredential = new Buffer('testing:testing123').toString('base64');
 
const getPaymentAuthToken = async (data) => {
 
  try {
    const config = {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Basic ${paymentCredential}`
      }
    };
    const URL = 'https://fts.cardconnect.com:6443/cardconnect/rest/auth';
    return await axios.put(URL, data, config);
 
  } catch (error) {
    throw (error);
  }
}
 
const makeCharge = async (data) => {
 
  try {
    const config = {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Basic ${paymentCredential}`
      }
    };
 
    const URL = 'https://fts.cardconnect.com:6443/cardconnect/rest/capture';
   return await axios.put(URL, data, config);
 
  } catch (error) {
    throw (error);
  }
}
 
(async() => {
  const paymentRequest = await getPaymentAuthToken({
    account: '4444333322221111',
    merchid: '496160873888',
    amount: '1000', // for charging $1.00
    expiry: '1260',
    currency: 'USD'
  });
 
  const charge = await makeCharge({
    merchid: paymentRequest.data.merchid,
    retref: paymentRequest.data.retref
  });
 console.log(charge);
 
})();

 

In the above code, At the top we have method getPaymentAuthToken method used for getting auth token for card connect server. Test credentials for sandbox has been used everywhere in the file. In middle there is a makeCharge method which is actually charging the required amount from the card/bank detail.

Run the app

node server.js

 

Conclusion

Integration of CardConnect payment is very easy with Node.js. If you are new to Node.js then click here find many demos to start the app for enterprise-level application

Let me know your thoughts over the email demo.jsonworld@gmail.com. I would love to hear them and If you like this article, share with your friends.

Thank you!


WHAT'S NEW

Find other similar Articles here: