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

[Refactor] Use new API Command: VerifyIdentityForBankAccount #10967

Merged
merged 23 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
920d451
Use new verifyIdentityForBankAccount API command
MariaHCD Sep 13, 2022
0b60999
Add bankAccountID request parameter
MariaHCD Sep 14, 2022
8112223
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Sep 14, 2022
d24febf
Remove obsolete comment
MariaHCD Sep 14, 2022
ffa6da7
Fix import
MariaHCD Sep 14, 2022
5d4667b
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Sep 19, 2022
af5039d
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Sep 26, 2022
6149a61
Fix trailing space
MariaHCD Sep 26, 2022
fb27cd1
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Sep 27, 2022
b0098c2
Merge remote-tracking branch 'origin/maxence-fapifb' into maria-refac…
MariaHCD Sep 27, 2022
16af862
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Sep 30, 2022
59f427d
Fix params for verifyIdentityForBankAccount
MariaHCD Sep 30, 2022
b110f15
Improve function name
MariaHCD Sep 30, 2022
5dea641
Fix linter errors
MariaHCD Sep 30, 2022
421f73d
Create new component for requestor onfido step
MariaHCD Sep 30, 2022
5939835
Only pass onfidoData
MariaHCD Sep 30, 2022
5dacb3a
Merge remote-tracking branch 'origin/maria-refactor-verify-identity-f…
MariaHCD Sep 30, 2022
f0ba654
Fix Onfido component
MariaHCD Sep 30, 2022
745b9d5
Merge remote-tracking branch 'origin/main' into maria-refactor-verify…
MariaHCD Sep 30, 2022
cd39544
Fix Onfido flow and linter errors
MariaHCD Sep 30, 2022
44f9c50
Fix function order and add DocBlock
MariaHCD Sep 30, 2022
822c927
Update props
MariaHCD Oct 4, 2022
a8f673f
Remove redundant state
MariaHCD Oct 4, 2022
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
14 changes: 14 additions & 0 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ function connectBankAccountManually(bankAccountID, accountNumber, routingNumber,
}, getVBBADataForOnyx());
}

/**
* Verify the user's identity via Onfido
*
* @param {Number} bankAccountID
* @param {Object} onfidoData
*/
function verifyIdentityForBankAccount(bankAccountID, onfidoData) {
API.write('VerifyIdentityForBankAccount', {
bankAccountID,
onfidoData: JSON.stringify(onfidoData),
}, getVBBADataForOnyx());
}

export {
addPersonalBankAccount,
connectBankAccountManually,
Expand All @@ -300,6 +313,7 @@ export {
clearOnfidoToken,
updatePersonalInformationForBankAccount,
validateBankAccount,
verifyIdentityForBankAccount,
updateCompanyInformationForBankAccount,
connectBankAccountWithPlaid,
updatePlaidData,
Expand Down
82 changes: 82 additions & 0 deletions src/pages/ReimbursementAccount/RequestorOnfidoStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import {ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import styles from '../../styles/styles';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import * as BankAccounts from '../../libs/actions/BankAccounts';
import Onfido from '../../components/Onfido';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import * as ReimbursementAccountUtils from '../../libs/ReimbursementAccountUtils';
import Growl from '../../libs/Growl';
import reimbursementAccountPropTypes from './reimbursementAccountPropTypes';
import CONST from '../../CONST';

const propTypes = {
/** Bank account currently in setup */
/* eslint-disable-next-line react/no-unused-prop-types */
reimbursementAccount: reimbursementAccountPropTypes.isRequired,
onfidoToken: PropTypes.string,
onComplete: PropTypes.func.isRequired,
...withLocalizePropTypes,
};

const defaultProps = {
onfidoToken: '',
};

class RequestorOnfidoStep extends React.Component {
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
}

submit(onfidoData) {
BankAccounts.verifyIdentityForBankAccount(
ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0),
onfidoData,
);
this.props.onComplete();
MariaHCD marked this conversation as resolved.
Show resolved Hide resolved
}

render() {
return (
<ScrollView contentContainerStyle={styles.flex1}>
<Onfido
sdkToken={this.props.onfidoToken}
onUserExit={() => {
// We're taking the user back to the company step. They will need to come back to the requestor step to make the Onfido flow appear again.
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY);
}}
onError={() => {
// In case of any unexpected error we log it to the server, show a growl, and return the user back to the company step so they can try again.
Growl.error(this.props.translate('onfidoStep.genericError'), 10000);
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY);
}}
onSuccess={(onfidoData) => {
this.submit(onfidoData);
}}
/>
</ScrollView>
);
}
}

RequestorOnfidoStep.propTypes = propTypes;
RequestorOnfidoStep.defaultProps = defaultProps;

