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

[WIP] Update Payment flow on clicking Pay #50640

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
31823cc
add strings
rezkiy37 Oct 11, 2024
3948c12
add invoice case for getBankAccountRoute
rezkiy37 Oct 11, 2024
a2d1b9a
add invoice payment menu items
rezkiy37 Oct 11, 2024
f4f708a
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 14, 2024
905f8e5
add payment method button
rezkiy37 Oct 14, 2024
94647a4
pay invoice command accepts method id
rezkiy37 Oct 14, 2024
0080e82
integrate payment logic
rezkiy37 Oct 14, 2024
abed35d
pass account type
rezkiy37 Oct 15, 2024
e45613d
set add debit card route
rezkiy37 Oct 15, 2024
8b081a7
render all payment methods
rezkiy37 Oct 15, 2024
1302948
clear todo
rezkiy37 Oct 15, 2024
699a035
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 16, 2024
2e05df0
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 17, 2024
16f0136
Revert "set add debit card route"
rezkiy37 Oct 17, 2024
dbd3e10
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 25, 2024
4a8928a
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Oct 28, 2024
5168b6f
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Nov 6, 2024
3e5d028
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Nov 14, 2024
ee24a29
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Nov 19, 2024
27edab4
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Nov 20, 2024
38d4636
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Nov 25, 2024
90712f2
Merge branch 'main' of https://github.com/rezkiy37/Expensify into fea…
rezkiy37 Dec 4, 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
12 changes: 10 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import DelegateNoAccessModal from './DelegateNoAccessModal';
import HeaderWithBackButton from './HeaderWithBackButton';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import type {PaymentMethod} from './KYCWall/types';
import MoneyReportHeaderStatusBar from './MoneyReportHeaderStatusBar';
import type {MoneyRequestHeaderStatusBarProps} from './MoneyRequestHeaderStatusBar';
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
Expand Down Expand Up @@ -181,7 +182,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const shouldDisplaySearchRouter = !isReportInRHP || isSmallScreenWidth;

