From 3355f8e4c2deae5d56c6e880cc696faae126d363 Mon Sep 17 00:00:00 2001 From: David Bondy Date: Tue, 23 May 2023 17:04:17 -0600 Subject: [PATCH 1/3] re-adding paywithwallet functionality for manual requests --- src/libs/actions/IOU.js | 14 ++++++++++++++ src/pages/iou/IOUDetailsModal.js | 12 +++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index d606f668cb06..3c425d7a8e9d 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1172,6 +1172,19 @@ function payMoneyRequest(paymentType, chatReport, iouReport) { } } +/** + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} recipient + */ +function payMoneyRequestWithWallet(chatReport, iouReport, recipient) { + const {params, optimisticData, successData, failureData} = getPayMoneyRequestParams(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.EXPENSIFY); + + API.write('PayMoneyRequestWithWallet', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); +} + export { deleteMoneyRequest, splitBill, @@ -1180,6 +1193,7 @@ export { sendMoneyElsewhere, sendMoneyViaPaypal, payMoneyRequest, + payMoneyRequestWithWallet, setIOUSelectedCurrency, setMoneyRequestDescription, sendMoneyWithWallet, diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index 84de2a089242..603011edb2a5 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -133,6 +133,16 @@ class IOUDetailsModal extends Component { return reportActionWithPendingAction ? reportActionWithPendingAction.pendingAction : undefined; } + onPressSettlementButton(paymentMethodType) { + // Payment via Expensify Wallet is handled differently for now so make sure we call the right API + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { + IOU.payMoneyRequestWithWallet(this.props.chatReport, this.props.iouReport, recipient); + return; + } + + IOU.payMoneyRequest(paymentMethodType, this.props.chatReport, this.props.iouReport) + } + render() { const sessionEmail = lodashGet(this.props.session, 'email', null); const pendingAction = this.findPendingAction(); @@ -175,7 +185,7 @@ class IOUDetailsModal extends Component { {hasOutstandingIOU && this.props.iouReport.managerEmail === sessionEmail && ( IOU.payMoneyRequest(paymentMethodType, this.props.chatReport, this.props.iouReport)} + onPress={this.onPressSettlementButton} shouldShowPaypal={Boolean(lodashGet(this.props, 'iouReport.submitterPayPalMeAddress'))} currency={lodashGet(this.props, 'iouReport.currency')} enablePaymentsRoute={ROUTES.IOU_DETAILS_ENABLE_PAYMENTS} From 0de3008ff7ef4c409780c415f689c1613f61d020 Mon Sep 17 00:00:00 2001 From: David Bondy Date: Wed, 24 May 2023 11:43:28 -0600 Subject: [PATCH 2/3] re-remove code and "streamline" when we will call different APIs --- src/libs/actions/IOU.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3c425d7a8e9d..2f710d5a88a5 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1165,26 +1165,17 @@ function payMoneyRequest(paymentType, chatReport, iouReport) { }; const {params, optimisticData, successData, failureData} = getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentType); - API.write('PayMoneyRequest', params, {optimisticData, successData, failureData}); + // For now we need to call the PayMoneyRequestWithWallet API since PayMoneyRequest was not updated to work with + // Expensify Wallets. + const apiCommand = paymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY ? 'PayMoneyRequestWithWallet' : 'PayMoneyRequest'; + + API.write(apiCommand, params, {optimisticData, successData, failureData}); Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); if (paymentType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(iouReport.total, recipient.payPalMeAddress, iouReport.currency)); } } -/** - * @param {Object} chatReport - * @param {Object} iouReport - * @param {Object} recipient - */ -function payMoneyRequestWithWallet(chatReport, iouReport, recipient) { - const {params, optimisticData, successData, failureData} = getPayMoneyRequestParams(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.EXPENSIFY); - - API.write('PayMoneyRequestWithWallet', params, {optimisticData, successData, failureData}); - - Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); -} - export { deleteMoneyRequest, splitBill, @@ -1193,7 +1184,6 @@ export { sendMoneyElsewhere, sendMoneyViaPaypal, payMoneyRequest, - payMoneyRequestWithWallet, setIOUSelectedCurrency, setMoneyRequestDescription, sendMoneyWithWallet, From fd4ec9100495f66b8c4c042c82fdc66798705d47 Mon Sep 17 00:00:00 2001 From: David Bondy Date: Wed, 24 May 2023 11:44:24 -0600 Subject: [PATCH 3/3] move logic for API switching into the action since this is needed to be called in at least 3 places --- src/pages/iou/IOUDetailsModal.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index 603011edb2a5..84de2a089242 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -133,16 +133,6 @@ class IOUDetailsModal extends Component { return reportActionWithPendingAction ? reportActionWithPendingAction.pendingAction : undefined; } - onPressSettlementButton(paymentMethodType) { - // Payment via Expensify Wallet is handled differently for now so make sure we call the right API - if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { - IOU.payMoneyRequestWithWallet(this.props.chatReport, this.props.iouReport, recipient); - return; - } - - IOU.payMoneyRequest(paymentMethodType, this.props.chatReport, this.props.iouReport) - } - render() { const sessionEmail = lodashGet(this.props.session, 'email', null); const pendingAction = this.findPendingAction(); @@ -185,7 +175,7 @@ class IOUDetailsModal extends Component { {hasOutstandingIOU && this.props.iouReport.managerEmail === sessionEmail && ( IOU.payMoneyRequest(paymentMethodType, this.props.chatReport, this.props.iouReport)} shouldShowPaypal={Boolean(lodashGet(this.props, 'iouReport.submitterPayPalMeAddress'))} currency={lodashGet(this.props, 'iouReport.currency')} enablePaymentsRoute={ROUTES.IOU_DETAILS_ENABLE_PAYMENTS}