Class DefaultPaymentCaptureService

    • Constructor Detail

      • DefaultPaymentCaptureService

        public DefaultPaymentCaptureService​(PaymentProvider paymentProvider)
    • Method Detail

      • captureFulfillmentTotal

        public List<TransactionExecutionResponse> captureFulfillmentTotal​(@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 capturing an amount from the Order's payments
        Specified by:
        captureFulfillmentTotal in interface PaymentCaptureService
        Parameters:
        order - The order whose payments should be used to captured 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
      • identifyAmountToCapturePerPayment

        protected List<org.springframework.data.util.Pair<PaymentSummary,​javax.money.MonetaryAmount>> identifyAmountToCapturePerPayment​(@NonNull
                                                                                                                                              @NonNull com.broadleafcommerce.order.client.domain.Order order,
                                                                                                                                              @NonNull
                                                                                                                                              @NonNull javax.money.MonetaryAmount totalToCapture,
                                                                                                                                              @Nullable
                                                                                                                                              com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Determine how the total to capture should be distributed among the order's payments.
        Parameters:
        order - The order whose payments should be captured
        totalToCapture - The total that should be captured for the order
        Returns:
        a list of Pair containers holding an authorized payment and the amount that should be captured against that payment
        Throws:
        PaymentCaptureException - if the order's payments can't cover the requested total to capture
      • 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
        Returns:
        The payment summaries that have some amount that is available to be captured
      • sortPaymentsByPriority

        protected List<PaymentSummary> sortPaymentsByPriority​(List<PaymentSummary> paymentSummaries)
        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,
                                                             @NonNull
                                                             @NonNull javax.money.MonetaryAmount amountToCapture,
                                                             @Nullable
                                                             com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Captures the amount specified against the provided payment.
        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 the capture transaction fails