Class ExternalPaymentTransactionResultListener

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

public class ExternalPaymentTransactionResultListener extends Object
Listens for PaymentTransactionResultEvents for transactions that were executed outside the Broadleaf ecosystem as part of a checkout interaction (e.g. some 3DS interactions and most HPP interactions). From there, it determines if the cart's payments have successful checkout transactions matching the cart total. If so, then an event is sent to finalize the cart. Note: This flow all requires that the cart status is DefaultCartStatuses.AWAITING_PAYMENT_FINALIZATION, which should have been declared with the initial checkout attempt.
Author:
mariestandeven
  • Field Details

    • idempotentMessageConsumptionService

      protected final com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageConsumptionService
    • typeFactory

      protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory
    • cartProvider

      protected final CartProvider cartProvider
    • paymentProvider

      protected final PaymentProvider<PaymentSummary> paymentProvider
    • checkoutProperties

      protected final CartOperationCheckoutProperties checkoutProperties
  • Constructor Details

    • ExternalPaymentTransactionResultListener

      public ExternalPaymentTransactionResultListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageConsumptionService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, CartProvider cartProvider, PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties checkoutProperties)
  • Method Details

    • listen

      @StreamListener("externalPaymentTransactionResultInput") public void listen(org.springframework.messaging.Message<PaymentTransactionResultEvent> message)
    • processMessage

      protected void processMessage(@NonNull @NonNull org.springframework.messaging.Message<PaymentTransactionResultEvent> message)
    • shouldProcessTransactionResult

      protected boolean shouldProcessTransactionResult(@NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • retrieveCart

      protected com.broadleafcommerce.cart.client.domain.Cart retrieveCart(@NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • shouldFinalizeCart

      protected boolean shouldFinalizeCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • checkIfTransactionTypeMatchesExpectedType

      protected boolean checkIfTransactionTypeMatchesExpectedType(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • cartPaymentAmountsMatchCartTotal

      protected boolean cartPaymentAmountsMatchCartTotal(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @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
      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 String gatewayType, @NonNull @NonNull String paymentType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • 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)
    • 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
    • getIdempotentMessageConsumptionService

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

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

      protected CartProvider getCartProvider()
    • getPaymentProvider

      protected PaymentProvider<PaymentSummary> getPaymentProvider()
    • getCheckoutProperties

      protected CartOperationCheckoutProperties getCheckoutProperties()