From 804d2672cdd944c4694ffbe83a1345cb17d0d3ac Mon Sep 17 00:00:00 2001 From: Mikko Koski Date: Thu, 29 Jun 2017 13:50:11 +0300 Subject: [PATCH] Use payinTotal and payoutTotal instead of total and commission --- .../OrderDetailsPanel/OrderDetailsPanel.js | 2 +- .../SaleDetailsPanel/SaleDetailsPanel.js | 22 +++++++++---------- src/util/propTypes.js | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.js index ca821776..34c5b315 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.js @@ -15,7 +15,7 @@ const breakdown = transaction => { const bookingStart = booking.attributes.start; const bookingEnd = booking.attributes.end; const unitPrice = listing.attributes.price; - const totalPrice = tx.attributes.total; + const totalPrice = tx.attributes.payinTotal; if (!bookingStart || !bookingEnd || !unitPrice || !totalPrice) { return null; diff --git a/src/components/SaleDetailsPanel/SaleDetailsPanel.js b/src/components/SaleDetailsPanel/SaleDetailsPanel.js index eac2da77..6a6968d4 100644 --- a/src/components/SaleDetailsPanel/SaleDetailsPanel.js +++ b/src/components/SaleDetailsPanel/SaleDetailsPanel.js @@ -15,19 +15,19 @@ import css from './SaleDetailsPanel.css'; // TODO: This is a temporary function to calculate the booking // price. This should be removed when the API supports dry-runs and we // can take the total price from the transaction itself. -const estimatedProviderTotalPrice = (customerTotalPrice, commission) => { +const estimatedCommission = (customerTotalPrice, providerTotalPrice) => { const { subUnitDivisor, currency } = config.currencyConfig; - if (customerTotalPrice.currency !== currency || commission.currency !== currency) { + if (customerTotalPrice.currency !== currency || providerTotalPrice.currency !== currency) { throw new Error('Transaction total or commission currency does not match marketplace currency'); } const numericCustomerTotalPrice = convertMoneyToNumber(customerTotalPrice, subUnitDivisor); - const numericCommission = convertMoneyToNumber(commission, subUnitDivisor); - const numericTotalPrice = new Decimal(numericCustomerTotalPrice) - .minus(numericCommission) + const numericProviderTotalPrice = convertMoneyToNumber(providerTotalPrice, subUnitDivisor); + const numericCommission = new Decimal(numericProviderTotalPrice) + .minus(numericCustomerTotalPrice) .toNumber(); - return new types.Money(convertUnitToSubUnit(numericTotalPrice, subUnitDivisor), currency); + return new types.Money(convertUnitToSubUnit(numericCommission, subUnitDivisor), currency); }; const breakdown = transaction => { @@ -37,14 +37,14 @@ const breakdown = transaction => { const bookingStart = booking.attributes.start; const bookingEnd = booking.attributes.end; const unitPrice = listing.attributes.price; - const customerTotalPrice = tx.attributes.total; - const commission = tx.attributes.commission; + const customerTotalPrice = tx.attributes.payinTotal; + const providerTotalPrice = tx.attributes.payoutTotal; - if (!bookingStart || !bookingEnd || !unitPrice || !customerTotalPrice || !commission) { + if (!bookingStart || !bookingEnd || !unitPrice || !customerTotalPrice || !providerTotalPrice) { return null; } - const totalPrice = estimatedProviderTotalPrice(customerTotalPrice, commission); + const commission = estimatedCommission(customerTotalPrice, providerTotalPrice); return ( { bookingStart={bookingStart} bookingEnd={bookingEnd} unitPrice={unitPrice} - totalPrice={totalPrice} + totalPrice={providerTotalPrice} commission={commission} /> ); diff --git a/src/util/propTypes.js b/src/util/propTypes.js index bedfa103..97e275e6 100644 --- a/src/util/propTypes.js +++ b/src/util/propTypes.js @@ -147,12 +147,12 @@ export const transaction = shape({ id: uuid.isRequired, type: value('transaction').isRequired, attributes: shape({ - commission: money.isRequired, createdAt: instanceOf(Date).isRequired, lastTransitionedAt: instanceOf(Date).isRequired, lastTransition: string, state: oneOf(TX_STATES).isRequired, - total: money.isRequired, + payinTotal: money.isRequired, + payoutTotal: money.isRequired, }), booking, listing,