Class DefaultCheckoutService

  • All Implemented Interfaces:
    CheckoutService

    public class DefaultCheckoutService
    extends Object
    implements CheckoutService
    Default implementation of the CheckoutService that is responsible for processing checkout requests
    Author:
    Chad Harchar (charchar), Chris Kittrell (ckittrell)
    • Method Summary

      All Methods Instance Methods Concrete 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 CheckoutWorkflowException e, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)  
      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 org.springframework.context.MessageSource getMessageSource()  
      protected PaymentProvider<PaymentSummary> getPaymentProvider()  
      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 checkout
      CheckoutResponse 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 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.
      protected boolean shouldResetCartStatus​(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String originalCartStatus, @NonNull CheckoutWorkflowException 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 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 via lockPayments(Cart, 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 checkout
      protected 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
    • 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 interface CheckoutService
        Parameters:
        cart - The cart with which to process checkout.
        requestId - The id representing this request to checkout
        securityCodes - The map of card security codes keyed by payment id for processing saved payments
        contextInfo - 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 validate
        requestId - 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 validate
        requestId - 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 updated
        requestId - The checkout request id
        contextInfo - 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 the CheckoutWorkflow 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 locked
        contextInfo - 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 via lockPayments(Cart, ContextInfo).
        Parameters:
        paymentLockTokens - A map of payment id to lock token that was previously obtained by calling lockPayments(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)
      • shouldResetCartStatus

        protected boolean shouldResetCartStatus​(@NonNull
                                                @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                @NonNull
                                                @NonNull String originalCartStatus,
                                                @NonNull
                                                @NonNull CheckoutWorkflowException 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 request
        originalCartStatus - The status of the cart prior to attempting checkout
        e - The CheckoutWorkflowException 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 request
        originalCartStatus - The status of the cart prior to attempting checkout
        e - The PaymentLockException 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 finalized
        paymentLockTokens - 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 id
        contextInfo - 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

        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)
      • 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)
      • getCartProvider

        protected CartProvider getCartProvider()
      • getCheckoutCompletionProducer

        protected com.broadleafcommerce.common.messaging.checkout.CheckoutCompletionProducer getCheckoutCompletionProducer()
      • getMessageSource

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

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