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

feat: Update corpay fields logic, integrate API #52812

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dc0c88f
feat: Update corpay fields logic, integrate API
pasyukevich Nov 20, 2024
ac7c181
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Nov 20, 2024
d4b2165
fix: variable value
pasyukevich Nov 20, 2024
54e779f
feat: Add Corpay bank account creation parameters and update related …
pasyukevich Nov 26, 2024
026f483
fix: Update variable name for destination country in currency selection
pasyukevich Nov 26, 2024
8f819ee
feat: Enhance Corpay bank account creation with loading and success s…
pasyukevich Nov 26, 2024
f34597b
feat: Add loading and success states for Corpay bank account fields
pasyukevich Nov 27, 2024
8d81057
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Nov 27, 2024
70d9667
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Nov 29, 2024
7d70ba6
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Nov 29, 2024
4fe1b77
Refactor reimbursement account state management to replace isSuccess …
pasyukevich Dec 5, 2024
ce518e2
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Dec 5, 2024
d86cfbb
Update title handling for account holder country in confirmation step
pasyukevich Dec 5, 2024
3db5474
Refactor reimbursement account handling to include isSuccess flag and…
pasyukevich Dec 12, 2024
ba6e9a8
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Dec 12, 2024
8bd08c7
Remove unused parameter 'preferredMethod' from Confirmation component
pasyukevich Dec 12, 2024
d6eacef
Remove redundant condition from reimbursement account success check i…
pasyukevich Dec 12, 2024
c3cd9c6
Add isLoading flag cleaning
pasyukevich Dec 12, 2024
1482c01
Update formID reference in Confirmation component and adjust styles
pasyukevich Dec 13, 2024
199e4db
Add margin styles to submit button in Confirmation component
pasyukevich Dec 13, 2024
b59d729
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Dec 13, 2024
6970071
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Dec 16, 2024
3fa6692
Add loading indicator to BankAccountDetails and update Confirmation s…
pasyukevich Dec 17, 2024
b85737c
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Dec 18, 2024
2db773b
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Dec 18, 2024
478a3fd
fix: eslint, policyID update to possible undefined
pasyukevich Dec 19, 2024
00b8ec4
fix: COUNTRY field to reimbursement account form and update related …
pasyukevich Dec 19, 2024
eae246d
fix: rollback redundant changes
pasyukevich Dec 20, 2024
1eab5d2
fix: clear draft values for reimbursement account form on currency se…
pasyukevich Dec 20, 2024
ccc859e
Merge branch 'main' into feature/GR-step-two-api-integration
pasyukevich Dec 20, 2024
fe927bf
fix: clear form errors on confirmation step and update country field …
pasyukevich Dec 23, 2024
a87e41f
fix: remove unnecessary flex style from bank account details components
pasyukevich Dec 23, 2024
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
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ const CONST = {
HANG_TIGHT: 4,
},
},
BANK_INFO_STEP_ACCOUNT_HOLDER_KEY_PREFIX: 'accountHolder',
},
INCORPORATION_TYPES: {
LLC: 'LLC',
Expand Down
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ const ONYXKEYS = {
/** The user's Concierge reportID */
CONCIERGE_REPORT_ID: 'conciergeReportID',

/* Corpay fieds to be used in the bank account creation setup */
CORPAY_FIELDS: 'corpayFields',

/** The user's session that will be preserved when using imported state */
PRESERVED_USER_SESSION: 'preservedUserSession',

Expand Down Expand Up @@ -1044,6 +1047,7 @@ type OnyxValuesMapping = {
[ONYXKEYS.SHOULD_SHOW_SAVED_SEARCH_RENAME_TOOLTIP]: boolean;
[ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES]: Record<string, string>;
[ONYXKEYS.CONCIERGE_REPORT_ID]: string;
[ONYXKEYS.CORPAY_FIELDS]: OnyxTypes.CorpayFields;
[ONYXKEYS.PRESERVED_USER_SESSION]: OnyxTypes.Session;
[ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING]: OnyxTypes.DismissedProductTraining;
};
Expand Down
8 changes: 8 additions & 0 deletions src/libs/API/parameters/BankAccountCreateCorpayParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type BankAccountCreateCorpayParams = {
type: number;
isSavings: boolean;
isWithdrawal: boolean;
inputs: string;
};

export default BankAccountCreateCorpayParams;
8 changes: 8 additions & 0 deletions src/libs/API/parameters/GetCorpayBankAccountFieldsParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type GetCorpayBankAccountFieldsParams = {
countryISO: string;
currency: string;
isWithdrawal: boolean;
isBusinessBankAccount: boolean;
};

export default GetCorpayBankAccountFieldsParams;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type VerifyIdentityForBankAccountParams = {
bankAccountID: number;
onfidoData: string;
policyID: string;
policyID?: string;
};
Comment on lines 1 to 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: This is wrong. PolicyID should not be optional. Confirmed this with internal team about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will handle this. Not to worry here.

export default VerifyIdentityForBankAccountParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type {default as RestartBankAccountSetupParams} from './RestartBankAccoun
export type {default as AddSchoolPrincipalParams} from './AddSchoolPrincipalParams';
export type {default as AuthenticatePusherParams} from './AuthenticatePusherParams';
export type {default as BankAccountHandlePlaidErrorParams} from './BankAccountHandlePlaidErrorParams';
export type {default as BankAccountCreateCorpayParams} from './BankAccountCreateCorpayParams';
export type {default as BeginAppleSignInParams} from './BeginAppleSignInParams';
export type {default as BeginGoogleSignInParams} from './BeginGoogleSignInParams';
export type {default as BeginSignInParams} from './BeginSignInParams';
Expand All @@ -29,6 +30,7 @@ export type {default as ExpandURLPreviewParams} from './ExpandURLPreviewParams';
export type {default as GetMissingOnyxMessagesParams} from './GetMissingOnyxMessagesParams';
export type {default as GetNewerActionsParams} from './GetNewerActionsParams';
export type {default as GetOlderActionsParams} from './GetOlderActionsParams';
export type {default as GetCorpayBankAccountFieldsParams} from './GetCorpayBankAccountFieldsParams';
export type {default as GetPolicyCategoriesParams} from './GetPolicyCategories';
export type {default as GetReportPrivateNoteParams} from './GetReportPrivateNoteParams';
export type {default as GetRouteParams} from './GetRouteParams';
Expand Down
4 changes: 4 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ const WRITE_COMMANDS = {
SELF_TOUR_VIEWED: 'SelfTourViewed',
UPDATE_INVOICE_COMPANY_NAME: 'UpdateInvoiceCompanyName',
UPDATE_INVOICE_COMPANY_WEBSITE: 'UpdateInvoiceCompanyWebsite',
BANK_ACCOUNT_CREATE_CORPAY: 'BankAccount_CreateCorpay',
UPDATE_WORKSPACE_CUSTOM_UNIT: 'UpdateWorkspaceCustomUnit',
VALIDATE_USER_AND_GET_ACCESSIBLE_POLICIES: 'ValidateUserAndGetAccessiblePolicies',
DISMISS_PRODUCT_TRAINING: 'DismissProductTraining',
Expand Down Expand Up @@ -773,6 +774,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.HOLD_MONEY_REQUEST_ON_SEARCH]: Parameters.HoldMoneyRequestOnSearchParams;
[WRITE_COMMANDS.APPROVE_MONEY_REQUEST_ON_SEARCH]: Parameters.ApproveMoneyRequestOnSearchParams;
[WRITE_COMMANDS.UNHOLD_MONEY_REQUEST_ON_SEARCH]: Parameters.UnholdMoneyRequestOnSearchParams;
[WRITE_COMMANDS.BANK_ACCOUNT_CREATE_CORPAY]: Parameters.BankAccountCreateCorpayParams;

[WRITE_COMMANDS.REQUEST_REFUND]: null;
[WRITE_COMMANDS.CONNECT_POLICY_TO_SAGE_INTACCT]: Parameters.ConnectPolicyToSageIntacctParams;
Expand Down Expand Up @@ -900,6 +902,7 @@ type WriteCommandParameters = {
};

const READ_COMMANDS = {
GET_CORPAY_BANK_ACCOUNT_FIELDS: 'GetCorpayBankAccountFields',
CONNECT_POLICY_TO_QUICKBOOKS_ONLINE: 'ConnectPolicyToQuickbooksOnline',
CONNECT_POLICY_TO_XERO: 'ConnectPolicyToXero',
SYNC_POLICY_TO_QUICKBOOKS_ONLINE: 'SyncPolicyToQuickbooksOnline',
Expand Down Expand Up @@ -981,6 +984,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_PLAID_BANK_ACCOUNT_SELECTOR]: Parameters.OpenPlaidBankAccountSelectorParams;
[READ_COMMANDS.GET_OLDER_ACTIONS]: Parameters.GetOlderActionsParams;
[READ_COMMANDS.GET_NEWER_ACTIONS]: Parameters.GetNewerActionsParams;
[READ_COMMANDS.GET_CORPAY_BANK_ACCOUNT_FIELDS]: Parameters.GetCorpayBankAccountFieldsParams;
[READ_COMMANDS.EXPAND_URL_PREVIEW]: Parameters.ExpandURLPreviewParams;
[READ_COMMANDS.GET_REPORT_PRIVATE_NOTE]: Parameters.GetReportPrivateNoteParams;
[READ_COMMANDS.OPEN_ROOM_MEMBERS_PAGE]: Parameters.OpenRoomMembersPageParams;
Expand Down
212 changes: 76 additions & 136 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type {PersonalBankAccountForm} from '@src/types/form';
import type {ACHContractStepProps, BeneficialOwnersStepProps, CompanyStepProps, RequestorStepProps} from '@src/types/form/ReimbursementAccountForm';
import type {ACHContractStepProps, BeneficialOwnersStepProps, CompanyStepProps, ReimbursementAccountForm, RequestorStepProps} from '@src/types/form/ReimbursementAccountForm';
import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount';
import type {BankAccountStep, ReimbursementAccountStep, ReimbursementAccountSubStep} from '@src/types/onyx/ReimbursementAccount';
import type {OnyxData} from '@src/types/onyx/Request';
Expand Down Expand Up @@ -334,7 +334,7 @@ function validateBankAccount(bankAccountID: number, validateCode: string, policy
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
isLoading: false,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('bankAccount.error.validationAmounts'),
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
],
Expand All @@ -344,166 +344,104 @@ function validateBankAccount(bankAccountID: number, validateCode: string, policy
}

function getCorpayBankAccountFields(country: string, currency: string) {
// TODO - Use parameters when API is ready
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const parameters = {
countryISO: country,
currency,
isWithdrawal: true,
isBusinessBankAccount: true,
};

// return API.read(READ_COMMANDS.GET_CORPAY_BANK_ACCOUNT_FIELDS, parameters);
return {
bankCountry: 'AU',
bankCurrency: 'AUD',
classification: 'Business',
destinationCountry: 'AU',
formFields: [
const onyxData: OnyxData = {
optimisticData: [
{
errorMessage: 'Swift must be less than 12 characters',
id: 'swiftBicCode',
isRequired: false,
isRequiredInValueSet: true,
label: 'Swift Code',
regEx: '^.{0,12}$',
validationRules: [
{
errorMessage: 'Swift must be less than 12 characters',
regEx: '^.{0,12}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.CORPAY_FIELDS,
value: {
isLoading: true,
isSuccess: false,
},
},
],
successData: [
{
errorMessage: 'Beneficiary Bank Name must be less than 250 characters',
id: 'bankName',
isRequired: true,
isRequiredInValueSet: true,
label: 'Bank Name',
regEx: '^.{0,250}$',
validationRules: [
{
errorMessage: 'Beneficiary Bank Name must be less than 250 characters',
regEx: '^.{0,250}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.CORPAY_FIELDS,
value: {
isLoading: false,
isSuccess: true,
},
},
],
failureData: [
{
errorMessage: 'City must be less than 100 characters',
id: 'bankCity',
isRequired: true,
isRequiredInValueSet: true,
label: 'Bank City',
regEx: '^.{0,100}$',
validationRules: [
{
errorMessage: 'City must be less than 100 characters',
regEx: '^.{0,100}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.CORPAY_FIELDS,
value: {
isLoading: false,
isSuccess: false,
},
},
],
};

return API.read(READ_COMMANDS.GET_CORPAY_BANK_ACCOUNT_FIELDS, parameters, onyxData);
}

function createCorpayBankAccount(fields: ReimbursementAccountForm) {
const parameters = {
type: 1,
isSavings: false,
isWithdrawal: true,
inputs: JSON.stringify(fields),
};

const onyxData: OnyxData = {
optimisticData: [
{
errorMessage: 'Bank Address Line 1 must be less than 1000 characters',
id: 'bankAddressLine1',
isRequired: true,
isRequiredInValueSet: true,
label: 'Bank Address',
regEx: '^.{0,1000}$',
validationRules: [
{
errorMessage: 'Bank Address Line 1 must be less than 1000 characters',
regEx: '^.{0,1000}$',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
isLoading: true,
isCreateCorpayBankAccount: true,
},
},
],
successData: [
{
detailedRule: [
{
isRequired: true,
value: [
{
errorMessage: 'Beneficiary Account Number is invalid. Value should be 1 to 50 characters long.',
regEx: '^.{1,50}$',
ruleDescription: '1 to 50 characters',
},
],
},
],
errorMessage: 'Beneficiary Account Number is invalid. Value should be 1 to 50 characters long.',
id: 'accountNumber',
isRequired: true,
isRequiredInValueSet: true,
label: 'Account Number (iACH)',
regEx: '^.{1,50}$',
validationRules: [
{
errorMessage: 'Beneficiary Account Number is invalid. Value should be 1 to 50 characters long.',
regEx: '^.{1,50}$',
ruleDescription: '1 to 50 characters',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
isLoading: false,
isCreateCorpayBankAccount: false,
isSuccess: true,
},
},
],
failureData: [
{
detailedRule: [
{
isRequired: true,
value: [
{
errorMessage: 'BSB Number is invalid. Value should be exactly 6 digits long.',
regEx: '^[0-9]{6}$',
ruleDescription: 'Exactly 6 digits',
},
],
},
],
errorMessage: 'BSB Number is invalid. Value should be exactly 6 digits long.',
id: 'routingCode',
isRequired: true,
isRequiredInValueSet: true,
label: 'BSB Number',
regEx: '^[0-9]{6}$',
validationRules: [
{
errorMessage: 'BSB Number is invalid. Value should be exactly 6 digits long.',
regEx: '^[0-9]{6}$',
ruleDescription: 'Exactly 6 digits',
},
{
errorMessage: 'The following characters are not allowed: <,>, "',
regEx: '^[^<>\\x22]*$',
},
],
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
isLoading: false,
isCreateCorpayBankAccount: false,
isSuccess: false,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
],
paymentMethods: ['E'],
preferredMethod: 'E',
};

return API.write(WRITE_COMMANDS.BANK_ACCOUNT_CREATE_CORPAY, parameters, onyxData);
}

function clearReimbursementAccount() {
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, null);
}

function clearReimbursementAccountBankCreation() {
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {isCreateCorpayBankAccount: null, isSuccess: null, isLoading: null});
}

/**
* Function to display and fetch data for Reimbursement Account step
* @param stepToOpen - current step to open
Expand Down Expand Up @@ -629,7 +567,7 @@ function verifyIdentityForBankAccount(bankAccountID: number, onfidoData: OnfidoD
const parameters: VerifyIdentityForBankAccountParams = {
bankAccountID,
onfidoData: JSON.stringify(onfidoData),
policyID: policyID ?? '-1',
policyID,
};

API.write(WRITE_COMMANDS.VERIFY_IDENTITY_FOR_BANK_ACCOUNT, parameters, getVBBADataForOnyx());
Expand Down Expand Up @@ -712,6 +650,7 @@ export {
openPlaidView,
connectBankAccountManually,
connectBankAccountWithPlaid,
createCorpayBankAccount,
deletePaymentBankAccount,
handlePlaidError,
setPersonalBankAccountContinueKYCOnSuccess,
Expand All @@ -730,6 +669,7 @@ export {
clearPersonalBankAccountSetupType,
validatePlaidSelection,
getCorpayBankAccountFields,
clearReimbursementAccountBankCreation,
};

export type {BusinessAddress, PersonalAddress};
4 changes: 2 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,9 @@ function clearAvatarErrors(policyID: string) {
* Optimistically update the general settings. Set the general settings as pending until the response succeeds.
* If the response fails set a general error message. Clear the error message when updating.
*/
function updateGeneralSettings(policyID: string, name: string, currencyValue?: string) {
function updateGeneralSettings(name: string, currencyValue?: string, policyID?: string) {
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
if (!policy) {
if (!policy || !policyID) {
return;
}

Expand Down
Loading
Loading