From b3ed05974411c6b38375a216ffd452089c9e2462 Mon Sep 17 00:00:00 2001 From: Mikko Koski Date: Wed, 18 Oct 2017 15:04:41 +0300 Subject: [PATCH 1/2] Changes how refund is shown in the price breakdown - Previously, commission line item was shown even if the transaction was cancelled. This gave the impression that commission was taken even in transactions that were fully refunded. This is now change. Commission line is not shown at all, if it has been refunded. - If transaction is declined, total is shown as zero (API change). - If transaction is declined, refund line item is shown. In addition, subtotal is also shown. --- .../BookingBreakdown/BookingBreakdown.js | 39 ++++++++++--------- src/util/propTypes.js | 1 + 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/components/BookingBreakdown/BookingBreakdown.js b/src/components/BookingBreakdown/BookingBreakdown.js index 5afaa1a7..7c51172e 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.js +++ b/src/components/BookingBreakdown/BookingBreakdown.js @@ -54,13 +54,16 @@ export const BookingBreakdownComponent = props => { ); const nightPurchase = transaction.attributes.lineItems.find( - item => item.code === 'line-item/night' + item => item.code === 'line-item/night' && !item.reversal ); const providerCommissionLineItem = transaction.attributes.lineItems.find( - item => item.code === 'line-item/provider-commission' + item => item.code === 'line-item/provider-commission' && !item.reversal ); const refund = transaction.attributes.lineItems.find( - item => item.code === (isProvider ? 'line-item/provider-refund' : 'line-item/customer-refund') + item => item.code === 'line-item/night' && item.reversal + ); + const commissionRefund = transaction.attributes.lineItems.find( + item => item.code === 'line-item/provider-commission' && item.reversal ); const refundInfo = refund ? ( @@ -80,9 +83,22 @@ export const BookingBreakdownComponent = props => { const formattedUnitPrice = formatMoney(intl, nightPurchase.unitPrice); // If commission is passed it will be shown as a fee already reduces from the total price - let subTotalInfo = null; let commissionInfo = null; + // Show night purchase line total (unit price * quantity) as a subtotal. + // PLEASE NOTE that this assumes that the transaction doesn't have other + // line item types than nights (e.g. week, month, year). + const showSubTotal = isProvider || refund; + const formattedSubTotal = formatMoney(intl, nightPurchase.lineTotal); + const subTotalInfo = showSubTotal ? ( +
+ + + + {formattedSubTotal} +
+ ) : null; + if (isProvider) { if (!isValidCommission(providerCommissionLineItem)) { // eslint-disable-next-line no-console @@ -90,23 +106,10 @@ export const BookingBreakdownComponent = props => { throw new Error('Commission should be present and the value should be zero or negative'); } - // Show night purchase line total (unit price * quantity) as a subtotal. - // PLEASE NOTE that this assumes that the transaction doesn't have other - // line item types than nights (e.g. week, month, year). - const formattedSubTotal = formatMoney(intl, nightPurchase.lineTotal); - subTotalInfo = ( -
- - - - {formattedSubTotal} -
- ); - const commission = providerCommissionLineItem.lineTotal; const formattedCommission = commission ? formatMoney(intl, commission) : null; - commissionInfo = ( + commissionInfo = commissionRefund ? null : (
diff --git a/src/util/propTypes.js b/src/util/propTypes.js index f9533acd..226b7d05 100644 --- a/src/util/propTypes.js +++ b/src/util/propTypes.js @@ -200,6 +200,7 @@ export const transaction = shape({ quantity: instanceOf(Decimal), unitPrice: money, lineTotal: money, + reversal: bool, }) ).isRequired, }), From d468f5eb963068123e77542f3edd3e27543121f5 Mon Sep 17 00:00:00 2001 From: Mikko Koski Date: Wed, 18 Oct 2017 16:17:17 +0300 Subject: [PATCH 2/2] Add isRequired to props --- src/util/propTypes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/propTypes.js b/src/util/propTypes.js index 226b7d05..e71c5f0b 100644 --- a/src/util/propTypes.js +++ b/src/util/propTypes.js @@ -198,9 +198,9 @@ export const transaction = shape({ shape({ code: string.isRequired, quantity: instanceOf(Decimal), - unitPrice: money, - lineTotal: money, - reversal: bool, + unitPrice: money.isRequired, + lineTotal: money.isRequired, + reversal: bool.isRequired, }) ).isRequired, }),