Class DefaultPaymentDistributionService
java.lang.Object
com.broadleafcommerce.orderoperation.service.payment.DefaultPaymentDistributionService
- All Implemented Interfaces:
PaymentDistributionService
A service responsible for distributing payment amounts based on the payments' ratios from an
Order.- Author:
- Sunny Yu
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultPaymentDistributionService(SplitRoundingHelper splitRoundingHelper, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.order.client.domain.payment.PaymentDistributionDetailbuildPaymentDistributionDetail(@NonNull PaymentSummary paymentSummary, @NonNull Map<String, BigDecimal> distributionRatioByPaymentId) List<com.broadleafcommerce.order.client.domain.payment.PaymentDistributionDetail>buildPaymentDistributionDetails(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull List<PaymentSummary> orderPayments) distributePaymentAmounts(@NonNull PaymentDistributionDto dto) Distributes a payment amount across different payments based on the details specified inPaymentDistributionDto.protected javax.money.MonetaryAmountgetAmountToExecute(@NonNull javax.money.MonetaryAmount distributedAmount, @NonNull ExecutablePayment executablePayment, @NonNull javax.money.MonetaryAmount amountRemaining) protected Map<String,BigDecimal> getPaymentDistributionRatios(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull List<PaymentSummary> payments) Gets a map of payment distribution ratios by payment ids.protected RoundingModeGets theRoundingModeto use for roundingMonetaryAmount.protected intGets the scale to use for roundingMonetaryAmount.protected SplitRoundingHelperprotected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanshouldUseExecutableAmount(javax.money.MonetaryAmount executableAmount, javax.money.MonetaryAmount totalToExecute) Determines if theExecutablePayment.getExecutableAmount()should be used instead.protected voidvalidatePaymentDistributionDetails(@NonNull List<com.broadleafcommerce.order.client.domain.payment.PaymentDistributionDetail> paymentDistributionDetails) Validates the payment distribution details to ensure that the ratios add up to 100%.protected voidvalidatePaymentDistributionDto(@NonNull PaymentDistributionDto dto)
-
Constructor Details
-
DefaultPaymentDistributionService
public DefaultPaymentDistributionService(SplitRoundingHelper splitRoundingHelper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
buildPaymentDistributionDetails
public List<com.broadleafcommerce.order.client.domain.payment.PaymentDistributionDetail> buildPaymentDistributionDetails(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull List<PaymentSummary> orderPayments) Description copied from interface:PaymentDistributionServiceBuilds a list ofPaymentDistributionDetailsfrom the givenOrderand itsPaymentSummaries.By default, the
PaymentDistributionDetail.getRatio()is calculated by dividing eachPaymentSummary.getAmount()byOrderPricing.getTotal().- Specified by:
buildPaymentDistributionDetailsin interfacePaymentDistributionService- Parameters:
order- theOrderto buildPaymentDistributionDetailsfororderPayments- thePaymentSummariesfor theOrder- Returns:
- a list of
PaymentDistributionDetailsfrom the givenOrderand itsPaymentSummaries.
-
distributePaymentAmounts
public PaymentDistributionResult distributePaymentAmounts(@NonNull @NonNull PaymentDistributionDto dto) Description copied from interface:PaymentDistributionServiceDistributes a payment amount across different payments based on the details specified inPaymentDistributionDto.- Specified by:
distributePaymentAmountsin interfacePaymentDistributionService- Parameters:
dto- thePaymentDistributionDtocontaining the details for the payment distributions- Returns:
- the
PaymentDistributionResultdescribing the result of the distributions
-
getPaymentDistributionRatios
protected Map<String,BigDecimal> getPaymentDistributionRatios(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull List<PaymentSummary> payments) Gets a map of payment distribution ratios by payment ids.- Parameters:
order- theOrderto get the total frompayments- thePaymentSummariesfor the order- Returns:
- a map of payment distribution ratios by payment ids
-
buildPaymentDistributionDetail
protected com.broadleafcommerce.order.client.domain.payment.PaymentDistributionDetail buildPaymentDistributionDetail(@NonNull @NonNull PaymentSummary paymentSummary, @NonNull @NonNull Map<String, BigDecimal> distributionRatioByPaymentId) -
validatePaymentDistributionDetails
protected void validatePaymentDistributionDetails(@NonNull @NonNull List<com.broadleafcommerce.order.client.domain.payment.PaymentDistributionDetail> paymentDistributionDetails) Validates the payment distribution details to ensure that the ratios add up to 100%.- Parameters:
paymentDistributionDetails- thePaymentDistributionDetailsto validate
-
validatePaymentDistributionDto
-
getAmountToExecute
protected javax.money.MonetaryAmount getAmountToExecute(@NonNull @NonNull javax.money.MonetaryAmount distributedAmount, @NonNull @NonNull ExecutablePayment executablePayment, @NonNull @NonNull javax.money.MonetaryAmount amountRemaining) -
shouldUseExecutableAmount
protected boolean shouldUseExecutableAmount(javax.money.MonetaryAmount executableAmount, javax.money.MonetaryAmount totalToExecute) Determines if theExecutablePayment.getExecutableAmount()should be used instead.The payment's executable amount should be used when the amounts difference is less than or equal to a penny. This is useful to ensure that the payment isn't left with just a penny available to execute later due to rounding.
For example, let's say the payment has a executable amount of $10.99, but the
totalToExecuteis calculated to be $10.98 due to the distribution ratio and rounding. In this case, the executable amount should be used instead.- Parameters:
executableAmount- theExecutablePayment.getExecutableAmount()totalToExecute- the amount to execute- Returns:
- true if the payment's executable amount should be used instead, otherwise false
-
getRoundingScale
protected int getRoundingScale()Gets the scale to use for roundingMonetaryAmount.Custom rounding scale should be added here.
- Returns:
- the scale to use for rounding
MonetaryAmount
-
getRoundingMode
Gets theRoundingModeto use for roundingMonetaryAmount.Custom rounding mode should be added here.
- Returns:
- the
RoundingModeto use for roundingMonetaryAmount
-
getSplitRoundingHelper
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-