Class DefaultPaymentRefundService

java.lang.Object
com.broadleafcommerce.orderoperation.service.payment.DefaultPaymentRefundService
All Implemented Interfaces:
PaymentRefundService

public class DefaultPaymentRefundService extends Object implements PaymentRefundService
Author:
Samarth Dhruva (samarthd)
  • Constructor Details

    • DefaultPaymentRefundService

      public DefaultPaymentRefundService(PaymentPriorityStrategy paymentPriorityStrategy, OrderProvider<com.broadleafcommerce.order.client.domain.Order> orderProvider, ReturnAuthorizationProvider<com.broadleafcommerce.order.client.domain.ReturnAuthorization> returnAuthorizationProvider, PaymentProvider paymentProvider, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • refundAndCompletePendingReturnConfirmations

      public List<TransactionExecutionResponse> refundAndCompletePendingReturnConfirmations(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, @NonNull @NonNull com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentRefundService
      Finds all pending ReturnConfirmations on the given ReturnAuthorization (for ReturnAuthorizationItems whose ReturnAuthorizationItem.getReturnType() supports refunds), issues refunds for them, and updates the ReturnConfirmation.getStatus() based on the refund responses.
      Specified by:
      refundAndCompletePendingReturnConfirmations in interface PaymentRefundService
      Parameters:
      order - the order for which the refunds need to be issued
      orderFulfillments - the list of all of the order's fulfillments
      returnAuthorization - the return authorization containing pending confirmations that need to be refunded and completed
      contextInfo - context information surrounding multitenant state
      Returns:
      the updated order, or null if there were no pending return confirmations on the return authorization
    • extractPendingReturnConfirmationsByFulfillmentId

      protected Map<String,List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> extractPendingReturnConfirmationsByFulfillmentId(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments)
      Extracts all of the returnAuthorization's pending return confirmations (for ReturnAuthorizationItems whose ReturnAuthorizationItem.getReturnType() supports refunds) and groups them by order fulfillment ID.
      Parameters:
      returnAuthorization - the return authorization whose pending return confirmations need to be extracted
      orderFulfillments - the list of all of the order's fulfillments
      Returns:
      the pending return confirmations from the returnAuthorization grouped by order fulfillment ID
    • returnTypeIsRefundable

      protected boolean returnTypeIsRefundable(com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem item)
    • getPaymentWithRefundableAmounts

      protected List<DefaultPaymentRefundService.PaymentWithRefundableAmount> getPaymentWithRefundableAmounts(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Looks through the given Order and returns all PaymentWithRefundableAmounts that have some non-reverse amount still available for refund.

      For example, if there's a PaymentSummary.getAmountAvailableForRefund() greater than 0, this method would return the PaymentSummary along with the amount available for refund.

      Parameters:
      order - the order whose payment summaries should be searched for refundable amounts
      Returns:
      a list of PaymentWithRefundableAmounts from PaymentSummaries on the Order which has amount available for refund. The list is sorted such that payments with higher refund priority are first.
    • sortPaymentsByPriority

      protected List<PaymentSummary> sortPaymentsByPriority(@NonNull @NonNull List<PaymentSummary> paymentSummaries, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Given a list of PaymentSummaries, sorts them in order of which should be refunded first.

      Any custom logic for refund payment priority should be added here.

      Parameters:
      paymentSummaries - the list of PaymentSummaries to sort based on refund priority
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      a new list representing the sorted result
    • sortPaymentsByPriority

      @Deprecated protected List<PaymentSummary> sortPaymentsByPriority(List<PaymentSummary> paymentSummaries)
      Deprecated.
      Given a list of PaymentSummaries, sorts them in order of which should be refunded first.

      Any custom logic for refund payment priority should be added here.

      Parameters:
      paymentSummaries - the list of PaymentSummaries to sort based on refund priority
      Returns:
      a new list representing the sorted result
    • validateEntireRequestedAmountIsAvailableForRefund

      protected void validateEntireRequestedAmountIsAvailableForRefund(@NonNull @NonNull Map<String,List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order)
      Sums the total amount that needs to be refunded for pendingReturnConfirmationsByFulfillmentId, and compares it to the sum of available refundable amounts in paymentWithRefundableAmounts.

      Will throw PaymentRefundException if the total refundable amount is insufficient.

      This validation should be performed as early as possible to prevent partial error states.

      Parameters:
      pendingReturnConfirmationsByFulfillmentId - a map from fulfillment ID to all pending return confirmations for it
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund
      order - the order for which this return is occurring
      Throws:
      PaymentRefundException - if the available refundable amount cannot cover the total to refund
    • validateEntireRequestedAmountIsAvailableForRefund

      protected void validateEntireRequestedAmountIsAvailableForRefund(@NonNull @NonNull javax.money.MonetaryAmount totalToRefund, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order)
      Compares the total amount to refund to the sum of available refundable amounts in paymentWithRefundableAmounts.

      Will throw PaymentRefundException if the total refundable amount is insufficient.

      This validation should be performed as early as possible to prevent partial error states.

      Parameters:
      totalToRefund - the amount to refund
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund
      order - the order for which this refund is occurring
      Throws:
      PaymentRefundException - if the available refundable amount cannot cover the total to refund
    • buildReturnPaymentRefundPackages

      protected List<DefaultPaymentRefundService.ReturnPaymentRefundPackage> buildReturnPaymentRefundPackages(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull Map<String,List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts)
      Iterates through pendingReturnConfirmationsByFulfillmentId, consuming amounts from paymentWithRefundableAmounts as necessary and building ReturnPaymentRefundPackages.

      Note that the actual amounts in paymentWithRefundableAmounts will be mutated and decreased after a fulfillment consumes part/all of a refundable amount. This allows multiple fulfillments to refund against the same payment without exceeding its available amount.

      Parameters:
      pendingReturnConfirmationsByFulfillmentId - a map from fulfillment ID to all pending return confirmations for it
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund
      Returns:
      a list of all ReturnPaymentRefundPackages that should be processed to refund the pending ReturnConfirmations.
    • buildReturnPaymentRefundPackages

      protected List<DefaultPaymentRefundService.ReturnPaymentRefundPackage> buildReturnPaymentRefundPackages(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull @NonNull com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, @NonNull @NonNull String fulfillmentId)
      Builds ReturnPaymentRefundPackages for the given PaymentWithRefundableAmounts and ReturnConfirmation.
      Parameters:
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund
      returnConfirmation - the ReturnConfirmation that this refund is for
      fulfillmentId - the OrderFulfillment.getId() that this ReturnConfirmation is for
      Returns:
      a list of ReturnPaymentRefundPackages for the given PaymentWithRefundableAmounts and ReturnConfirmation
    • issueRefunds

      protected List<TransactionExecutionResponse> issueRefunds(List<? extends DefaultPaymentRefundService.PaymentRefundPackage> paymentRefundPackages, com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Given a list of ReturnPaymentRefundPackages, executes the refunds against the paymentProvider to actually issue the refund.

      Returns the responses for each refund.

      Parameters:
      paymentRefundPackages - a list of payment refund packages whose refunds need to be executed
      order - the Order that this refund is for
      contextInfo - context information surrounding multitenant state
      Returns:
      the refund execution responses after issuing all refunds
      Throws:
      PaymentTransactionFailureException - if any of the refunds were not successfully executed
    • getPaymentsById

      protected Map<String,PaymentSummary> getPaymentsById(List<? extends DefaultPaymentRefundService.PaymentRefundPackage> refundPackages)
      Gets a map of payments by its id from the given list of PaymentRefundPackages.

      This is useful to keep the PaymentSummaries with the latest PaymentSummary.getVersion().

      Parameters:
      refundPackages - a list of PaymentRefundPackages to get the payments from
      Returns:
      a map of payments by its id
    • updateRefundPackagePayment

      protected void updateRefundPackagePayment(@NonNull @NonNull DefaultPaymentRefundService.PaymentRefundPackage refundPackage, @NonNull @NonNull Map<String,PaymentSummary> paymentsById)
      Updates the DefaultPaymentRefundService.PaymentRefundPackage.getPayment() based on the given paymentsById.

      This is necessary to ensure that the DefaultPaymentRefundService.PaymentRefundPackage.getPayment() is the latest payment based on recently executed transaction. Otherwise, the PaymentSummary.getVersion() would be stale and therefore not able to execute transactions.

      Parameters:
      refundPackage - the DefaultPaymentRefundService.PaymentRefundPackage to update
      paymentsById - the map of latest PaymentSummaries by PaymentSummary.getPaymentId()
    • getPaymentIds

      @Deprecated(since="1.7.2", forRemoval=true) protected List<String> getPaymentIds(List<? extends DefaultPaymentRefundService.PaymentRefundPackage> refundPackages)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1.7.2, no longer used
      Gets a list of payment ids from the given list of PaymentRefundPackages.
      Parameters:
      refundPackages - a list of PaymentRefundPackages to get the payment ids from
      Returns:
      a list of payment ids
    • issueRefund

      protected TransactionExecutionResponse issueRefund(@NonNull @NonNull DefaultPaymentRefundService.PaymentRefundPackage refundPackage, @NonNull @NonNull String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Executes the refund for the given DefaultPaymentRefundService.ReturnPaymentRefundPackage against the paymentProvider to actually issue the refund.
      Parameters:
      refundPackage - the DefaultPaymentRefundService.ReturnPaymentRefundPackage to execute the refund for
      lockToken - the token that owns the payment lock
      contextInfo - context information surrounding multitenant state
      Returns:
      the TransactionExecutionResponse from the refund transaction
      See Also:
    • updateReturnAuthorizationAfterRefund

      @Deprecated(since="1.7.2", forRemoval=true) protected com.broadleafcommerce.order.client.domain.ReturnAuthorization updateReturnAuthorizationAfterRefund(List<DefaultPaymentRefundService.ReturnPaymentRefundPackage> paymentRefundPackages, com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1.7.2, the status of the ReturnAuthorization are updated in updateReturnAuthorization(List, ReturnAuthorization, String, ContextInfo) based on the refund transaction responses.
      Updates the given ReturnAuthorization based on the given list of DefaultPaymentRefundService.PaymentRefundPackage.getAmountToRefund().

      By default, the sum of the total refunded amounts from refund amounts is added to ReturnAuthorization.getTotalRefunded(). Any custom logic should be added here.

      Parameters:
      paymentRefundPackages - a list of payment refund packages whose refund transactions are executed
      returnAuthorization - the return authorization that should be updated
      Returns:
      the updated ReturnAuthorization
    • completePendingConfirmationsAndPersist

      @Deprecated(since="1.7.2", forRemoval=true) protected com.broadleafcommerce.order.client.domain.ReturnAuthorization completePendingConfirmationsAndPersist(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, String orderId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1.7.2, the status of the return confirmations are updated in updateReturnAuthorization(List, ReturnAuthorization, String, ContextInfo) based on the refund transaction responses.
      Finds each of the pending ReturnConfirmations on the ReturnAuthorization, marks them as completed, and persists the return authorization.
      Parameters:
      returnAuthorization - the return authorization whose pending return confirmations should be marked completed
      orderId - the ID of the order the return authorization is for
      contextInfo - context information surrounding multitenant state
      Returns:
      the updated return authorization
    • updateReturnAuthorization

      protected com.broadleafcommerce.order.client.domain.ReturnAuthorization updateReturnAuthorization(@NonNull @NonNull List<DefaultPaymentRefundService.ReturnPaymentRefundPackage> paymentRefundPackages, @NonNull @NonNull com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, @NonNull @NonNull String orderId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Updates the given ReturnAuthorization and its ReturnConfirmations based on the refund transaction responses.
      Parameters:
      paymentRefundPackages - the PaymentRefundPackages containing all the refund transaction responses
      returnAuthorization - the ReturnAuthorization to update
      orderId - the order id
      contextInfo - context information surrounding multitenant state
      Returns:
      the updated return authorization based on refund transaction responses
    • getAmountTotal

      protected javax.money.MonetaryAmount getAmountTotal(@NonNull @NonNull List<TransactionExecutionResponse> transactionResponses, Function<TransactionExecutionResponse,javax.money.MonetaryAmount> amountGetter, javax.money.CurrencyUnit currency)
      Gets the total of the TransactionExecutionResponses based on the amountGetter.
      Parameters:
      transactionResponses - the TransactionExecutionResponses to sum
      amountGetter - the getter for the MonetaryAmount to sum
      currency - the CurrencyUnit
      Returns:
      the total of the TransactionExecutionResponses based on the amountGetter
    • updateReturnAuthorizationAmounts

      protected void updateReturnAuthorizationAmounts(@NonNull @NonNull com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, @NonNull @NonNull javax.money.MonetaryAmount amountRefunded, @NonNull @NonNull javax.money.MonetaryAmount amountFailedToRefund, @NonNull @NonNull javax.money.MonetaryAmount refundAmountAwaitingResult)
      Updates the amounts of the given ReturnAuthorization.
      Parameters:
      returnAuthorization - the ReturnAuthorization to update
      amountRefunded - the amount successfully refunded
      amountFailedToRefund - the amount failed to refund
      refundAmountAwaitingResult - the refund amount awaiting result
    • updateReturnConfirmation

      protected void updateReturnConfirmation(@NonNull @NonNull com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, @NonNull @NonNull javax.money.MonetaryAmount amountRefunded, @NonNull @NonNull javax.money.MonetaryAmount amountFailedToRefund, @NonNull @NonNull javax.money.MonetaryAmount refundAmountAwaitingResult)
      Updates the amounts and the status of the given ReturnConfirmation.
      Parameters:
      returnConfirmation - the ReturnAuthorization to update
      amountRefunded - the amount successfully refunded
      amountFailedToRefund - the amount failed to refund
      refundAmountAwaitingResult - the refund amount awaiting result
    • determineReturnConfirmationStatus

      protected String determineReturnConfirmationStatus(@NonNull @NonNull com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, @NonNull @NonNull javax.money.MonetaryAmount amountSuccess, @NonNull @NonNull javax.money.MonetaryAmount amountFailed, @NonNull @NonNull javax.money.MonetaryAmount amountAwaitingResult)
      Determines the status of the given ReturnConfirmation based on the given amounts.

      Any custom logic should be added here.

      Parameters:
      returnConfirmation - the ReturnConfirmation to determine the status for
      amountSuccess - the amount that was successfully refunded
      amountFailed - the amount failed to refund
      amountAwaitingResult - the refund amount that is awaiting transaction result
      Returns:
      the ReturnConfirmationStatus
    • buildPaymentDistributionDto

      protected PaymentDistributionDto buildPaymentDistributionDto(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull javax.money.MonetaryAmount totalToDistribute, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts)
    • buildPaymentRefundPackagesFromDistribution

      protected List<DefaultPaymentRefundService.PaymentRefundPackage> buildPaymentRefundPackagesFromDistribution(@NonNull @NonNull PaymentDistributionResult distributionResult, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull String fulfillmentId, boolean isForReturnConfirmation, @Nullable com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation)
      Builds a list of PaymentRefundPackages from the given PaymentDistributionResult.
      Parameters:
      distributionResult - the PaymentDistributionResult containing the amount to distribute across different payments
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund, sorted by payment priority
      order - the Order that this refund is related to
      fulfillmentId - the id of the fulfillment that this refund is related to
      isForReturnConfirmation - whether the refund packages are for a ReturnConfirmation
      returnConfirmation - the ReturnConfirmation that the refund packages are for. Should be null if isForReturnConfirmation is false
      Returns:
      a list of PaymentRefundPackages from the given PaymentDistributionResult
    • getPaymentWithRefundableAmountById

      protected DefaultPaymentRefundService.PaymentWithRefundableAmount getPaymentWithRefundableAmountById(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, String paymentId)
      Parameters:
      paymentWithRefundableAmounts - a list of PaymentWithRefundableAmounts to find it from
      paymentId - the id of the payment
      Returns:
      the DefaultPaymentRefundService.PaymentWithRefundableAmount that matches the given payment id
      Throws:
      IllegalStateException - if there's no DefaultPaymentRefundService.PaymentWithRefundableAmount that matches the given payment id
    • buildReturnRefundPackage

      protected DefaultPaymentRefundService.ReturnPaymentRefundPackage buildReturnRefundPackage(PaymentSummary payment, javax.money.MonetaryAmount amountToRefund, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, String orderFulfillmentId)
    • buildPaymentWithRefundableAmount

      protected DefaultPaymentRefundService.PaymentWithRefundableAmount buildPaymentWithRefundableAmount(PaymentSummary paymentSummary)
    • refundFulfillment

      public List<TransactionExecutionResponse> refundFulfillment(javax.money.MonetaryAmount amountToRefund, com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentRefundService
      Issues refund(s) for the given amount for the OrderFulfillment.
      Specified by:
      refundFulfillment in interface PaymentRefundService
      Parameters:
      amountToRefund - the amount to refund
      order - the order for which the refund(s) need to be issued
      fulfillment - the fulfillment to refund
      contextInfo - context information surrounding multitenant state
      Returns:
      the updated order
    • buildFulfillmentPaymentRefundPackages

      protected List<DefaultPaymentRefundService.PaymentRefundPackage> buildFulfillmentPaymentRefundPackages(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull javax.money.MonetaryAmount totalToRefund, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts)
      Builds PaymentRefundPackages to refund for the fulfillment, consuming amounts from transactionsWithRefundableAmountsByPaymentId as necessary.
      Parameters:
      fulfillment - the fulfillment to refund
      totalToRefund - the total amount to refund
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund
      Returns:
      a list of all PaymentRefundPackages that should be processed to refund the fulfillment
    • buildPaymentRefundPackages

      protected List<DefaultPaymentRefundService.PaymentRefundPackage> buildPaymentRefundPackages(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull String fulfillmentId, @NonNull @NonNull javax.money.MonetaryAmount totalToRefund, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, boolean isForReturnConfirmation, @Nullable com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation)
    • buildFromPaymentDistributionDetails

      protected List<DefaultPaymentRefundService.PaymentRefundPackage> buildFromPaymentDistributionDetails(@NonNull @NonNull javax.money.MonetaryAmount totalToRefund, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull String fulfillmentId, boolean isForReturnConfirmation, @Nullable com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation)
      Builds a list of PaymentRefundPackages based on the Order.getPaymentDistributionDetails().

      This will always execute a refund amount for each payment based on its distribution, regardless the total amount to refund.

      Parameters:
      totalToRefund - the total to refund
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund, sorted by payment priority
      order - the Order that this refund is related to
      fulfillmentId - the id of the fulfillment that this refund is related to
      isForReturnConfirmation - whether the refund packages are for a ReturnConfirmation
      returnConfirmation - the ReturnConfirmation that the refund packages are for. Should be null if isForReturnConfirmation is false
      Returns:
      a list of PaymentRefundPackages based on the Order.getPaymentDistributionDetails()
    • buildFromPaymentPriority

      protected List<DefaultPaymentRefundService.PaymentRefundPackage> buildFromPaymentPriority(@NonNull @NonNull javax.money.MonetaryAmount totalToRefund, @NonNull @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull String fulfillmentId, boolean isForReturnConfirmation, @Nullable com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation)
      Builds a list of PaymentRefundPackages based on the payment priority.

      This will refund as much as possible for each payment based on its available amount, to minimize the total number of payment executions.

      Parameters:
      totalToRefund - the total to refund
      paymentWithRefundableAmounts - a list of DefaultPaymentRefundService.PaymentWithRefundableAmount containing the refundable PaymentSummary along with its amount available to refund, sorted by payment priority
      order - the Order that this refund is related to
      fulfillmentId - the id of the fulfillment that this refund is related to
      isForReturnConfirmation - whether the refund packages are for a ReturnConfirmation
      returnConfirmation - the ReturnConfirmation that the refund packages are for. Should be null if isForReturnConfirmation is false
      Returns:
      a list of PaymentRefundPackages the payment priority
    • getNextPaymentWithRefundableAmount

      protected DefaultPaymentRefundService.PaymentWithRefundableAmount getNextPaymentWithRefundableAmount(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts)
      Gets the next DefaultPaymentRefundService.PaymentWithRefundableAmount that has amount available for refund.
      Parameters:
      paymentWithRefundableAmounts - a list of PaymentWithRefundableAmounts to find it from
      Returns:
      the next DefaultPaymentRefundService.PaymentWithRefundableAmount that has amount available for refund
      Throws:
      IllegalStateException - if there's no DefaultPaymentRefundService.PaymentWithRefundableAmount that has amount available for refund
    • getAmountToRefund

      protected javax.money.MonetaryAmount getAmountToRefund(DefaultPaymentRefundService.PaymentWithRefundableAmount paymentWithRefundableAmount, javax.money.MonetaryAmount remainingToRefund)
      Gets the amount to refund based on the given DefaultPaymentRefundService.PaymentWithRefundableAmount and remaining to refund.
      Parameters:
      paymentWithRefundableAmount - the DefaultPaymentRefundService.PaymentWithRefundableAmount to get the amount to refund from
      remainingToRefund - the remaining amount to refund
      Returns:
      the amount to refund based on the given DefaultPaymentRefundService.PaymentWithRefundableAmount and remaining to refund
    • buildFulfillmentRefundPackage

      protected DefaultPaymentRefundService.PaymentRefundPackage buildFulfillmentRefundPackage(PaymentSummary payment, javax.money.MonetaryAmount amountToRefund, String orderFulfillmentId)
    • getAmountOrZero

      protected <T> javax.money.MonetaryAmount getAmountOrZero(@NonNull T object, @NonNull @NonNull Function<T,javax.money.MonetaryAmount> amountGetter, @NonNull @NonNull javax.money.CurrencyUnit currency)
    • getPaymentPriorityStrategy

      protected PaymentPriorityStrategy getPaymentPriorityStrategy()
    • getOrderProvider

      protected OrderProvider<com.broadleafcommerce.order.client.domain.Order> getOrderProvider()
    • getReturnAuthorizationProvider

      protected ReturnAuthorizationProvider<com.broadleafcommerce.order.client.domain.ReturnAuthorization> getReturnAuthorizationProvider()
    • getPaymentProvider

      protected PaymentProvider getPaymentProvider()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getOrderOperationServiceProperties

      protected OrderOperationServiceProperties getOrderOperationServiceProperties()
    • setOrderOperationServiceProperties

      @Autowired public void setOrderOperationServiceProperties(OrderOperationServiceProperties orderOperationServiceProperties)
    • getPaymentDistributionService

      protected PaymentDistributionService getPaymentDistributionService()
    • setPaymentDistributionService

      @Autowired public void setPaymentDistributionService(PaymentDistributionService paymentDistributionService)