From 79e61c1581867090d9ed379a8979ce2b2923abb2 Mon Sep 17 00:00:00 2001 From: "Shiva Shankaran, Akshaya" Date: Thu, 20 Dec 2018 16:08:40 +0530 Subject: [PATCH 1/2] modified downloading code to print status on the console --- Samples/Reporting/CoreServices/DownloadReport.js | 14 ++++++++++++-- .../CoreServices/DownloadFileWithFileIdentifier.js | 14 +++++++++++--- .../CoreServices/GetSearchResults.js | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Samples/Reporting/CoreServices/DownloadReport.js b/Samples/Reporting/CoreServices/DownloadReport.js index d5b134e..f43a7c5 100644 --- a/Samples/Reporting/CoreServices/DownloadReport.js +++ b/Samples/Reporting/CoreServices/DownloadReport.js @@ -2,6 +2,7 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); +var fs = require('fs'); var filePath = path.resolve('Data/Configuration.js'); var configuration = require(filePath); @@ -27,13 +28,22 @@ function downloadReport(callback) { console.log('****************Download Report****************'); - 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)); } + if(response){ + console.log('\n Response of download report: '+JSON.stringify(response)); + console.log('\nResponse Code of download report : ' + JSON.stringify(response['status'])); + if(JSON.stringify(response['status']) === '200'){ + const stream = fs.createWriteStream(downloadFilePath); + response.pipe(stream); + console.log('\n File downloaded at the below location :\n' + apiClient.downloadFilePath); + } + } callback(error, data); }); - console.log('File downloaded at the below location :\n' + apiClient.downloadFilePath); + } catch (error) { console.log(error); } diff --git a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js index 007fc96..9472c32 100644 --- a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js +++ b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js @@ -2,6 +2,7 @@ var cybersourceRestApi = require('cybersource-rest-client'); var path = require('path'); +var fs = require('fs'); var filePath = path.resolve('Data/Configuration.js'); var configuration = require(filePath); @@ -25,14 +26,21 @@ function downloadFileWithFileIdentifier(callback) { console.log('****************Download File with Identifier****************'); - 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: '); + if(response){ + console.log('\n Response of download report: '+JSON.stringify(response)); + console.log('\nResponse Code of download report : ' + JSON.stringify(response['status'])); + if(JSON.stringify(response['status']) === '200'){ + const stream = fs.createWriteStream(downloadFilePath); + response.pipe(stream); + console.log('\n File downloaded at the below location :\n' + apiClient.downloadFilePath); + } + } callback(error, data); }); - console.log('File downloaded at the below location :\n' + apiClient.downloadFilePath); } catch (error) { console.log(error); } diff --git a/Samples/TransactionSearch/CoreServices/GetSearchResults.js b/Samples/TransactionSearch/CoreServices/GetSearchResults.js index 6ad0d2b..37c42dc 100644 --- a/Samples/TransactionSearch/CoreServices/GetSearchResults.js +++ b/Samples/TransactionSearch/CoreServices/GetSearchResults.js @@ -14,7 +14,7 @@ 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 ********************* '); From 995956219f4dd130b6f6584c5e5b82c96ba75349 Mon Sep 17 00:00:00 2001 From: "Shiva Shankaran, Akshaya" Date: Thu, 20 Dec 2018 16:28:48 +0530 Subject: [PATCH 2/2] Removed setting filepath in apiclient --- Samples/Reporting/CoreServices/DownloadReport.js | 3 +-- .../CoreServices/DownloadFileWithFileIdentifier.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Samples/Reporting/CoreServices/DownloadReport.js b/Samples/Reporting/CoreServices/DownloadReport.js index f43a7c5..ee0b4a9 100644 --- a/Samples/Reporting/CoreServices/DownloadReport.js +++ b/Samples/Reporting/CoreServices/DownloadReport.js @@ -17,7 +17,6 @@ function downloadReport(callback) { //File name in which report get downloaded var downloadFilePath = 'Resource\\reportName.xml'; - apiClient.downloadFilePath = path.resolve(downloadFilePath); var instance = new cybersourceRestApi.ReportDownloadsApi(configObject, apiClient); @@ -38,7 +37,7 @@ function downloadReport(callback) { if(JSON.stringify(response['status']) === '200'){ const stream = fs.createWriteStream(downloadFilePath); response.pipe(stream); - console.log('\n File downloaded at the below location :\n' + apiClient.downloadFilePath); + console.log('\n File downloaded at the below location :\n' + path.resolve(downloadFilePath)); } } callback(error, data); diff --git a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js index 9472c32..86a29e2 100644 --- a/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js +++ b/Samples/SecureFileShare/CoreServices/DownloadFileWithFileIdentifier.js @@ -17,7 +17,6 @@ function downloadFileWithFileIdentifier(callback) { //File name in which report get downloaded var downloadFilePath = 'Resource\\DownloadFileWithFileIdentifier.csv'; - apiClient.downloadFilePath = path.resolve(downloadFilePath); var instance = new cybersourceRestApi.SecureFileShareApi(configObject, apiClient); var fileId = 'VFJSUmVwb3J0LTc4NTVkMTNmLTkzOTgtNTExMy1lMDUzLWEyNTg4ZTBhNzE5Mi5jc3YtMjAxOC0xMC0yMA=='; @@ -36,7 +35,7 @@ function downloadFileWithFileIdentifier(callback) { if(JSON.stringify(response['status']) === '200'){ const stream = fs.createWriteStream(downloadFilePath); response.pipe(stream); - console.log('\n File downloaded at the below location :\n' + apiClient.downloadFilePath); + console.log('\n File downloaded at the below location :\n' + path.resolve(downloadFilePath)); } } callback(error, data);