Class ExternalPaymentTransactionCartFinalizationListener

java.lang.Object
com.broadleafcommerce.cartoperation.service.messaging.finalizecart.ExternalPaymentTransactionCartFinalizationListener

public class ExternalPaymentTransactionCartFinalizationListener extends Object
Message listener used to finalize carts that are in the DefaultCartStatuses.AWAITING_PAYMENT_FINALIZATION cart status. Prior to finalizing the cart, this listener first verifies that the cart's payments have successful checkout transactions matching the cart total. While it's expected that this validation is completed prior to sending a ExternalPaymentTransactionCartFinalizationEvent, this listener double-checks the validity of the cart finalization attempt.
Author:
Dima Myroniuk (dmyroniuk)
  • Constructor Details

  • Method Details

    • listen

      @StreamListener("externalPaymentTransactionCartFinalizationInput") public void listen(org.springframework.messaging.Message<ExternalPaymentTransactionCartFinalizationEvent> message)
    • process

      protected void process(@NonNull @NonNull org.springframework.messaging.Message<ExternalPaymentTransactionCartFinalizationEvent> message)
    • processCart

      protected void processCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that the cart's payments have successful checkout transactions that match the cart total. If so, attempts to finalize the cart.
      Parameters:
      cart - the Cart that is to be finalized
      contextInfo - context information related to multitenancy.
    • buildCheckoutProcessDto

      protected CheckoutProcessDto buildCheckoutProcessDto(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String checkoutRequestId, @NonNull @NonNull List<PaymentSummary> cartPayments, @NonNull @NonNull Map<String,String> paymentLockTokens)
    • finalizeCart

      protected void finalizeCart(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Finalizes the cart for checkout.
      Parameters:
      processDto - the CheckoutProcessDto to finalize
      contextInfo - context information around sandbox and multitenant state
    • paymentAmountsMatchCartTotal

      protected boolean paymentAmountsMatchCartTotal(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<PaymentSummary> cartPayments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Determines if all the payments for the given Cart add up to cart's total.

      If all the cart's payments have results but the amounts don't add up to cart's total, that means one or more payments failed, as failed transactions are excluded from the amounts in PaymentSummary.

      Parameters:
      cart - the Cart to check against
      cartPayments - the PaymentSummaries owned by the cart
      contextInfo - context information around sandbox and multitenant state
      Returns:
      true if all the payments for the given Cart match the cart's total, otherwise false
      Throws:
      UnsupportedOperationException - if the checkout transaction type is not supported
    • getCheckoutTransactionType

      protected String getCheckoutTransactionType(@NonNull @NonNull PaymentSummary paymentSummary, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Based on the provided PaymentSummary, determine which TransactionType should be used to execute the payment stage of the checkout.
      Parameters:
      paymentSummary - One of the cart's payment summaries
      Returns:
      The desired transaction type for the gateway
    • 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)
    • getLatestCheckoutRequestId

      protected String getLatestCheckoutRequestId(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
      Gets the latest checkout request id for the given Cart.
      Parameters:
      cart - the Cart to get the latest checkout request id from
      Returns:
      the latest checkout request id for the given Cart
    • buildUpdateContextInfoFromCart

      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildUpdateContextInfoFromCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
      Builds a ContextInfo with OperationType.UPDATE from the given Cart.

      This is useful to make requests for Cart in the correct context, since scheduled job itself doesn't have application context. This method makes it easier to achieve that rather than creating new endpoints for each operation to ignore application context.

      Parameters:
      cart - the Cart to build the context info from
      Returns:
      a ContextInfo with OperationType.UPDATE from the given Cart
    • buildContextInfoForUpdate

      @Nullable protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForUpdate(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfoForRead)
      Builds a ContextInfo object for OperationType.UPDATE
      Parameters:
      contextInfoForRead - the ContextInfo with OperationType.READ to build from
      Returns:
      a ContextInfo object for OperationType.UPDATE
    • unlockPayments

      protected void unlockPayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Sends a request to PaymentTransactionServices to unlock the cart's payments, based on the lock tokens that were previously obtained via PaymentProvider.lockAndRetrieveCartPayments(Cart, ContextInfo).
      Parameters:
      cart - The cart that owns the locked payments
      paymentLockTokens - The payment lock tokens that were obtained from PaymentProvider.lockAndRetrieveCartPayments(Cart, ContextInfo)
      contextInfo - The context of the user's request
    • getIdempotentMessageService

      protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getCartProvider

      protected CartProvider getCartProvider()
    • getPaymentProvider

      protected PaymentProvider<PaymentSummary> getPaymentProvider()
    • getCheckoutWorkflow

      protected CheckoutWorkflow getCheckoutWorkflow()
    • getCheckoutService

      protected CheckoutService getCheckoutService()
    • getCheckoutProperties

      protected CartOperationCheckoutProperties getCheckoutProperties()