Class DefaultPaymentRefundService
- All Implemented Interfaces:
PaymentRefundService
- Author:
- Samarth Dhruva (samarthd)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An intermediary data structure used internally byDefaultPaymentRefundService
to keep track of a fulfillment refund that will be executed.static class
An intermediary data structure used internally byDefaultPaymentRefundService
to keep track of a refundable payment on anOrder
and the non-reversed amount that is actually available for refund on it.static class
An intermediary data structure used internally byDefaultPaymentRefundService
to keep track of a return refund that will be executed. -
Constructor Summary
ConstructorDescriptionDefaultPaymentRefundService
(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 Summary
Modifier and TypeMethodDescriptionbuildFromPaymentDistributionDetails
(@NonNull javax.money.MonetaryAmount totalToRefund, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull String fulfillmentId, boolean isForReturnConfirmation, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation) Builds a list ofPaymentRefundPackages
based on theOrder.getPaymentDistributionDetails()
.buildFromPaymentPriority
(@NonNull javax.money.MonetaryAmount totalToRefund, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull String fulfillmentId, boolean isForReturnConfirmation, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation) Builds a list ofPaymentRefundPackages
based on the payment priority.buildFulfillmentPaymentRefundPackages
(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull javax.money.MonetaryAmount totalToRefund, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts) BuildsPaymentRefundPackages
to refund for the fulfillment, consuming amounts fromtransactionsWithRefundableAmountsByPaymentId
as necessary.buildFulfillmentRefundPackage
(PaymentSummary payment, javax.money.MonetaryAmount amountToRefund, String orderFulfillmentId) protected PaymentDistributionDto
buildPaymentDistributionDto
(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull javax.money.MonetaryAmount totalToDistribute, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts) buildPaymentRefundPackages
(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull String fulfillmentId, @NonNull javax.money.MonetaryAmount totalToRefund, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, boolean isForReturnConfirmation, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation) buildPaymentRefundPackagesFromDistribution
(@NonNull PaymentDistributionResult distributionResult, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull String fulfillmentId, boolean isForReturnConfirmation, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation) Builds a list ofPaymentRefundPackages
from the givenPaymentDistributionResult
.buildPaymentWithRefundableAmount
(PaymentSummary paymentSummary) buildReturnPaymentRefundPackages
(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, @NonNull String fulfillmentId) BuildsReturnPaymentRefundPackages
for the givenPaymentWithRefundableAmounts
andReturnConfirmation
.buildReturnPaymentRefundPackages
(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull Map<String, List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts) Iterates throughpendingReturnConfirmationsByFulfillmentId
, consuming amounts frompaymentWithRefundableAmounts
as necessary and buildingReturnPaymentRefundPackages
.buildReturnRefundPackage
(PaymentSummary payment, javax.money.MonetaryAmount amountToRefund, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, String orderFulfillmentId) protected com.broadleafcommerce.order.client.domain.ReturnAuthorization
completePendingConfirmationsAndPersist
(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, String orderId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated, for removal: This API element is subject to removal in a future version.protected String
determineReturnConfirmationStatus
(@NonNull com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, @NonNull javax.money.MonetaryAmount amountSuccess, @NonNull javax.money.MonetaryAmount amountFailed, @NonNull javax.money.MonetaryAmount amountAwaitingResult) Determines the status of the givenReturnConfirmation
based on the given amounts.extractPendingReturnConfirmationsByFulfillmentId
(com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments) Extracts all of thereturnAuthorization
's pending return confirmations (forReturnAuthorizationItems
whoseReturnAuthorizationItem.getReturnType()
supports refunds) and groups them by order fulfillment ID.protected <T> javax.money.MonetaryAmount
getAmountOrZero
(T object, @NonNull Function<T, javax.money.MonetaryAmount> amountGetter, @NonNull javax.money.CurrencyUnit currency) protected javax.money.MonetaryAmount
getAmountToRefund
(DefaultPaymentRefundService.PaymentWithRefundableAmount paymentWithRefundableAmount, javax.money.MonetaryAmount remainingToRefund) Gets the amount to refund based on the givenDefaultPaymentRefundService.PaymentWithRefundableAmount
and remaining to refund.protected javax.money.MonetaryAmount
getAmountTotal
(@NonNull List<TransactionExecutionResponse> transactionResponses, Function<TransactionExecutionResponse, javax.money.MonetaryAmount> amountGetter, javax.money.CurrencyUnit currency) Gets the total of theTransactionExecutionResponses
based on theamountGetter
.getNextPaymentWithRefundableAmount
(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts) Gets the nextDefaultPaymentRefundService.PaymentWithRefundableAmount
that has amount available for refund.protected OrderOperationServiceProperties
protected OrderProvider<com.broadleafcommerce.order.client.domain.Order>
protected PaymentDistributionService
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 usedprotected PaymentPriorityStrategy
protected PaymentProvider
protected Map<String,
PaymentSummary> getPaymentsById
(List<? extends DefaultPaymentRefundService.PaymentRefundPackage> refundPackages) Gets a map of payments by its id from the given list ofPaymentRefundPackages
.getPaymentWithRefundableAmountById
(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, String paymentId) Gets theDefaultPaymentRefundService.PaymentWithRefundableAmount
from the given payment id.getPaymentWithRefundableAmounts
(@NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Looks through the givenOrder
and returns allPaymentWithRefundableAmounts
that have some non-reverse amount still available for refund.protected ReturnAuthorizationProvider<com.broadleafcommerce.order.client.domain.ReturnAuthorization>
protected com.broadleafcommerce.common.extension.TypeFactory
protected TransactionExecutionResponse
issueRefund
(DefaultPaymentRefundService.PaymentRefundPackage refundPackage, @NonNull String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Executes the refund for the givenDefaultPaymentRefundService.ReturnPaymentRefundPackage
against thepaymentProvider
to actually issue the refund.protected List<TransactionExecutionResponse>
issueRefunds
(List<? extends DefaultPaymentRefundService.PaymentRefundPackage> paymentRefundPackages, com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Given a list ofReturnPaymentRefundPackages
, executes the refunds against thepaymentProvider
to actually issue the refund.refundAndCompletePendingReturnConfirmations
(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull List<com.broadleafcommerce.order.client.domain.OrderFulfillment> orderFulfillments, @NonNull com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds all pendingReturnConfirmations
on the givenReturnAuthorization
(forReturnAuthorizationItems
whoseReturnAuthorizationItem.getReturnType()
supports refunds), issues refunds for them, and updates theReturnConfirmation.getStatus()
based on the refund responses.refundFulfillment
(javax.money.MonetaryAmount amountToRefund, com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Issues refund(s) for the given amount for theOrderFulfillment
.protected boolean
returnTypeIsRefundable
(com.broadleafcommerce.order.client.domain.ReturnAuthorizationItem item) void
setOrderOperationServiceProperties
(OrderOperationServiceProperties orderOperationServiceProperties) void
setPaymentDistributionService
(PaymentDistributionService paymentDistributionService) protected List<PaymentSummary>
sortPaymentsByPriority
(@NonNull List<PaymentSummary> paymentSummaries, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Given a list ofPaymentSummaries
, sorts them in order of which should be refunded first.protected List<PaymentSummary>
sortPaymentsByPriority
(List<PaymentSummary> paymentSummaries) Deprecated.since 1.7.2, in favor ofsortPaymentsByPriority(List, ContextInfo)
protected void
updateRefundPackagePayment
(@NonNull DefaultPaymentRefundService.PaymentRefundPackage refundPackage, @NonNull Map<String, PaymentSummary> paymentsById) Updates theDefaultPaymentRefundService.PaymentRefundPackage.getPayment()
based on the givenpaymentsById
.protected com.broadleafcommerce.order.client.domain.ReturnAuthorization
updateReturnAuthorization
(@NonNull List<DefaultPaymentRefundService.ReturnPaymentRefundPackage> paymentRefundPackages, @NonNull com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, @NonNull String orderId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Updates the givenReturnAuthorization
and itsReturnConfirmations
based on therefund transaction responses
.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 theReturnAuthorization
are updated inupdateReturnAuthorization(List, ReturnAuthorization, String, ContextInfo)
based on the refund transaction responses.protected void
updateReturnAuthorizationAmounts
(@NonNull com.broadleafcommerce.order.client.domain.ReturnAuthorization returnAuthorization, @NonNull javax.money.MonetaryAmount amountRefunded, @NonNull javax.money.MonetaryAmount amountFailedToRefund, @NonNull javax.money.MonetaryAmount refundAmountAwaitingResult) Updates the amounts of the givenReturnAuthorization
.protected void
updateReturnConfirmation
(@NonNull com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, @NonNull javax.money.MonetaryAmount amountRefunded, @NonNull javax.money.MonetaryAmount amountFailedToRefund, @NonNull javax.money.MonetaryAmount refundAmountAwaitingResult) Updates the amounts and the status of the givenReturnConfirmation
.protected void
validateEntireRequestedAmountIsAvailableForRefund
(@NonNull Map<String, List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull com.broadleafcommerce.order.client.domain.Order order) Sums the total amount that needs to be refunded forpendingReturnConfirmationsByFulfillmentId
, and compares it to the sum of available refundable amounts inpaymentWithRefundableAmounts
.protected void
validateEntireRequestedAmountIsAvailableForRefund
(@NonNull javax.money.MonetaryAmount totalToRefund, @NonNull List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, @NonNull com.broadleafcommerce.order.client.domain.Order order) Compares the total amount to refund to the sum of available refundable amounts inpaymentWithRefundableAmounts
.
-
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 pendingReturnConfirmations
on the givenReturnAuthorization
(forReturnAuthorizationItems
whoseReturnAuthorizationItem.getReturnType()
supports refunds), issues refunds for them, and updates theReturnConfirmation.getStatus()
based on the refund responses.- Specified by:
refundAndCompletePendingReturnConfirmations
in interfacePaymentRefundService
- Parameters:
order
- the order for which the refunds need to be issuedorderFulfillments
- the list of all of the order's fulfillmentsreturnAuthorization
- the return authorization containing pending confirmations that need to be refunded and completedcontextInfo
- 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 thereturnAuthorization
's pending return confirmations (forReturnAuthorizationItems
whoseReturnAuthorizationItem.getReturnType()
supports refunds) and groups them by order fulfillment ID.- Parameters:
returnAuthorization
- the return authorization whose pending return confirmations need to be extractedorderFulfillments
- 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 givenOrder
and returns allPaymentWithRefundableAmounts
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 thePaymentSummary
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
fromPaymentSummaries
on theOrder
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 ofPaymentSummaries
, 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 ofPaymentSummaries
to sort based on refund prioritycontextInfo
- 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.since 1.7.2, in favor ofsortPaymentsByPriority(List, ContextInfo)
Given a list ofPaymentSummaries
, 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 ofPaymentSummaries
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 forpendingReturnConfirmationsByFulfillmentId
, and compares it to the sum of available refundable amounts inpaymentWithRefundableAmounts
.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 itpaymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
along with its amount available to refundorder
- 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 inpaymentWithRefundableAmounts
.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 refundpaymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
along with its amount available to refundorder
- 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 throughpendingReturnConfirmationsByFulfillmentId
, consuming amounts frompaymentWithRefundableAmounts
as necessary and buildingReturnPaymentRefundPackages
.Note that the actual
amounts
inpaymentWithRefundableAmounts
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 itpaymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
along with its amount available to refund- Returns:
- a list of all
ReturnPaymentRefundPackages
that should be processed to refund the pendingReturnConfirmations
.
-
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) BuildsReturnPaymentRefundPackages
for the givenPaymentWithRefundableAmounts
andReturnConfirmation
.- Parameters:
paymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
along with its amount available to refundreturnConfirmation
- theReturnConfirmation
that this refund is forfulfillmentId
- theOrderFulfillment.getId()
that thisReturnConfirmation
is for- Returns:
- a list of
ReturnPaymentRefundPackages
for the givenPaymentWithRefundableAmounts
andReturnConfirmation
-
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 ofReturnPaymentRefundPackages
, executes the refunds against thepaymentProvider
to actually issue the refund.Returns the responses for each refund.
- Parameters:
paymentRefundPackages
- a list of payment refund packages whose refunds need to be executedorder
- theOrder
that this refund is forcontextInfo
- 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 ofPaymentRefundPackages
.This is useful to keep the
PaymentSummaries
with the latestPaymentSummary.getVersion()
.- Parameters:
refundPackages
- a list ofPaymentRefundPackages
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 theDefaultPaymentRefundService.PaymentRefundPackage.getPayment()
based on the givenpaymentsById
.This is necessary to ensure that the
DefaultPaymentRefundService.PaymentRefundPackage.getPayment()
is the latest payment based on recently executed transaction. Otherwise, thePaymentSummary.getVersion()
would be stale and therefore not able to execute transactions.- Parameters:
refundPackage
- theDefaultPaymentRefundService.PaymentRefundPackage
to updatepaymentsById
- the map of latestPaymentSummaries
byPaymentSummary.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 usedGets a list of payment ids from the given list ofPaymentRefundPackages
.- Parameters:
refundPackages
- a list ofPaymentRefundPackages
to get the payment ids from- Returns:
- a list of payment ids
-
issueRefund
protected TransactionExecutionResponse issueRefund(DefaultPaymentRefundService.PaymentRefundPackage refundPackage, @NonNull @NonNull String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Executes the refund for the givenDefaultPaymentRefundService.ReturnPaymentRefundPackage
against thepaymentProvider
to actually issue the refund.- Parameters:
refundPackage
- theDefaultPaymentRefundService.ReturnPaymentRefundPackage
to execute the refund forlockToken
- the token that owns the payment lockcontextInfo
- 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 theReturnAuthorization
are updated inupdateReturnAuthorization(List, ReturnAuthorization, String, ContextInfo)
based on the refund transaction responses.Updates the givenReturnAuthorization
based on the given list ofDefaultPaymentRefundService.PaymentRefundPackage.getAmountToRefund()
.By default, the sum of the total refunded amounts from
refund amounts
is added toReturnAuthorization.getTotalRefunded()
. Any custom logic should be added here.- Parameters:
paymentRefundPackages
- a list of payment refund packages whose refund transactions are executedreturnAuthorization
- 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 inupdateReturnAuthorization(List, ReturnAuthorization, String, ContextInfo)
based on the refund transaction responses.Finds each of the pendingReturnConfirmations
on theReturnAuthorization
, marks them as completed, and persists the return authorization.- Parameters:
returnAuthorization
- the return authorization whose pending return confirmations should be marked completedorderId
- the ID of the order the return authorization is forcontextInfo
- 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 givenReturnAuthorization
and itsReturnConfirmations
based on therefund transaction responses
.- Parameters:
paymentRefundPackages
- thePaymentRefundPackages
containing all therefund transaction responses
returnAuthorization
- theReturnAuthorization
to updateorderId
- the order idcontextInfo
- 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 theTransactionExecutionResponses
based on theamountGetter
.- Parameters:
transactionResponses
- theTransactionExecutionResponses
to sumamountGetter
- the getter for theMonetaryAmount
to sumcurrency
- theCurrencyUnit
- Returns:
- the total of the
TransactionExecutionResponses
based on theamountGetter
-
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 givenReturnAuthorization
.- Parameters:
returnAuthorization
- theReturnAuthorization
to updateamountRefunded
- the amount successfully refundedamountFailedToRefund
- the amount failed to refundrefundAmountAwaitingResult
- 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 givenReturnConfirmation
.- Parameters:
returnConfirmation
- theReturnAuthorization
to updateamountRefunded
- the amount successfully refundedamountFailedToRefund
- the amount failed to refundrefundAmountAwaitingResult
- 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 givenReturnConfirmation
based on the given amounts.Any custom logic should be added here.
- Parameters:
returnConfirmation
- theReturnConfirmation
to determine the status foramountSuccess
- the amount that was successfully refundedamountFailed
- the amount failed to refundamountAwaitingResult
- 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 ofPaymentRefundPackages
from the givenPaymentDistributionResult
.- Parameters:
distributionResult
- thePaymentDistributionResult
containing the amount to distribute across different paymentspaymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
along with its amount available to refund, sorted by payment priorityorder
- theOrder
that this refund is related tofulfillmentId
- the id of the fulfillment that this refund is related toisForReturnConfirmation
- whether the refund packages are for aReturnConfirmation
returnConfirmation
- theReturnConfirmation
that the refund packages are for. Should be null ifisForReturnConfirmation
is false- Returns:
- a list of
PaymentRefundPackages
from the givenPaymentDistributionResult
-
getPaymentWithRefundableAmountById
protected DefaultPaymentRefundService.PaymentWithRefundableAmount getPaymentWithRefundableAmountById(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, String paymentId) Gets theDefaultPaymentRefundService.PaymentWithRefundableAmount
from the given payment id.- Parameters:
paymentWithRefundableAmounts
- a list ofPaymentWithRefundableAmounts
to find it frompaymentId
- the id of the payment- Returns:
- the
DefaultPaymentRefundService.PaymentWithRefundableAmount
that matches the given payment id - Throws:
IllegalStateException
- if there's noDefaultPaymentRefundService.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 theOrderFulfillment
.- Specified by:
refundFulfillment
in interfacePaymentRefundService
- Parameters:
amountToRefund
- the amount to refundorder
- the order for which the refund(s) need to be issuedfulfillment
- the fulfillment to refundcontextInfo
- 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) BuildsPaymentRefundPackages
to refund for the fulfillment, consuming amounts fromtransactionsWithRefundableAmountsByPaymentId
as necessary.- Parameters:
fulfillment
- the fulfillment to refundtotalToRefund
- the total amount to refundpaymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
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 ofPaymentRefundPackages
based on theOrder.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 refundpaymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
along with its amount available to refund, sorted by payment priorityorder
- theOrder
that this refund is related tofulfillmentId
- the id of the fulfillment that this refund is related toisForReturnConfirmation
- whether the refund packages are for aReturnConfirmation
returnConfirmation
- theReturnConfirmation
that the refund packages are for. Should be null ifisForReturnConfirmation
is false- Returns:
- a list of
PaymentRefundPackages
based on theOrder.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 ofPaymentRefundPackages
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 refundpaymentWithRefundableAmounts
- a list ofDefaultPaymentRefundService.PaymentWithRefundableAmount
containing the refundablePaymentSummary
along with its amount available to refund, sorted by payment priorityorder
- theOrder
that this refund is related tofulfillmentId
- the id of the fulfillment that this refund is related toisForReturnConfirmation
- whether the refund packages are for aReturnConfirmation
returnConfirmation
- theReturnConfirmation
that the refund packages are for. Should be null ifisForReturnConfirmation
is false- Returns:
- a list of
PaymentRefundPackages
the payment priority
-
getNextPaymentWithRefundableAmount
protected DefaultPaymentRefundService.PaymentWithRefundableAmount getNextPaymentWithRefundableAmount(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts) Gets the nextDefaultPaymentRefundService.PaymentWithRefundableAmount
that has amount available for refund.- Parameters:
paymentWithRefundableAmounts
- a list ofPaymentWithRefundableAmounts
to find it from- Returns:
- the next
DefaultPaymentRefundService.PaymentWithRefundableAmount
that has amount available for refund - Throws:
IllegalStateException
- if there's noDefaultPaymentRefundService.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 givenDefaultPaymentRefundService.PaymentWithRefundableAmount
and remaining to refund.- Parameters:
paymentWithRefundableAmount
- theDefaultPaymentRefundService.PaymentWithRefundableAmount
to get the amount to refund fromremainingToRefund
- 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
-
getOrderProvider
-
getReturnAuthorizationProvider
protected ReturnAuthorizationProvider<com.broadleafcommerce.order.client.domain.ReturnAuthorization> getReturnAuthorizationProvider() -
getPaymentProvider
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getOrderOperationServiceProperties
-
setOrderOperationServiceProperties
@Autowired public void setOrderOperationServiceProperties(OrderOperationServiceProperties orderOperationServiceProperties) -
getPaymentDistributionService
-
setPaymentDistributionService
@Autowired public void setPaymentDistributionService(PaymentDistributionService paymentDistributionService)
-
updateReturnAuthorization(List, ReturnAuthorization, String, ContextInfo)
based on the refund transaction responses.