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

Create updateCompanyInformationForBankAccount in App #11026

Merged
merged 17 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
65 changes: 64 additions & 1 deletion src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Onyx from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import CONST from '../../CONST';
import * as API from '../API';
import ONYXKEYS from '../../ONYXKEYS';
Expand Down Expand Up @@ -42,13 +44,21 @@ function clearPlaid() {
Onyx.set(ONYXKEYS.PLAID_LINK_TOKEN, '');
}

/** Reimbursement account actively being set up */
let reimbursementAccountInSetup = {};
Onyx.connect({
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
callback: (val) => {
reimbursementAccountInSetup = lodashGet(val, 'achData', {});
},
});

/**
* Helper method to build the Onyx data required during setup of a Verified Business Bank Account
*
* @returns {Object}
*/
// We'll remove the below once this function is used by the VBBA commands that are yet to be implemented
/* eslint-disable no-unused-vars */
function getVBBADataForOnyx() {
return {
optimisticData: [
Expand Down Expand Up @@ -193,10 +203,63 @@ function validateBankAccount(bankAccountID, validateCode) {
});
}

/**
* @param {Object} data
* @returns {Object}
*/
function mergeWithLocalACHData(data) {
const updatedACHData = {
...reimbursementAccountInSetup,
...data,

// This param tells Web-Secure that this bank account is from NewDot so we can modify links back to the correct
// app in any communications. It also will be used to provision a customer for the Expensify card automatically
// once their bank account is successfully validated.
enableCardAfterVerified: true,
};

if (data && !_.isUndefined(data.isSavings)) {
updatedACHData.isSavings = Boolean(data.isSavings);
}
if (!updatedACHData.setupType) {
updatedACHData.setupType = updatedACHData.plaidAccountID
? CONST.BANK_ACCOUNT.SETUP_TYPE.PLAID
: CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL;
}

return updatedACHData;
}

/**
* Updates the bank account in db with the company step data
*
* @param {Object} params
* @param {String} [params.companyName]
* @param {String} [params.addressStreet]
* @param {String} [params.addressCity]
* @param {String} [params.addressState]
* @param {String} [params.addressZipCode]
* @param {String} [params.companyPhone]
* @param {String} [params.website]
* @param {String} [params.companyTaxID]
* @param {String} [params.incorporationType]
* @param {String} [params.incorporationState]
* @param {String} [params.incorporationDate]
* @param {Boolean} [params.hasNoConnectionToCannabis]
*/
function updateCompanyInformationForBankAccount(params) {
API.write(
'UpdateCompanyInformationForBankAccount',
mergeWithLocalACHData(params),
getVBBADataForOnyx(),
);
}

export {
addPersonalBankAccount,
deletePaymentBankAccount,
clearPersonalBankAccount,
clearPlaid,
validateBankAccount,
updateCompanyInformationForBankAccount,
};
2 changes: 1 addition & 1 deletion src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class CompanyStep extends React.Component {
}

const incorporationDate = moment(this.state.incorporationDate).format(CONST.DATE.MOMENT_FORMAT_STRING);
BankAccounts.setupWithdrawalAccount({
BankAccounts.updateCompanyInformationForBankAccount({
...this.state,
incorporationDate,
companyTaxID: this.state.companyTaxID.replace(CONST.REGEX.NON_NUMERIC, ''),
Expand Down