Class CartPaymentMethodValidationActivity
java.lang.Object
com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CartPaymentMethodValidationActivity
- All Implemented Interfaces:
CheckoutWorkflowActivity,RequiresSecurePaymentInformationActivity
public class CartPaymentMethodValidationActivity
extends Object
implements RequiresSecurePaymentInformationActivity
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 Summary
ConstructorsConstructorDescriptionCartPaymentMethodValidationActivity(PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties properties, org.springframework.context.MessageSource messageSource) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleandoesFeeCartItemExist(CheckoutPaymentMethodOption.FeeDto fee, @NonNull Map<String, List<com.broadleafcommerce.cart.client.domain.CartItem>> existingFeesByName, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected booleandoFulfillmentExclusionsPassForCOD(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected booleandoFulfillmentInclusionsPassForCOD(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) execute(@NonNull CheckoutProcessDto processDto, @NonNull Map<String, String> securityCodes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Method responsible for executing some work against the cart that requires secure payment information in checkout.protected StringgetApplicationIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<CheckoutPaymentMethodOption>getCheckoutPaymentMethodOptions(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected CheckoutPaymentMethodServiceprotected StringgetCheckoutTransactionType(@NonNull PaymentSummary paymentSummary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Based on the providedPaymentSummary, determine whichTransactionTypeshould be used to execute the payment stage of the checkout.protected StringgetCheckoutTransactionType(@NonNull String gatewayType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.protected StringgetMessage(@NonNull String errorMessage, Object... args) protected org.springframework.context.MessageSourceprotected PaymentProvider<PaymentSummary>protected CartOperationCheckoutPropertiesprotected com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationServiceprotected StringgetTenantIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanhasCollectOnDeliveryPayments(@NonNull List<PaymentSummary> paymentSummaries) protected booleanhasValidAmountAuthorizedOrCaptured(@NonNull javax.money.MonetaryAmount amountAuthorizedOrCapturedOrPending, @NonNull PaymentSummary paymentSummary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that the amount authorized or captured fully covers the payment total amount.protected booleanisCartMaxTotalAllowedForCOD(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected booleanisCartMinTotalAllowedForCOD(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected booleanisCollectOnDeliverySelected(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Determines if any of theCart.getFulfillmentGroups()has aDefaultCollectOnDeliveryStatus.SELECTEDstatus in theirFulfillmentGroup.getAttributes().protected booleanisExternalTransactionExpected(@NonNull PaymentSummary paymentSummary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Based on the providedPaymentGatewayType, determine if the expected transaction is external.protected booleanisUsingCollectOnDelivery(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup) rollback(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Method responsible for rolling back any work that was done during the execution of theCheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo)method.voidsetCheckoutPaymentMethodService(CheckoutPaymentMethodService checkoutPaymentMethodService) voidsetCreditAccountTransactionExecutionProvider(CreditAccountTransactionExecutionProvider creditAccountTransactionExecutionProvider) voidsetSpelRuleEvaluationService(com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService spelRuleEvaluationService) voidsetTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected voidvalidateCartHasActivePayment(@NonNull CheckoutProcessDto processDto) Validate that the cart has at least one active payment.protected voidvalidateCollectOnDeliveryFees(@NonNull CheckoutProcessDto processDto, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidvalidateCollectOnDeliveryFulfilmentInclusionsAndExclusions(@NonNull CheckoutProcessDto processDto, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup codFulfillmentGroup, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidvalidateCollectOnDeliveryMinAndMaxCartAmounts(@NonNull CheckoutProcessDto processDto, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidvalidateCollectOnDeliveryPaymentConfiguration(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validate that COD payments are valid and correctly configured in the cart context.protected voidvalidatePaymentAmount(@NonNull CheckoutProcessDto processDto) Validate that each of thePaymentSummariesare responsible for a zero or greater amount.protected voidvalidatePaymentAmountSum(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validate that the sum of thePaymentSummary amountsis equal to the cart total (CartPricing.getTotal()).protected voidvalidatePaymentMethodAvailability(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validate that the payments on the cart are available in the current context.protected voidvalidatePaymentTransactionAmountSums(@NonNull CheckoutProcessDto processDto, 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.protected voidvalidateStoreCreditAccountBalanceIfNeeded(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that the store credit account has sufficient funds if needed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.RequiresSecurePaymentInformationActivity
execute
-
Constructor Details
-
CartPaymentMethodValidationActivity
public CartPaymentMethodValidationActivity(PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties properties, org.springframework.context.MessageSource messageSource)
-
-
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:RequiresSecurePaymentInformationActivityMethod responsible for executing some work against the cart that requires secure payment information in checkout.- Specified by:
executein interfaceRequiresSecurePaymentInformationActivity- Parameters:
processDto- TheCheckoutProcessDtothat 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
CheckoutProcessDtofollowing 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:CheckoutWorkflowActivityMethod responsible for rolling back any work that was done during the execution of theCheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo)method.- Specified by:
rollbackin interfaceCheckoutWorkflowActivity- Parameters:
processDto- TheCheckoutProcessDtothat 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
CheckoutProcessDtofollowing the rollback of the activity.
-
isCollectOnDeliverySelected
protected boolean isCollectOnDeliverySelected(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Determines if any of theCart.getFulfillmentGroups()has aDefaultCollectOnDeliveryStatus.SELECTEDstatus in theirFulfillmentGroup.getAttributes().Any custom logic should be added here.
- Parameters:
cart- theCartbeing validated- Returns:
- true if the Collect on Delivery is selected, otherwise false
-
validateCartHasActivePayment
Validate that the cart has at least one active payment.- Parameters:
processDto- theCheckoutProcessDtothat 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- theCheckoutProcessDtothat 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
Validate that each of thePaymentSummariesare 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- theCheckoutProcessDtothat 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 withcontextInfo- 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 thePaymentSummary amountsis equal to the cart total (CartPricing.getTotal()).- Parameters:
processDto- theCheckoutProcessDtothat we're attempting to checkout withcontextInfo- 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- theCheckoutProcessDtothat we're attempting to checkout withcontextInfo- 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 resultpaymentSummary- the payment summarycontextInfo- 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- theCheckoutProcessDtothat we're attempting to checkout withcontextInfo- 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 providedPaymentGatewayType, determine if the expected transaction is external.- Parameters:
paymentSummary- the payment summarycontextInfo- 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 providedPaymentSummary, determine whichTransactionTypeshould be used to execute the payment stage of the checkout.- Parameters:
paymentSummary- One of the cart's payment summariescontextInfo- 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) Deprecated. -
getMessage
-
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
-
getProperties
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
getCheckoutPaymentMethodService
-
setCheckoutPaymentMethodService
@Autowired public void setCheckoutPaymentMethodService(CheckoutPaymentMethodService checkoutPaymentMethodService) -
setCreditAccountTransactionExecutionProvider
@Autowired public void setCreditAccountTransactionExecutionProvider(CreditAccountTransactionExecutionProvider 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)
-
getCheckoutTransactionType(PaymentSummary, ContextInfo)