Class DefaultCheckoutService
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.checkout.DefaultCheckoutService
-
- All Implemented Interfaces:
CheckoutService
public class DefaultCheckoutService extends Object implements CheckoutService
Default implementation of theCheckoutService
that is responsible for processing checkout requests- Author:
- Chad Harchar (charchar), Chris Kittrell (ckittrell)
-
-
Constructor Summary
Constructors Constructor Description DefaultCheckoutService(CartStatusValidationHelper cartStatusValidationHelper, CheckoutWorkflow checkoutWorkflow, CartProvider cartProvider, com.broadleafcommerce.common.messaging.checkout.CheckoutCompletionProducer checkoutCompletionProducer, ExternalCartProperties externalCartProperties, PaymentProvider<PaymentSummary> paymentProvider, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
addCartLinks(com.broadleafcommerce.cart.client.domain.CheckoutCart checkoutCart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected CheckoutResponse
buildFailedCheckoutResponse(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, @NonNull CheckoutException e, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected CheckoutResponse
buildFailedCheckoutResponse(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, @NonNull CheckoutWorkflowException e, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Deprecated.protected CheckoutResponse
buildFailedCheckoutResponse(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, @NonNull PaymentLockException e, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected CheckoutResponse
buildSuccessfulCheckoutResponse(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected String
createOrderNumber(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
Creates a new order number for a submitted cart.protected com.broadleafcommerce.cart.client.domain.Cart
finalizeCart(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Map<String,String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Following a successful checkout, this method is responsible for recording the finalized state of the cart.protected void
finalizePayments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Map<String,String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected com.broadleafcommerce.cart.client.domain.CartLink
getCartItemLink(com.broadleafcommerce.cart.client.domain.CheckoutCart checkoutCart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected CartProvider
getCartProvider()
protected CartStatusValidationHelper
getCartStatusValidationHelper()
protected com.broadleafcommerce.common.messaging.checkout.CheckoutCompletionProducer
getCheckoutCompletionProducer()
protected CheckoutWorkflow
getCheckoutWorkflow()
protected ExternalCartProperties
getExternalCartProperties()
protected com.broadleafcommerce.cart.client.domain.CartLink
getFulfillmentGroupLink(com.broadleafcommerce.cart.client.domain.CheckoutCart checkoutCart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected String
getMessage(@NonNull String errorMessage, Object... args)
protected org.springframework.retry.support.RetryTemplate
getMessageRetryTemplate()
protected org.springframework.context.MessageSource
getMessageSource()
protected PaymentProvider<PaymentSummary>
getPaymentProvider()
protected StaleCartItemsService
getStaleCartItemsService()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected Map<String,String>
lockPayments(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Sends request to PaymentTransactionServices to lock the cart's related payments.protected com.broadleafcommerce.cart.client.domain.Cart
prepareCartForCheckout(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Updates the cart with the checkout request ID and status for checkoutCheckoutResponse
processCheckout(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, @NonNull Map<String,String> securityCodes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Process checkout against the provided cartprotected com.broadleafcommerce.cart.client.domain.Cart
removeStaleCartItems(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Map<String,String> paymentLockTokens, @NonNull CheckoutException e, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
RemovesCartItems
from theCart
that can no longer be found in the catalog & reprices the cart.protected void
sendCheckoutCompletionMessage(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Send a message to notify external services (and internal listeners) of the completed checkout so that they can react accordingly.void
setMessageRetryTemplate(org.springframework.retry.support.RetryTemplate messageRetryTemplate)
void
setStaleCartItemsService(StaleCartItemsService staleCartItemsService)
protected boolean
shouldResetCartStatus(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String originalCartStatus, @NonNull CheckoutException e)
Determines whether or not the cart's status should be reset after encountering an unexpected exception during checkout.protected boolean
shouldResetCartStatus(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String originalCartStatus, @NonNull CheckoutWorkflowException e)
Deprecated.protected boolean
shouldResetCartStatus(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String originalCartStatus, @NonNull PaymentLockException e)
Determines whether or not the cart's status should be reset after encountering an unexpected exception during checkout.protected void
unlockPayments(@NonNull Map<String,String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Sends a request to PaymentTransactionServices to unlock the cart's payments, based on the lock tokens that were previously obtained vialockPayments(Cart, ContextInfo)
.protected com.broadleafcommerce.cart.client.domain.Cart
updateCartStatus(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String cartStatus, boolean updateCart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected com.broadleafcommerce.cart.client.domain.Cart
updateCartStatus(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String cartStatus, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected void
validateCheckoutRequest(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId)
Validates the cart for checkoutprotected void
validateRequestId(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId)
Validates that the current requestId is not already associated to the cart-
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.CheckoutService
processCheckout
-
-
-
-
Constructor Detail
-
DefaultCheckoutService
public DefaultCheckoutService(CartStatusValidationHelper cartStatusValidationHelper, CheckoutWorkflow checkoutWorkflow, CartProvider cartProvider, com.broadleafcommerce.common.messaging.checkout.CheckoutCompletionProducer checkoutCompletionProducer, ExternalCartProperties externalCartProperties, PaymentProvider<PaymentSummary> paymentProvider, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Detail
-
processCheckout
public CheckoutResponse processCheckout(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @NonNull @NonNull Map<String,String> securityCodes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CheckoutService
Process checkout against the provided cart- Specified by:
processCheckout
in interfaceCheckoutService
- Parameters:
cart
- The cart with which to process checkout.requestId
- The id representing this request to checkoutsecurityCodes
- The map of card security codes keyed by payment id for processing saved paymentscontextInfo
- Context information around sandbox and multitenant state.- Returns:
- The cart after it has gone through checkout.
-
validateCheckoutRequest
protected void validateCheckoutRequest(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId)
Validates the cart for checkout- Parameters:
cart
- The cart to validaterequestId
- The checkout request id
-
validateRequestId
protected void validateRequestId(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId)
Validates that the current requestId is not already associated to the cart- Parameters:
cart
- The cart to validaterequestId
- The checkout request id- Throws:
CheckoutWorkflowException
- Thrown if the current requestId is already present in the cart's past checkout submissions
-
prepareCartForCheckout
protected com.broadleafcommerce.cart.client.domain.Cart prepareCartForCheckout(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Updates the cart with the checkout request ID and status for checkout- Parameters:
cart
- The cart to be updatedrequestId
- The checkout request idcontextInfo
- Context information around sandbox and multitenant state
-
lockPayments
protected Map<String,String> lockPayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Sends request to PaymentTransactionServices to lock the cart's related payments. This is done to ensure that all of the work done within theCheckoutWorkflow
and checkout process in general is consistently interacting with payments that will not change. With these locks in place, only this executing process will have access to modify the payments, until the lock TTL expires. Note: make sure that the checkout process can sufficiently be contained within the payment lock TTL. This can be configured in PaymentTransactionServices.- Parameters:
cart
- the cart whose payments are to be lockedcontextInfo
- The context of the user's request- Returns:
- A map of payment id to lock token.
-
unlockPayments
protected void unlockPayments(@NonNull @NonNull Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Sends a request to PaymentTransactionServices to unlock the cart's payments, based on the lock tokens that were previously obtained vialockPayments(Cart, ContextInfo)
.- Parameters:
paymentLockTokens
- A map of payment id to lock token that was previously obtained by callinglockPayments(Cart, ContextInfo)
contextInfo
- The context of the user's request
-
updateCartStatus
protected com.broadleafcommerce.cart.client.domain.Cart updateCartStatus(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String cartStatus, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
updateCartStatus
protected com.broadleafcommerce.cart.client.domain.Cart updateCartStatus(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String cartStatus, boolean updateCart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
removeStaleCartItems
protected com.broadleafcommerce.cart.client.domain.Cart removeStaleCartItems(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Map<String,String> paymentLockTokens, @NonNull @NonNull CheckoutException e, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
RemovesCartItems
from theCart
that can no longer be found in the catalog & reprices the cart.- Parameters:
cart
- The cart that contains stale cart itemspaymentLockTokens
- Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.e
- TheCheckoutException
thrown due to the presence of stale cart itemscontextInfo
- context information around sandbox and multitenant state- Returns:
- The repriced (but not updated) cart that no longer includes stale cart items
-
shouldResetCartStatus
@Deprecated protected boolean shouldResetCartStatus(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String originalCartStatus, @NonNull @NonNull CheckoutWorkflowException e)
Deprecated.Determines whether or not the cart's status should be reset after encountering an unexpected exception during checkout.- Parameters:
cart
- The cart related to the checkout requestoriginalCartStatus
- The status of the cart prior to attempting checkoute
- TheCheckoutWorkflowException
that caused the checkout to fail- Returns:
- whether or not the cart's status should be reset after encountering an unexpected exception during checkout.
-
shouldResetCartStatus
protected boolean shouldResetCartStatus(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String originalCartStatus, @NonNull @NonNull CheckoutException e)
Determines whether or not the cart's status should be reset after encountering an unexpected exception during checkout.- Parameters:
cart
- The cart related to the checkout requestoriginalCartStatus
- The status of the cart prior to attempting checkoute
- TheCheckoutWorkflowException
that caused the checkout to fail- Returns:
- whether or not the cart's status should be reset after encountering an unexpected exception during checkout.
-
shouldResetCartStatus
protected boolean shouldResetCartStatus(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String originalCartStatus, @NonNull @NonNull PaymentLockException e)
Determines whether or not the cart's status should be reset after encountering an unexpected exception during checkout.- Parameters:
cart
- The cart related to the checkout requestoriginalCartStatus
- The status of the cart prior to attempting checkoute
- ThePaymentLockException
that caused the checkout to fail- Returns:
- whether or not the cart's status should be reset after encountering an unexpected exception during checkout.
-
finalizeCart
protected com.broadleafcommerce.cart.client.domain.Cart finalizeCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Following a successful checkout, this method is responsible for recording the finalized state of the cart.- Parameters:
cart
- The cart that has completed checkout, but needs to be marked as finalizedpaymentLockTokens
- Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.contextInfo
- context information around sandbox and multitenant state- Returns:
- The finalized cart
-
finalizePayments
protected void finalizePayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
createOrderNumber
protected String createOrderNumber(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)
Creates a new order number for a submitted cart.- Returns:
- New order number for submitted cart.
-
sendCheckoutCompletionMessage
protected void sendCheckoutCompletionMessage(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Send a message to notify external services (and internal listeners) of the completed checkout so that they can react accordingly.- Parameters:
cart
- The cart that has completed checkout. This should be the primary content of the out-going message.requestId
- The checkout request idcontextInfo
- Context information around sandbox and multitenant state.
-
addCartLinks
protected void addCartLinks(com.broadleafcommerce.cart.client.domain.CheckoutCart checkoutCart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
getFulfillmentGroupLink
protected com.broadleafcommerce.cart.client.domain.CartLink getFulfillmentGroupLink(com.broadleafcommerce.cart.client.domain.CheckoutCart checkoutCart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
getCartItemLink
protected com.broadleafcommerce.cart.client.domain.CartLink getCartItemLink(com.broadleafcommerce.cart.client.domain.CheckoutCart checkoutCart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
buildSuccessfulCheckoutResponse
protected CheckoutResponse buildSuccessfulCheckoutResponse(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
buildFailedCheckoutResponse
@Deprecated protected CheckoutResponse buildFailedCheckoutResponse(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @NonNull @NonNull CheckoutWorkflowException e, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Deprecated.
-
buildFailedCheckoutResponse
protected CheckoutResponse buildFailedCheckoutResponse(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @NonNull @NonNull CheckoutException e, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
buildFailedCheckoutResponse
protected CheckoutResponse buildFailedCheckoutResponse(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @NonNull @NonNull PaymentLockException e, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
getMessage
protected String getMessage(@NonNull @NonNull String errorMessage, @Nullable Object... args)
-
getCartStatusValidationHelper
protected CartStatusValidationHelper getCartStatusValidationHelper()
-
getCheckoutWorkflow
protected CheckoutWorkflow getCheckoutWorkflow()
-
getCartProvider
protected CartProvider getCartProvider()
-
getCheckoutCompletionProducer
protected com.broadleafcommerce.common.messaging.checkout.CheckoutCompletionProducer getCheckoutCompletionProducer()
-
getExternalCartProperties
protected ExternalCartProperties getExternalCartProperties()
-
getPaymentProvider
protected PaymentProvider<PaymentSummary> getPaymentProvider()
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
setStaleCartItemsService
@Autowired public void setStaleCartItemsService(StaleCartItemsService staleCartItemsService)
-
getStaleCartItemsService
protected StaleCartItemsService getStaleCartItemsService()
-
setMessageRetryTemplate
@Autowired @Qualifier("checkoutCompletionMessageRetryTemplate") public void setMessageRetryTemplate(org.springframework.retry.support.RetryTemplate messageRetryTemplate)
-
getMessageRetryTemplate
protected org.springframework.retry.support.RetryTemplate getMessageRetryTemplate()
-
-