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
ThisCheckoutWorkflowActivity
is responsible for validating that the cart includesPaymentSummaries
whose sum is equal toCartPricing.getTotal()
. Additionally, this activity is responsible for verifying transaction amounts that have been or should have been successfully executed previously. For example, ifCartOperationCheckoutProperties.isCheckoutTransactionExternalByGateway(String, String, String)
is true for this request, then this activity will verify that the PaymentSummary'sPaymentSummary.getAmountAuthorized()
orPaymentSummary.getAmountCaptured()
matches thePaymentSummary.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 thePaymentSummary.getAmountAuthorized()
orPaymentSummary.getAmountCaptured()
is either zero (requiring a transaction inPaymentTransactionExecutionActivity
) or equal to thePaymentSummary.getAmount()
.- Author:
- Chad Harchar (charchar), Chris Kittrell (ckittrell)
-
-
Constructor Summary
Constructors Constructor Description CartPaymentMethodValidationActivity(PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties properties, org.springframework.context.MessageSource messageSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
doesFeeCartItemExist(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 boolean
doFulfillmentExclusionsPassForCOD(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected boolean
doFulfillmentInclusionsPassForCOD(@NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
CheckoutProcessDto
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 String
getApplicationIdFromContext(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 CheckoutPaymentMethodService
getCheckoutPaymentMethodService()
protected String
getCheckoutTransactionType(@NonNull String gatewayType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Based on the providedPaymentGatewayType
, determine whichTransactionType
should be used to execute the payment stage of the checkout.protected CreditAccountTransactionExecutionProvider
getCreditAccountTransactionExecutionProvider()
protected String
getMessage(@NonNull String errorMessage, Object... args)
protected org.springframework.context.MessageSource
getMessageSource()
protected PaymentProvider<PaymentSummary>
getPaymentProvider()
protected CartOperationCheckoutProperties
getProperties()
protected com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService
getSpelRuleEvaluationService()
protected String
getTenantIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected boolean
hasCollectOnDeliveryPayments(@NonNull List<PaymentSummary> paymentSummaries)
protected boolean
hasValidAmountAuthorizedOrCaptured(@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 boolean
isCartMaxTotalAllowedForCOD(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected boolean
isCartMinTotalAllowedForCOD(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected boolean
isCollectOnDeliverySelected(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
Determines if any of theCart.getFulfillmentGroups()
has aDefaultCollectOnDeliveryStatus.SELECTED
status in theirFulfillmentGroup.getAttributes()
.protected boolean
isExternalTransactionExpected(@NonNull PaymentSummary paymentSummary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Based on the providedPaymentGatewayType
, determine if the expected transaction is external.protected boolean
isUsingCollectOnDelivery(com.broadleafcommerce.cart.client.domain.FulfillmentGroup fulfillmentGroup)
CheckoutProcessDto
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.void
setCheckoutPaymentMethodService(CheckoutPaymentMethodService checkoutPaymentMethodService)
void
setCreditAccountTransactionExecutionProvider(CreditAccountTransactionExecutionProvider creditAccountTransactionExecutionProvider)
void
setSpelRuleEvaluationService(com.broadleafcommerce.rulesengine.expression.service.SpelRuleEvaluationService spelRuleEvaluationService)
void
setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory)
protected void
validateCartHasActivePayment(@NonNull CheckoutProcessDto processDto)
Validate that the cart has at least one active payment.protected void
validateCollectOnDeliveryFees(@NonNull CheckoutProcessDto processDto, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void
validateCollectOnDeliveryFulfilmentInclusionsAndExclusions(@NonNull CheckoutProcessDto processDto, @NonNull com.broadleafcommerce.cart.client.domain.FulfillmentGroup codFulfillmentGroup, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void
validateCollectOnDeliveryMinAndMaxCartAmounts(@NonNull CheckoutProcessDto processDto, @NonNull CheckoutPaymentMethodOption codCheckoutPaymentMethodOption, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void
validateCollectOnDeliveryPaymentConfiguration(@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 void
validatePaymentAmount(@NonNull CheckoutProcessDto processDto)
Validate that each of thePaymentSummaries
are responsible for a zero or greater amount.protected void
validatePaymentAmountSum(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Validate that the sum of thePaymentSummary amounts
is equal to the cart total (CartPricing.getTotal()
).protected void
validatePaymentMethodAvailability(@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 void
validatePaymentTransactionAmountSums(@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 void
validateStoreCreditAccountBalanceIfNeeded(@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, wait
-
Methods inherited from interface com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.RequiresSecurePaymentInformationActivity
execute
-
-
-
-
Constructor Detail
-
CartPaymentMethodValidationActivity
public CartPaymentMethodValidationActivity(PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties properties, org.springframework.context.MessageSource messageSource)
-
-
Method Detail
-
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 interfaceRequiresSecurePaymentInformationActivity
- Parameters:
processDto
- TheCheckoutProcessDto
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 theCheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo)
method.- Specified by:
rollback
in interfaceCheckoutWorkflowActivity
- Parameters:
processDto
- TheCheckoutProcessDto
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 theCart.getFulfillmentGroups()
has aDefaultCollectOnDeliveryStatus.SELECTED
status in theirFulfillmentGroup.getAttributes()
.Any custom logic should be added here.
- Parameters:
cart
- theCart
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
- theCheckoutProcessDto
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
- theCheckoutProcessDto
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 thePaymentSummaries
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
- theCheckoutProcessDto
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 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 amounts
is equal to the cart total (CartPricing.getTotal()
).- Parameters:
processDto
- theCheckoutProcessDto
that 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
- theCheckoutProcessDto
that 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
- theCheckoutProcessDto
that 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 String gatewayType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Based on the providedPaymentGatewayType
, determine whichTransactionType
should be used to execute the payment stage of the checkout.- Parameters:
gatewayType
- The payment gateway's unique identifier that should be used to lookup the desired transaction typecontextInfo
- Context information around sandbox and multitenant state- Returns:
- The desired transaction type for the gateway
- See Also:
CartOperationCheckoutProperties.getCheckoutTransactionTypeByGateway(String, String, String)
-
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)
-
-