Class DefaultPaymentCaptureService
- All Implemented Interfaces:
PaymentCaptureService
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected List<PaymentExecutionRequest>
buildFromPaymentDistributionDetails
(@NonNull javax.money.MonetaryAmount totalToExecute, @NonNull List<ExecutablePayment> executablePayments, @NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a list ofPaymentExecutionRequests
based on theOrder.getPaymentDistributionDetails()
.protected List<PaymentExecutionRequest>
buildFromPaymentPriority
(@NonNull javax.money.MonetaryAmount totalToExecute, @NonNull List<ExecutablePayment> executablePayments, @NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a list ofPaymentExecutionRequests
based on the payment priority.protected com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim
buildFulfillmentCaptureClaim
(@NonNull String paymentId, @NonNull javax.money.MonetaryAmount amountToClaim, String fulfillmentId) Builds aFulfillmentCaptureClaim
based on the givenPaymentSummary
and amount to claim.protected List<com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim>
buildFulfillmentCaptureClaims
(List<PaymentExecutionRequest> claimRequests, String fulfillmentId) Builds a list ofFulfillmentCaptureClaims
based on the givenpayment claim requests
protected PaymentExecutionRequest
buildPaymentExecutionRequest
(@NonNull ExecutablePayment executablePayment, @NonNull javax.money.MonetaryAmount amountToExecute, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<PaymentExecutionRequest>
buildPaymentExecutionRequests
(@NonNull javax.money.MonetaryAmount totalToExecute, @NonNull List<ExecutablePayment> executablePayments, @NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected TransactionExecutionResponse
captureAmount
(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull PaymentSummary paymentSummary, @NonNull String lockToken, @NonNull javax.money.MonetaryAmount amountToCapture, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Captures the amount specified against the provided payment.protected List<com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim>
claimAlreadyCapturedAmountsIfPossible
(@NonNull List<PaymentExecutionRequest> executionRequests, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Claims capture transactions that were executed during the checkout flow (AuthAndCapture checkout transaction type) if possible.claimAndCaptureFulfillment
(@NonNull javax.money.MonetaryAmount totalToCapture, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Responsible for claiming and/or capturing an amount from theOrder's
payments.protected List<TransactionExecutionResponse>
executeCaptures
(@NonNull List<PaymentExecutionRequest> paymentExecutionRequests, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Executes capture transactions based on the givenPaymentExecutionRequests
.protected javax.money.MonetaryAmount
getAmountAvailableForCapture
(@NonNull PaymentSummary payment) Determines the amount that can be captured for this paymentprotected javax.money.MonetaryAmount
getAmountToCapture
(@NonNull PaymentSummary payment, @NonNull javax.money.MonetaryAmount remainingToCapture) Based on the payment & the remaining to capture, return the amount that should be captured for this paymentprotected javax.money.MonetaryAmount
getAmountToExecute
(@NonNull javax.money.MonetaryAmount totalToExecute, @NonNull ExecutablePayment executablePayment) protected javax.money.MonetaryAmount
getClaimableAmount
(@NonNull PaymentSummary payment, com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaimSummary claimSummary) protected <P extends PaymentSummary>
Map<String,com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaimSummary> getClaimSummaryByPaymentId
(@NonNull List<P> payments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets a map ofFulfillmentCaptureClaimSummary
by the payment id.protected List<ExecutablePayment>
getExecutablePayments
(@NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a sorted list ofExecutablePayments
representingPaymentSummaries
that are available for claim or capture for the givenOrder
.protected FulfillmentCaptureClaimProvider
protected OrderOperationServiceProperties
protected PaymentDistributionService
getPaymentIds
(List<org.springframework.data.util.Pair<PaymentSummary, javax.money.MonetaryAmount>> amountToCapturePerPayment) Gets a list of payment ids from the given list of amounts to capture per payment.protected PaymentPriorityStrategy
protected PaymentProvider
protected List<PaymentSummary>
getPaymentsWithAmountAvailableForCapture
(@NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Identifies the order's payments that have some amount that is available to be captured.protected List<PaymentSummary>
getPaymentsWithAmountAvailableToClaim
(@NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the order's payments that have some amount that is available to be claimed.protected com.broadleafcommerce.common.extension.TypeFactory
void
setFulfillmentCaptureClaimProvider
(FulfillmentCaptureClaimProvider fulfillmentCaptureClaimProvider) void
setOrderOperationServiceProperties
(OrderOperationServiceProperties orderOperationServiceProperties) void
setPaymentDistributionService
(PaymentDistributionService paymentDistributionService) void
setPaymentPriorityStrategy
(PaymentPriorityStrategy paymentPriorityStrategy) void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected List<ExecutablePayment>
sortExecutablePaymentsByPriority
(List<ExecutablePayment> executablePayments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Given a list ofExecutablePayments
, sorts them in order of which should be captured first.protected List<PaymentSummary>
sortPaymentsByPriority
(List<PaymentSummary> paymentSummaries) Deprecated.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 captured first.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.orderoperation.service.payment.PaymentCaptureService
captureFulfillment, captureFulfillmentTotal
-
Constructor Details
-
DefaultPaymentCaptureService
-
-
Method Details
-
claimAndCaptureFulfillment
public CaptureFulfillmentResult claimAndCaptureFulfillment(@NonNull @NonNull javax.money.MonetaryAmount totalToCapture, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentCaptureService
Responsible for claiming and/or capturing an amount from theOrder's
payments.If there are payments already captured during the checkout flow, meaning the checkout transaction type was
DefaultTransactionTypes.AUTHORIZE_AND_CAPTURE
, this method will claim those captured amounts instead of executing unnecessary capture transactions.In a multi-payment scenario with different checkout transaction types, there may be a mixture of claiming and executing the capture transactions for a single
OrderFulfillment
.- Specified by:
claimAndCaptureFulfillment
in interfacePaymentCaptureService
- Parameters:
totalToCapture
- The amount to claim and/or capture for theOrderFulfillment
order
- The order whose payments should be used to claim and/or capture the specified amountfulfillment
- The fulfillment to claim and/or capture payment(s) forcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- the
CaptureFulfillmentResult
containing details about how the fulfillment was claimed and/or captured
-
getExecutablePayments
protected List<ExecutablePayment> getExecutablePayments(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a sorted list ofExecutablePayments
representingPaymentSummaries
that are available for claim or capture for the givenOrder
.- Parameters:
order
- theOrder
to build theExecutablePayments
forcontextInfo
- context information around sandbox and multitenant state- Returns:
- a list of
ExecutablePayments
representingPaymentSummaries
that are available for claim or capture for the givenOrder
-
buildPaymentExecutionRequests
protected List<PaymentExecutionRequest> buildPaymentExecutionRequests(@NonNull @NonNull javax.money.MonetaryAmount totalToExecute, @NonNull @NonNull List<ExecutablePayment> executablePayments, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
buildFromPaymentDistributionDetails
protected List<PaymentExecutionRequest> buildFromPaymentDistributionDetails(@NonNull @NonNull javax.money.MonetaryAmount totalToExecute, @NonNull @NonNull List<ExecutablePayment> executablePayments, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a list ofPaymentExecutionRequests
based on theOrder.getPaymentDistributionDetails()
.This will always execute a payment transaction for each payment based on its distribution, regardless the total amount to execute.
- Parameters:
totalToExecute
- the total to executeexecutablePayments
- a list ofExecutablePayments
containing the executablePaymentSummary
along with its amount available to execute, sorted by payment priorityorder
- theOrder
that the execution requests are related tocontextInfo
- context information around sandbox and multitenant state- Returns:
- a list of
PaymentExecutionRequests
based on theOrder.getPaymentDistributionDetails()
-
buildFromPaymentPriority
protected List<PaymentExecutionRequest> buildFromPaymentPriority(@NonNull @NonNull javax.money.MonetaryAmount totalToExecute, @NonNull @NonNull List<ExecutablePayment> executablePayments, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds a list ofPaymentExecutionRequests
based on the payment priority.This will capture/claim as much as possible for each payment based on its available amount, to minimize the total number of payment executions.
- Parameters:
totalToExecute
- the total to executeexecutablePayments
- a list ofExecutablePayments
containing the executablePaymentSummary
along with its amount available to execute, sorted by payment priorityorder
- theOrder
that the execution requests are related tocontextInfo
- context information around sandbox and multitenant state- Returns:
- a list of
PaymentExecutionRequests
based on theOrder.getPaymentDistributionDetails()
-
buildPaymentExecutionRequest
protected PaymentExecutionRequest buildPaymentExecutionRequest(@NonNull @NonNull ExecutablePayment executablePayment, @NonNull @NonNull javax.money.MonetaryAmount amountToExecute, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getAmountToExecute
protected javax.money.MonetaryAmount getAmountToExecute(@NonNull @NonNull javax.money.MonetaryAmount totalToExecute, @NonNull @NonNull ExecutablePayment executablePayment) -
executeCaptures
protected List<TransactionExecutionResponse> executeCaptures(@NonNull @NonNull List<PaymentExecutionRequest> paymentExecutionRequests, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Executes capture transactions based on the givenPaymentExecutionRequests
.- Parameters:
paymentExecutionRequests
- ThePaymentExecutionRequests
used to execute the capture transactionsorder
- The order whose payments should be used to capture the specified amountfulfillment
- The fulfillment to capture payment forcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- the
TransactionExecutionResponses
for all the capture transactions - Throws:
PaymentCaptureException
- If the totalToCapture is too high and cannot be handled by the order's paymentsPaymentTransactionFailureException
- If a payment capture transaction fails
-
claimAlreadyCapturedAmountsIfPossible
protected List<com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim> claimAlreadyCapturedAmountsIfPossible(@NonNull @NonNull List<PaymentExecutionRequest> executionRequests, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Claims capture transactions that were executed during the checkout flow (AuthAndCapture checkout transaction type) if possible.Note that only payments with captured amounts with the matching
Order.getCheckoutRequestId()
are considered claimable.- Parameters:
executionRequests
- ThePaymentExecutionRequests
containing requests to claimfulfillment
- The fulfillment to claim the capture transactions forcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- a list of
FulfillmentCaptureClaims
representing the amounts that have been claimed
-
getPaymentsWithAmountAvailableToClaim
protected List<PaymentSummary> getPaymentsWithAmountAvailableToClaim(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the order's payments that have some amount that is available to be claimed.This method retrieves payments with checkout-executed capture transactions, meaning the checkout transaction type was
DefaultTransactionTypes.AUTHORIZE_AND_CAPTURE
, so that we can claim already-executed capture amounts rather than executing unnecessary capture transactions.- Parameters:
order
- the order whose payments should be capturedcontextInfo
- context information around sandbox and multitenant state- Returns:
- the payment summaries that have some amount that is available to be claimed
-
getClaimSummaryByPaymentId
protected <P extends PaymentSummary> Map<String,com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaimSummary> getClaimSummaryByPaymentId(@NonNull @NonNull List<P> payments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets a map ofFulfillmentCaptureClaimSummary
by the payment id.- Parameters:
payments
- The payments to get the claim summaries forcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- a map of
FulfillmentCaptureClaimSummary
by the payment id
-
getClaimableAmount
protected javax.money.MonetaryAmount getClaimableAmount(@NonNull @NonNull PaymentSummary payment, @Nullable com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaimSummary claimSummary) -
buildFulfillmentCaptureClaims
protected List<com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim> buildFulfillmentCaptureClaims(List<PaymentExecutionRequest> claimRequests, String fulfillmentId) Builds a list ofFulfillmentCaptureClaims
based on the givenpayment claim requests
- Parameters:
claimRequests
- a list ofpayment claim requests
fulfillmentId
- theOrderFulfillment.getId()
that the claims are for- Returns:
- a list of
FulfillmentCaptureClaims
based on the givenpayment claim requests
-
buildFulfillmentCaptureClaim
protected com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim buildFulfillmentCaptureClaim(@NonNull @NonNull String paymentId, @NonNull @NonNull javax.money.MonetaryAmount amountToClaim, String fulfillmentId) Builds aFulfillmentCaptureClaim
based on the givenPaymentSummary
and amount to claim.- Parameters:
paymentId
- the payment id to claim againstamountToClaim
- theMonetaryAmount
to claimfulfillmentId
- theOrderFulfillment.getId()
that the claims are for- Returns:
- a
FulfillmentCaptureClaim
based on the givenPaymentSummary
and amount to claim
-
getPaymentsWithAmountAvailableForCapture
protected List<PaymentSummary> getPaymentsWithAmountAvailableForCapture(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Identifies the order's payments that have some amount that is available to be captured.- Parameters:
order
- The order whose payments should be capturedcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- The payment summaries that have some amount that is available to be captured
-
sortExecutablePaymentsByPriority
protected List<ExecutablePayment> sortExecutablePaymentsByPriority(List<ExecutablePayment> executablePayments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Given a list ofExecutablePayments
, sorts them in order of which should be captured first.Any custom logic for capture payment priority should be added here.
- Parameters:
executablePayments
- the list ofExecutablePayments
to sortcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- a new list representing the sorted result
-
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 captured first.Any custom logic for capture payment priority should be added here.
- Parameters:
paymentSummaries
- the list ofPaymentSummaries
to sort based on capture 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 captured first. By default, the same list is returned.Any custom logic for capture payment priority should be added here.
- Parameters:
paymentSummaries
- the list ofPaymentSummaries
to sort based on capture priority- Returns:
- a new list representing the sorted result
-
getAmountToCapture
protected javax.money.MonetaryAmount getAmountToCapture(@NonNull @NonNull PaymentSummary payment, @NonNull @NonNull javax.money.MonetaryAmount remainingToCapture) Based on the payment & the remaining to capture, return the amount that should be captured for this payment- Parameters:
payment
- The authorized payment that we're considering for captureremainingToCapture
- The remaining total for the order that should be captured- Returns:
- The amount that should be captured for this payment
-
getAmountAvailableForCapture
protected javax.money.MonetaryAmount getAmountAvailableForCapture(@NonNull @NonNull PaymentSummary payment) Determines the amount that can be captured for this payment- Parameters:
payment
- The authorized payment that is a candidate for capture- Returns:
- The payment's amount that is available for capture
-
getPaymentIds
protected List<String> getPaymentIds(List<org.springframework.data.util.Pair<PaymentSummary, javax.money.MonetaryAmount>> amountToCapturePerPayment) Gets a list of payment ids from the given list of amounts to capture per payment.- Parameters:
amountToCapturePerPayment
- a list ofPair
containers holding an authorized payment and the amount that should be captured against that payment- Returns:
- a list of payment ids
-
captureAmount
protected TransactionExecutionResponse captureAmount(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull PaymentSummary paymentSummary, @NonNull @NonNull String lockToken, @NonNull @NonNull javax.money.MonetaryAmount amountToCapture, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Captures the amount specified against the provided payment.If one of the
TransactionExecutionDetails
in theTransactionExecutionResponse
failed, aPaymentTransactionFailureException
is thrown.- Parameters:
fulfillment
- The fulfillment to capture payment forpaymentSummary
- The payment that is being capturedlockToken
- the token that owns the payment lockamountToCapture
- The amount that should be captured against the provided authorize transactioncontextInfo
- Context information around sandbox and multitenant state.- Returns:
- The
TransactionExecutionResponse
of the capture transaction - Throws:
PaymentTransactionFailureException
- if one of the capture transactions fails
-
getPaymentProvider
-
getPaymentPriorityStrategy
-
setPaymentPriorityStrategy
-
getFulfillmentCaptureClaimProvider
-
setFulfillmentCaptureClaimProvider
@Autowired public void setFulfillmentCaptureClaimProvider(FulfillmentCaptureClaimProvider fulfillmentCaptureClaimProvider) -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
getOrderOperationServiceProperties
-
setOrderOperationServiceProperties
@Autowired public void setOrderOperationServiceProperties(OrderOperationServiceProperties orderOperationServiceProperties) -
getPaymentDistributionService
-
setPaymentDistributionService
@Autowired public void setPaymentDistributionService(PaymentDistributionService paymentDistributionService)
-
sortPaymentsByPriority(List, ContextInfo)