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

Add ability to download statement PDF #7873

Merged
merged 12 commits into from
Mar 2, 2022
12 changes: 12 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,17 @@ function TransferWalletBalance(parameters) {
return Network.post(commandName, parameters);
}

/**
* Fetches the filename of the user's statement
* @param {Object} parameters
* @param {String} [parameters.period]
* @return {Promise}
*/
function GetStatementPDF(parameters) {
const commandName = 'GetStatementPDF';
return Network.post(commandName, parameters);
}

export {
Authenticate,
AuthenticateWithAccountID,
Expand All @@ -1253,6 +1264,7 @@ export {
Get,
GetAccountStatus,
GetShortLivedAuthToken,
GetStatementPDF,
GetIOUReport,
GetFullPolicy,
GetPolicySummaryList,
Expand Down
22 changes: 22 additions & 0 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import NetworkConnection from '../NetworkConnection';
import redirectToSignIn from './SignInRedirect';
import NameValuePair from './NameValuePair';
import Growl from '../Growl';
import CONFIG from '../../CONFIG';
import * as Localize from '../Localize';
import * as CloseAccountActions from './CloseAccount';
import * as Link from './Link';
import getSkinToneEmojiFromIndex from '../../components/EmojiPicker/getSkinToneEmojiFromIndex';
import fileDownload from '../fileDownload';

let sessionAuthToken = '';
let sessionEmail = '';
Expand Down Expand Up @@ -397,6 +399,25 @@ function joinScreenShare(accessToken, roomName) {
clearScreenShareRequest();
}

/**
* Downloads the statement PDF for the provided period
* @param {String} period YYYYMM format
*/
function downloadStatementPDF(period) {
API.GetStatementPDF({period})
.then((response) => {
if (response.jsonCode === 200 && response.filename) {
const downloadFileName = `Expensify_Statement_${response.period}.pdf`;
const pdfURL = `${CONFIG.EXPENSIFY.URL_EXPENSIFY_COM}secure?secureType=pdfreport&filename=${response.filename}&downloadName=${downloadFileName}`;

fileDownload(pdfURL, downloadFileName);
} else {
Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000);
}
})
.catch(() => Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000));
}

export {
changePasswordAndNavigate,
closeAccount,
Expand All @@ -416,4 +437,5 @@ export {
setFrequentlyUsedEmojis,
joinScreenShare,
clearScreenShareRequest,
downloadStatementPDF,
};
5 changes: 5 additions & 0 deletions src/pages/wallet/WalletStatementPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ONYXKEYS from '../../ONYXKEYS';
import compose from '../../libs/compose';
import CONFIG from '../../CONFIG';
import WalletStatementModal from '../../components/WalletStatementModal';
import * as User from '../../libs/actions/User';


const propTypes = {
/** The route object passed to this page from the navigator */
Expand All @@ -37,11 +39,14 @@ const WalletStatementPage = (props) => {
const title = `${monthName} ${year} statement`;

const url = `${CONFIG.EXPENSIFY.URL_EXPENSIFY_COM}statement.php?period=${yearMonth}`;

thienlnam marked this conversation as resolved.
Show resolved Hide resolved
return (
<ScreenWrapper>
<HeaderWithCloseButton
title={Str.recapitalize(title)}
shouldShowDownloadButton
onCloseButtonPress={() => Navigation.dismissModal(true)}
onDownloadButtonPress={() => User.downloadStatementPDF(yearMonth)}
/>
<WalletStatementModal
statementPageURL={url}
Expand Down