Node Module for integrating CCAvenue Payment gateway in Node.js
Before using this module, please make sure you have your merchant_id and working_key for test and production environment from CCAVenue payment gateway.
$ npm install node-ccavenue --save
or
$ yarn add node-ccavenue
Make sure your test / production merchantId and workingKey are stored as environment variables (best practice)
const nodeCCAvenue = require('node-ccavenue');
const ccav = new nodeCCAvenue({
merchant_id: process.env.test_merchant_id || process.env.prod_merchant_id,
working_key: process.env.test_working_key || process.env.prod_working_key,
});
You are free to use the encryption and decryption methods from the package. Which are exported as is.
const encryptedData = ccav.encrypt('Just plain text to encrypt or uri encoded order information');
console.log(encryptedData); // Proceed further
const decryptedData = ccav.decrypt(encryptedData);
console.log(decryptedData); // Proceed further
No need to use the encrypt function in this case.
const orderParams = {
order_id: 8765432,
currency: 'INR',
amount: '100',
redirect_url: encodeURIComponent(`http://localhost:3000/api/redirect_url/`)
billing_name: 'Name of the customer',
// etc etc
};
const encryptedOrderData = ccav.getEncryptedOrder(orderParams);
console.log(encryptedOrderData); // Proceed further
// Considering this is your redirect_url
router.post('/api/redirect_url', (req, res) => {
const { encResp } = req.body;
const decryptedJsonResponse = ccav.redirectResponseToJson(encResp);
// To check order_status: -
console.log(decryptedJsonResponse.order_status);
});
Feel free to open issues if you find any, or simply fork and create a pull request