From 25e5b485c935ce1fe5a57403e7b8dc17fd47db32 Mon Sep 17 00:00:00 2001 From: "Shiva Shankaran, Akshaya" Date: Fri, 25 Jan 2019 17:17:17 +0530 Subject: [PATCH 1/6] Implemented POC changes in samplecodes --- Samples/Flex/CoreServices/GenerateKey.js | 22 +++++----- Samples/Flex/CoreServices/TokenizeCard.js | 42 ++++++++++++------- Samples/Flex/KeyGenerationNoEnc.js | 24 ++++++----- .../Payments/CoreServices/CapturePayment.js | 32 +++++++------- .../ProcessAuthorizationReversal.js | 33 ++++++++------- .../Payments/CoreServices/ProcessCredit.js | 20 +++++---- .../Payments/CoreServices/ProcessPayment.js | 22 +++++----- .../Payments/CoreServices/RefundCapture.js | 30 +++++++------ .../Payments/CoreServices/RefundPayment.js | 32 +++++++------- Samples/Payments/CoreServices/VoidCapture.js | 32 +++++++------- Samples/Payments/CoreServices/VoidCredit.js | 32 +++++++------- Samples/Payments/CoreServices/VoidPayment.js | 32 +++++++------- Samples/Payments/CoreServices/VoidRefund.js | 28 +++++++------ Samples/Payouts/CoreServices/ProcessPayout.js | 23 +++++----- .../CoreServices/CreateAdhocReport.js | 23 +++++----- ...SubscriptionForReportNameByOrganization.js | 42 +++++++++---------- ...eSubscriptionOfReportNameByOrganization.js | 21 +++++----- .../Reporting/CoreServices/DownloadReport.js | 29 +++++++++---- .../CoreServices/GetAllSubscriptions.js | 20 +++++---- .../CoreServices/GetAvailableReports.js | 19 +++++---- .../CoreServices/GetNotificationOfChanges.js | 19 +++++---- .../GetPurchaseAndRefundDetails.js | 19 +++++---- .../CoreServices/GetReportBasedOnReportid.js | 19 +++++---- .../CoreServices/GetReportDefinition.js | 19 +++++---- .../GetReportingResourceInformation.js | 19 +++++---- .../GetSubscriptionForReportName.js | 19 +++++---- .../CoreServices/RetrieveAvailableReports.js | 19 +++++---- .../DownloadFileWithFileIdentifier.js | 29 ++++++++----- .../CoreServices/GetListOfFiles.js | 19 +++++---- .../CreateInstrumentIdentifier.js | 28 +++++++------ .../CoreServices/CreatePaymentInstrument.js | 22 +++++----- .../DeleteInstrumentIdentifier.js | 33 ++++++++------- .../CoreServices/DeletePaymentInstrument.js | 28 +++++++------ .../RetrieveAllPaymentInstruments.js | 31 +++++++------- .../RetrieveInstrumentIdentifier.js | 36 +++++++++------- .../CoreServices/RetrievePaymentInstrument.js | 30 +++++++------ .../UpdateInstrumentIdentifier.js | 28 ++++++------- .../CoreServices/UpdatePaymentInstrument.js | 29 ++++++------- .../CoreServices/GetIndividualBatchFile.js | 29 ++++++------- .../CoreServices/GetListOfBatchFiles.js | 19 +++++---- .../CoreServices/RetrieveTransaction.js | 29 ++++++------- .../CoreServices/CreateSearchRequest.js | 22 +++++----- .../CoreServices/GetSearchResults.js | 22 +++++----- .../CoreServices/GetUserInformation.js | 19 +++++---- 44 files changed, 627 insertions(+), 517 deletions(-) diff --git a/Samples/Flex/CoreServices/GenerateKey.js b/Samples/Flex/CoreServices/GenerateKey.js index 12c7615..518c0ea 100644 --- a/Samples/Flex/CoreServices/GenerateKey.js +++ b/Samples/Flex/CoreServices/GenerateKey.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * Generate a one-time use public key and key ID to encrypt the card number @@ -27,18 +27,18 @@ function generateKey(callback) { 'generatePublicKeyRequest': request }; - console.log('\n*************** Generate Key ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.generatePublicKey(options, function (error, data, response) { if (error) { - console.log('Error : ' + error); - console.log('Error status code : ' + error.statusCode); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('Data : ' + JSON.stringify(data)); - } - console.log('Response : ' + JSON.stringify(response)); - console.log('Response Code Of GenerateKey : ' + response['status']); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + } callback(error, data); }); } catch (error) { @@ -47,7 +47,7 @@ function generateKey(callback) { } if (require.main === module) { generateKey(function () { - console.log('generateKey end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.generateKey = generateKey; diff --git a/Samples/Flex/CoreServices/TokenizeCard.js b/Samples/Flex/CoreServices/TokenizeCard.js index f01c1bf..9c9153c 100644 --- a/Samples/Flex/CoreServices/TokenizeCard.js +++ b/Samples/Flex/CoreServices/TokenizeCard.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var verify = require('../VerifyToken.js'); /** @@ -35,13 +35,13 @@ function tokenizeCard(callback) { var options = { 'generatePublicKeyRequest': KeyRequest }; - - keyInstance.generatePublicKey(options, function (error, data, response) { + console.log('\n[BEGIN] REQUEST & RESPONSE OF: Generate Key \n'); + keyInstance.generatePublicKey(options, function (error, data, response) { if (error) { - console.log('Error : ' + error); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } else if (data) { - keyId = data['keyId']; + keyId = data.keyId; publicKey = data.der['publicKey']; var tokenizeRequest = new cybersourceRestApi.TokenizeRequest(); @@ -51,23 +51,35 @@ function tokenizeCard(callback) { var options = { 'tokenizeRequest': tokenizeRequest }; - console.log('\n*************** Tokenize Card ********************* '); + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + } + console.log('\n[END] REQUEST & RESPONSE OF: Generate Key \n'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); tokenizeInstance.tokenize(options, function (error, data, response) { if (error) { - console.log('Error : ' + error.stack); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } else if (data) { var result = verify(publicKey, data); - console.log('Response of tokenization : ' + JSON.stringify(response)); - console.log('Response code of tokenization: ' + response['status']); - console.log('KeyId: ' + keyId); - console.log('PublicKey : ' + publicKey); - console.log('Token Verified : ' + result); + console.log('\n KeyId: ' + keyId); + console.log('\n PublicKey : ' + publicKey); + console.log('\n Token Verified : ' + result); + } + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } callback(error, data); }); } - console.log('Response code of generatePublicKey: ' + response['status']); }); } catch (error) { @@ -77,7 +89,7 @@ function tokenizeCard(callback) { } if (require.main === module) { tokenizeCard(function () { - console.log('tokenizeCard end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.tokenizeCard = tokenizeCard; diff --git a/Samples/Flex/KeyGenerationNoEnc.js b/Samples/Flex/KeyGenerationNoEnc.js index 83a78c3..bc5d895 100644 --- a/Samples/Flex/KeyGenerationNoEnc.js +++ b/Samples/Flex/KeyGenerationNoEnc.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); function keyGenerationNoEnc(callback) { @@ -16,24 +16,26 @@ function keyGenerationNoEnc(callback) { var options = { 'generatePublicKeyRequest': request }; - console.log('\n*************** Key Generation NoEnc ********************* '); - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.generatePublicKey(options, function (error, data, response) { + if (error) { - console.log('Error : ' + error); - } - else if (data) { - console.log('Data : ' + JSON.stringify(data)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - console.log('Response : ' + JSON.stringify(response)); - console.log('Response id : ' + response['status']); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + } callback(error, data); }); } if (require.main === module) { keyGenerationNoEnc(function () { - console.log('key generation end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.keyGenerationNoEnc = keyGenerationNoEnc; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/CapturePayment.js b/Samples/Payments/CoreServices/CapturePayment.js index 2b9c956..eedb565 100644 --- a/Samples/Payments/CoreServices/CapturePayment.js +++ b/Samples/Payments/CoreServices/CapturePayment.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var processPayment = require('./ProcessPayment'); /** @@ -30,24 +30,29 @@ function processCaptureAPayment(callback) { var enableCapture = false; + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); processPayment.processPayment(function (error, data) { - if (data) { - var id = data['id']; - console.log('\n*************** Capture Payment *********************'); - console.log('Payment ID passing to capturePayment : ' + id); - + console.log('\n[END] REQUEST & RESPONSE OF: ProcessPayment\n'); + if (!error) { + var id = data.id; instance.capturePayment(request, id, function (error, data, response) { if (error) { - console.log('\nError in capture payment: ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Capture Payment : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Capture Payment : ' + JSON.stringify(response)); - console.log('\nResponse Code of Capture a payment : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); - + } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); } }, enableCapture); } catch (error) { @@ -56,7 +61,6 @@ function processCaptureAPayment(callback) { } if (require.main === module) { processCaptureAPayment(function () { - console.log('CapturePayment end.'); }); } module.exports.processCaptureAPayment = processCaptureAPayment; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/ProcessAuthorizationReversal.js b/Samples/Payments/CoreServices/ProcessAuthorizationReversal.js index c149ceb..c38f925 100644 --- a/Samples/Payments/CoreServices/ProcessAuthorizationReversal.js +++ b/Samples/Payments/CoreServices/ProcessAuthorizationReversal.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var processPayment = require('./ProcessPayment'); /** @@ -29,25 +29,29 @@ function processAuthorizationReversal(callback) { request.reversalInformation = reversalInformation; var enableCapture = false; - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); processPayment.processPayment(function (error, data) { - if (data) { - var id = data['id']; - console.log('\n*************** Authorizarion Reversal ********************* '); - console.log('Payment ID passing to authReversal : ' + id); - + console.log('\n[END] REQUEST & RESPONSE OF: ProcessPayment\n'); + if (!error) { + var id = data.id; instance.authReversal(id, request, function (error, data, response) { if (error) { - console.log('\nError in authReversal: ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of authReversal : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of authReversal : ' + JSON.stringify(response)); - console.log('\nResponse Code of authReversal : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); - + } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); } }, enableCapture); @@ -57,7 +61,6 @@ function processAuthorizationReversal(callback) { } if (require.main === module) { processAuthorizationReversal(function () { - console.log('Process Authorization Reversal end'); }); } module.exports.processAuthorizationReversal = processAuthorizationReversal; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/ProcessCredit.js b/Samples/Payments/CoreServices/ProcessCredit.js index cc785b3..90665c9 100644 --- a/Samples/Payments/CoreServices/ProcessCredit.js +++ b/Samples/Payments/CoreServices/ProcessCredit.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call CreditApi, @@ -49,16 +49,19 @@ function processACredit(callback) { request.orderInformation = orderInformation; request.paymentInformation = paymentInformation; - console.log('\n*************** Process Credit ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.createCredit(request, function (error, data, response) { if (error) { - console.log('\nError in process a credit : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of process a credit : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of process a credit : ' + JSON.stringify(response)); - console.log('\nResponse Code of process a credit : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); } catch (error) { @@ -67,7 +70,6 @@ function processACredit(callback) { } if (require.main === module) { processACredit(function () { - console.log('Process Credit end.'); }); } module.exports.processACredit = processACredit; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/ProcessPayment.js b/Samples/Payments/CoreServices/ProcessPayment.js index a7c3cb8..d94973b 100644 --- a/Samples/Payments/CoreServices/ProcessPayment.js +++ b/Samples/Payments/CoreServices/ProcessPayment.js @@ -2,14 +2,14 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call PaymentApi, * createPayment method will create a new payment */ -function processPayment(callback, enableCapture) { +function processPayment(callback, enableCapture) { try { var configObject = new configuration(); var instance = new cybersourceRestApi.PaymentsApi(configObject); @@ -79,17 +79,19 @@ function processPayment(callback, enableCapture) { if (enableCapture === true) { request.processingInformation.capture = true; } - console.log('\n*************** Process Payment ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.createPayment(request, function (error, data, response) { if (error) { - console.log('\nError in process a payment : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of process a payment : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of process a payment : ' + JSON.stringify(response)); - console.log('\nResponse Code of process a payment : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -98,7 +100,7 @@ function processPayment(callback, enableCapture) { } if (require.main === module) { processPayment(function () { - console.log('\nProcessPayment end.'); + console.log('\n [END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }, false); } module.exports.processPayment = processPayment; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/RefundCapture.js b/Samples/Payments/CoreServices/RefundCapture.js index 5173b52..3580cd2 100644 --- a/Samples/Payments/CoreServices/RefundCapture.js +++ b/Samples/Payments/CoreServices/RefundCapture.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var capturePayment = require('./CapturePayment'); /** * This is a sample code to call RefundApi, @@ -25,25 +25,30 @@ function refundACapture(callback) { orderInformation.amountDetails = amountDetails; request.orderInformation = orderInformation; + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); capturePayment.processCaptureAPayment(function (error, data) { - if (data) { - var id = data['id']; - console.log('\n*************** Refund Capture ********************* '); - console.log('\nCapture ID passing to refundCapture : ' + id); + if (!error) { + var id = data.id; instance.refundCapture(request, id, function (error, data, response) { if (error) { - console.log('\nError in Refund Capture : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData in Refund Capture: ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Refund Capture: ' + JSON.stringify(response)); - console.log('\nResponse Code of Refund Capture : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); - }); } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); } catch (error) { console.log(error); @@ -51,7 +56,6 @@ function refundACapture(callback) { } if (require.main === module) { refundACapture(function () { - console.log('Refund Capture end.'); }); } module.exports.refundACapture = refundACapture; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/RefundPayment.js b/Samples/Payments/CoreServices/RefundPayment.js index 6476a99..23fdcd8 100644 --- a/Samples/Payments/CoreServices/RefundPayment.js +++ b/Samples/Payments/CoreServices/RefundPayment.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var processPayment = require('./ProcessPayment'); /** @@ -29,25 +29,30 @@ function refundAPayment(callback) { request.orderInformation = orderInformation; var enableCapture = true; - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); processPayment.processPayment(function (error, data) { - if (data) { - var id = data['id']; - console.log('\n*************** Refund Payment ********************* '); - console.log('Payment ID passing to refundPayment : ' + id); + console.log('\n[END] REQUEST & RESPONSE OF: processPayment \n'); + if (!error) { + var id = data.id; instance.refundPayment(request, id, function (error, data, response) { if (error) { - console.log('\nError in Refund payment: ' + error); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Refund Payment : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Refund Payment : ' + JSON.stringify(response)); - console.log('\nResponse Code of Refund Payment : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); - + } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); } }, enableCapture); } catch (error) { @@ -56,7 +61,6 @@ function refundAPayment(callback) { } if (require.main === module) { refundAPayment(function () { - console.log('Refund Payment end.'); }); } module.exports.refundAPayment = refundAPayment; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/VoidCapture.js b/Samples/Payments/CoreServices/VoidCapture.js index f3cec79..f396726 100644 --- a/Samples/Payments/CoreServices/VoidCapture.js +++ b/Samples/Payments/CoreServices/VoidCapture.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var capturePayment = require('./CapturePayment'); /** * This is a sample code to call VoidApi, @@ -20,25 +20,30 @@ function voidACapture(callback) { var clientReferenceInformation = new cybersourceRestApi.Ptsv2paymentsClientReferenceInformation(); clientReferenceInformation.code = 'test_capture_void'; request.clientReferenceInformation = clientReferenceInformation; - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); capturePayment.processCaptureAPayment(function (error, data) { - if (data) { - var id = data['id']; - console.log('\n*************** Void Capture ********************* ' ); - console.log('\nCapture ID passing to voidCapture : ' + id); + if (!error) { + var id = data.id; instance.voidCapture(request, id, function (error, data, response) { if (error) { - console.log('Error : ' + error); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Void Capture : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Void Capture : ' + JSON.stringify(response)); - console.log('\nResponse Code of Void Capture : ' + JSON.stringify(response['status'])); - callback(error,data); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); }); } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); } catch (error) { console.log(error); @@ -46,7 +51,6 @@ function voidACapture(callback) { } if (require.main === module) { voidACapture(function () { - console.log('VoidCapture end.'); }); } module.exports.voidACapture = voidACapture; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/VoidCredit.js b/Samples/Payments/CoreServices/VoidCredit.js index b37cf1b..eebe23a 100644 --- a/Samples/Payments/CoreServices/VoidCredit.js +++ b/Samples/Payments/CoreServices/VoidCredit.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var processCredit = require('./ProcessCredit'); /** * This is a sample code to call VoidApi, @@ -22,25 +22,30 @@ function voidACredit(callback) { var request = new cybersourceRestApi.VoidCreditRequest(); request.clientReferenceInformation = clientReferenceInformation; + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); processCredit.processACredit(function (error, data) { - if (data) { - var id = data['id']; - console.log('\n*************** Void Credit ********************* ' ); - console.log('\nCredit ID passing to voidCredit : ' + id); - - + if (!error) { + var id = data.id; + instance.voidCredit(request, id, function (error, data, response) { if (error) { - console.log('Error in Void Credit : ' + error); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Void Credit : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Void Credit : ' + JSON.stringify(response)); - console.log('\nResponse Code of void credit : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); } catch (error) { console.log(error); @@ -48,7 +53,6 @@ function voidACredit(callback) { } if (require.main === module) { voidACredit(function () { - console.log('Void credit end.'); }); } module.exports.voidACredit = voidACredit; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/VoidPayment.js b/Samples/Payments/CoreServices/VoidPayment.js index 4241f7d..e42a481 100644 --- a/Samples/Payments/CoreServices/VoidPayment.js +++ b/Samples/Payments/CoreServices/VoidPayment.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var processPayment = require('./ProcessPayment'); /** @@ -25,25 +25,30 @@ function voidPayment(callback) { request.clientReferenceInformation = clientReferenceInformation; var enableCapture = true; - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); processPayment.processPayment(function (error, data) { + console.log('\n[END] REQUEST & RESPONSE OF: ProcessPayment \n'); if (data) { - var id = data['id']; - console.log('\n*************** Void Payment ********************* '); - console.log('Payment ID passing to voidPayment : ' + id); - + var id = data.id; + instance.voidPayment(request, id, function (error, data, response) { if (error) { - console.log('\nError in void payment: ' + error); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of void Payment : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of void Payment : ' + JSON.stringify(response)); - console.log('\nResponse Code of void Payment : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); - + } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); } }, enableCapture); @@ -53,7 +58,6 @@ function voidPayment(callback) { } if (require.main === module) { voidPayment(function () { - console.log('Void Payment end.'); }); } module.exports.voidPayment = voidPayment; \ No newline at end of file diff --git a/Samples/Payments/CoreServices/VoidRefund.js b/Samples/Payments/CoreServices/VoidRefund.js index 6dfc7c0..c325a13 100644 --- a/Samples/Payments/CoreServices/VoidRefund.js +++ b/Samples/Payments/CoreServices/VoidRefund.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var refundPayment = require('./RefundPayment'); /** * This is a sample code to call VoidApi, @@ -21,25 +21,30 @@ function voidARefund(callback) { var request = new cybersourceRestApi.VoidRefundRequest(); request.clientReferenceInformation = clientReferenceInformation; + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); refundPayment.refundAPayment(function (error, data) { if (data) { - var id = data['id']; - console.log('\n*************** Void Refund ********************* '); - console.log('Refund ID passing to voidRefund : ' + id); + var id = data.id; instance.voidRefund(request, id, function (error, data, response) { if (error) { - console.log('\nError in void refund: ' + error); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of void refund : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of void refund : ' + JSON.stringify(response)); - console.log('\nResponse Code of void refund : ' + JSON.stringify(response['status'])); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); - + } + else{ + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); } }); } catch (error) { @@ -48,7 +53,6 @@ function voidARefund(callback) { } if (require.main === module) { voidARefund(function () { - console.log('Void Refund end.'); }); } module.exports.voidARefund = voidARefund; \ No newline at end of file diff --git a/Samples/Payouts/CoreServices/ProcessPayout.js b/Samples/Payouts/CoreServices/ProcessPayout.js index 5a6c95a..26dd5e0 100644 --- a/Samples/Payouts/CoreServices/ProcessPayout.js +++ b/Samples/Payouts/CoreServices/ProcessPayout.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); function processPayout(callback) { try { @@ -81,16 +81,19 @@ function processPayout(callback) { request.recipientInformation = recipientInformation; request.payoutsOptions = payoutsOptions; - console.log('\n*************** Process Payout ********************* '); - instance.octCreatePayment(request, function (error, data, response) { + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + + instance.octCreatePayment(request, function (error, data, response) { if (error) { - console.log('\nError in Process Payout : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Process Payout : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Process Payout : ' + JSON.stringify(response)); - console.log('\nResponse Code of Process Payout :' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -99,7 +102,7 @@ function processPayout(callback) { } if (require.main === module) { processPayout(function () { - console.log('Process Payout end.'); + console.log('\n [END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.processPayout = processPayout; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/CreateAdhocReport.js b/Samples/Reporting/CoreServices/CreateAdhocReport.js index 5ef7e54..bc5dba0 100644 --- a/Samples/Reporting/CoreServices/CreateAdhocReport.js +++ b/Samples/Reporting/CoreServices/CreateAdhocReport.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportsApi, @@ -34,17 +34,18 @@ function createAdhocReport(callback) { request.reportPreferences = reportPreferences; request.reportFields = ['Request.RequestID', 'Request.TransactionDate', 'Request.MerchantID']; - console.log('\n*************** Create Adhoc Report ********************* '); - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.createReport(request, opts, function (error, data, response) { - if (error) { - console.log('\nError in create adhoc report : ' + error); + if (error) { + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of create adhoc report : ' + JSON.stringify(data)); + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of create adhoc report : ' + JSON.stringify(response)); - console.log('\nResponse Code of create adhoc report : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -53,7 +54,7 @@ function createAdhocReport(callback) { } if (require.main === module) { createAdhocReport(function () { - console.log('create adhoc report end.'); + console.log('\n[END] REQUEST & RESPONSE OF:'+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.createAdhocReport = createAdhocReport; diff --git a/Samples/Reporting/CoreServices/CreateReportSubscriptionForReportNameByOrganization.js b/Samples/Reporting/CoreServices/CreateReportSubscriptionForReportNameByOrganization.js index 572cf72..2fa4129 100644 --- a/Samples/Reporting/CoreServices/CreateReportSubscriptionForReportNameByOrganization.js +++ b/Samples/Reporting/CoreServices/CreateReportSubscriptionForReportNameByOrganization.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var deleteSubscription = require('./DeleteSubscriptionOfReportNameByOrganization'); /** * This is a sample code to call ReportSubscriptionsApi, @@ -25,31 +25,29 @@ function CreateSubscriptionReport(callback) { request.reportMimeType = 'application/xml'; request.reportFrequency = 'MONTHLY'; request.timezone = 'GMT'; - request.startTime = '0900'; + request.startTime = '0942'; request.startDay = 1; - request.reportName = 'testrest_subcription_v1'; + request.reportName = 'yyy'; - console.log('****************Create Report Subscrption****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF:'+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.createSubscription(request, function (error, data, response) { if (error) { - console.log('\nError in create report subscription : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of create report subscription : ' + JSON.stringify(data)); - } - console.log('\nResponse of create report subscription : ' + JSON.stringify(response)); - var status = JSON.stringify(response['status']); - console.log('\nResponse Code of create report subscription : ' + status); - if (status === '201') { - deleteSubscription.deleteSubscriptionReport(request.reportName, function (error, data) { - if (error) { - console.log('Error occured in deleting the report subscription'); - } - else if(data){ - console.log('Deleted the report subscription to clear the bad values in backend'); - } - }); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + if (response['status'] === 201) { + deleteSubscription.deleteSubscriptionReport(request.reportName, function (error, data) { + if (!error) { + console.log('\n[END] REQUEST & RESPONSE OF: DeleteSubscriptionOfReportNameByOrganization\n'); + } + }); + } } callback(error, request.reportName); }); @@ -59,7 +57,7 @@ function CreateSubscriptionReport(callback) { } if (require.main === module) { CreateSubscriptionReport(function () { - console.log('Create report subscription end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.CreateSubscriptionReport = CreateSubscriptionReport; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/DeleteSubscriptionOfReportNameByOrganization.js b/Samples/Reporting/CoreServices/DeleteSubscriptionOfReportNameByOrganization.js index 3c14a7f..77b8d74 100644 --- a/Samples/Reporting/CoreServices/DeleteSubscriptionOfReportNameByOrganization.js +++ b/Samples/Reporting/CoreServices/DeleteSubscriptionOfReportNameByOrganization.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportSubscriptionsApi, @@ -14,21 +14,22 @@ function deleteSubscriptionReport(name, callback) { var configObject = new configuration(); var instance = new cybersourceRestApi.ReportSubscriptionsApi(configObject); - var reportName = 'testrest_v2'; if (name !== '') reportName = name; - console.log('****************Delete Subscription of Report Name****************'); + + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.deleteSubscription(reportName, function (error, data, response) { if (error) { - console.log('\nError in Delete subscription of report name : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Delete subscription of report name : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Delete subscription of report name : ' + JSON.stringify(response)); - console.log('\nResponse Code of Delete subscription of report name : ' + JSON.stringify(response['status'])); callback(error, data); }); @@ -38,7 +39,7 @@ function deleteSubscriptionReport(name, callback) { } if (require.main === module) { deleteSubscriptionReport('', function () { - console.log('Delete subscription of report name end.'); + console.log('\n[END] REQUEST & RESPONSE OF:'+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.deleteSubscriptionReport = deleteSubscriptionReport; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/DownloadReport.js b/Samples/Reporting/CoreServices/DownloadReport.js index d5b134e..90ee193 100644 --- a/Samples/Reporting/CoreServices/DownloadReport.js +++ b/Samples/Reporting/CoreServices/DownloadReport.js @@ -2,8 +2,9 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var fs = require('fs'); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportDownloadsApi, @@ -15,8 +16,7 @@ function downloadReport(callback) { var apiClient = new cybersourceRestApi.ApiClient(); //File name in which report get downloaded - var downloadFilePath = 'Resource\\reportName.xml'; - apiClient.downloadFilePath = path.resolve(downloadFilePath); + var downloadFilePath = path.join('Resource','reportName.xml'); var instance = new cybersourceRestApi.ReportDownloadsApi(configObject, apiClient); @@ -25,22 +25,33 @@ function downloadReport(callback) { var opts = []; opts['organizationId'] = 'testrest'; - console.log('****************Download Report****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); - instance.downloadReport(reportDate, reportName, opts, function (error, data) { + instance.downloadReport(reportDate, reportName, opts, function (error, data, response) { if (error) { - console.log('\nError in Download report : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); + } + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + JSON.stringify(response) + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + if(JSON.stringify(response['status']) === '200'){ + const stream = fs.createWriteStream(downloadFilePath); + response.pipe(stream); + console.log('\n File downloaded at the below location :\n' + path.resolve(downloadFilePath)); + } } callback(error, data); }); - console.log('File downloaded at the below location :\n' + apiClient.downloadFilePath); + } catch (error) { console.log(error); } } if (require.main === module) { downloadReport(function () { - console.log('Download report end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.downloadReport = downloadReport; diff --git a/Samples/Reporting/CoreServices/GetAllSubscriptions.js b/Samples/Reporting/CoreServices/GetAllSubscriptions.js index 0289f93..823127f 100644 --- a/Samples/Reporting/CoreServices/GetAllSubscriptions.js +++ b/Samples/Reporting/CoreServices/GetAllSubscriptions.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportSubscriptionsApi, @@ -14,17 +14,19 @@ function getAllSubscriptions(callback) { var configObject = new configuration(); var instance = new cybersourceRestApi.ReportSubscriptionsApi(configObject); - console.log('****************Get All Subscription****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getAllSubscriptions(function (error, data, response) { + if (error) { - console.log('\nError in get all subscriptions : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of get all subscriptions : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of get all subscriptions : ' + JSON.stringify(response)); - console.log('\nResponse Code of get all subscriptions : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -33,7 +35,7 @@ function getAllSubscriptions(callback) { } if (require.main === module) { getAllSubscriptions(function () { - console.log('Get all subscription end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getAllSubscriptions = getAllSubscriptions; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/GetAvailableReports.js b/Samples/Reporting/CoreServices/GetAvailableReports.js index f676eaa..2f58dd6 100644 --- a/Samples/Reporting/CoreServices/GetAvailableReports.js +++ b/Samples/Reporting/CoreServices/GetAvailableReports.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportsApi, @@ -20,17 +20,18 @@ function RetrieveAvailableReports(callback) { var opts = []; opts['organizationId'] = 'testrest'; - console.log('****************Get Available Reports****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.searchReports(startTime, endTime, timeQueryType, opts, function (error, data, response) { if (error) { - console.log('\nError in get available reports : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of get available reports : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of get available reports : ' + JSON.stringify(response)); - console.log('\nResponse Code of get available reports : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -39,7 +40,7 @@ function RetrieveAvailableReports(callback) { } if (require.main === module) { RetrieveAvailableReports(function () { - console.log('Retrieve Available Reports end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.RetrieveAvailableReports = RetrieveAvailableReports; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/GetNotificationOfChanges.js b/Samples/Reporting/CoreServices/GetNotificationOfChanges.js index e625c67..76b67b2 100644 --- a/Samples/Reporting/CoreServices/GetNotificationOfChanges.js +++ b/Samples/Reporting/CoreServices/GetNotificationOfChanges.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call NotificationOfChangesApi, @@ -17,17 +17,18 @@ function getNotificationOfChanges(callback) { var startTime = '2018-10-01T12:00:00-05:00'; var endTime = '2018-10-30T12:00:00-05:00'; - console.log('****************Get Notification of Changes****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF:'+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getNotificationOfChangeReport(startTime, endTime, function (error, data, response) { if (error) { - console.log('\nError in Get notification of changes : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Get notification of changes : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Get notification of changes : ' + JSON.stringify(response)); - console.log('\nResponse Code of Get notification of changes : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -37,7 +38,7 @@ function getNotificationOfChanges(callback) { } if (require.main === module) { getNotificationOfChanges(function () { - console.log('Get notification of changes end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getNotificationOfChanges = getNotificationOfChanges; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/GetPurchaseAndRefundDetails.js b/Samples/Reporting/CoreServices/GetPurchaseAndRefundDetails.js index 3006b05..020ca83 100644 --- a/Samples/Reporting/CoreServices/GetPurchaseAndRefundDetails.js +++ b/Samples/Reporting/CoreServices/GetPurchaseAndRefundDetails.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call PurchaseAndRefundDetailsApi, @@ -24,17 +24,18 @@ function getPurchaseAndRefundDetails(callback) { opts['offset'] = '20'; opts['limit'] = '2000'; - console.log('****************Get Purchase and Refund Details****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getPurchaseAndRefundDetails(startTime, endTime, opts, function (error, data, response) { if (error) { - console.log('\nError in Get purchase and refund details : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Get purchase and refund details : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Get purchase and refund details : ' + JSON.stringify(response)); - console.log('\nResponse Code of Get purchase and refund details : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -44,7 +45,7 @@ function getPurchaseAndRefundDetails(callback) { } if (require.main === module) { getPurchaseAndRefundDetails(function () { - console.log('Get purchase and refund details end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getPurchaseAndRefundDetails = getPurchaseAndRefundDetails; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/GetReportBasedOnReportid.js b/Samples/Reporting/CoreServices/GetReportBasedOnReportid.js index 6c13a95..d3b168a 100644 --- a/Samples/Reporting/CoreServices/GetReportBasedOnReportid.js +++ b/Samples/Reporting/CoreServices/GetReportBasedOnReportid.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportsApi, @@ -18,17 +18,18 @@ function getReportBasedOnReportid(callback) { var opts = []; opts['organizationId'] = 'testrest'; - console.log('****************Get Reports based on ReportID****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF :'+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getReportByReportId(reportId, opts, function (error, data, response) { if (error) { - console.log('\nError in get reports based on reportID : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of get reports based on reportID : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of get reports based on reportID : ' + JSON.stringify(response)); - console.log('\nResponse Code of get reports based on reportID : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -38,7 +39,7 @@ function getReportBasedOnReportid(callback) { } if (require.main === module) { getReportBasedOnReportid(function () { - console.log('get report based on report id end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getReportBasedOnReportid = getReportBasedOnReportid; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/GetReportDefinition.js b/Samples/Reporting/CoreServices/GetReportDefinition.js index 7db6f88..46cf77e 100644 --- a/Samples/Reporting/CoreServices/GetReportDefinition.js +++ b/Samples/Reporting/CoreServices/GetReportDefinition.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportDefinitionsApi, @@ -18,17 +18,18 @@ function getReportDefinition(callback) { var opts = {}; - console.log('****************Get Reports Definition****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF :'+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getResourceInfoByReportDefinition(reportDefinitionName, opts, function (error, data, response) { if (error) { - console.log('\nError in get report definition : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of get report definition : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of get report definition : ' + JSON.stringify(response)); - console.log('\nResponse Code of get report definition : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -37,7 +38,7 @@ function getReportDefinition(callback) { } if (require.main === module) { getReportDefinition(function () { - console.log('Get report definition end.'); + console.log('\n[END] REQUEST & RESPONSE OF :'+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getReportDefinition = getReportDefinition; \ No newline at end of file diff --git a/Samples/Reporting/CoreServices/GetReportingResourceInformation.js b/Samples/Reporting/CoreServices/GetReportingResourceInformation.js index 35e5eb8..0b6ed2e 100644 --- a/Samples/Reporting/CoreServices/GetReportingResourceInformation.js +++ b/Samples/Reporting/CoreServices/GetReportingResourceInformation.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportSubscriptionsApi, @@ -16,17 +16,18 @@ function getReportResourceInformation(callback) { var opts = []; opts['organizationId'] = 'testrest'; - console.log('****************Get Reports Resource Information****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF : '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getResourceV2Info(opts, function (error, data, response) { if (error) { - console.log('\nError in get reports resource Information : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of get reports resource Information : ' + JSON.stringify(data)); + else if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of get reports resource Information : ' + JSON.stringify(response)); - console.log('\nResponse Code of get reports resource Information : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -36,7 +37,7 @@ function getReportResourceInformation(callback) { } if (require.main === module) { getReportResourceInformation(function () { - console.log('get report resource information end.'); + console.log('\n[END] REQUEST & RESPONSE OF :'+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getReportResourceInformation = getReportResourceInformation; diff --git a/Samples/Reporting/CoreServices/GetSubscriptionForReportName.js b/Samples/Reporting/CoreServices/GetSubscriptionForReportName.js index 98c9e60..cca164f 100644 --- a/Samples/Reporting/CoreServices/GetSubscriptionForReportName.js +++ b/Samples/Reporting/CoreServices/GetSubscriptionForReportName.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportSubscriptionsApi, @@ -16,17 +16,18 @@ function getSubscriptionForReportName(callback) { var reportName = 'createsubscription_report'; - console.log('****************Get Subscription for Report name****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getSubscription(reportName, function (error, data, response) { if (error) { - console.log('\nError in get subscription for report name : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of get subscription for report name : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of get subscription for report name : ' + JSON.stringify(response)); - console.log('\nResponse Code of get subscription for report name : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -35,7 +36,7 @@ function getSubscriptionForReportName(callback) { } if (require.main === module) { getSubscriptionForReportName(function () { - console.log('Get subscription for report name end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getSubscriptionForReportName = getSubscriptionForReportName; diff --git a/Samples/Reporting/CoreServices/RetrieveAvailableReports.js b/Samples/Reporting/CoreServices/RetrieveAvailableReports.js index bb79aa2..8ea1f14 100644 --- a/Samples/Reporting/CoreServices/RetrieveAvailableReports.js +++ b/Samples/Reporting/CoreServices/RetrieveAvailableReports.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call ReportsApi, @@ -20,17 +20,18 @@ function RetrieveAvailableReports(callback) { var opts = []; opts['organizationId'] = 'testrest'; - console.log('****************Retrieve Available Reports****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.searchReports(startTime, endTime, timeQueryType, opts, function (error, data, response) { if (error) { - console.log('\nError in Retrieve Available Reports : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Retrieve Available Reports : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Retrieve Available Reports : ' + JSON.stringify(response)); - console.log('\nResponse Code of Retrieve Available Reports : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -39,7 +40,7 @@ function RetrieveAvailableReports(callback) { } if (require.main === module) { RetrieveAvailableReports(function () { - console.log('Retrieve Available Reports end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.RetrieveAvailableReports = RetrieveAvailableReports; \ No newline at end of file diff --git a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js index 007fc96..2778e0b 100644 --- a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js +++ b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js @@ -2,8 +2,9 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var fs = require('fs'); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call SecureFileShareApi, @@ -15,24 +16,32 @@ function downloadFileWithFileIdentifier(callback) { var apiClient = new cybersourceRestApi.ApiClient(); //File name in which report get downloaded - var downloadFilePath = 'Resource\\DownloadFileWithFileIdentifier.csv'; - apiClient.downloadFilePath = path.resolve(downloadFilePath); + var downloadFilePath = path.join('Resource','DownloadFileWithFileIdentifier.csv'); var instance = new cybersourceRestApi.SecureFileShareApi(configObject, apiClient); var fileId = 'VFJSUmVwb3J0LTc4NTVkMTNmLTkzOTgtNTExMy1lMDUzLWEyNTg4ZTBhNzE5Mi5jc3YtMjAxOC0xMC0yMA=='; var opts = []; opts['organizationId'] = 'testrest'; - console.log('****************Download File with Identifier****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); - instance.getFile(fileId, opts, function (error, data) { + instance.getFile(fileId, opts, function (error, data, response) { if (error) { - console.log('\nError in download file with identifier : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); + } + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + JSON.stringify(response) + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + if(JSON.stringify(response['status']) === '200'){ + const stream = fs.createWriteStream(downloadFilePath); + response.pipe(stream); + console.log('\n File downloaded at the below location :\n' + path.resolve(downloadFilePath)); + } } - console.log('\n: '); callback(error, data); }); - console.log('File downloaded at the below location :\n' + apiClient.downloadFilePath); } catch (error) { console.log(error); } @@ -40,7 +49,7 @@ function downloadFileWithFileIdentifier(callback) { } if (require.main === module) { downloadFileWithFileIdentifier(function () { - console.log('Download file with file identifier end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.downloadFileWithFileIdentifier = downloadFileWithFileIdentifier; \ No newline at end of file diff --git a/Samples/SecureFileShare/CoreServices/GetListOfFiles.js b/Samples/SecureFileShare/CoreServices/GetListOfFiles.js index c3fd017..731e5db 100644 --- a/Samples/SecureFileShare/CoreServices/GetListOfFiles.js +++ b/Samples/SecureFileShare/CoreServices/GetListOfFiles.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call SearchTransactionsApi, @@ -19,17 +19,18 @@ function getListOfFiles(callback) { var opts = []; opts['organizationId'] = 'testrest'; - console.log('****************Getlist of Files****************'); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getFileDetails(startDate, endDate, opts, function (error, data, response) { if (error) { - console.log('\nError in getlist of files : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of getlist of files : ' + JSON.stringify(data)); + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of getlist of files : ' + JSON.stringify(response)); - console.log('\nResponse Code of getlist of files : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -38,7 +39,7 @@ function getListOfFiles(callback) { } if (require.main === module) { getListOfFiles(function () { - console.log('Method call complete.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getListOfFiles = getListOfFiles; \ No newline at end of file diff --git a/Samples/TMS/CoreServices/CreateInstrumentIdentifier.js b/Samples/TMS/CoreServices/CreateInstrumentIdentifier.js index 8b80574..f4273c7 100644 --- a/Samples/TMS/CoreServices/CreateInstrumentIdentifier.js +++ b/Samples/TMS/CoreServices/CreateInstrumentIdentifier.js @@ -1,9 +1,9 @@ 'use strict'; -var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var cybersourceRestApi = require('cybersource-rest-client'); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call TMS InstrumentIdentifierApi, @@ -37,20 +37,23 @@ function createInstrumentIdentifier(callback) { body.processingInformation = processingInformation; var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; - - console.log('\n*************** Create Instrument Identifier ********************* '); + + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + instance.tmsV1InstrumentidentifiersPost(profileId, body, function (error, data, response) { if (error) { - console.log('\nError in create instrument identifier : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Create instrument identifier : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); } - console.log('\nResponse of Create instrument identifier : ' + JSON.stringify(response)); - console.log('\nResponse Code of Create instrument identifier :' + JSON.stringify(response['status'])); callback(error,data); - }); - + }); } catch (error) { console.log(error); } @@ -58,7 +61,6 @@ function createInstrumentIdentifier(callback) { if (require.main === module) { createInstrumentIdentifier(function () { - console.log('Create instrument identifier end.'); }); } module.exports.createInstrumentIdentifier = createInstrumentIdentifier; \ No newline at end of file diff --git a/Samples/TMS/CoreServices/CreatePaymentInstrument.js b/Samples/TMS/CoreServices/CreatePaymentInstrument.js index 6d25b56..3f3166c 100644 --- a/Samples/TMS/CoreServices/CreatePaymentInstrument.js +++ b/Samples/TMS/CoreServices/CreatePaymentInstrument.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call TMS PaymentInstrumentApi, @@ -23,7 +23,7 @@ function createPaymentInstrument(callback) { var billTo = new cybersourceRestApi.Tmsv1paymentinstrumentsBillTo(); billTo.firstName = 'John'; billTo.lastName = 'Deo'; - billTo.company = 'require(\'cybersource-rest-client\');'; + billTo.company = 'CyberSource'; billTo.address1 = '12 Main Street'; billTo.address2 = '20 My Street'; billTo.locality = 'San Francisco'; @@ -46,17 +46,20 @@ function createPaymentInstrument(callback) { var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; - console.log('\n*************** Create PaymentInstrument ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.tmsV1PaymentinstrumentsPost(profileId, body, function (error, data, response) { if (error) { - console.log('\nError in create PaymentInstrument : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Create PaymentInstrument : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); } - console.log('\nResponse of Create PaymentInstrument : ' + JSON.stringify(response)); - console.log('\nResponse Code of Create PaymentInstrument :' + JSON.stringify(response['status'])); callback(error, data); }); @@ -67,7 +70,6 @@ function createPaymentInstrument(callback) { if (require.main === module) { createPaymentInstrument(function () { - console.log('Create PaymentInstrument end.'); }); } module.exports.createPaymentInstrument = createPaymentInstrument; diff --git a/Samples/TMS/CoreServices/DeleteInstrumentIdentifier.js b/Samples/TMS/CoreServices/DeleteInstrumentIdentifier.js index c299417..0a457cf 100644 --- a/Samples/TMS/CoreServices/DeleteInstrumentIdentifier.js +++ b/Samples/TMS/CoreServices/DeleteInstrumentIdentifier.js @@ -1,9 +1,9 @@ 'use strict'; -var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var cybersourceRestApi = require('cybersource-rest-client'); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var retrieveInstrumentIdentifier = require('./RetrieveInstrumentIdentifier'); /** @@ -17,33 +17,34 @@ function removeInstrumentIdentifier(callback) { var instance = new cybersourceRestApi.InstrumentIdentifierApi(configObject); var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; - - retrieveInstrumentIdentifier.retriveAInstrumentIdentifier(function (error, data) { + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + retrieveInstrumentIdentifier.retriveAInstrumentIdentifier(function (error, data) { if (!error) { - var tokenId = data['id']; - console.log('\n*************** Delete instrument identifier ********************* '); - console.log('\nToken ID passing to instrumentidentifiersTokenIdDelete : ' + tokenId); - + var tokenId = data.id; instance.tmsV1InstrumentidentifiersTokenIdDelete(profileId, tokenId, function (error, data, response) { if (error) { - console.log('\nError in Delete instrument identifier : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Delete instrument identifier : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); } - console.log('\nResponse of Delete instrument identifier : ' + JSON.stringify(response)); - console.log('\nResponse Code of Delete instrument identifier :' + JSON.stringify(response['status'])); callback(error, data); }); } + else { + console.log('\n[END] REQUEST & RESPONSE OF '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); } catch (error) { console.log(error); } } if (require.main === module) { - removeInstrumentIdentifier(function () { - console.log('Delete instrument identifier end'); + removeInstrumentIdentifier(function () { }); } module.exports.removeInstrumentIdentifier = removeInstrumentIdentifier; \ No newline at end of file diff --git a/Samples/TMS/CoreServices/DeletePaymentInstrument.js b/Samples/TMS/CoreServices/DeletePaymentInstrument.js index c61fe1d..5a3f003 100644 --- a/Samples/TMS/CoreServices/DeletePaymentInstrument.js +++ b/Samples/TMS/CoreServices/DeletePaymentInstrument.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var retrievePaymentInstrument = require('./RetrievePaymentInstrument'); /** @@ -16,25 +16,28 @@ function retrivePaymentIdentifiers(callback) { var instance = new cybersourceRestApi.PaymentInstrumentsApi(configObject); var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); retrievePaymentInstrument.retrivePaymentIdentifiers(function (error, data) { if (!error) { - var tokenId = data['id']; - console.log('\n*************** Delete PaymentInstrument ********************* '); - console.log('\nToken ID passing to paymentinstrumentsTokenIdDelete : ' + tokenId); - + var tokenId = data.id; + instance.tmsV1PaymentinstrumentsTokenIdDelete(profileId, tokenId, function (error, data, response) { if (error) { - console.log('\nError in Delete PaymentInstrument : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Delete PaymentInstrument : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); } - console.log('\nResponse of Delete PaymentInstrument : ' + JSON.stringify(response)); - console.log('\nResponse Code of Delete PaymentInstrument :' + JSON.stringify(response['status'])); callback(error, data); }); } + else{ + console.log('\n[END] REQUEST & RESPONSE OF '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); } catch (error) { console.log(error); @@ -42,7 +45,6 @@ function retrivePaymentIdentifiers(callback) { } if (require.main === module) { retrivePaymentIdentifiers(function () { - console.log('PaymentInstrument delete end.'); }); } module.exports.retrivePaymentIdentifiers = retrivePaymentIdentifiers; \ No newline at end of file diff --git a/Samples/TMS/CoreServices/RetrieveAllPaymentInstruments.js b/Samples/TMS/CoreServices/RetrieveAllPaymentInstruments.js index a710c0c..6e4236b 100644 --- a/Samples/TMS/CoreServices/RetrieveAllPaymentInstruments.js +++ b/Samples/TMS/CoreServices/RetrieveAllPaymentInstruments.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var createInstrumentIdentifier = require('./CreateInstrumentIdentifier'); /** @@ -18,25 +18,29 @@ function retriveAllPaymentInstruments(callback) { var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; var options = null; - + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); createInstrumentIdentifier.createInstrumentIdentifier(function (error, data) { if (!error) { - var tokenId = data['id']; - console.log('\n*************** Retrieve all payment instruments ********************* '); - console.log('\nToken ID passing to instrumentidentifiersTokenIdPaymentinstrumentsGet : ' + tokenId); - + var tokenId = data.id; instance.tmsV1InstrumentidentifiersTokenIdPaymentinstrumentsGet(profileId, tokenId, options, function (error, data, response) { if (error) { - console.log('\nError in Retrieve all payment instruments : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Retrieve all payment instruments : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); } - console.log('\nResponse of Retrieve all payment instruments : ' + JSON.stringify(response)); - console.log('\nResponse Code of Retrieve all payment instruments :' + JSON.stringify(response['status'])); - callback(error, data); + callback(error, data); }); } + else + { + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); } catch (error) { console.log(error); @@ -44,7 +48,6 @@ function retriveAllPaymentInstruments(callback) { } if (require.main === module) { retriveAllPaymentInstruments(function () { - console.log('Retrieve all payment instruments end'); }); } module.exports.retriveAllPaymentInstruments = retriveAllPaymentInstruments; \ No newline at end of file diff --git a/Samples/TMS/CoreServices/RetrieveInstrumentIdentifier.js b/Samples/TMS/CoreServices/RetrieveInstrumentIdentifier.js index d68de35..feb546f 100644 --- a/Samples/TMS/CoreServices/RetrieveInstrumentIdentifier.js +++ b/Samples/TMS/CoreServices/RetrieveInstrumentIdentifier.js @@ -1,9 +1,9 @@ 'use strict'; -var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var cybersourceRestApi = require('cybersource-rest-client'); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var createInstrumentIdentifier = require('./CreateInstrumentIdentifier'); /** @@ -17,33 +17,37 @@ function retriveAInstrumentIdentifier(callback) { var instance = new cybersourceRestApi.InstrumentIdentifierApi(configObject); var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; - - createInstrumentIdentifier.createInstrumentIdentifier(function (error, data) { + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + createInstrumentIdentifier.createInstrumentIdentifier(function (error, data) { if (!error) { - var tokenId = data['id']; - console.log('\n*************** Retrieve instrument identifier ********************* '); - console.log('\nToken ID passing to instrumentidentifiersTokenIdGet : ' + tokenId); - + var tokenId = data.id; instance.tmsV1InstrumentidentifiersTokenIdGet(profileId, tokenId, function (error, data, response) { if (error) { - console.log('\nError in Retrieve instrument identifier : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Retrieve instrument identifier : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); } - console.log('\nResponse of Retrieve instrument identifier : ' + JSON.stringify(response)); - console.log('\nResponse Code of Retrieve instrument identifier :' + JSON.stringify(response['status'])); - callback(error, data); + callback(error, data); }); } + else + { + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); + } catch (error) { console.log(error); } } if (require.main === module) { retriveAInstrumentIdentifier(function () { - console.log('Retrieve InstrumentIdentifer end.'); }); } module.exports.retriveAInstrumentIdentifier = retriveAInstrumentIdentifier; \ No newline at end of file diff --git a/Samples/TMS/CoreServices/RetrievePaymentInstrument.js b/Samples/TMS/CoreServices/RetrievePaymentInstrument.js index ff21a46..f75514e 100644 --- a/Samples/TMS/CoreServices/RetrievePaymentInstrument.js +++ b/Samples/TMS/CoreServices/RetrievePaymentInstrument.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var createPaymentInstrument = require('./CreatePaymentInstrument'); /** @@ -17,24 +17,29 @@ function retrivePaymentIdentifiers(callback) { var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); createPaymentInstrument.createPaymentInstrument(function (error, data) { if (!error) { - var tokenId = data['id']; - console.log('\n*************** Retrieve PaymentInstrument ********************* '); - console.log('\nToken ID passing to paymentinstrumentsTokenIdGet : ' + tokenId); - + var tokenId = data.id; instance.tmsV1PaymentinstrumentsTokenIdGet(profileId, tokenId, function (error, data, response) { if (error) { - console.log('\nError in Retrieve PaymentInstrument : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Retrieve PaymentInstrument : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); } - console.log('\nResponse of Retrieve PaymentInstrument : ' + JSON.stringify(response)); - console.log('\nResponse Code of Retrieve PaymentInstrument :' + JSON.stringify(response['status'])); - callback(error, data); + callback(error, data); }); } + else + { + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + callback(error, data); + } }); } catch (error) { console.log(error); @@ -42,7 +47,6 @@ function retrivePaymentIdentifiers(callback) { } if (require.main === module) { retrivePaymentIdentifiers(function () { - console.log('PaymentInstrument end.'); }); } module.exports.retrivePaymentIdentifiers = retrivePaymentIdentifiers; \ No newline at end of file diff --git a/Samples/TMS/CoreServices/UpdateInstrumentIdentifier.js b/Samples/TMS/CoreServices/UpdateInstrumentIdentifier.js index 092421e..700ec37 100644 --- a/Samples/TMS/CoreServices/UpdateInstrumentIdentifier.js +++ b/Samples/TMS/CoreServices/UpdateInstrumentIdentifier.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var retrieveInstrumentIdentifier = require('./RetrieveInstrumentIdentifier'); @@ -29,23 +29,23 @@ function updateInstrumentIdentifier(callback) { body.processingInformation = processingInformation; var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; - + + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); retrieveInstrumentIdentifier.retriveAInstrumentIdentifier(function (error, data) { if (!error) { - var tokenId = data['id']; - console.log('\n*************** Patch instrument identifier ********************* '); - console.log('\nToken ID passing to instrumentidentifiersTokenIdPatch : ' + tokenId); - - + var tokenId = data.id; + instance.tmsV1InstrumentidentifiersTokenIdPatch(profileId, tokenId, body, function (error, data, response) { if (error) { - console.log('\nError in Patch instrument identifier : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Patch instrument identifier : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data ); + console.log('\n API RESPONSE BODY : ' + response.text ); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of Patch instrument identifier : ' + JSON.stringify(response)); - console.log('\nResponse Code of Patch instrument identifier :' + JSON.stringify(response['status'])); callback(error, data); }); } @@ -56,7 +56,7 @@ function updateInstrumentIdentifier(callback) { } if (require.main === module) { updateInstrumentIdentifier(function () { - console.log('update instrument identifier end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.updateInstrumentIdentifier = updateInstrumentIdentifier; diff --git a/Samples/TMS/CoreServices/UpdatePaymentInstrument.js b/Samples/TMS/CoreServices/UpdatePaymentInstrument.js index 98f90b3..45c3a6c 100644 --- a/Samples/TMS/CoreServices/UpdatePaymentInstrument.js +++ b/Samples/TMS/CoreServices/UpdatePaymentInstrument.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); var retrievePaymentInstrument = require('./RetrievePaymentInstrument'); /** @@ -45,23 +45,24 @@ function updatePaymentInstrument(callback) { var profileId = '93B32398-AD51-4CC2-A682-EA3E93614EB1'; + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); retrievePaymentInstrument.retrivePaymentIdentifiers(function (error, data) { if (!error) { - var tokenId = data['id']; - console.log('\n*************** Update PaymentInstrument ********************* '); - console.log('\nToken ID passing to paymentinstrumentsTokenIdPatch : ' + tokenId); + var tokenId = data.id; instance.tmsV1PaymentinstrumentsTokenIdPatch(profileId, tokenId, request, function (error, data, response) { if (error) { - console.log('\nError in Update PaymentInstrument : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of Update PaymentInstrument : ' + JSON.stringify(data)); - } - console.log('\nResponse of Update PaymentInstrument : ' + JSON.stringify(response)); - console.log('\nResponse Code of Update PaymentInstrument :' + JSON.stringify(response['status'])); - callback(error, data); - }); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data ); + console.log('\n API RESPONSE BODY : ' + response.text ); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + } + callback(error, data); + }); } }); } catch (error) { @@ -70,7 +71,7 @@ function updatePaymentInstrument(callback) { } if (require.main === module) { updatePaymentInstrument(function () { - console.log('Update PaymentInstrument end'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.updatePaymentInstrument = updatePaymentInstrument; \ No newline at end of file diff --git a/Samples/TransactionBatches/CoreServices/GetIndividualBatchFile.js b/Samples/TransactionBatches/CoreServices/GetIndividualBatchFile.js index c28cc43..4e116d1 100644 --- a/Samples/TransactionBatches/CoreServices/GetIndividualBatchFile.js +++ b/Samples/TransactionBatches/CoreServices/GetIndividualBatchFile.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call TransactionBatchApi, @@ -16,24 +16,25 @@ function getIndividualBatchFile(callback) { var id = 'Owcyk6pl'; - console.log('\n*************** Retrieve Batch File ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); - instance.ptsV1TransactionBatchesIdGet(id, function (error, data, response) { - if (error) { - console.log('\nError in retrieve batch file : ' + JSON.stringify(error)); - } - else if (data) { - console.log('\nData of retrieve batch file : ' + JSON.stringify(data)); - } - console.log('\nResponse of retrieve batch file : ' + JSON.stringify(response)); - console.log('\nResponse Code of retrieve batch file : ' + JSON.stringify(response['status'])); - callback(error, data); + instance.ptsV1TransactionBatchesIdGet(id, function (error, data, response) { + if (error) { + console.log('\n API ERROR : \n ' + JSON.stringify(error)); + } + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + } + callback(error, data); }); } if (require.main === module) { getIndividualBatchFile(function () { - console.log('Retrieve batch file end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getIndividualBatchFile = getIndividualBatchFile; diff --git a/Samples/TransactionBatches/CoreServices/GetListOfBatchFiles.js b/Samples/TransactionBatches/CoreServices/GetListOfBatchFiles.js index 8105066..bee4ea3 100644 --- a/Samples/TransactionBatches/CoreServices/GetListOfBatchFiles.js +++ b/Samples/TransactionBatches/CoreServices/GetListOfBatchFiles.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call TransactionBatchApi, @@ -17,17 +17,18 @@ function getListOfBatchFiles(callback) { var startTime = '2018-10-01T20:34:24.000Z'; var endTime = '2018-10-29T23:27:25.000Z'; - console.log('\n*************** Retrieve list of batch file ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.ptsV1TransactionBatchesGet(startTime, endTime, function (error, data, response) { if (error) { - console.log('\nError in retrieve list of batch file : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of retrieve list of batch file : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of retrieve list of batch file : ' + JSON.stringify(response)); - console.log('\nResponse Code of retrieve list of batch file : ' + JSON.stringify(response['status'])); callback(error, data); }); @@ -37,7 +38,7 @@ function getListOfBatchFiles(callback) { } if (require.main === module) { getListOfBatchFiles(function () { - console.log('RetriveL List of Batch files end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getListOfBatchFiles = getListOfBatchFiles; \ No newline at end of file diff --git a/Samples/TransactionDetails/CoreServices/RetrieveTransaction.js b/Samples/TransactionDetails/CoreServices/RetrieveTransaction.js index b12fe02..f6ae530 100644 --- a/Samples/TransactionDetails/CoreServices/RetrieveTransaction.js +++ b/Samples/TransactionDetails/CoreServices/RetrieveTransaction.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call TransactionDetailsApi, @@ -16,24 +16,25 @@ function retrieveTransaction(callback) { var id = '5408386919326811103004'; - console.log('\n*************** Retrieve Transaction ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); - instance.getTransaction(id, function (error, data, response) { - if (error) { - console.log('Error in Retrieve Transaction Details : ' + JSON.stringify(error)); - } - else if (data) { - console.log('\n Retrieve Transaction Details Data : ' + JSON.stringify(data)); - } - console.log('\n Retrieve Transaction Details Response : ' + JSON.stringify(response)); - console.log('\n Retrieve Transaction Details Response code : ' + response['status']); - callback(error, data); + instance.getTransaction(id, function (error, data, response) { + if (error) { + console.log('\n API ERROR : \n ' + JSON.stringify(error)); + } + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + } + callback(error, data); }); } if (require.main === module) { retrieveTransaction(function () { - console.log('Retrieve Transaction Details end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.retrieveTransaction = retrieveTransaction; \ No newline at end of file diff --git a/Samples/TransactionSearch/CoreServices/CreateSearchRequest.js b/Samples/TransactionSearch/CoreServices/CreateSearchRequest.js index d60c08d..756ec30 100644 --- a/Samples/TransactionSearch/CoreServices/CreateSearchRequest.js +++ b/Samples/TransactionSearch/CoreServices/CreateSearchRequest.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call SearchTransactionsApi, @@ -23,17 +23,19 @@ function createSearchRequest(callback) { createSearchRequest.limit = 100; createSearchRequest.sort = 'id:asc, submitTimeUtc:asc'; - console.log('\n*************** Create Search Request ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); - instance.createSearch(createSearchRequest, function (error, data, response) { + instance.createSearch(createSearchRequest, function (error, data, response) { if (error) { - console.log('\nError in create search request : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of create search request : ' + JSON.stringify(data)); + if (response) { + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of create search request : ' + JSON.stringify(response)); - console.log('\nResponse Code of create search request : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -42,7 +44,7 @@ function createSearchRequest(callback) { } if (require.main === module) { createSearchRequest(function () { - console.log('create search request end.'); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.createSearchRequest = createSearchRequest; diff --git a/Samples/TransactionSearch/CoreServices/GetSearchResults.js b/Samples/TransactionSearch/CoreServices/GetSearchResults.js index 6ad0d2b..b1d44e7 100644 --- a/Samples/TransactionSearch/CoreServices/GetSearchResults.js +++ b/Samples/TransactionSearch/CoreServices/GetSearchResults.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call SearchTransactionsApi, @@ -14,19 +14,21 @@ function getSearchResults(callback) { var configObject = new configuration(); var instance = new cybersourceRestApi.SearchTransactionsApi(configObject); - var id = '95f6ab1c-d64d-4fdb-949d-cf174405c21f'; + var id = '27c74a80-c923-4034-a929-d968f194d774'; - console.log('\n*************** Get Search Result ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getSearch(id, function (error, data, response) { + if (error) { - console.log('\nError in get search result : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of get search result : ' + JSON.stringify(data)); + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of get search result : ' + JSON.stringify(response)); - console.log('\nResponse Code of get search result : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -36,7 +38,7 @@ function getSearchResults(callback) { } if (require.main === module) { getSearchResults(function () { - console.log('get transaction search end.'); + console.log('\n [END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getSearchResults = getSearchResults; \ No newline at end of file diff --git a/Samples/UserManagement/CoreServices/GetUserInformation.js b/Samples/UserManagement/CoreServices/GetUserInformation.js index 7a6739c..c68d010 100644 --- a/Samples/UserManagement/CoreServices/GetUserInformation.js +++ b/Samples/UserManagement/CoreServices/GetUserInformation.js @@ -2,8 +2,8 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); -var filePath = path.resolve('Data/Configuration.js'); -var configuration = require(filePath); +var filePath = path.join('Data','Configuration.js'); +var configuration = require(path.resolve(filePath)); /** * This is a sample code to call UserManagementApi, @@ -18,17 +18,18 @@ function getUserInformation(callback) { var opts = []; opts['organizationId'] = 'testrest'; - console.log('\n*************** Retrieve User Information ********************* '); + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.getUsers(opts, function (error, data, response) { if (error) { - console.log('\nError in retrieve user information : ' + JSON.stringify(error)); + console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - else if (data) { - console.log('\nData of retrieve user information : ' + JSON.stringify(data)); + if(response){ + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); } - console.log('\nResponse of retrieve user information : ' + JSON.stringify(response)); - console.log('\nResponse Code of get user information : ' + JSON.stringify(response['status'])); callback(error, data); }); } catch (error) { @@ -37,7 +38,7 @@ function getUserInformation(callback) { } if (require.main === module) { getUserInformation(function () { - console.log('Retrieve UserInformation end.'); + console.log('\n [END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } module.exports.getUserInformation = getUserInformation; From f371a0a326bd33a3fb1b560aaa39ac69bbbea79b Mon Sep 17 00:00:00 2001 From: ghari18 <38495299+ghari18@users.noreply.github.com> Date: Thu, 31 Jan 2019 10:30:07 +0530 Subject: [PATCH 2/6] Update Configuration.js --- Data/Configuration.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Data/Configuration.js b/Data/Configuration.js index ab873ba..bb8912b 100644 --- a/Data/Configuration.js +++ b/Data/Configuration.js @@ -22,7 +22,7 @@ const KeyPass = 'testrest'; // logging parameters const EnableLog = true; const LogFileName = 'cybs'; -const LogDirectory = '../log'; +const LogDirectory = './log'; const LogfileMaxSize = '5242880'; //10 MB In Bytes // Constructor for Configuration From 5fc1b4358c51f55bfa9a4978e5350cd71077342f Mon Sep 17 00:00:00 2001 From: ghari18 <38495299+ghari18@users.noreply.github.com> Date: Thu, 31 Jan 2019 13:22:36 +0530 Subject: [PATCH 3/6] Update KeyGenerationNoEnc.js addressing internal review comments --- Samples/Flex/KeyGenerationNoEnc.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Samples/Flex/KeyGenerationNoEnc.js b/Samples/Flex/KeyGenerationNoEnc.js index bc5d895..e38c6db 100644 --- a/Samples/Flex/KeyGenerationNoEnc.js +++ b/Samples/Flex/KeyGenerationNoEnc.js @@ -1,7 +1,7 @@ 'use strict'; -var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); +var cybersourceRestApi = require('cybersource-rest-client'); var filePath = path.join('Data','Configuration.js'); var configuration = require(path.resolve(filePath)); @@ -18,24 +18,22 @@ function keyGenerationNoEnc(callback) { }; console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); instance.generatePublicKey(options, function (error, data, response) { - + console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); if (error) { console.log('\n API ERROR : \n ' + JSON.stringify(error)); } - if (response) { - console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); - console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API RESPONSE BODY : ' + response.text + '\n'); console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); - } + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); callback(error, data); }); } if (require.main === module) { - keyGenerationNoEnc(function () { - console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + keyGenerationNoEnc(function () { }); } -module.exports.keyGenerationNoEnc = keyGenerationNoEnc; \ No newline at end of file +module.exports.keyGenerationNoEnc = keyGenerationNoEnc; From a9e7fcaf0458d2760fee6b3292303623d8af010b Mon Sep 17 00:00:00 2001 From: ghari18 <38495299+ghari18@users.noreply.github.com> Date: Thu, 31 Jan 2019 13:24:04 +0530 Subject: [PATCH 4/6] Update TokenizeCard.js addressing internal review comments --- Samples/Flex/CoreServices/TokenizeCard.js | 43 ++++++++--------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/Samples/Flex/CoreServices/TokenizeCard.js b/Samples/Flex/CoreServices/TokenizeCard.js index 9c9153c..4cd60c3 100644 --- a/Samples/Flex/CoreServices/TokenizeCard.js +++ b/Samples/Flex/CoreServices/TokenizeCard.js @@ -1,10 +1,11 @@ 'use strict'; -var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); +var cybersourceRestApi = require('cybersource-rest-client'); var filePath = path.join('Data','Configuration.js'); var configuration = require(path.resolve(filePath)); var verify = require('../VerifyToken.js'); +var NoencKeygen = require('../KeyGenerationNoEnc.js'); /** * This is a sample code to call KeyGenerationApi which will return key and @@ -26,21 +27,11 @@ function tokenizeCard(callback) { var configObject = new configuration(); var tokenizeInstance = new cybersourceRestApi.FlexTokenApi(configObject); - - var keyInstance = new cybersourceRestApi.KeyGenerationApi(configObject); - - var KeyRequest = new cybersourceRestApi.GeneratePublicKeyRequest(); - KeyRequest.encryptionType = 'None'; - - var options = { - 'generatePublicKeyRequest': KeyRequest - }; - console.log('\n[BEGIN] REQUEST & RESPONSE OF: Generate Key \n'); - keyInstance.generatePublicKey(options, function (error, data, response) { - if (error) { - console.log('\n API ERROR : \n ' + JSON.stringify(error)); - } - else if (data) { + + console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + + NoencKeygen.keyGenerationNoEnc(function (error, data) { + if (data) { keyId = data.keyId; publicKey = data.der['publicKey']; @@ -50,17 +41,9 @@ function tokenizeCard(callback) { var options = { 'tokenizeRequest': tokenizeRequest - }; - if(response){ - console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); - console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); - console.log('\n API RESPONSE BODY : ' + response.text + '\n'); - console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); - console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); - } - console.log('\n[END] REQUEST & RESPONSE OF: Generate Key \n'); - console.log('\n[BEGIN] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + }; tokenizeInstance.tokenize(options, function (error, data, response) { + if (error) { console.log('\n API ERROR : \n ' + JSON.stringify(error)); } @@ -70,9 +53,9 @@ function tokenizeCard(callback) { console.log('\n PublicKey : ' + publicKey); console.log('\n Token Verified : ' + result); } - if(response){ + if(response){ console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); - console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); + console.log('\n API REQUEST BODY : \n' + response.request._data + '\n'); console.log('\n API RESPONSE BODY : ' + response.text + '\n'); console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); @@ -80,6 +63,10 @@ function tokenizeCard(callback) { callback(error, data); }); } + else + { + callback(error, data); + } }); } catch (error) { From 6ea32bae8250af2d63a9a1ab69c44c3d0c3ca48a Mon Sep 17 00:00:00 2001 From: sshasee <46436438+sshasee@users.noreply.github.com> Date: Tue, 19 Feb 2019 12:58:30 +0530 Subject: [PATCH 5/6] Update DownloadReport.js corrected response printing issues --- Samples/Reporting/CoreServices/DownloadReport.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Samples/Reporting/CoreServices/DownloadReport.js b/Samples/Reporting/CoreServices/DownloadReport.js index 90ee193..146661c 100644 --- a/Samples/Reporting/CoreServices/DownloadReport.js +++ b/Samples/Reporting/CoreServices/DownloadReport.js @@ -33,14 +33,18 @@ function downloadReport(callback) { } if(response){ console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); - console.log('\n API RESPONSE BODY : ' + JSON.stringify(response) + '\n'); - console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); - console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); - if(JSON.stringify(response['status']) === '200'){ + if(JSON.stringify(response['status']) === '200'){ const stream = fs.createWriteStream(downloadFilePath); response.pipe(stream); + console.log('\n API RESPONSE BODY : ' ); + response.pipe(process.stdout); + } + response.on('end', function() { + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); console.log('\n File downloaded at the below location :\n' + path.resolve(downloadFilePath)); - } + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + }); } callback(error, data); }); @@ -51,7 +55,7 @@ function downloadReport(callback) { } if (require.main === module) { downloadReport(function () { - console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + }); } module.exports.downloadReport = downloadReport; From d57125e32f5de4a825cad55697549a81723ace0e Mon Sep 17 00:00:00 2001 From: sshasee <46436438+sshasee@users.noreply.github.com> Date: Tue, 19 Feb 2019 13:06:57 +0530 Subject: [PATCH 6/6] printing the response for download --- .../DownloadFileWithFileIdentifier.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js index 2778e0b..61536fd 100644 --- a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js +++ b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js @@ -31,14 +31,18 @@ function downloadFileWithFileIdentifier(callback) { } if(response){ console.log('\n API REQUEST HEADERS : \n' + JSON.stringify(response.req._headers,0,2)); - console.log('\n API RESPONSE BODY : ' + JSON.stringify(response) + '\n'); - console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); - console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); - if(JSON.stringify(response['status']) === '200'){ + if(JSON.stringify(response['status']) === '200'){ const stream = fs.createWriteStream(downloadFilePath); response.pipe(stream); - console.log('\n File downloaded at the below location :\n' + path.resolve(downloadFilePath)); + console.log('\n API RESPONSE BODY : ' ); + response.pipe(process.stdout); } + response.on('end', function() { + console.log('\n API RESPONSE CODE : ' + JSON.stringify(response['status'])); + console.log('\n API RESPONSE HEADERS : \n' + JSON.stringify(response.header,0,2)); + console.log('\n File downloaded at the below location :\n' + path.resolve(downloadFilePath)); + console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); + }); } callback(error, data); }); @@ -49,7 +53,6 @@ function downloadFileWithFileIdentifier(callback) { } if (require.main === module) { downloadFileWithFileIdentifier(function () { - console.log('\n[END] REQUEST & RESPONSE OF: '+ path.basename(__filename, path.extname(__filename)) + '\n'); }); } -module.exports.downloadFileWithFileIdentifier = downloadFileWithFileIdentifier; \ No newline at end of file +module.exports.downloadFileWithFileIdentifier = downloadFileWithFileIdentifier;