how to integrate ccavenue payment gateway with standard instruction in node js. Please suggest workflow.
I created JSON with required parameters and encrypt data with working key. when i post following encrypted data at URL : https://apitest.ccavenue.com/apis/servlet/DoWebTrans with content type: x-www-form-urlencoded then getting following error
status=1&enc_response=Access_code: Invalid Parameter&enc_error_code=51407
const post_data = {
si_type:"fixed",
si_ref_no:requestBody.subscription_uuid,
si_amount: (requestBody.monthly_price*requestBody.allowed_users),
si_setup_amount:(requestBody.monthly_price*requestBody.allowed_users),
si_currency:requestBody.currency,
si_start_date:formattedDate,
si_frequency:frequency,
si_frequency_type:frequency_type,
si_billing_cycle:billing_cycle,
si_customer_email:user.email,
si_customer_mobile_number:user.phone_number,
si_customer_name:(user.fullName)?user.fullName:user.firstName+' '+user.lastName,
si_billing_address:'Mayur Vihar',
si_billing_city:'Delhi',
si_billing_country:'India',
si_billing_state:'Delhi',
si_billing_zip:'122002',
si_shipping_address:'Mayur Vihar',
si_shipping_city:'Delhi',
si_shipping_country:'India',
si_shipping_state:'Delhi',
si_shipping_zip:'122002',
}
const encrypted_data = await UtilsCCAvenue.encrypt(buildMerchantData(post_data), working_key);
UtilsCCAvenue.js
const crypto = require('crypto');
exports.encrypt = async(plainText, workingKey) => {
const secretKey = hexToBin(md5(workingKey));
const initVector = Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]);
const cipher = crypto.createCipheriv('aes-128-cbc', secretKey, initVector);
let encryptedData = cipher.update(pkcs5Pad(plainText), 'utf-8', 'hex');
encryptedData += cipher.final('hex');
return encryptedData;
}
function hexToBin(hexString) {
return Buffer.from(hexString, 'hex');
}
function md5(data) {
return crypto.createHash('md5').update(data).digest('hex');
}
function pkcs5Pad(data) {
const blockSize = 16;
const padLength = blockSize - (data.length % blockSize);
const padding = String.fromCharCode(padLength).repeat(padLength);
return data + padding;
}