diff --git a/src/CONST.js b/src/CONST.js index bb628a57b521..c0e0209b9eeb 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -167,6 +167,7 @@ const CONST = { // not be changed. PAYMENT_TYPE: { ELSEWHERE: 'Elsewhere', + EXPENSIFY: 'Expensify', PAYPAL_ME: 'PayPal.me', VENMO: 'Venmo', }, diff --git a/src/languages/en.js b/src/languages/en.js index 3013f21ad119..49cdf1fc16ea 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -108,6 +108,7 @@ export default { pay: 'Pay', viewDetails: 'View Details', settleElsewhere: 'I\'ll settle up elsewhere', + settleExpensify: 'Pay with Expensify', settlePaypalMe: 'Pay with PayPal.me', settleVenmo: 'Pay with Venmo', request: ({amount}) => `Request ${amount}`, diff --git a/src/libs/API.js b/src/libs/API.js index 36ab90483c5a..0643de20f78c 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -455,6 +455,17 @@ function PayIOU(parameters) { return Network.post(commandName, parameters); } +/** + * @param {Object} parameters + * @param {Number} parameters.reportID + * @returns {Promise} + */ +function PayWithWallet(parameters) { + const commandName = 'PayWithWallet'; + requireParameters(['reportID'], parameters, commandName); + return Network.post(commandName, parameters); +} + /** * @param {Object} parameters * @param {String} parameters.emailList @@ -800,6 +811,7 @@ export { Graphite_Timer, Log, PayIOU, + PayWithWallet, PersonalDetails_GetForEmails, PersonalDetails_Update, Plaid_GetLinkToken, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 8c01fdaa7e14..54a6410ae444 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -153,10 +153,10 @@ function payIOUReport({ chatReportID, reportID, paymentMethodType, amount, currency, submitterPhoneNumber, submitterPayPalMeAddress, }) { Onyx.merge(ONYXKEYS.IOU, {loading: true, error: false}); - API.PayIOU({ - reportID, - paymentMethodType, - }) + const payIOUPromise = paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY + ? API.PayWithWallet({reportID}) + : API.PayIOU({reportID, paymentMethodType}); + payIOUPromise .then((response) => { if (response.jsonCode !== 200) { throw new Error(response.message); @@ -171,7 +171,7 @@ function payIOUReport({ fetchIOUReportByIDAndUpdateChatReport(reportID, chatReportID); // Once we have successfully paid the IOU we will transfer the user to their platform of choice if they have - // selected something other than a manual settlement e.g. Venmo or PayPal.me + // selected something other than a manual settlement or Expensify Wallet e.g. Venmo or PayPal.me if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) { openURLInNewTab(buildPayPalPaymentUrl(amount, submitterPayPalMeAddress, currency)); } else if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.VENMO) { diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index 39e3d03bdde9..3716f4dfd91d 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -102,6 +102,7 @@ class IOUDetailsModal extends Component { this.isComponentMounted = true; fetchIOUReportByID(this.props.route.params.iouReportID, this.props.route.params.chatReportID); this.addVenmoPaymentOptionIfAvailable(); + this.addExpensifyPaymentOptionIfAvailable(); } componentWillUnmount() { @@ -173,10 +174,27 @@ class IOUDetailsModal extends Component { }); } + /** + * Checks to see if we can use Expensify. + * The report currency must be USD. + */ + addExpensifyPaymentOptionIfAvailable() { + if (lodashGet(this.props, 'iouReport.currency') !== CONST.CURRENCY.USD) { + return; + } + + // Make it the first payment option and set it as the default. + this.setState(prevState => ({ + paymentOptions: [CONST.IOU.PAYMENT_TYPE.EXPENSIFY, ...prevState.paymentOptions], + paymentType: CONST.IOU.PAYMENT_TYPE.EXPENSIFY, + })); + } + render() { const sessionEmail = lodashGet(this.props.session, 'email', null); const reportIsLoading = _.isUndefined(this.props.iouReport); const paymentTypeTextOptions = { + [CONST.IOU.PAYMENT_TYPE.EXPENSIFY]: this.props.translate('iou.settleExpensify'), [CONST.IOU.PAYMENT_TYPE.VENMO]: this.props.translate('iou.settleVenmo'), [CONST.IOU.PAYMENT_TYPE.PAYPAL_ME]: this.props.translate('iou.settlePaypalMe'), [CONST.IOU.PAYMENT_TYPE.ELSEWHERE]: this.props.translate('iou.settleElsewhere'),