Skip to content

PGP MTLS BATCH UPLOAD SAMPLES #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Resource/batchApiMTLS/batchapiTest.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
merchantID=qaebc2,batchID=rgdltnd0,recordCount=2,statusEmail=ynachire@visa.com,targetAPIVersion=1.86,creationDate=2025-03-05,reference=
merchantID,merchantReferenceCode,merchantDefinedData_field1,ccAuthService_run,billTo_firstName,billTo_lastName,billTo_email,billTo_street1,billTo_city,billTo_state,billTo_country,billTo_postalCode,card_accountNumber,card_expirationMonth,card_expirationYear,card_cardType,purchaseTotals_currency,purchaseTotals_grandTotalAmount,item_#_productCode
qaebc2,1,4837,true,Jay,Smith,ynachire@visa.com,8 Mission Street,San Francisco,CA,US,94101,4111111111111111,12,2036,001,GBP,8.00,1
qaebc2,2,7209,true,Jay,Smith,ynachire@visa.com,8 Mission Street,San Francisco,CA,US,94101,4111111111111111,12,2036,001,GBP,8.00,1
END,SUM=16.00
91 changes: 91 additions & 0 deletions Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict';

const path = require('path');
const BatchUploadWithMTLSApi = require('cybersource-rest-client/src/api/BatchUploadWithMTLSApi');

function writeLogAudit(status) {
const filename = path.basename(__filename).split('.')[0];
console.log(`[Sample Code Testing] [${filename}] ${status}`);
}

function run(callback) {
try {
// File path: add your own path
const fileName = 'batchapiTest.csv';
const inputFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/', fileName);

// Env Host name
const environmentHostname = 'secure-batch-test.cybersource.com';

// PGP Public Key Path: add your own path
const publicKeyFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/bts-encryption-public.asc');

// Client Private Key Path: add your own path
const clientPrivateKeyFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_private_key.key');

// Client Certificate Path: add your own path
const clientCertFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_cert.crt');

// Server Certificate Path: add your own path
const serverTrustCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem');

// Log configuration
const log_config = {
enableLog: true,
logFileName: 'cybs-batch-upload',
logDirectory: './logs',
logFileMaxSize: 5242880,
loggingLevel: 'debug',
enableMasking: false
};


const apiInstance = new BatchUploadWithMTLSApi(log_config);

const opts = {
inputFilePath,
environmentHostname,
publicKeyFilePath,
clientPrivateKeyFilePath,
clientCertFilePath,
serverTrustCertPath,
// clientKeyPassword: undefined, // add if needed
verify_ssl: true
};

apiInstance.uploadBatchAPIWithKeys(
opts,
function (error, result) {
if (error) {
if (error.message) {
console.log('\nError :', error.message);
} else if (error.error && error.error.message) {
console.log('\nError :', error.error.message);
} else {
console.log('\nError :', JSON.stringify(error, null, 2));
}
writeLogAudit('Error');
} else if (result) {
const responseCode = result.status;
const responseMessage = result.statusText;
console.log('ResponseCode :', responseCode);
console.log('ResponseMessage :', responseMessage);
writeLogAudit(responseCode);
}
if (callback) callback(error, result);
}
);
} catch (e) {
console.log('\nException : ' + e);
writeLogAudit('Exception');
if (callback) callback(e);
}
}

if (require.main === module) {
run(function () {
console.log('\nBatchUploaMTLSWithKeys Sample end.');
});
}

module.exports.run = run;
83 changes: 83 additions & 0 deletions Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

const path = require('path');
const BatchUploadWithMTLSApi = require('cybersource-rest-client/src/api/BatchUploadWithMTLSApi');

function writeLogAudit(status) {
const filename = path.basename(__filename).split('.')[0];
console.log(`[Sample Code Testing] [${filename}] ${status}`);
}

function run(callback) {
try {
// Input file: : add your own path
const inputFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/batchapiTest.csv');
// Host name
const envHostName = 'secure-batch-test.cybersource.com';

// Path of public key for pgp encryption: add your own path
const publicKeyFile = path.resolve(__dirname, '../../Resource/batchApiMTLS/bts-encryption-public.asc');
// Path (P12) containing client private key and cert: add your own path
const clientCertP12FilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/pushtest.p12');

// Store password: : add your own
const clientCertP12Password = 'changeit';

// Server cert: : add your own path
const serverTrustCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem');
const log_config = {
enableLog: true,
logFileName: 'cybs-batch-upload',
logDirectory: './logs',
logFileMaxSize: 5242880,
loggingLevel: 'debug'
};

const apiInstance = new BatchUploadWithMTLSApi(log_config);

const opts = {
inputFilePath,
environmentHostname: envHostName,
publicKeyFilePath: publicKeyFile,
clientCertP12FilePath,
clientCertP12Password,
serverTrustCertPath,
verify_ssl: true
};

apiInstance.uploadBatchAPIWithP12(
opts,
function (error, result) {
if (error) {
if (error.message) {
console.log('\nError :', error.message);
} else if (error.error && error.error.message) {
console.log('\nError :', error.error.message);
} else {
console.log('\nError :', JSON.stringify(error, null, 2));
}
writeLogAudit('Error');
} else if (result) {
const responseCode = result.status;
const responseMessage = result.statusText;
console.log('ResponseCode :', responseCode);
console.log('ResponseMessage :', responseMessage);
writeLogAudit(responseCode);
}
if (callback) callback(error, result);
}
);
} catch (e) {
console.log('\nException : ' + e);
writeLogAudit('Exception');
if (callback) callback(e);
}
}

if (require.main === module) {
run(function () {
console.log('\nBatchUploadMTLSWithP12 Sample end.');
});
}

module.exports.run = run;