Skip to content

Commit

Permalink
Merge pull request #3174 from Expensify/jasper-IOUPayWithExpensifyOption
Browse files Browse the repository at this point in the history
[IOU] Pay with Expensify option
  • Loading branch information
Gonals authored May 31, 2021
2 parents 33bb245 + de4ba98 commit 01b2091
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const CONST = {
// not be changed.
PAYMENT_TYPE: {
ELSEWHERE: 'Elsewhere',
EXPENSIFY: 'Expensify',
PAYPAL_ME: 'PayPal.me',
VENMO: 'Venmo',
},
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
12 changes: 12 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -800,6 +811,7 @@ export {
Graphite_Timer,
Log,
PayIOU,
PayWithWallet,
PersonalDetails_GetForEmails,
PersonalDetails_Update,
Plaid_GetLinkToken,
Expand Down
10 changes: 5 additions & 5 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions src/pages/iou/IOUDetailsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 01b2091

Please sign in to comment.