Skip to content
Closed
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
1 change: 0 additions & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ const CONST = {
ODOMETER_EXPENSES: 'odometerExpenses',
NEW_DOT_HOME: 'newDotHome',
SINGLE_USE_AND_EXPIRE_BY_CARDS: 'singleUseAndExpireByCards',
PAY_INVOICE_VIA_EXPENSIFY: 'payInvoiceViaExpensify',
PERSONAL_CARD_IMPORT: 'personalCardImport',
SUGGESTED_FOLLOWUPS: 'suggestedFollowups',
},
Expand Down
21 changes: 6 additions & 15 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ function SettlementButton({
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const isPayInvoiceViaExpensifyBetaEnabled = isBetaEnabled(CONST.BETAS.PAY_INVOICE_VIA_EXPENSIFY);
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, accountID, email ?? '');

const isInvoiceReport = (!isEmptyObject(iouReport) && isInvoiceReportUtil(iouReport)) || false;
Expand Down Expand Up @@ -340,7 +339,7 @@ function SettlementButton({
}

if (isInvoiceReport) {
const showPayViaExpensifyOptions = isPayInvoiceViaExpensifyBetaEnabled && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const hasActivePolicyAsAdmin = !!activePolicy && isPolicyAdmin(activePolicy) && isPaidGroupPolicy(activePolicy);

const isActivePolicyCurrencySupported = isCurrencySupportedForDirectReimbursement(activePolicy?.outputCurrency ?? '');
Expand Down Expand Up @@ -382,8 +381,8 @@ function SettlementButton({
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
};
return [
...(showPayViaExpensifyOptions ? getPaymentSubItems(payAsBusiness) : []),
...(showPayViaExpensifyOptions && isPolicyCurrencySupported ? [addBankAccountItem] : []),
...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []),
...(isCurrencySupported && isPolicyCurrencySupported ? [addBankAccountItem] : []),
{
text: translate('iou.payElsewhere', ''),
icon: icons.Cash,
Expand All @@ -400,24 +399,17 @@ function SettlementButton({
};

if (isIndividualInvoiceRoomUtil(chatReport)) {
// Gate default so main split button never triggers Pay via Expensify when beta is off (or currency unsupported).
let invoiceDefaultValue = lastPaymentMethod ?? CONST.IOU.PAYMENT_TYPE.ELSEWHERE;
if (showPayViaExpensifyOptions && (hasIntentToPay || lastPaymentMethod === CONST.IOU.PAYMENT_TYPE.EXPENSIFY)) {
invoiceDefaultValue = CONST.IOU.PAYMENT_TYPE.EXPENSIFY;
} else if (lastPaymentMethod === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
invoiceDefaultValue = CONST.IOU.PAYMENT_TYPE.ELSEWHERE;
}
buttonOptions.push({
text: translate('iou.settlePersonal', formattedAmount),
icon: icons.User,
value: invoiceDefaultValue,
value: hasIntentToPay ? CONST.IOU.PAYMENT_TYPE.EXPENSIFY : (lastPaymentMethod ?? CONST.IOU.PAYMENT_TYPE.ELSEWHERE),
backButtonText: translate('iou.individual'),
subMenuItems: getInvoicesOptions(false),
});
buttonOptions.push({
text: translate('iou.settleBusiness', formattedAmount),
icon: icons.Building,
value: invoiceDefaultValue,
value: hasIntentToPay ? CONST.IOU.PAYMENT_TYPE.EXPENSIFY : (lastPaymentMethod ?? CONST.IOU.PAYMENT_TYPE.ELSEWHERE),
backButtonText: translate('iou.business'),
subMenuItems: getInvoicesOptions(true),
});
Expand Down Expand Up @@ -455,7 +447,6 @@ function SettlementButton({
activeAdminPolicies,
checkForNecessaryAction,
icons,
isPayInvoiceViaExpensifyBetaEnabled,
]);

const selectPaymentType = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType) => {
Expand All @@ -470,7 +461,7 @@ function SettlementButton({

if (isInvoiceReport) {
// if user has intent to pay, we should get the only bank account information to pay the invoice.
if (hasIntentToPay && isPayInvoiceViaExpensifyBetaEnabled) {
if (hasIntentToPay) {
const currentBankInformation = formattedPaymentMethods.at(0) as BankAccount;
Comment on lines +464 to 465

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard invoice one-tap pay on eligible Expensify option

This unconditional if (hasIntentToPay) now forces invoice payments down the EXPENSIFY path even when that option is not actually eligible (for example, unsupported invoice currency, or formattedPaymentMethods still empty while Onyx data is loading). That bypasses the isCurrencySupported gating used to build invoice submenu options and can either trigger an invalid pay-via-Expensify attempt or crash when formattedPaymentMethods.at(0) is undefined and currentBankInformation.accountData is accessed. Gate this branch with the same eligibility check used for invoice options and verify a payment method exists before forcing Expensify.

Useful? React with 👍 / 👎.

onPress(
CONST.IOU.PAYMENT_TYPE.EXPENSIFY,
Expand Down
9 changes: 3 additions & 6 deletions src/hooks/useBulkPayOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import {useMemoizedLazyExpensifyIcons} from './useLazyAsset';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';
import usePermissions from './usePermissions';
import usePolicy from './usePolicy';
import useThemeStyles from './useThemeStyles';

Expand Down Expand Up @@ -68,8 +67,6 @@ function useBulkPayOptions({
const policy = usePolicy(selectedPolicyID);
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selectedReportID}`, {canBeMissing: true});
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${iouReport?.chatReportID}`, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const isPayInvoiceViaExpensifyBetaEnabled = isBetaEnabled(CONST.BETAS.PAY_INVOICE_VIA_EXPENSIFY);
const activeAdminPolicies = useActiveAdminPolicies();
const isIOUReport = isIOUReportUtil(selectedReportID);
const isExpenseReport = isExpenseReportUtil(selectedReportID);
Expand Down Expand Up @@ -177,7 +174,7 @@ function useBulkPayOptions({
}

if (isInvoiceReport) {
const showPayViaExpensifyOptions = isPayInvoiceViaExpensifyBetaEnabled && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const getInvoicesOptions = (payAsBusiness: boolean) => {
const addBankAccountItem = {
text: translate('bankAccount.addBankAccount'),
Expand All @@ -188,8 +185,8 @@ function useBulkPayOptions({
},
};
return [
...(showPayViaExpensifyOptions ? getPaymentSubItems(payAsBusiness) : []),
...(showPayViaExpensifyOptions ? [addBankAccountItem] : []),
...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []),
...(isCurrencySupported ? [addBankAccountItem] : []),
{
text: translate('iou.payElsewhere', ''),
icon: icons.Cash,
Expand Down
13 changes: 5 additions & 8 deletions src/hooks/usePaymentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import {useMemoizedLazyExpensifyIcons} from './useLazyAsset';
import useLocalize from './useLocalize';
import useOnyx from './useOnyx';
import usePermissions from './usePermissions';
import usePolicy from './usePolicy';
import useThemeStyles from './useThemeStyles';

Expand Down Expand Up @@ -101,8 +100,6 @@ function usePaymentOptions({
const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult);
const [bankAccountList = getEmptyObject<BankAccountList>()] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const [fundList = getEmptyObject<FundList>()] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const isPayInvoiceViaExpensifyBetaEnabled = isBetaEnabled(CONST.BETAS.PAY_INVOICE_VIA_EXPENSIFY);
const lastPaymentMethodRef = useRef(lastPaymentMethod);

useEffect(() => {
Expand Down Expand Up @@ -166,7 +163,7 @@ function usePaymentOptions({

if (isInvoiceReport) {
const formattedPaymentMethods = formatPaymentMethods(bankAccountList, fundList, styles, translate);
const showPayViaExpensifyOptions = isPayInvoiceViaExpensifyBetaEnabled && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const getPaymentSubItems = (payAsBusiness: boolean) => {
const requiredAccountType = payAsBusiness ? CONST.BANK_ACCOUNT.TYPE.BUSINESS : CONST.BANK_ACCOUNT.TYPE.PERSONAL;
return formattedPaymentMethods
Expand Down Expand Up @@ -202,14 +199,14 @@ function usePaymentOptions({
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
backButtonText: translate('iou.individual'),
subMenuItems: [
...(showPayViaExpensifyOptions ? getPaymentSubItems(false) : []),
...(isCurrencySupported ? getPaymentSubItems(false) : []),
{
text: translate('iou.payElsewhere', ''),
icon: icons.Cash,
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
onSelected: () => onPress(CONST.IOU.PAYMENT_TYPE.ELSEWHERE),
},
...(showPayViaExpensifyOptions ? [addBankAccountItem] : []),
...(isCurrencySupported ? [addBankAccountItem] : []),
],
});
}
Expand All @@ -220,8 +217,8 @@ function usePaymentOptions({
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
backButtonText: translate('iou.business'),
subMenuItems: [
...(showPayViaExpensifyOptions ? getPaymentSubItems(true) : []),
...(showPayViaExpensifyOptions ? [addBankAccountItem] : []),
...(isCurrencySupported ? getPaymentSubItems(true) : []),
...(isCurrencySupported ? [addBankAccountItem] : []),
{
text: translate('iou.payElsewhere', ''),
icon: icons.Cash,
Expand Down
Loading