const confirmPayment = useCallback(
(type?: PaymentMethodType | undefined, payAsBusiness?: boolean) => {
(type?: PaymentMethodType | undefined, payAsBusiness?: boolean, methodID?: number, paymentMethod?: PaymentMethod) => {
if (!type || !chatReport) {
return;
}
Expand All @@ -192,7 +193,14 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
} else if (isAnyTransactionOnHold) {
setIsHoldMenuVisible(true);
} else if (ReportUtils.isInvoiceReport(moneyRequestReport)) {
IOU.payInvoice(type, chatReport, moneyRequestReport, payAsBusiness);
IOU.payInvoice(
type,
chatReport,
moneyRequestReport,
payAsBusiness,
paymentMethod === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT ? methodID : undefined,
paymentMethod === CONST.PAYMENT_METHODS.DEBIT_CARD ? methodID : undefined,
);
} else {
IOU.payMoneyRequest(type, chatReport, moneyRequestReport, true);
}
Expand Down
12 changes: 10 additions & 2 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Button from '@components/Button';
import DelegateNoAccessModal from '@components/DelegateNoAccessModal';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import type {PaymentMethod} from '@components/KYCWall/types';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import ProcessMoneyReportHoldMenu from '@components/ProcessMoneyReportHoldMenu';
Expand Down Expand Up @@ -213,7 +214,7 @@ function ReportPreview({
HapticFeedback.longPress();
}, []);
const confirmPayment = useCallback(
(type: PaymentMethodType | undefined, payAsBusiness?: boolean) => {
(type: PaymentMethodType | undefined, payAsBusiness?: boolean, methodID?: number, paymentMethod?: PaymentMethod) => {
if (!type) {
return;
}
Expand All @@ -227,7 +228,14 @@ function ReportPreview({
setIsPaidAnimationRunning(true);
HapticFeedback.longPress();
if (ReportUtils.isInvoiceReport(iouReport)) {
IOU.payInvoice(type, chatReport, iouReport, payAsBusiness);
IOU.payInvoice(
type,
chatReport,
iouReport,
payAsBusiness,
paymentMethod === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT ? methodID : undefined,
paymentMethod === CONST.PAYMENT_METHODS.DEBIT_CARD ? methodID : undefined,
);
} else {
IOU.payMoneyRequest(type, chatReport, iouReport);
}
Expand Down
37 changes: 37 additions & 0 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import * as Expensicons from '@components/Icon/Expensicons';
import KYCWall from '@components/KYCWall';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as PaymentUtils from '@libs/PaymentUtils';
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as SubscriptionUtils from '@libs/SubscriptionUtils';
Expand Down Expand Up @@ -61,6 +63,7 @@ function SettlementButton({
onlyShowPayElsewhere,
wrapperStyle,
}: SettlementButtonProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
// The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here.
Expand All @@ -73,6 +76,9 @@ function SettlementButton({

const isLoadingLastPaymentMethod = isLoadingOnyxValue(lastPaymentMethodResult);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [bankAccountList = {}] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [fundList = {}] = useOnyx(ONYXKEYS.FUND_LIST);

const isInvoiceReport = (!isEmptyObject(iouReport) && ReportUtils.isInvoiceReport(iouReport)) || false;
const shouldShowPaywithExpensifyOption = !shouldHidePaymentOptions;
const shouldShowPayElsewhereOption = !shouldHidePaymentOptions && !isInvoiceReport;
Expand Down Expand Up @@ -125,13 +131,33 @@ function SettlementButton({
}

if (isInvoiceReport) {
const formattedPaymentMethods = PaymentUtils.formatPaymentMethods(bankAccountList, fundList, styles);
const getPaymentSubitems = (payAsBusiness: boolean) =>
formattedPaymentMethods.map((formattedPaymentMethod) => ({
text: formattedPaymentMethod?.title ?? '',
description: formattedPaymentMethod?.description ?? '',
icon: formattedPaymentMethod?.icon,
onSelected: () => onPress(CONST.IOU.PAYMENT_TYPE.VBBA, payAsBusiness, formattedPaymentMethod.methodID, formattedPaymentMethod.accountType),
}));

if (ReportUtils.isIndividualInvoiceRoom(chatReport)) {
buttonOptions.push({
text: translate('iou.settlePersonal', {formattedAmount}),
icon: Expensicons.User,
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
backButtonText: translate('iou.individual'),
subMenuItems: [
...getPaymentSubitems(false),
{
text: translate('workspace.invoices.paymentMethods.addBankAccount'),
icon: Expensicons.Bank,
onSelected: () => Navigation.navigate(addBankAccountRoute),
},
{
text: translate('workspace.invoices.paymentMethods.addDebitOrCreditCard'),
icon: Expensicons.CreditCard,
onSelected: () => Navigation.navigate(addDebitCardRoute),
},
{
text: translate('iou.payElsewhere', {formattedAmount: ''}),
icon: Expensicons.Cash,
Expand All @@ -148,6 +174,17 @@ function SettlementButton({
value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE,
backButtonText: translate('iou.business'),
subMenuItems: [
...getPaymentSubitems(true),
{
text: translate('workspace.invoices.paymentMethods.addBankAccount'),
icon: Expensicons.Bank,
onSelected: () => Navigation.navigate(addBankAccountRoute),
},
{
text: translate('workspace.invoices.paymentMethods.addCorporateCard'),
icon: Expensicons.CreditCard,
onSelected: () => Navigation.navigate(addDebitCardRoute),
},
{
text: translate('iou.payElsewhere', {formattedAmount: ''}),
icon: Expensicons.Cash,
Expand Down
3 changes: 2 additions & 1 deletion src/components/SettlementButton/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {StyleProp, ViewStyle} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {PaymentMethod} from '@components/KYCWall/types';
import type ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type {ButtonSizeValue} from '@src/styles/utils/types';
Expand All @@ -11,7 +12,7 @@ type EnablePaymentsRoute = typeof ROUTES.ENABLE_PAYMENTS | typeof ROUTES.IOU_SEN

type SettlementButtonProps = {
/** Callback to execute when this button is pressed. Receives a single payment type argument. */
onPress: (paymentType?: PaymentMethodType, payAsBusiness?: boolean) => void;
onPress: (paymentType?: PaymentMethodType, payAsBusiness?: boolean, methodID?: number, paymentMethod?: PaymentMethod) => void;

/** Callback when the payment options popover is shown */
onPaymentOptionsShow?: () => void;
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4061,6 +4061,8 @@ const translations = {
business: 'Business',
chooseInvoiceMethod: 'Choose a payment method below:',
addBankAccount: 'Add bank account',
addDebitOrCreditCard: 'Add debit or credit card',
addCorporateCard: 'Add corporate card',
payingAsIndividual: 'Paying as an individual',
payingAsBusiness: 'Paying as a business',
},
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4107,6 +4107,8 @@ const translations = {
business: 'Empresas',
chooseInvoiceMethod: 'Elija un método de pago:',
addBankAccount: 'Añadir cuenta bancaria',
addDebitOrCreditCard: 'Agrega una tarjeta de débito o crédito',
addCorporateCard: 'Agrega una tarjeta corporativa',
payingAsIndividual: 'Pago individual',
payingAsBusiness: 'Pagar como una empresa',
},
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/parameters/PayInvoiceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type PayInvoiceParams = Partial<CreateWorkspaceParams> & {
reportActionID: string;
paymentMethodType: PaymentMethodType;
payAsBusiness: boolean;
bankAccountID?: number;
fundID?: number;
};

export default PayInvoiceParams;
10 changes: 9 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,15 @@ function isPublicAnnounceRoom(report: OnyxEntry<Report>): boolean {
* else since the report is a personal IOU, the route should be for personal bank account.
*/
function getBankAccountRoute(report: OnyxEntry<Report>): Route {
return isPolicyExpenseChat(report) ? ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('', report?.policyID) : ROUTES.SETTINGS_ADD_BANK_ACCOUNT;
if (isPolicyExpenseChat(report)) {
return ROUTES.BANK_ACCOUNT_WITH_STEP_TO_OPEN.getRoute('', report?.policyID);
}

if (isInvoiceRoom(report) && report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS) {
return ROUTES.WORKSPACE_INVOICES.getRoute(report?.invoiceReceiver?.policyID);
}

return ROUTES.SETTINGS_ADD_BANK_ACCOUNT;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7627,7 +7627,14 @@ function payMoneyRequest(paymentType: PaymentMethodType, chatReport: OnyxTypes.R
API.write(apiCommand, params, {optimisticData, successData, failureData});
}

function payInvoice(paymentMethodType: PaymentMethodType, chatReport: OnyxTypes.Report, invoiceReport: OnyxEntry<OnyxTypes.Report>, payAsBusiness = false) {
function payInvoice(
paymentMethodType: PaymentMethodType,
chatReport: OnyxTypes.Report,
invoiceReport: OnyxEntry<OnyxTypes.Report>,
payAsBusiness = false,
bankAccountID?: number,
fundID?: number,
) {
const recipient = {accountID: invoiceReport?.ownerAccountID ?? -1};
const {
optimisticData,
Expand Down Expand Up @@ -7657,6 +7664,14 @@ function payInvoice(paymentMethodType: PaymentMethodType, chatReport: OnyxTypes.
payAsBusiness,
};

if (bankAccountID) {
params.bankAccountID = bankAccountID;
}

if (fundID) {
params.fundID = fundID;
}

if (policyID) {
params = {
...params,
Expand Down
Loading