diff --git a/src/components/ReportActionItem/IOUAction.js b/src/components/ReportActionItem/IOUAction.js index 71717dad1faf..affa1035eb64 100644 --- a/src/components/ReportActionItem/IOUAction.js +++ b/src/components/ReportActionItem/IOUAction.js @@ -25,6 +25,9 @@ const propTypes = { chatReport: PropTypes.shape({ /** The participants of this report */ participants: PropTypes.arrayOf(PropTypes.string), + + /** Whether the chat report has an outstanding IOU */ + hasOutstandingIOU: PropTypes.bool.isRequired, }), /** Whether the IOU is hovered so we can modify its style */ @@ -43,6 +46,12 @@ const IOUAction = (props) => { const launchDetailsModal = () => { Navigation.navigate(ROUTES.getIouDetailsRoute(props.chatReportID, props.action.originalMessage.IOUReportID)); }; + + const shouldShowIOUPreview = ( + props.isMostRecentIOUReportAction + && Boolean(props.action.originalMessage.IOUReportID) + && props.chatReport.hasOutstandingIOU) || props.action.originalMessage.type === 'pay'; + return ( <> { shouldAllowViewDetails={Boolean(props.action.originalMessage.IOUReportID)} onViewDetailsPressed={launchDetailsModal} /> - {((props.isMostRecentIOUReportAction && Boolean(props.action.originalMessage.IOUReportID)) - || (props.action.originalMessage.type === 'pay')) && ( - + {shouldShowIOUPreview && ( + )} ); diff --git a/src/components/SettlementButton.js b/src/components/SettlementButton.js index 12e38b6294be..5fdfb437802f 100644 --- a/src/components/SettlementButton.js +++ b/src/components/SettlementButton.js @@ -84,7 +84,7 @@ class SettlementButton extends React.Component { > {triggerKYCFlow => ( { if (iouPaymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ba52c58a2772..da0e6fd26a72 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -678,25 +678,30 @@ function buildOptimisticReportAction(sequenceNumber, text, file) { * @param {String} chatReportID - Report ID of the chat where the IOU is. * @param {String} currency - IOU currency. * @param {String} locale - Locale where the IOU is created + * @param {Boolean} isSendingMoney - If we send money the IOU should be created as settled * * @returns {Object} */ -function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, currency, locale) { +function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, currency, locale, isSendingMoney = false) { const formattedTotal = NumberFormatUtils.format(locale, total, { style: 'currency', currency, }); + return { + // If we're sending money, hasOutstandingIOU should be false + hasOutstandingIOU: !isSendingMoney, cachedTotal: formattedTotal, chatReportID, currency, - hasOutstandingIOU: true, managerEmail: userEmail, ownerEmail, reportID: generateReportID(), state: CONST.REPORT.STATE.SUBMITTED, - stateNum: 1, + stateNum: isSendingMoney + ? CONST.REPORT.STATE_NUM.SUBMITTED + : CONST.REPORT.STATE_NUM.PROCESSING, total, }; } @@ -707,15 +712,32 @@ function buildOptimisticIOUReport(ownerEmail, userEmail, total, chatReportID, cu * @param {Array} participants - List of logins for the IOU participants, excluding the current user login * @param {String} comment - IOU comment * @param {String} currency - IOU currency + * @param {String} paymentType - IOU paymentMethodType. Can be oneOf(Elsewhere, Expensify, PayPal.me) + * @param {Boolean} isSettlingUp - Whether we are settling up an IOU * @returns {Array} */ -function getIOUReportActionMessage(type, total, participants, comment, currency) { +function getIOUReportActionMessage(type, total, participants, comment, currency, paymentType = '', isSettlingUp = false) { const amount = NumberFormatUtils.format(preferredLocale, total / 100, {style: 'currency', currency}); const displayNames = _.map(participants, participant => getDisplayNameForParticipant(participant.login, true)); const who = displayNames.length < 3 ? displayNames.join(' and ') : `${displayNames.slice(0, -1).join(', ')}, and ${_.last(displayNames)}`; + let paymentMethodMessage; + switch (paymentType) { + case CONST.IOU.PAYMENT_TYPE.EXPENSIFY: + paymentMethodMessage = 'using wallet'; + break; + case CONST.IOU.PAYMENT_TYPE.ELSEWHERE: + paymentMethodMessage = 'elsewhere'; + break; + case CONST.IOU.PAYMENT_TYPE.PAYPAL_ME: + paymentMethodMessage = 'using PayPal.me'; + break; + default: + break; + } + let iouMessage; switch (type) { case CONST.IOU.REPORT_ACTION_TYPE.CREATE: @@ -731,7 +753,9 @@ function getIOUReportActionMessage(type, total, participants, comment, currency) iouMessage = `Declined the ${amount} request${comment && ` for ${comment}`}`; break; case CONST.IOU.REPORT_ACTION_TYPE.PAY: - iouMessage = `Paid ${amount} to ${who}${comment && ` for ${comment}`}`; + iouMessage = isSettlingUp + ? `Settled up ${paymentMethodMessage}` + : `Sent ${amount}${comment && ` for ${comment}`} ${paymentMethodMessage}`; break; default: break; @@ -757,10 +781,11 @@ function getIOUReportActionMessage(type, total, participants, comment, currency) * @param {String} paymentType - Only required if the IOUReportAction type is 'pay'. Can be oneOf(elsewhere, payPal, Expensify). * @param {String} iouTransactionID - Only required if the IOUReportAction type is oneOf(cancel, decline). Generates a randomID as default. * @param {String} iouReportID - Only required if the IOUReportActions type is oneOf(decline, cancel, pay). Generates a randomID as default. + * @param {String} isSettlingUp - Whether we are settling up an IOU. * * @returns {Object} */ -function buildOptimisticIOUReportAction(sequenceNumber, type, amount, currency, comment, participants, paymentType = '', iouTransactionID = '', iouReportID = '') { +function buildOptimisticIOUReportAction(sequenceNumber, type, amount, currency, comment, participants, paymentType = '', iouTransactionID = '', iouReportID = '', isSettlingUp) { const IOUTransactionID = iouTransactionID || NumberUtils.rand64(); const IOUReportID = iouReportID || generateReportID(); const originalMessage = { @@ -795,7 +820,7 @@ function buildOptimisticIOUReportAction(sequenceNumber, type, amount, currency, clientID: NumberUtils.generateReportActionClientID(), isAttachment: false, originalMessage, - message: getIOUReportActionMessage(type, amount, participants, comment, currency), + message: getIOUReportActionMessage(type, amount, participants, comment, currency, paymentType, isSettlingUp), person: [{ style: 'strong', text: lodashGet(currentUserPersonalDetails, 'displayName', currentUserEmail), diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 7aa9a5dcda51..dd8194584c9b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import _ from 'underscore'; import lodashGet from 'lodash/get'; +import Str from 'expensify-common/lib/str'; import CONST from '../../CONST'; import ONYXKEYS from '../../ONYXKEYS'; import ROUTES from '../../ROUTES'; @@ -157,7 +158,7 @@ function requestMoney(report, amount, currency, recipientEmail, participant, com // Now, let's add the data we need just when we are creating a new chat report if (isNewChat) { - const optimisticCreateAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); + const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page @@ -168,7 +169,7 @@ function requestMoney(report, amount, currency, recipientEmail, participant, com }; optimisticData[1].onyxMethod = CONST.ONYX.METHOD.SET; optimisticData[1].value = { - ...optimisticCreateAction, + ...optimisticCreatedAction, ...optimisticData[1].value, }; optimisticData[2].onyxMethod = CONST.ONYX.METHOD.SET; @@ -686,17 +687,13 @@ function payIOUReport({ }) { Onyx.merge(ONYXKEYS.IOU, {loading: true, error: false}); - const payIOUPromise = paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY - ? DeprecatedAPI.PayWithWallet({reportID, newIOUReportDetails}) - : DeprecatedAPI.PayIOU({reportID, paymentMethodType, newIOUReportDetails}); - // Build the url for Paypal.me if they have selected it instead of a manual settlement or Expensify Wallet let url; if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { url = buildPayPalPaymentUrl(amount, requestorPayPalMeAddress, currency); } - const promiseWithHandlers = payIOUPromise + const promiseWithHandlers = DeprecatedAPI.PayWithWallet({reportID, newIOUReportDetails}) .then((response) => { if (response.jsonCode !== 200) { switch (response.message) { @@ -724,11 +721,325 @@ function payIOUReport({ return promiseWithHandlers; } +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} paymentMethodType + * @param {String} managerEmail - Email of the person sending the money + * @param {Object} recipient - The user receiving the money + * @returns {Object} + */ +function getSendMoneyParams(report, amount, currency, comment, paymentMethodType, managerEmail, recipient) { + const recipientEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(recipient.login); + + const newIOUReportDetails = JSON.stringify({ + amount, + currency, + requestorEmail: recipientEmail, + comment, + idempotencyKey: Str.guid(), + }); + + let chatReport = report.reportID ? report : null; + let isNewChat = false; + if (!chatReport) { + chatReport = ReportUtils.getChatByParticipants([recipientEmail]); + } + if (!chatReport) { + chatReport = ReportUtils.buildOptimisticChatReport([recipientEmail]); + isNewChat = true; + } + const optimisticIOUReport = ReportUtils.buildOptimisticIOUReport(recipientEmail, managerEmail, amount, chatReport.reportID, currency, preferredLocale, true); + + // This will be deprecated soon, in case the migration happens before this PR is merged we'll need to adjust the code here + const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; + + const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + newSequenceNumber, + CONST.IOU.REPORT_ACTION_TYPE.PAY, + amount, + currency, + comment, + [recipient], + paymentMethodType, + '', + optimisticIOUReport.reportID, + ); + + // First, add data that will be used in all cases + const optimisticData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + ...chatReport, + lastVisitedTimestamp: Date.now(), + lastActionCreated: optimisticIOUReportAction.created, + lastReadSequenceNumber: newSequenceNumber, + maxSequenceNumber: newSequenceNumber, + lastMessageText: optimisticIOUReportAction.message[0].text, + lastMessageHtml: optimisticIOUReportAction.message[0].html, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticIOUReportAction.sequenceNumber]: { + ...optimisticIOUReportAction, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, + value: optimisticIOUReport, + }, + ]; + + const successData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticIOUReportAction.sequenceNumber]: { + pendingAction: null, + }, + }, + }, + ]; + + const failureData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticIOUReportAction.sequenceNumber]: { + errors: { + [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), + }, + }, + }, + }, + ]; + + // Now, let's add the data we need just when we are creating a new chat report + if (isNewChat) { + const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); + + // Change the method to set for new reports because it doesn't exist yet, is faster, + // and we need the data to be available when we navigate to the chat page + optimisticData[0].onyxMethod = CONST.ONYX.METHOD.SET; + optimisticData[0].value = { + ...optimisticData[0].value, + pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, + }; + optimisticData[1].onyxMethod = CONST.ONYX.METHOD.SET; + optimisticData[1].value = { + ...optimisticCreatedAction, + ...optimisticData[1].value, + }; + optimisticData[2].onyxMethod = CONST.ONYX.METHOD.SET; + } + + return { + params: { + iouReportID: optimisticIOUReport.reportID, + chatReportID: chatReport.reportID, + reportActionID: optimisticIOUReportAction.reportActionID, + paymentMethodType, + transactionID: optimisticIOUReportAction.originalMessage.IOUTransactionID, + clientID: optimisticIOUReportAction.sequenceNumber, + newIOUReportDetails, + }, + optimisticData, + successData, + failureData, + }; +} + +/** + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} recipient + * @param {String} paymentMethodType + * @returns {Object} + */ +function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { + const newSequenceNumber = Report.getMaxSequenceNumber(chatReport.reportID) + 1; + + const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + newSequenceNumber, + CONST.IOU.REPORT_ACTION_TYPE.PAY, + iouReport.total, + iouReport.currency, + '', + [recipient], + paymentMethodType, + '', + iouReport.reportID, + true, + ); + + const optimisticData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`, + value: { + ...chatReport, + lastVisitedTimestamp: Date.now(), + lastActionCreated: optimisticIOUReportAction.created, + lastReadSequenceNumber: newSequenceNumber, + maxSequenceNumber: newSequenceNumber, + lastMessageText: optimisticIOUReportAction.message[0].text, + lastMessageHtml: optimisticIOUReportAction.message[0].html, + hasOutstandingIOU: false, + iouReportID: null, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticIOUReportAction.sequenceNumber]: { + ...optimisticIOUReportAction, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + }, + }, + }, + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + ...iouReport, + hasOutstandingIOU: false, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + }, + }, + ]; + + const successData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticIOUReportAction.sequenceNumber]: { + pendingAction: null, + }, + }, + }, + ]; + + const failureData = [ + { + onyxMethod: CONST.ONYX.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + value: { + [optimisticIOUReportAction.sequenceNumber]: { + pendingAction: null, + errors: { + [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), + }, + }, + }, + }, + ]; + + return { + params: { + iouReportID: iouReport.reportID, + reportActionID: optimisticIOUReportAction.reportActionID, + paymentMethodType, + clientID: optimisticIOUReportAction.sequenceNumber, + }, + optimisticData, + successData, + failureData, + }; +} + +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} managerEmail - Email of the person sending the money + * @param {Object} recipient - The user receiving the money + */ +function sendMoneyElsewhere(report, amount, currency, comment, managerEmail, recipient) { + const { + params, optimisticData, successData, failureData, + } = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.ELSEWHERE, managerEmail, recipient); + + API.write('SendMoneyElsewhere', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); +} + +/** + * @param {Object} report + * @param {Number} amount + * @param {String} currency + * @param {String} comment + * @param {String} managerEmail - Email of the person sending the money + * @param {Object} recipient - The user receiving the money + */ +function sendMoneyViaPaypal(report, amount, currency, comment, managerEmail, recipient) { + const { + params, optimisticData, successData, failureData, + } = getSendMoneyParams(report, amount, currency, comment, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME, managerEmail, recipient); + + API.write('SendMoneyViaPaypal', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(params.chatReportID)); + + asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(amount, recipient.payPalMeAddress, currency)); +} + +/** + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} recipient + */ +function payMoneyRequestElsewhere(chatReport, iouReport, recipient) { + const { + params, optimisticData, successData, failureData, + } = getPayMoneyRequestParams(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.ELSEWHERE); + + API.write('PayMoneyRequestElsewhere', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); +} + +/** + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} recipient + */ +function payMoneyRequestViaPaypal(chatReport, iouReport, recipient) { + const { + params, optimisticData, successData, failureData, + } = getPayMoneyRequestParams(chatReport, iouReport, recipient, CONST.IOU.PAYMENT_TYPE.PAYPAL_ME); + + API.write('PayMoneyRequestViaPaypal', params, {optimisticData, successData, failureData}); + + Navigation.navigate(ROUTES.getReportRoute(chatReport.reportID)); + + asyncOpenURL(Promise.resolve(), buildPayPalPaymentUrl(iouReport.total, recipient.payPalMeAddress, iouReport.currency)); +} + export { cancelMoneyRequest, splitBill, splitBillAndOpenReport, requestMoney, payIOUReport, + sendMoneyElsewhere, + sendMoneyViaPaypal, + payMoneyRequestElsewhere, + payMoneyRequestViaPaypal, setIOUSelectedCurrency, }; diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 98c6aad2ad15..61731c29208f 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -75,19 +75,6 @@ function Get(parameters, shouldUseSecure = false) { return Network.post(commandName, parameters, CONST.NETWORK.METHOD.POST, shouldUseSecure); } -/** - * @param {Object} parameters - * @param {Number} parameters.reportID - * @param {String} parameters.paymentMethodType - * @param {Object} [parameters.newIOUReportDetails] - * @returns {Promise} - */ -function PayIOU(parameters) { - const commandName = 'PayIOU'; - requireParameters(['reportID', 'paymentMethodType'], parameters, commandName); - return Network.post(commandName, parameters); -} - /** * @param {Object} parameters * @param {Number} parameters.reportID @@ -163,7 +150,6 @@ export { DeleteLogin, Get, GetStatementPDF, - PayIOU, PayWithWallet, PersonalDetails_Update, ResendValidateCode, diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 5223f50b1637..66dc7bfb079a 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -196,7 +196,12 @@ class ReportActionItem extends Component { { if (this.props.action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { - ReportActions.deleteOptimisticReportAction(this.props.report.reportID, this.props.action.clientID); + const sequenceNumber = this.props.action.actionName + === CONST.REPORT.ACTIONS.TYPE.IOU + ? this.props.action + .sequenceNumber + : this.props.action.clientID; + ReportActions.deleteOptimisticReportAction(this.props.report.reportID, sequenceNumber); } else { ReportActions.clearReportActionErrors(this.props.report.reportID, this.props.action.sequenceNumber); } diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index d90b83f4b8b5..0d45271ab5b1 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -98,15 +98,40 @@ class IOUDetailsModal extends Component { /** * @param {String} paymentMethodType */ - performIOUPayment(paymentMethodType) { - IOU.payIOUReport({ - chatReportID: this.props.route.params.chatReportID, - reportID: this.props.route.params.iouReportID, - paymentMethodType, - amount: this.props.iouReport.total, - currency: this.props.iouReport.currency, - requestorPayPalMeAddress: this.props.iouReport.submitterPayPalMeAddress, - }); + payMoneyRequest(paymentMethodType) { + const recipient = { + login: this.props.iouReport.ownerEmail, + payPalMeAddress: this.props.iouReport.submitterPayPalMeAddress, + }; + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { + IOU.payMoneyRequestElsewhere( + this.props.chatReport, + this.props.iouReport, + recipient, + ); + return; + } + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { + IOU.payMoneyRequestViaPaypal( + this.props.chatReport, + this.props.iouReport, + recipient, + ); + return; + } + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) { + IOU.payIOUReport({ + chatReportID: this.props.route.params.chatReportID, + reportID: this.props.route.params.iouReportID, + paymentMethodType, + amount: this.props.iouReport.total, + currency: this.props.iouReport.currency, + requestorPayPalMeAddress: this.props.iouReport.submitterPayPalMeAddress, + }); + } } render() { @@ -139,7 +164,7 @@ class IOUDetailsModal extends Component { this.performIOUPayment(paymentMethodType)} + onPress={paymentMethodType => this.payMoneyRequest(paymentMethodType)} shouldShowPaypal={Boolean(lodashGet(this.props, 'iouReport.submitterPayPalMeAddress'))} currency={lodashGet(this.props, 'iouReport.currency')} enablePaymentsRoute={ROUTES.IOU_DETAILS_ENABLE_PAYMENTS} @@ -166,6 +191,9 @@ export default compose( iou: { key: ONYXKEYS.IOU, }, + chatReport: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.chatReportID}`, + }, iouReport: { key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.iouReportID}`, }, diff --git a/src/pages/iou/IOUModal.js b/src/pages/iou/IOUModal.js index 67b5ab23f2a7..78bd46ec93ec 100755 --- a/src/pages/iou/IOUModal.js +++ b/src/pages/iou/IOUModal.js @@ -25,7 +25,6 @@ import Tooltip from '../../components/Tooltip'; import CONST from '../../CONST'; import * as PersonalDetails from '../../libs/actions/PersonalDetails'; import withCurrentUserPersonalDetails from '../../components/withCurrentUserPersonalDetails'; -import ROUTES from '../../ROUTES'; import networkPropTypes from '../../components/networkPropTypes'; import {withNetwork} from '../../components/OnyxProvider'; import reportPropTypes from '../reportPropTypes'; @@ -286,28 +285,30 @@ class IOUModal extends Component { const amount = Math.round(this.state.amount * 100); const currency = this.props.iou.selectedCurrencyCode; const comment = this.state.comment; + const participant = this.state.participants[0]; + + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) { + IOU.sendMoneyElsewhere( + this.props.report, + amount, + currency, + comment, + this.props.currentUserPersonalDetails.login, + participant, + ); + return; + } - const newIOUReportDetails = JSON.stringify({ - amount, - currency, - requestorEmail: this.state.participants[0].login, - comment, - idempotencyKey: Str.guid(), - }); - - IOU.payIOUReport({ - chatReportID: lodashGet(this.props, 'route.params.reportID', ''), - reportID: '0', - paymentMethodType, - amount, - currency, - requestorPayPalMeAddress: this.state.participants[0].payPalMeAddress, - comment, - newIOUReportDetails, - }) - .finally(() => { - Navigation.navigate(ROUTES.REPORT); - }); + if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { + IOU.sendMoneyViaPaypal( + this.props.report, + amount, + currency, + comment, + this.props.currentUserPersonalDetails.login, + participant, + ); + } } /**