Skip to content
Open
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: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ 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: 15 additions & 6 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ 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 @@ -337,7 +338,7 @@ function SettlementButton({
}

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

const isActivePolicyCurrencySupported = isCurrencySupportedForDirectReimbursement(activePolicy?.outputCurrency ?? '');
Expand Down Expand Up @@ -379,8 +380,8 @@ function SettlementButton({
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
};
return [
...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []),
...(isCurrencySupported && isPolicyCurrencySupported ? [addBankAccountItem] : []),
...(showPayViaExpensifyOptions ? getPaymentSubItems(payAsBusiness) : []),
...(showPayViaExpensifyOptions && isPolicyCurrencySupported ? [addBankAccountItem] : []),
{
text: translate('iou.payElsewhere', {formattedAmount: ''}),
icon: icons.Cash,
Expand All @@ -397,17 +398,24 @@ 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: hasIntentToPay ? CONST.IOU.PAYMENT_TYPE.EXPENSIFY : (lastPaymentMethod ?? CONST.IOU.PAYMENT_TYPE.ELSEWHERE),
value: invoiceDefaultValue,
backButtonText: translate('iou.individual'),
subMenuItems: getInvoicesOptions(false),
});
buttonOptions.push({
text: translate('iou.settleBusiness', {formattedAmount}),
icon: icons.Building,
value: hasIntentToPay ? CONST.IOU.PAYMENT_TYPE.EXPENSIFY : (lastPaymentMethod ?? CONST.IOU.PAYMENT_TYPE.ELSEWHERE),
value: invoiceDefaultValue,
backButtonText: translate('iou.business'),
subMenuItems: getInvoicesOptions(true),
});
Expand Down Expand Up @@ -445,6 +453,7 @@ function SettlementButton({
activeAdminPolicies,
checkForNecessaryAction,
icons,
isPayInvoiceViaExpensifyBetaEnabled,
]);

const selectPaymentType = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType) => {
Expand All @@ -459,7 +468,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) {
if (hasIntentToPay && isPayInvoiceViaExpensifyBetaEnabled) {
const currentBankInformation = formattedPaymentMethods.at(0) as BankAccount;
onPress(
CONST.IOU.PAYMENT_TYPE.EXPENSIFY,
Expand Down
9 changes: 6 additions & 3 deletions src/hooks/useBulkPayOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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 @@ -67,6 +68,8 @@ 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 isIOUReport = isIOUReportUtil(selectedReportID);
const isExpenseReport = isExpenseReportUtil(selectedReportID);
const isInvoiceReport = isInvoiceReportUtil(selectedReportID);
Expand Down Expand Up @@ -172,7 +175,7 @@ function useBulkPayOptions({
}

if (isInvoiceReport) {
const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const showPayViaExpensifyOptions = isPayInvoiceViaExpensifyBetaEnabled && isCurrencySupportedForGlobalReimbursement(currency as CurrencyType);
const getInvoicesOptions = (payAsBusiness: boolean) => {
const addBankAccountItem = {
text: translate('bankAccount.addBankAccount'),
Expand All @@ -183,8 +186,8 @@ function useBulkPayOptions({
},
};
return [
...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []),
...(isCurrencySupported ? [addBankAccountItem] : []),
...(showPayViaExpensifyOptions ? getPaymentSubItems(payAsBusiness) : []),
...(showPayViaExpensifyOptions ? [addBankAccountItem] : []),
{
text: translate('iou.payElsewhere', {formattedAmount: ''}),
icon: icons.Cash,
Expand Down
13 changes: 8 additions & 5 deletions src/hooks/usePaymentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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 @@ -100,6 +101,8 @@ 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 @@ -163,7 +166,7 @@ function usePaymentOptions({

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