Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Report download status #10

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Samples/Reporting/CoreServices/DownloadReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -16,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);

Expand All @@ -27,13 +27,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' + path.resolve(downloadFilePath));
}
}
callback(error, data);
});
console.log('File downloaded at the below location :\n' + apiClient.downloadFilePath);

} catch (error) {
console.log(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -16,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==';
Expand All @@ -25,14 +25,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' + path.resolve(downloadFilePath));
}
}
callback(error, data);
});
console.log('File downloaded at the below location :\n' + apiClient.downloadFilePath);
} catch (error) {
console.log(error);
}
Expand Down
2 changes: 1 addition & 1 deletion Samples/TransactionSearch/CoreServices/GetSearchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ********************* ');

Expand Down