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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultPaymentRefundService.PaymentRefundPackage
An intermediary data structure used internally byDefaultPaymentRefundService
to keep track of a fulfillment refund that will be executed.static class
DefaultPaymentRefundService.PaymentWithRefundableAmount
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
DefaultPaymentRefundService.ReturnPaymentRefundPackage
An intermediary data structure used internally byDefaultPaymentRefundService
to keep track of a return refund that will be executed.
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected List<DefaultPaymentRefundService.PaymentRefundPackage>
buildFulfillmentPaymentRefundPackages(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, javax.money.MonetaryAmount totalToRefund, List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts)
BuildsPaymentRefundPackages
to refund for the fulfillment, consuming amounts fromtransactionsWithRefundableAmountsByPaymentId
as necessary.protected DefaultPaymentRefundService.PaymentRefundPackage
buildFulfillmentRefundPackage(PaymentSummary payment, javax.money.MonetaryAmount amountToRefund, String orderFulfillmentId)
protected DefaultPaymentRefundService.PaymentWithRefundableAmount
buildPaymentWithRefundableAmount(PaymentSummary paymentSummary)
protected List<DefaultPaymentRefundService.ReturnPaymentRefundPackage>
buildReturnPaymentRefundPackages(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, String fulfillmentId)
BuildsReturnPaymentRefundPackages
for the givenPaymentWithRefundableAmounts
andReturnConfirmation
.protected List<DefaultPaymentRefundService.ReturnPaymentRefundPackage>
buildReturnPaymentRefundPackages(Map<String,List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts)
Iterates throughpendingReturnConfirmationsByFulfillmentId
, consuming amounts frompaymentWithRefundableAmounts
as necessary and buildingReturnPaymentRefundPackages
.protected DefaultPaymentRefundService.ReturnPaymentRefundPackage
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.since 1.7.2, the status of the return confirmations are updated inupdateReturnAuthorization(List, ReturnAuthorization, String, ContextInfo)
based on the refund transaction responses.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.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.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
.protected DefaultPaymentRefundService.PaymentWithRefundableAmount
getNextPaymentWithRefundableAmount(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts)
Gets the nextDefaultPaymentRefundService.PaymentWithRefundableAmount
that has amount available for refund.protected OrderProvider<com.broadleafcommerce.order.client.domain.Order>
getOrderProvider()
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 usedprotected PaymentPriorityStrategy
getPaymentPriorityStrategy()
protected PaymentProvider
getPaymentProvider()
protected Map<String,PaymentSummary>
getPaymentsById(List<? extends DefaultPaymentRefundService.PaymentRefundPackage> refundPackages)
Gets a map of payments by its id from the given list ofPaymentRefundPackages
.protected List<DefaultPaymentRefundService.PaymentWithRefundableAmount>
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>
getReturnAuthorizationProvider()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
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.List<TransactionExecutionResponse>
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.List<TransactionExecutionResponse>
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)
protected List<PaymentSummary>
sortPaymentsByPriority(List<PaymentSummary> paymentSummaries)
Deprecated.since 1.7.2, in favor ofsortPaymentsByPriority(List, ContextInfo)
protected List<PaymentSummary>
sortPaymentsByPriority(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 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(Map<String,List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, 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(javax.money.MonetaryAmount totalToRefund, List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, com.broadleafcommerce.order.client.domain.Order order)
Compares the total amount to refund to the sum of available refundable amounts inpaymentWithRefundableAmounts
.
-
-
-
Constructor Detail
-
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 Detail
-
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(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(Map<String,List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, 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(javax.money.MonetaryAmount totalToRefund, List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, 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(Map<String,List<com.broadleafcommerce.order.client.domain.ReturnConfirmation>> pendingReturnConfirmationsByFulfillmentId, 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(List<DefaultPaymentRefundService.PaymentWithRefundableAmount> paymentWithRefundableAmounts, com.broadleafcommerce.order.client.domain.ReturnConfirmation returnConfirmation, 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:
PaymentTransactionSourceEntityType
-
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
-
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(com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, javax.money.MonetaryAmount totalToRefund, 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
-
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
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()
-
-