Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Final order processing

Final order processing

The final order processing during the checkout process is implemented by the CheckoutService. To perform a checkout, the CheckoutService requires a ShoppingCart and an OrderPayment. The ShoppingCart essentially represents an order for products, complete with the customer and shipping information. The OrderPayment provides information about how the customer will pay for the items in the cart. CheckoutService.checkout() is invoked with these two parameters and will throw an exception if anything goes wrong. The exception may be an EpServiceException, or any of the standard exceptions thrown by implementors of the PaymentGateway interface (see Payment Processing).

The main responsibility of the checkout operation is to process the payment and persist the order. It is assumed that customer and product information can be changed at any time; therefore, all information about the order, product, customer, and payment must be stored as copies in separate database tables.

The final order processing can be broken down into three subgroups of actions which occur after the customer confirms his/her purchase in the store checkout (see the abstractCheckoutServiceDelegate bean in the core project's service.xml file):

  1. Setup actions (setupActionList).
  2. Reversible actions (reversibleActionList).
  3. Finalize actions (finalizeActionList).
            <bean id="abstractCheckoutServiceDelegate" abstract="true" class="com.elasticpath.service.shoppingcart.impl.CheckoutServiceImpl">
		<property name="shippingServiceLevelService" ref="shippingServiceLevelService"/commerce-legacy/>

		<property name="setupActionList" ref="setupActions" />

		<property name="reversibleActionList" ref="reversibleActions"/commerce-legacy/>

		<property name="finalizeActionList" ref="finalizeActions" />

		<property name="beanFactory" ref="coreBeanFactory"/commerce-legacy/>

	<util:list id="setupActions" list-class="java.util.ArrayList">
		<ref bean="preCheckoutCheckoutAction" />
		<ref bean="shippingInformationCheckoutAction" />
		<ref bean="giftCertificateBalanceCheckerCheckoutAction" />
		<ref bean="stockCheckerCheckoutAction" />
		<ref bean="updateCustomerCheckoutAction" />

	<util:list id="reversibleActions" list-class="java.util.ArrayList">
		<ref bean="createNewOrderCheckoutAction" />
		<ref bean="populateOrderDataCheckoutAction" />
		<ref bean="createGiftCertificatesCheckoutAction" />
		<ref bean="populateTemplateOrderPaymentCheckoutAction" />
		<ref bean="authorizePaymentsCheckoutAction" />
		<ref bean="capturePaymentsCheckoutAction" />
		<ref bean="updateLimitedUsageNumbersCheckoutAction" />
		<ref bean="subscriptionCreditCheckCheckoutAction" />
		<ref bean="updateOrderCheckoutAction" />
		<ref bean="commitOrderTaxCheckoutAction" />
		<ref bean="processCouponCustomerAssignmentsCheckoutAction" />
		<ref bean="createNewOrderEventCheckoutAction" />

	<util:list id="finalizeActions" list-class="java.util.ArrayList">
		<ref bean="clearShoppingCartCheckoutAction" />
		<ref bean="postCheckoutCheckoutAction" />

This service.xml file can be modified to refer to your custom implementations of the CheckoutAction interface.

Processing Steps

Each step corresponds to one of the beans listed above.

  1. Verify inventory (stockCheckerCheckoutAction).
  2. Update customer (updateCustomerCheckoutAction).
  3. Create new order (createNewOrderCheckoutAction).
  4. Create purchased gift certificates (createGiftCertificatesCheckoutAction).
  5. Populate OrderPayment template object (populateTemplateOrderPaymentCheckoutAction).
  6. Process payments (processOrderPaymentsCheckoutAction).
  7. Update usage counts on limited-use coupons and promotions (updateLimitedUsageNumbersCheckoutAction).
  8. Conduct credit check for recurring charge items (subscriptionCreditCheckCheckoutAction).
  9. Persist order to database (updateOrderCheckoutAction).
  10. Assign promotion coupons to customer (processCouponCustomerAssignmentsCheckoutAction).
  11. Clear shopping cart (clearShoppingCartCheckoutAction).
  12. Send order confirmation e-mail (sendNotificationEmailCheckoutAction).
Note: Note:

preCheckoutCheckoutAction and postCheckoutCheckoutAction do nothing in the OOTB source code.

The CheckoutAction implementations of each step delegate to the following key classes and files:

Key classes and files

  • CheckoutService - Service that executes a checkout.
  • CheckoutEventHandler - Interface implemented by a class wired via Spring to the CheckoutService so that it can be notified of events during the checkout execution. This is useful for extending or modifying checkout functionality.
  • ShoppingCart - The shopping cart contains items to be purchased during a checkout.
  • OrderPayment - An order payment represents information about how the customer will pay for the order.
  • PaymentGateway - Interface implemented by payment gateways that handle financial transactions such as credit card or PayPal payments.
  • Order - Represents a completed order for products.
  • OrderSku - A snapshot of information about a purchased SKU at the time of checkout.
  • OrderShipment - Contains shipping information for an order.
  • Inventory - Contains inventory information for a particular product SKU.
  • OrderAddress - A snapshot of the customer's address (billing and shipping) at the time of checkout.

The CheckoutEventHandler

The CheckoutService Spring configuration injects a CheckoutEventHandler instance into the Service, which provides hooks into the checkout process at certain points. By creating a new class implementing the CheckoutEventHandler interface and wiring in the new class via the Spring configuration, one can easily extend the Checkout Process at certain steps to call custom methods. Three extensible points exist: preCheckout, postCheckout, and preCheckoutOrderPersist (called just before the newly-created Order is persisted).

For example, if you wanted to have some code that called a webservice in some other application every time a checkout was completed, you could write a new class extending the CheckoutEventHandler and put the code in that class' postCheckout() method. Then you would edit the Spring bean definition for the CheckoutService to inject your new class into the Service, and your code would automatically be called at the right time.

Important concepts


The checkout service is configured in Spring so that the checkout method does NOT run as a transaction. This is because we don't want to trigger transaction overhead while processing credit card payments. If the credit card payment is successful, checkout calls processOrder(), which does run as a transaction and handles the creation and storage of the order information. Transactions are configured on a per-method basis in the service.xml Spring configuration file.

Status Objects

Orders, OrderPayments, and OrderShipments all have Status fields: OrderStatus, OrderPaymentStatus, and OrderShipmentStatus respectively.

The current OrderStatus values are:


The current OrderPaymentStatus values are:


The current OrderShipmentStatus values are:


Creating an Order

The CheckoutService creates an Order object and passes it to the OrderService to persist.

Every Order must have a unique OrderNumber, set at Order creation time (not at persist time). Unique order numbers are obtained from the OrderService.getNextOrderNumber() method.


The OrderService provides services to query on Orders and persist Orders, but not to generate Orders. Order generation is performed by the CheckoutService.

There are methods to search for orders by various basic criteria, or you can pass in an OrderSearchCriteria object. The search methods must translate the given criteria into a Criteria String for the Persistence engine, and they do so via an OrderCriterion factory class.

Data replication

At order time a snapshot of various objects must be created and stored in separate tables to insulate the Order details from any future changes in prices, inventory, addresses, etc. Objects are copied as follows:

ProductSku --> OrderSku BillingAddress --> OrderAddress (for the Order) ShippingAddress --> OrderAddress (for the OrderShipment)

Attributes such as shipping cost, quantity, taxes, etc. are calculated at Order time and frozen in the appropriate object (Order, OrderShipment, OrderSku, etc).

Failed Orders

Failed orders are saved to the database (TORDER table) with the order's STATUS set to FAILED. The Quartz job, cleanupFailedOrdersJob, will eventually remove the failed order from your system.