Skip to content
Merged
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
8 changes: 6 additions & 2 deletions src/libs/actions/getCompanyCardBankConnection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {LinkAccount} from 'react-native-plaid-link-sdk';
import type {PlaidAccount} from 'react-plaid-link';
import {getApiRoot} from '@libs/ApiUtils';
import * as NetworkStore from '@libs/Network/NetworkStore';
import * as PolicyUtils from '@libs/PolicyUtils';
Expand All @@ -18,6 +20,7 @@ type CompanyCardPlaidConnection = {
feedName: string;
feed: string;
country: string;
plaidAccounts: string;
};

function getCompanyCardBankConnection(policyID?: string, bankName?: string) {
Expand Down Expand Up @@ -48,8 +51,8 @@ function getCompanyCardBankConnection(policyID?: string, bankName?: string) {
return `${commandURL}partners/banks/${bank}/oauth_callback.php?${new URLSearchParams(params).toString()}`;
}

function getCompanyCardPlaidConnection(policyID?: string, publicToken?: string, feed?: string, feedName?: string, country?: string) {
if (!policyID || !publicToken || !feed || !feedName || !country) {
function getCompanyCardPlaidConnection(policyID?: string, publicToken?: string, feed?: string, feedName?: string, country?: string, plaidAccounts?: LinkAccount[] | PlaidAccount[]) {
if (!policyID || !publicToken || !feed || !feedName || !country || !plaidAccounts?.length) {
return null;
}
const authToken = NetworkStore.getAuthToken();
Expand All @@ -60,6 +63,7 @@ function getCompanyCardPlaidConnection(policyID?: string, publicToken?: string,
publicToken,
country,
domainName: PolicyUtils.getDomainNameForPolicy(policyID),
plaidAccounts: JSON.stringify(plaidAccounts),
};

const commandURL = getApiRoot({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
const plaidToken = addNewCard?.data?.publicToken ?? assignCard?.data?.plaidAccessToken;
const plaidFeed = addNewCard?.data?.plaidConnectedFeed ?? assignCard?.data?.institutionId;
const plaidFeedName = addNewCard?.data?.plaidConnectedFeedName ?? assignCard?.data?.plaidConnectedFeedName;
const plaidAccounts = addNewCard?.data?.plaidAccounts ?? assignCard?.data?.plaidAccounts;
const country = addNewCard?.data?.selectedCountry;

const url =
isBetaEnabled(CONST.BETAS.PLAID_COMPANY_CARDS) && plaidToken
? getCompanyCardPlaidConnection(policyID, plaidToken, plaidFeed, plaidFeedName, country)
? getCompanyCardPlaidConnection(policyID, plaidToken, plaidFeed, plaidFeedName, country, plaidAccounts)
: getCompanyCardBankConnection(policyID, bankName);
const [cardFeeds] = useCardFeeds(policyID);
const [isConnectionCompleted, setConnectionCompleted] = useState(false);
Expand Down
7 changes: 3 additions & 4 deletions src/pages/workspace/companyCards/BankConnection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ function BankConnection({policyID: policyIDFromProps, feed, route}: BankConnecti
const {isOffline} = useNetwork();
const plaidToken = addNewCard?.data?.publicToken ?? assignCard?.data?.plaidAccessToken;
const plaidFeed = addNewCard?.data?.plaidConnectedFeed ?? assignCard?.data?.institutionId;
const plaidAccounts = addNewCard?.data?.plaidAccounts ?? assignCard?.data?.plaidAccounts;
const plaidFeedName = addNewCard?.data?.plaidConnectedFeedName ?? assignCard?.data?.plaidConnectedFeedName;
const country = addNewCard?.data?.selectedCountry;
const {isBetaEnabled} = usePermissions();
const isPlaid = isBetaEnabled(CONST.BETAS.PLAID_COMPANY_CARDS) && !!plaidToken;

const url =
isBetaEnabled(CONST.BETAS.PLAID_COMPANY_CARDS) && plaidToken
? getCompanyCardPlaidConnection(policyID, plaidToken, plaidFeed, plaidFeedName, country)
: getCompanyCardBankConnection(policyID, bankName);
const url = isPlaid ? getCompanyCardPlaidConnection(policyID, plaidToken, plaidFeed, plaidFeedName, country, plaidAccounts) : getCompanyCardBankConnection(policyID, bankName);
const isFeedExpired = feed ? isSelectedFeedExpired(cardFeeds?.settings?.oAuthAccountDetails?.[feed]) : false;
const headerTitleAddCards = !backTo ? translate('workspace.companyCards.addCards') : undefined;
const headerTitle = feed ? translate('workspace.companyCards.assignCard') : headerTitleAddCards;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function PlaidConnectionStep({feed}: {feed?: CompanyCardFeed}) {
plaidAccessToken: publicToken,
institutionId: plaidConnectedFeed,
plaidConnectedFeedName,
plaidAccounts: metadata?.accounts,
},
currentStep: CONST.COMPANY_CARD.STEP.BANK_CONNECTION,
});
Expand All @@ -135,6 +136,7 @@ function PlaidConnectionStep({feed}: {feed?: CompanyCardFeed}) {
publicToken,
plaidConnectedFeed,
plaidConnectedFeedName,
plaidAccounts: metadata?.accounts,
},
});
}}
Expand Down
5 changes: 5 additions & 0 deletions src/types/onyx/AssignCard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {LinkAccount} from 'react-native-plaid-link-sdk';
import type {PlaidAccount} from 'react-plaid-link';
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';

Expand Down Expand Up @@ -35,6 +37,9 @@ type AssignCardData = {

/** Plaid feed name */
plaidConnectedFeedName?: string;

/** Plaid accounts */
plaidAccounts?: LinkAccount[] | PlaidAccount[];
};

/** Model of assign card flow */
Expand Down
5 changes: 5 additions & 0 deletions src/types/onyx/CardFeeds.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {LinkAccount} from 'react-native-plaid-link-sdk';
import type {PlaidAccount} from 'react-plaid-link';
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type * as OnyxCommon from './OnyxCommon';
Expand Down Expand Up @@ -127,6 +129,9 @@ type AddNewCardFeedData = {

/** Feed name from Plaid connection */
plaidConnectedFeedName?: string;

/** Plaid accounts */
plaidAccounts?: LinkAccount[] | PlaidAccount[];
};

/** Issue new card flow steps */
Expand Down
Loading