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..8bef4e8 --- /dev/null +++ b/Samples/BatchUploadAPI/BatchUploaMTLSWithKeys.js @@ -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; \ No newline at end of file diff --git a/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js new file mode 100644 index 0000000..2dbc404 --- /dev/null +++ b/Samples/BatchUploadAPI/BatchUploadMTLSWithP12.js @@ -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; \ No newline at end of file