Class CartPaymentMethodValidationActivity

java.lang.Object
com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CartPaymentMethodValidationActivity
All Implemented Interfaces:
CheckoutWorkflowActivity, PaymentFinalizationActivity, RequiresSecurePaymentInformationActivity

public class CartPaymentMethodValidationActivity extends Object implements RequiresSecurePaymentInformationActivity, PaymentFinalizationActivity
This CheckoutWorkflowActivity is responsible for validating that the cart includes PaymentSummaries whose sum is equal to CartPricing.getTotal(). Additionally, this activity is responsible for verifying transaction amounts that have been or should have been successfully executed previously. For example, if CartOperationCheckoutProperties.isCheckoutTransactionExternalByGateway(String, String, String) is true for this request, then this activity will verify that the PaymentSummary's PaymentSummary.getAmountAuthorized() or PaymentSummary.getAmountCaptured() matches the PaymentSummary.getAmount(). Alternatively, if a second checkout attempt is being processed, and a transaction was successfully executed with the first checkout attempt, then this activity will validate that the PaymentSummary.getAmountAuthorized() or PaymentSummary.getAmountCaptured() is either zero (requiring a transaction in PaymentTransactionExecutionActivity) or equal to the PaymentSummary.getAmount().
Author:
Chad Harchar (charchar), Chris Kittrell (ckittrell)
  • Constructor Details

  • Method Details

    • execute

      public CheckoutProcessDto execute(@NonNull @NonNull CheckoutProcessDto processDto, @NonNull @NonNull Map<String,String> securityCodes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: RequiresSecurePaymentInformationActivity
      Method responsible for executing some work against the cart that requires secure payment information in checkout.
      Specified by:
      execute in interface RequiresSecurePaymentInformationActivity
      Parameters:
      processDto - The CheckoutProcessDto that we're attempting to checkout with.
      securityCodes - Secure codes that are passed to the gateway for verification during authorization or capture transactions.
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      The final state of the CheckoutProcessDto following the execution of the activity.
    • rollback

      public CheckoutProcessDto rollback(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CheckoutWorkflowActivity
      Method responsible for rolling back any work that was done during the execution of the CheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo) method.
      Specified by:
      rollback in interface CheckoutWorkflowActivity
      Parameters:
      processDto - The CheckoutProcessDto that we were attempting to checkout with, but ran into an exception/error.
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      The final state of the CheckoutProcessDto following the rollback of the activity.
    • isCollectOnDeliverySelected

      protected boolean isCollectOnDeliverySelected(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
      Determines if any of the Cart.getFulfillmentGroups() has a DefaultCollectOnDeliveryStatus.SELECTED status in their FulfillmentGroup.getAttributes().

      Any custom logic should be added here.

      Parameters:
      cart - the Cart being validated
      Returns:
      true if the Collect on Delivery is selected, otherwise false
    • validateCartHasActivePayment

      protected void validateCartHasActivePayment(@NonNull @NonNull CheckoutProcessDto processDto)
      Validate that the cart has at least one active payment.
      Parameters:
      processDto - the CheckoutProcessDto that we're attempting to checkout with
    • validatePaymentMethodAvailability

      protected void validatePaymentMethodAvailability(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validate that the payments on the cart are available in the current context.
      Parameters:
      processDto - the CheckoutProcessDto that we're attempting to checkout with
    • getCheckoutPaymentMethodOptions

      protected List<CheckoutPaymentMethodOption> getCheckoutPaymentMethodOptions(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validatePaymentAmount

      protected void validatePaymentAmount(@NonNull @NonNull CheckoutProcessDto processDto)
      Validate that each of the PaymentSummaries are responsible for a zero or greater amount. In some cases, a zero amount may be useful to signify a tokenized payment to be used in future billing (e.g. a free trial offer that allows an order to be placed with zero up front and billed the full amount after the trial expires or a "post-paid" plan cart item that is charged nothing up front and the actual bill amount is determined by usage at a later date).
      Parameters:
      processDto - the CheckoutProcessDto that we're attempting to checkout with
    • validateCollectOnDeliveryPaymentConfiguration

      protected void validateCollectOnDeliveryPaymentConfiguration(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validate that COD payments are valid and correctly configured in the cart context.
      Parameters:
      processDto - the information (cart, payments, etc.) that we're attempting to checkout with
      contextInfo - context information related to multitenancy
    • isUsingCollectOnDelivery

      protected boolean isUsingCollectOnDelivery(@Nullable com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup)
    • validateCollectOnDeliveryFees

      protected void validateCollectOnDeliveryFees(@NonNull @NonNull CheckoutProcessDto processDto, @NonNull @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateCollectOnDeliveryMinAndMaxCartAmounts

      protected void validateCollectOnDeliveryMinAndMaxCartAmounts(@NonNull @NonNull CheckoutProcessDto processDto, @NonNull @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateCollectOnDeliveryFulfilmentInclusionsAndExclusions

      protected void validateCollectOnDeliveryFulfilmentInclusionsAndExclusions(@NonNull @NonNull CheckoutProcessDto processDto, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup codFulfillmentGroup, @NonNull @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • doesFeeCartItemExist

      protected boolean doesFeeCartItemExist(@NonNull CheckoutPaymentMethodOption.FeeDto fee, @NonNull @NonNull Map<String,List<com.broadleafcommerce.cart.client.domain.CartItem>> existingFeesByName, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • isCartMaxTotalAllowedForCOD

      protected boolean isCartMaxTotalAllowedForCOD(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • isCartMinTotalAllowedForCOD

      protected boolean isCartMinTotalAllowedForCOD(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • doFulfillmentExclusionsPassForCOD

      protected boolean doFulfillmentExclusionsPassForCOD(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • doFulfillmentInclusionsPassForCOD

      protected boolean doFulfillmentInclusionsPassForCOD(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • hasCollectOnDeliveryPayments

      protected boolean hasCollectOnDeliveryPayments(@NonNull @NonNull List<PaymentSummary> paymentSummaries)
    • validatePaymentAmountSum

      protected void validatePaymentAmountSum(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validate that the sum of the PaymentSummary amounts is equal to the cart total (CartPricing.getTotal()).
      Parameters:
      processDto - the CheckoutProcessDto that we're attempting to checkout with
      contextInfo - context information around sandbox and multitenant state
    • validatePaymentTransactionAmountSums

      protected void validatePaymentTransactionAmountSums(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that the sum of authorized/captured amount of the successful transactions equal to the payment amount.
      Parameters:
      processDto - the CheckoutProcessDto that we're attempting to checkout with
      contextInfo - context information around sandbox and multitenant state
    • hasValidAmountAuthorizedOrCaptured

      protected boolean hasValidAmountAuthorizedOrCaptured(@NonNull @NonNull javax.money.MonetaryAmount amountAuthorizedOrCapturedOrPending, @NonNull @NonNull PaymentSummary paymentSummary, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that the amount authorized or captured fully covers the payment total amount.
      Parameters:
      amountAuthorizedOrCapturedOrPending - the amount authorized or captured or awaiting capture result
      paymentSummary - the payment summary
      contextInfo - context information around sandbox and multitenant state
      Returns:
      true if the amount authorized or captured fully covers the payment total amount, false otherwise
    • validateStoreCreditAccountBalanceIfNeeded

      protected void validateStoreCreditAccountBalanceIfNeeded(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that the store credit account has sufficient funds if needed.
      Parameters:
      processDto - the CheckoutProcessDto that we're attempting to checkout with
      contextInfo - context information related to multitenancy
    • isExternalTransactionExpected

      protected boolean isExternalTransactionExpected(@NonNull @NonNull PaymentSummary paymentSummary, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Based on the provided PaymentGatewayType, determine if the expected transaction is external.
      Parameters:
      paymentSummary - the payment summary
      contextInfo - context information around sandbox and multitenant state
    • 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
      contextInfo - Context information around sandbox and multitenant state
      Returns:
      The desired transaction type for the gateway
      See Also:
    • getCheckoutTransactionType

      @Deprecated protected String getCheckoutTransactionType(@NonNull @NonNull String gatewayType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getMessage

      protected String getMessage(@NonNull @NonNull String errorMessage, @Nullable Object... args)
    • 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<PaymentSummary> getPaymentProvider()
    • getProperties

      protected CartOperationCheckoutProperties getProperties()
    • getMessageSource

      protected org.springframework.context.MessageSource getMessageSource()
    • getCheckoutPaymentMethodService

      protected CheckoutPaymentMethodService getCheckoutPaymentMethodService()
    • setCheckoutPaymentMethodService

      @Autowired public void setCheckoutPaymentMethodService(CheckoutPaymentMethodService checkoutPaymentMethodService)
    • setCreditAccountTransactionExecutionProvider

      @Autowired public void setCreditAccountTransactionExecutionProvider(CreditAccountTransactionExecutionProvider creditAccountTransactionExecutionProvider)
    • getCreditAccountTransactionExecutionProvider

      protected CreditAccountTransactionExecutionProvider getCreditAccountTransactionExecutionProvider()
    • getTypeFactory

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

      @Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
    • getSpelRuleEvaluationService

      protected com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService getSpelRuleEvaluationService()
    • setSpelRuleEvaluationService

      @Autowired public void setSpelRuleEvaluationService(com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService spelRuleEvaluationService)