From 7ae8cf3deb57c8e17c477b938c068ecdc4e6718c Mon Sep 17 00:00:00 2001 From: mahmishr Date: Fri, 20 Jun 2025 10:26:39 +0530 Subject: [PATCH 1/4] samples updated --- Resource/batchApiMTLS/batchapiTest.csv | 5 ++ .../BatchUploadAPI/BatchUploaMTLSWithKeys.js | 67 +++++++++++++++++++ .../BatchUploadAPI/BatchUploadMTLSWithP12.js | 64 ++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 Resource/batchApiMTLS/batchapiTest.csv create mode 100644 Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js create mode 100644 Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js diff --git a/Resource/batchApiMTLS/batchapiTest.csv b/Resource/batchApiMTLS/batchapiTest.csv new file mode 100644 index 0000000..0b8df03 --- /dev/null +++ b/Resource/batchApiMTLS/batchapiTest.csv @@ -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 \ No newline at end of file diff --git a/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js new file mode 100644 index 0000000..1235080 --- /dev/null +++ b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js @@ -0,0 +1,67 @@ +'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 from resources folder + const fileName = 'batchapiTest.csv'; + const inputFile = path.resolve(__dirname, '../../Resource/batchApiMTLS/', fileName); + + // Env Host name + const envHostName = 'secure-batch-test.cybersource.com'; + + // PGP Public Key Path + const publicKeyPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/bts-encryption-public.asc'); + + // Client Private Key Path + const clientPrivateKeyPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_private_key.key'); + + // Client Certificate Path + const clientCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_cert.crt'); + + // Server Certificate Path + const serverCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem'); + + const apiInstance = new BatchUploadWithMTLSApi(); + + apiInstance.uploadBatchAPIWithKeys({ + inputFilePath: inputFile, + environmentHostname: envHostName, + publicKeyFilePath: publicKeyPath, + clientPrivateKeyFilePath: clientPrivateKeyPath, + clientCertFilePath: clientCertPath, + serverTrustCertPath: serverCertPath + }, function (error, result) { + if (error) { + console.log('\nError : ' + JSON.stringify(error)); + 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; \ No newline at end of file diff --git a/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js new file mode 100644 index 0000000..913375d --- /dev/null +++ b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js @@ -0,0 +1,64 @@ +'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 + 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 + const publicKeyFile = path.resolve(__dirname, '../../Resource/batchApiMTLS/bts-encryption-public.asc'); + // Store path (P12) containing client private key and cert + const p12Path = path.resolve(__dirname, '../../Resource/batchApiMTLS/pushtest.p12'); + + // Store password + const p12Password = 'changeit'; + + // Store path (server cert) + const serverCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem'); + + const apiInstance = new BatchUploadWithMTLSApi(); + + apiInstance.uploadBatchAPIWithP12({ + inputFilePath, + environmentHostname: envHostName, + publicKeyFilePath: publicKeyFile, + clientCertP12FilePath: p12Path, + clientCertP12Password: p12Password, + serverTrustCertPath: serverCertPath + }, function (error, result) { + if (error) { + console.log('\nError : ' + JSON.stringify(error)); + 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; \ No newline at end of file From cea1c5403c17822714bea4f7bfdffece2d32f61f Mon Sep 17 00:00:00 2001 From: mahmishr Date: Tue, 24 Jun 2025 11:19:30 +0530 Subject: [PATCH 2/4] log config --- .../BatchUploadAPI/BatchUploaMTLSWithKeys.js | 30 +++++++++++++------ .../BatchUploadAPI/BatchUploadMTLSWithP12.js | 27 ++++++++++++----- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js index 1235080..02614d2 100644 --- a/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js +++ b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js @@ -29,16 +29,28 @@ function run(callback) { // Server Certificate Path const serverCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem'); - const apiInstance = new BatchUploadWithMTLSApi(); + // Log configuration + const log_config = { + enableLog: true, + logFileName: 'cybs-batch-upload', + logDirectory: './logs', + logFileMaxSize: 5242880, + loggingLevel: 'debug', + enableMasking: false + }; - apiInstance.uploadBatchAPIWithKeys({ - inputFilePath: inputFile, - environmentHostname: envHostName, - publicKeyFilePath: publicKeyPath, - clientPrivateKeyFilePath: clientPrivateKeyPath, - clientCertFilePath: clientCertPath, - serverTrustCertPath: serverCertPath - }, function (error, result) { + const apiInstance = new BatchUploadWithMTLSApi(log_config); + + apiInstance.uploadBatchAPIWithKeys( + inputFile, + envHostName, + publicKeyPath, + clientPrivateKeyPath, + clientCertPath, + serverCertPath, + undefined, + undefined, + function (error, result) { if (error) { console.log('\nError : ' + JSON.stringify(error)); writeLogAudit('Error'); diff --git a/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js index 913375d..c4e2835 100644 --- a/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js +++ b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js @@ -26,16 +26,27 @@ function run(callback) { // Store path (server cert) const serverCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem'); - const apiInstance = new BatchUploadWithMTLSApi(); + //Log configuration + const log_config = { + enableLog: true, + logFileName: 'cybs-batch-upload', + logDirectory: './logs', + logFileMaxSize: 5242880, + loggingLevel: 'debug', + enableMasking: false + }; - apiInstance.uploadBatchAPIWithP12({ + const apiInstance = new BatchUploadWithMTLSApi(log_config); + + apiInstance.uploadBatchAPIWithP12( inputFilePath, - environmentHostname: envHostName, - publicKeyFilePath: publicKeyFile, - clientCertP12FilePath: p12Path, - clientCertP12Password: p12Password, - serverTrustCertPath: serverCertPath - }, function (error, result) { + envHostName, + publicKeyFile, + p12Path, + p12Password, + serverCertPath, + true, + function (error, result) { if (error) { console.log('\nError : ' + JSON.stringify(error)); writeLogAudit('Error'); From b7dc8b7fb2a8b17f100cf06fe645ed43a6b9a03c Mon Sep 17 00:00:00 2001 From: mahmishr Date: Wed, 25 Jun 2025 09:17:31 +0530 Subject: [PATCH 3/4] samples updated with opts --- .../BatchUploadAPI/BatchUploaMTLSWithKeys.js | 73 +++++++++++-------- .../BatchUploadAPI/BatchUploadMTLSWithP12.js | 70 ++++++++++-------- 2 files changed, 81 insertions(+), 62 deletions(-) diff --git a/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js index 02614d2..01a6ce7 100644 --- a/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js +++ b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js @@ -10,24 +10,24 @@ function writeLogAudit(status) { function run(callback) { try { - // File path from resources folder + // File path: add your own path const fileName = 'batchapiTest.csv'; - const inputFile = path.resolve(__dirname, '../../Resource/batchApiMTLS/', fileName); + const inputFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/', fileName); // Env Host name - const envHostName = 'secure-batch-test.cybersource.com'; + const environmentHostname = 'secure-batch-test.cybersource.com'; - // PGP Public Key Path - const publicKeyPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/bts-encryption-public.asc'); + // PGP Public Key Path: add your own path + const publicKeyFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/bts-encryption-public.asc'); - // Client Private Key Path - const clientPrivateKeyPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_private_key.key'); + // Client Private Key Path: add your own path + const clientPrivateKeyFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_private_key.key'); - // Client Certificate Path - const clientCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_cert.crt'); + // Client Certificate Path: add your own path + const clientCertFilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/client_cert.crt'); - // Server Certificate Path - const serverCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem'); + // Server Certificate Path: add your own path + const serverTrustCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem'); // Log configuration const log_config = { @@ -38,31 +38,42 @@ function run(callback) { 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( - inputFile, - envHostName, - publicKeyPath, - clientPrivateKeyPath, - clientCertPath, - serverCertPath, - undefined, - undefined, - function (error, result) { - if (error) { - console.log('\nError : ' + JSON.stringify(error)); - writeLogAudit('Error'); - } else if (result) { - const responseCode = result.status; - const responseMessage = result.statusText; - console.log('ResponseCode :', responseCode); - console.log('ResponseMessage :', responseMessage); - writeLogAudit(responseCode); + 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); } - if (callback) callback(error, result); - }); + ); } catch (e) { console.log('\nException : ' + e); writeLogAudit('Exception'); diff --git a/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js index c4e2835..2dbc404 100644 --- a/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js +++ b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js @@ -10,55 +10,63 @@ function writeLogAudit(status) { function run(callback) { try { - // Input file + // 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 + // Path of public key for pgp encryption: add your own path const publicKeyFile = path.resolve(__dirname, '../../Resource/batchApiMTLS/bts-encryption-public.asc'); - // Store path (P12) containing client private key and cert - const p12Path = path.resolve(__dirname, '../../Resource/batchApiMTLS/pushtest.p12'); + // Path (P12) containing client private key and cert: add your own path + const clientCertP12FilePath = path.resolve(__dirname, '../../Resource/batchApiMTLS/pushtest.p12'); - // Store password - const p12Password = 'changeit'; + // Store password: : add your own + const clientCertP12Password = 'changeit'; - // Store path (server cert) - const serverCertPath = path.resolve(__dirname, '../../Resource/batchApiMTLS/serverCasCert.pem'); - - //Log configuration + // 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', - enableMasking: false + loggingLevel: 'debug' }; const apiInstance = new BatchUploadWithMTLSApi(log_config); - apiInstance.uploadBatchAPIWithP12( + const opts = { inputFilePath, - envHostName, - publicKeyFile, - p12Path, - p12Password, - serverCertPath, - true, - function (error, result) { - if (error) { - console.log('\nError : ' + JSON.stringify(error)); - writeLogAudit('Error'); - } else if (result) { - const responseCode = result.status; - const responseMessage = result.statusText; - console.log('ResponseCode :', responseCode); - console.log('ResponseMessage :', responseMessage); - writeLogAudit(responseCode); + 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); } - if (callback) callback(error, result); - }); + ); } catch (e) { console.log('\nException : ' + e); writeLogAudit('Exception'); From f5f8f5c2d653b62b7d61e51607d04dfae6bbe432 Mon Sep 17 00:00:00 2001 From: mahmishr Date: Wed, 25 Jun 2025 09:20:16 +0530 Subject: [PATCH 4/4] Update BatchUploaMTLSWithKeys.js --- Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js index 01a6ce7..8bef4e8 100644 --- a/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js +++ b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js @@ -63,7 +63,8 @@ function run(callback) { console.log('\nError :', error.error.message); } else { console.log('\nError :', JSON.stringify(error, null, 2)); - } writeLogAudit('Error'); + } + writeLogAudit('Error'); } else if (result) { const responseCode = result.status; const responseMessage = result.statusText;