export default compose(
withLocalize,
withOnyx({
reimbursementAccount: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
},
onfidoToken: {
key: ONYXKEYS.ONFIDO_TOKEN,
},
reimbursementAccountDraft: {
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT_DRAFT,
},
}),
)(RequestorOnfidoStep);
51 changes: 13 additions & 38 deletions src/pages/ReimbursementAccount/RequestorStep.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import lodashGet from 'lodash/get';
import {ScrollView, View} from 'react-native';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import moment from 'moment';
Expand All @@ -16,14 +16,13 @@ import Text from '../../components/Text';
import * as BankAccounts from '../../libs/actions/BankAccounts';
import IdentityForm from './IdentityForm';
import * as ValidationUtils from '../../libs/ValidationUtils';
import Onfido from '../../components/Onfido';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import * as ReimbursementAccountUtils from '../../libs/ReimbursementAccountUtils';
import Growl from '../../libs/Growl';
import reimbursementAccountPropTypes from './reimbursementAccountPropTypes';
import ReimbursementAccountForm from './ReimbursementAccountForm';
import * as Link from '../../libs/actions/Link';
import RequestorOnfidoStep from './RequestorOnfidoStep';

const propTypes = {
/** Bank account currently in setup */
Expand All @@ -42,6 +41,7 @@ class RequestorStep extends React.Component {

this.submit = this.submit.bind(this);
this.clearErrorsAndSetValues = this.clearErrorsAndSetValues.bind(this);
this.setOnfidoAsComplete = this.setOnfidoAsComplete.bind(this);

this.state = {
firstName: ReimbursementAccountUtils.getDefaultStateForField(props, 'firstName'),
Expand All @@ -53,7 +53,6 @@ class RequestorStep extends React.Component {
dob: ReimbursementAccountUtils.getDefaultStateForField(props, 'dob'),
ssnLast4: ReimbursementAccountUtils.getDefaultStateForField(props, 'ssnLast4'),
isControllingOfficer: ReimbursementAccountUtils.getDefaultStateForField(props, 'isControllingOfficer', false),
onfidoData: lodashGet(props, ['reimbursementAccount', 'achData', 'onfidoData'], ''),
isOnfidoSetupComplete: lodashGet(props, ['achData', 'isOnfidoSetupComplete'], false),
};

Expand All @@ -74,6 +73,13 @@ class RequestorStep extends React.Component {
this.getErrors = () => ReimbursementAccountUtils.getErrors(this.props);
}

/**
* Update state to indicate that the user has completed the Onfido verification process
*/
setOnfidoAsComplete() {
this.setState({isOnfidoSetupComplete: true});
}

/**
* Clear the errors associated to keys in values if found and store the new values in the state.
*
Expand Down Expand Up @@ -147,20 +153,6 @@ class RequestorStep extends React.Component {
BankAccounts.updatePersonalInformationForBankAccount(payload);
}

submitOnfidoVerification() {
if (!this.validate()) {
return;
}

const payload = {
bankAccountID: ReimbursementAccountUtils.getDefaultStateForField(this.props, 'bankAccountID', 0),
...this.state,
dob: moment(this.state.dob).format(CONST.DATE.MOMENT_FORMAT_STRING),
};

BankAccounts.setupWithdrawalAccount(payload);
}

render() {
const achData = this.props.reimbursementAccount.achData;
const shouldShowOnfido = achData.useOnfido && this.props.onfidoToken && !this.state.isOnfidoSetupComplete;
Expand All @@ -183,26 +175,9 @@ class RequestorStep extends React.Component {
onCloseButtonPress={Navigation.dismissModal}
/>
{shouldShowOnfido ? (
<ScrollView contentContainerStyle={styles.flex1}>
<Onfido
sdkToken={this.props.onfidoToken}
onUserExit={() => {
// We're taking the user back to the company step. They will need to come back to the requestor step to make the Onfido flow appear again.
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY);
}}
onError={() => {
// In case of any unexpected error we log it to the server, show a growl, and return the user back to the company step so they can try again.
Growl.error(this.props.translate('onfidoStep.genericError'), 10000);
BankAccounts.goToWithdrawalAccountSetupStep(CONST.BANK_ACCOUNT.STEP.COMPANY);
}}
onSuccess={(onfidoData) => {
this.setState({
onfidoData,
isOnfidoSetupComplete: true,
}, this.submitOnfidoVerification);
}}
/>
</ScrollView>
<RequestorOnfidoStep
onComplete={this.setOnfidoAsComplete}
/>
) : (
<ReimbursementAccountForm
onSubmit={this.submit}
Expand Down