Class CartPaymentMethodValidationActivity
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CartPaymentMethodValidationActivity
-
- All Implemented Interfaces:
CheckoutWorkflowActivity
public class CartPaymentMethodValidationActivity extends Object implements CheckoutWorkflowActivity
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 com.broadleafcommerce.cart.client.domain.Cart
execute(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Method responsible for executing some work against the cart that is required for checkout.protected String
getApplicationIdFromContext(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 javax.money.CurrencyUnit
getCurrencyUnit(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected String
getMessage(@NonNull String errorMessage, Object... args)
protected org.springframework.context.MessageSource
getMessageSource()
protected PaymentProvider<PaymentSummary>
getPaymentProvider()
protected CartOperationCheckoutProperties
getProperties()
protected String
getTenantIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected javax.money.MonetaryAmount
getZeroAmount(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected javax.money.MonetaryAmount
getZeroAmount(@NonNull javax.money.CurrencyUnit currencyUnit)
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
isExternalTransactionExpected(@NonNull PaymentSummary paymentSummary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Based on the providedPaymentGatewayType
, determine if the expected transaction is external.com.broadleafcommerce.cart.client.domain.Cart
rollback(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Method responsible for rolling back any work that was done during the execution of the#execute(Cart, String)
method.void
setCheckoutPaymentMethodService(CheckoutPaymentMethodService checkoutPaymentMethodService)
protected void
validateCartHasActivePayment(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<PaymentSummary> paymentSummaries)
Validate that the cart has at least one active payment.protected void
validatePaymentAmount(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<PaymentSummary> paymentSummaries)
Validate that each of thePaymentSummaries
are responsible for a zero or greater amount.protected void
validatePaymentAmountSum(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<PaymentSummary> paymentSummaries, 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 com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<PaymentSummary> paymentSummaries, 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 com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<PaymentSummary> paymentSummaries, 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.
-
-
-
Constructor Detail
-
CartPaymentMethodValidationActivity
public CartPaymentMethodValidationActivity(PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties properties, org.springframework.context.MessageSource messageSource)
-
-
Method Detail
-
execute
public com.broadleafcommerce.cart.client.domain.Cart execute(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CheckoutWorkflowActivity
Method responsible for executing some work against the cart that is required for checkout. This may include, but is not limited to, cart validation checks, inventory reservations, or payment authorizations.- Specified by:
execute
in interfaceCheckoutWorkflowActivity
- Parameters:
cart
- TheCart
that we're attempting to checkout with.requestId
- The id used to identify changes tied to the specific execution requestcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- The final state of the cart following the execution of the activity.
-
rollback
public com.broadleafcommerce.cart.client.domain.Cart rollback(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @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#execute(Cart, String)
method.- Specified by:
rollback
in interfaceCheckoutWorkflowActivity
- Parameters:
cart
- TheCart
that we were attempting to checkout with, but ran into an exception/error.requestId
- The id used to identify changes tied to the specific execution requestcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- The final state of the cart following the rollback of the activity.
-
validateCartHasActivePayment
protected void validateCartHasActivePayment(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<PaymentSummary> paymentSummaries)
Validate that the cart has at least one active payment.- Parameters:
cart
- theCart
that we're attempting to checkout withpaymentSummaries
- the payment summaries for the specified cart
-
validatePaymentMethodAvailability
protected void validatePaymentMethodAvailability(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<PaymentSummary> paymentSummaries, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Validate that the payments on the cart are available in the current context.- Parameters:
cart
- theCart
that we're attempting to checkout withpaymentSummaries
- the payment summaries for the specified cart
-
validatePaymentAmount
protected void validatePaymentAmount(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<PaymentSummary> paymentSummaries)
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 product that is charged nothing up front and the actual bill amount is determined by usage at a later date).- Parameters:
cart
- theCart
that we're attempting to checkout withpaymentSummaries
- the payment summaries for the specified cart
-
validatePaymentAmountSum
protected void validatePaymentAmountSum(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<PaymentSummary> paymentSummaries, @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:
cart
- theCart
that we're attempting to checkout withpaymentSummaries
- the payment summaries for the specified cartcontextInfo
- context information around sandbox and multitenant state
-
validatePaymentTransactionAmountSums
protected void validatePaymentTransactionAmountSums(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<PaymentSummary> paymentSummaries, @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:
cart
- theCart
that we're attempting to checkout withpaymentSummaries
- the payment summaries for the specified cartcontextInfo
- 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
-
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)
-
getZeroAmount
protected javax.money.MonetaryAmount getZeroAmount(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
getCurrencyUnit
@NonNull protected javax.money.CurrencyUnit getCurrencyUnit(com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
getZeroAmount
@NonNull protected javax.money.MonetaryAmount getZeroAmount(@NonNull @NonNull javax.money.CurrencyUnit currencyUnit)
-
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)
-
-