Class DefaultPaymentCaptureService

java.lang.Object
com.broadleafcommerce.orderoperation.service.payment.DefaultPaymentCaptureService
All Implemented Interfaces:
PaymentCaptureService

public class DefaultPaymentCaptureService extends Object implements PaymentCaptureService
  • Constructor Details

    • DefaultPaymentCaptureService

      public DefaultPaymentCaptureService(PaymentProvider paymentProvider)
  • 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 the Order'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 interface PaymentCaptureService
      Parameters:
      totalToCapture - The amount to claim and/or capture for the OrderFulfillment
      order - The order whose payments should be used to claim and/or capture the specified amount
      fulfillment - The fulfillment to claim and/or capture payment(s) for
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      the CaptureFulfillmentResult containing details about how the fulfillment was claimed and/or captured
    • autoCapturePaymentsIfNecessary

      public List<TransactionExecutionResponse> autoCapturePaymentsIfNecessary(com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentCaptureService
      This method is used to auto-capture payments for the gateway types specified in OrderOperationPaymentProperties.getAutoCapturePaymentGateways(String, String) list.
      Specified by:
      autoCapturePaymentsIfNecessary in interface PaymentCaptureService
      Parameters:
      order - The order whose payments should be used to capture the auto payment
      contextInfo - Context information around sandbox and multitenant state
      Returns:
      the TransactionExecutionResponses for all the capture transactions
    • 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 of ExecutablePayments representing PaymentSummaries that are available for claim or capture for the given Order.
      Parameters:
      order - the Order to build the ExecutablePayments for
      contextInfo - context information around sandbox and multitenant state
      Returns:
      a list of ExecutablePayments representing PaymentSummaries that are available for claim or capture for the given Order
    • 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 of PaymentExecutionRequests based on the Order.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 execute
      executablePayments - a list of ExecutablePayments containing the executable PaymentSummary along with its amount available to execute, sorted by payment priority
      order - the Order that the execution requests are related to
      contextInfo - context information around sandbox and multitenant state
      Returns:
      a list of PaymentExecutionRequests based on the Order.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 of PaymentExecutionRequests 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 execute
      executablePayments - a list of ExecutablePayments containing the executable PaymentSummary along with its amount available to execute, sorted by payment priority
      order - the Order that the execution requests are related to
      contextInfo - context information around sandbox and multitenant state
      Returns:
      a list of PaymentExecutionRequests based on the Order.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 given PaymentExecutionRequests.
      Parameters:
      paymentExecutionRequests - The PaymentExecutionRequests used to execute the capture transactions
      order - The order whose payments should be used to capture the specified amount
      fulfillment - The fulfillment to capture payment for
      contextInfo - 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 payments
      PaymentTransactionFailureException - If a payment capture transaction fails
    • getPaymentExecutionRequestsForAutoCapturing

      protected List<PaymentExecutionRequest> getPaymentExecutionRequestsForAutoCapturing(@NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • executeAutoCaptures

      protected List<TransactionExecutionResponse> executeAutoCaptures(@NonNull @NonNull List<PaymentExecutionRequest> executionRequestsForAutoCapturing, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • executeAutoCaptureTransaction

      protected TransactionExecutionResponse executeAutoCaptureTransaction(@NonNull @NonNull PaymentSummary paymentSummary, @NonNull @NonNull String lockToken, @NonNull @NonNull TransactionExecutionRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • 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 - The PaymentExecutionRequests containing requests to claim
      fulfillment - The fulfillment to claim the capture transactions for
      contextInfo - 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 captured
      contextInfo - 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 of FulfillmentCaptureClaimSummary by the payment id.
      Parameters:
      payments - The payments to get the claim summaries for
      contextInfo - 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

      @Deprecated(forRemoval=true) protected List<com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim> buildFulfillmentCaptureClaims(List<PaymentExecutionRequest> claimRequests, String fulfillmentId)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • buildFulfillmentCaptureClaims

      protected List<com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim> buildFulfillmentCaptureClaims(@NonNull @NonNull List<PaymentExecutionRequest> claimRequests, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment)
      Builds a list of FulfillmentCaptureClaims based on the given payment claim requests
      Parameters:
      claimRequests - a list of payment claim requests
      orderFulfillment - the OrderFulfillment that the claims are for
      Returns:
      a list of FulfillmentCaptureClaims based on the given payment claim requests
    • buildFulfillmentCaptureClaim

      @Deprecated(forRemoval=true) protected com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim buildFulfillmentCaptureClaim(@NonNull @NonNull String paymentId, @NonNull @NonNull javax.money.MonetaryAmount amountToClaim, String fulfillmentId)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • buildFulfillmentCaptureClaim

      protected com.broadleafcommerce.order.client.domain.FulfillmentCaptureClaim buildFulfillmentCaptureClaim(@NonNull @NonNull String paymentId, @NonNull @NonNull javax.money.MonetaryAmount amountToClaim, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment)
      Builds a FulfillmentCaptureClaim based on the given PaymentSummary and amount to claim.

      The deprecated buildFulfillmentCaptureClaim(String, MonetaryAmount, String) method is called for the sake of backward compatibility and ensure that customization is used, if any.

      Parameters:
      paymentId - the payment id to claim against
      amountToClaim - the MonetaryAmount to claim
      orderFulfillment - the OrderFulfillment that the claims are for
      Returns:
      a FulfillmentCaptureClaim based on the given PaymentSummary 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 captured
      contextInfo - 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 of ExecutablePayments, 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 of ExecutablePayments to sort
      contextInfo - 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 of PaymentSummaries, 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 of PaymentSummaries to sort based on capture priority
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      a new list representing the sorted result
    • sortPaymentsByPriority

      @Deprecated protected List<PaymentSummary> sortPaymentsByPriority(List<PaymentSummary> paymentSummaries)
      Deprecated.
      Given a list of PaymentSummaries, sorts them in order of which should be captured first. By default, the same list is returned.

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

      Parameters:
      paymentSummaries - the list of PaymentSummaries 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 capture
      remainingToCapture - 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 of Pair 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, 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 the TransactionExecutionResponse failed, a PaymentTransactionFailureException is thrown.

      Parameters:
      fulfillment - The fulfillment to capture payment for
      paymentSummary - The payment that is being captured
      lockToken - the token that owns the payment lock
      amountToCapture - The amount that should be captured against the provided authorize transaction
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      The TransactionExecutionResponse of the capture transaction
      Throws:
      PaymentTransactionFailureException - if one of the capture transactions fails
    • captureAmount

      protected TransactionExecutionResponse captureAmount(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull PaymentSummary paymentSummary, @NonNull @NonNull String lockToken, TransactionAmountDetails transactionAmountDetails, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Captures the amount specified against the provided payment.

      If one of the TransactionExecutionDetails in the TransactionExecutionResponse failed, a PaymentTransactionFailureException is thrown.

      Parameters:
      fulfillment - The fulfillment to capture payment for
      paymentSummary - The payment that is being captured
      lockToken - the token that owns the payment lock
      transactionAmountDetails - The amount that should be captured against the provided authorize transaction
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      The TransactionExecutionResponse of the capture transaction
      Throws:
      PaymentTransactionFailureException - if one of the capture transactions fails
    • getApplicationIdFromContext

      @Nullable protected String getApplicationIdFromContext(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getTenantIdFromContext

      @Nullable protected String getTenantIdFromContext(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getPaymentProvider

      protected PaymentProvider getPaymentProvider()
    • getPaymentPriorityStrategy

      protected PaymentPriorityStrategy getPaymentPriorityStrategy()
    • setPaymentPriorityStrategy

      @Autowired public void setPaymentPriorityStrategy(PaymentPriorityStrategy paymentPriorityStrategy)
    • getFulfillmentCaptureClaimProvider

      protected FulfillmentCaptureClaimProvider 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

      protected OrderOperationServiceProperties getOrderOperationServiceProperties()
    • setOrderOperationServiceProperties

      @Autowired public void setOrderOperationServiceProperties(OrderOperationServiceProperties orderOperationServiceProperties)
    • getPaymentDistributionService

      protected PaymentDistributionService getPaymentDistributionService()
    • setPaymentDistributionService

      @Autowired public void setPaymentDistributionService(PaymentDistributionService paymentDistributionService)
    • getOrderOperationPaymentProperties

      protected OrderOperationPaymentProperties getOrderOperationPaymentProperties()
    • setOrderOperationPaymentProperties

      @Autowired public void setOrderOperationPaymentProperties(OrderOperationPaymentProperties orderOperationPaymentProperties)