---
title: Order processing
slug: commerce-connect-15/docs/order-processing
docTags: 
createdAt: 2026-07-30T20:34:43.000Z
---

Processing of purchase orders and related items is based on classes and methods in the `EPiServer.Commerce.Order` and `EPiServer.Commerce.Marketing` namespaces.

These are the key interfaces:

- `EPiServer.Commerce.Order.IOrderGroupExtensions`
- `EPiServer.Commerce.Order.IInventoryProcessor`. See [Update inventory](docId:91dFqzt0di6yLJ2kRVPY_) and [Adjust inventory](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.ILineItemValidator`. See [Validate line item](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IPaymentProcessor`. See [Process payments](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IPaymentPlanProcessor`. See [Process payment plans](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IPaymentPlanExtensions`. See [Process payment plan extensions](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IPlacedPriceProcessor`. See [Update placed price](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IFulfillmentWarehouseProcessor`.
- `EPiServer.Commerce.Order.IPurchaseOrderProcessor`. See [Process purchase orders](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IPurchaseOrderExtensions`. See [Process purchase order extensions](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IShipmentProcessor`. See [Process shipments](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IShipmentProcessorExtensions`. See [Process shipment extensions](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Order.IShipmentExtensions`. See [Process shipment extensions](docId:91dFqzt0di6yLJ2kRVPY_).
- `EPiServer.Commerce.Marketing.IPromotionEngine`. See [Apply discount](docId:91dFqzt0di6yLJ2kRVPY_).

The example code below passes dependencies to the extension methods so you can unit test your applications.

## Validation issues

When performing different actions on an IOrderGroup, issues can cause modifications to line items. These warnings and errors are represented in the class `EPiServer.Commerce.Order.ValidationIssue`. Most processing tasks take a parameter with an `Action\<ILineItem, ValidationIssue>`, which allows the caller to collect this information so a message about the issue can be displayed to the user.

## Validate line items

Validating the status of line item is useful to make sure the product is active, within the valid date range, and that the catalog entry is available in the current market.

The following example shows how to validate line items in a cart and check for validation issues.

```csharp
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var lineItemValidator = ServiceLocator.Current.GetInstance<ILineItemValidator>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart(contactId, "Default");
var validationIssues = new Dictionary<ILineItem, ValidationIssue>();
    
//Check all line items on cart
cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.Add(item, issue), lineItemValidator);
    
//Check one lineitem
var lineItem = cart.GetAllLineItems().First();
if (!lineItemValidator.Validate(lineItem, cart.Market, (item, issue) => validationIssues.Add(item, issue)))
  {
    //Check validationIssues for problems
  }
```

## Update placed price

Updating the placed price is useful when a shopper has an item in the cart for an extended period of time. It is recommended to add validation to check if the product price has changed, and if needed update the price.

The following example shows how to check and update placed price for line items.

```csharp
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var placedPriceProcessor = ServiceLocator.Current.GetInstance<IPlacedPriceProcessor>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart(contactId, "Default");
var validationIssues = new Dictionary<ILineItem, ValidationIssue>();
    
//Update all placed prices on the cart
cart.UpdatePlacedPriceOrRemoveLineItems(PrincipalInfo.CurrentPrincipal.GetCustomerContact(),
  (item, issue) => validationIssues.Add(item, issue), placedPriceProcessor);
    
//Update line item placed price
var lineItem = cart.GetAllLineItems().First();
lineItem.UpdatePlacedPrice(PrincipalInfo.CurrentPrincipal.GetCustomerContact(), cart.Market,
  cart.Currency,(item, issue) => validationIssues.Add(item, issue), placedPriceProcessor);
    
//Update line item placed price
var lineItem = cart.GetAllLineItems().First();
placedPriceProcessor.UpdatePlacedPrice(lineItem, PrincipalInfo.CurrentPrincipal.GetCustomerContact(),
  cart.Market, cart.Currency,(item, issue) => validationIssues.Add(item, issue));
```

## Apply discounts

Applying discounts runs the promotion engine to evaluate and apply discounts to the `IOrderGroup`. If certain discounts require coupons, add the coupons to the `IOrderForm` before running `ApplyDiscounts`.

The following example shows how to check for discounts on items in a cart.

```csharp
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var promotionEngine = ServiceLocator.Current.GetInstance<IPromotionEngine>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart(contactId, "Default");
    
//run apply discounts on the cart
var rewardDescriptions = cart.ApplyDiscounts(promotionEngine, new PromotionEngineSettings());
    
//run apply discounts on the cart
var rewardDescriptions = promotionEngine.Run(cart, new PromotionEngineSettings());
```

## Process payments

Processing payments runs each configured payment through its respective payment provider.

The following example shows how to run the payment processor for a cart.

```csharp
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var paymentProcessor = ServiceLocator.Current.GetInstance<IPaymentProcessor>();
var orderGroupCalculator = ServiceLocator.Current.GetInstance<IOrderGroupCalculator>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart(contactId, "Default");

//Process payments for the cart
cart.ProcessPayments(paymentProcessor, orderGroupCalculator);
```

## Update inventory

`UpdateInventory` checks that a sufficient quantity of inventory exists for the selected shipment warehouse. This method also updates the line item with the available quantity or, if none are available, removes it.

The following example shows how to update inventory information for a cart.

```csharp
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var inventoryProcessor = ServiceLocator.Current.GetInstance<IInventoryProcessor>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart(contactId, "Default");
var validationIssues = new Dictionary<ILineItem, ValidationIssue>();
    
//Update Inventory on cart
cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.Add(item, issue), inventoryProcessor);
    
//Update inventory on shipment line items
var shipment = cart.GetFirstShipment();
inventoryProcessor.UpdateInventoryOrRemoveLineItem(shipment, (item, issue) => validationIssues.Add(item, issue));
```

## Adjust inventory

`AdjustInventory` adjusts the inventory for each line item and removes it if no inventory exists. This operation is done in sequence for each shipment in an `IOrderGroup`, or for a specific shipment if the `IInventoryProcessor` method is called directly.

The behavior changes based on the value of the `IOrderGroup OrderStatus` property. If calling the `IInventoryProcessor` directly, you should pass the status of the shipment's parent `IOrderGroup`:

- `Completed` – Makes permanent the reservation of inventory, decrementing available quantity.
- `Canceled` – Cancels the reservation of inventory, incrementing available quantity.
- `InProgress || AwaitingExchange` – Reserves inventory to fulfill the shipment.

In addition, the value of `IShipment.OrderShipmentStatus` may override the behavior for a specific shipment.

- `Shipped` – Same behavior as `OrderStatus.Completed` but is applied regardless of the value of `IOrderGroup.OrderStatus`.
- `Cancelled` – Same behavior as `OrderStatus.Cancelled` but is applied regardless of the value of `IOrderGroup.OrderStatus`.

The following example shows how to adjust inventory information for line items in a cart.

```csharp
var orderRepository = ServiceLocator.Current.GetInstance<IOrderRepository>();
var inventoryProcessor = ServiceLocator.Current.GetInstance<IInventoryProcessor>();
var contactId = PrincipalInfo.CurrentPrincipal.GetContactId();
var cart = orderRepository.LoadCart(contactId, "Default");
var validationIssues = new Dictionary<ILineItem, ValidationIssue>();
    
//Adjust Inventory on cart
cart.AdjustInventoryOrRemoveLineItems((item, issue) => validationIssues.Add(item, issue), inventoryProcessor);
    
//Adjust inventory on shipment line items
var shipment = cart.GetFirstShipment();
inventoryProcessor.AdjustInventoryOrRemoveLineItems(shipment, cart.OrderStatus, (item, issue) => validationIssues.Add(item, issue));
```

## Process purchase orders

`IPurchaseOrderProcessor` contains functionality for putting and releasing orders on hold, canceling orders, and starting order processing.

The following example shows how to use `HoldOrder()` to put a purchase order on hold.

```csharp
IOrderRepository orderRepository;
IPurchaseOrderProcessor purchaseOrderProcessor;
// ...
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
purchaseOrderProcessor.HoldOrder(purchaseOrder);
```

The following example shows how to use `ReleaseOrder()` to release a purchase order from hold.

```csharp
IOrderRepository orderRepository;
IPurchaseOrderProcessor purchaseOrderProcessor;
// ...
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
purchaseOrderProcessor.ReleaseOrder(purchaseOrder);
```

The following example shows how to use `CancelOrder()` to cancel a purchase order.

```csharp
IOrderRepository orderRepository;
IPurchaseOrderProcessor purchaseOrderProcessor;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
purchaseOrderProcessor.CancelOrder(purchaseOrder);
```

The following example shows how to use `ProcessOrder()` to start processing a purchase order.

```csharp
IOrderRepository orderRepository;
IPurchaseOrderProcessor purchaseOrderProcessor;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
purchaseOrderProcessor.ProcessOrder(purchaseOrder);
```

## Process purchase order extensions

`IPurchaseOrderExtensions` extends the functionality provided with `IPurchaseOrderProcessor`.

The following example shows how to use `IsPaid()` to determine if a purchase order is paid.

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var isPaid = purchaseOrder.IsPaid();
```

The following example shows how to use `CanBeCancelled()` to determine if purchase order can be cancelled.

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var canBeCancelled = purchaseOrder.CanBeCancelled();
```

The following example shows how to use `CanBePutOnHold()` to determine if the purchase order can be put on hold.

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var canBeHold = purchaseOrder.CanBePutOnHold();
```

The following example shows how to use `HasAwaitingStockReturns()` to determine if the purchase order has any awaiting stock returns.

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var awaitingStockReturns = purchaseOrder.HasAwaitingStockReturns();
```

The following example shows how to use `HasAwaitingReturnCompletable()` to determine if the purchase order has any awaiting return completable.

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var awaitingReturnCompletable = purchaseOrder.HasAwaitingReturnCompletable();
```

The following example shows how to use `GetActiveReturnForms()` to get a purchase order's active return forms (moved from `DefaultReturnPurchaseOrderCalculator`).

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var activeReturnForms = purchaseOrder.GetActiveReturnForms();
```

The following example shows how to use `CanReleaseShipment()` to determine if a shipment can be released.

```csharp
IOrderRepository orderRepository;
IShipment shipment;
    
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var canReleaseShipment = purchaseOrder.CanReleaseShipment(shipment);
```

The following example shows how to use `CanCancelShipment()` to determine if a shipment can be cancelled.

```csharp
IOrderRepository orderRepository;
IShipment shipment;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var canCancelShipment = purchaseOrder.CanCancelShipment(shipment);
```

The following example shows how to use `CanReturnShipment()` to determine if a shipment can be returned.

```csharp
IOrderRepository orderRepository;
IShipment shipment;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var canReturnShipment = purchaseOrder.CanReturnShipment(shipment);
```

The following example shows how to use `CanCompleteShipment()` to determine if a shipment can be completed.

```csharp
IOrderRepository orderRepository;
IShipment shipment;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
var canCompleteShipment = purchaseOrder.CanCompleteShipment(shipment);
```

## Process shipments

`IShipmentProcessor` contains functionality for canceling, completing, and realizing shipments, and adding them to and from warehouse picklists.

The following example shows how to use `CancelShipment()` to cancel a shipment.

```csharp
IOrderRepository orderRepository;
IShipmentProcessor shipmentProcessor;
Shipment shipment;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
shipmentProcessor.CancelShipment(purchaseOrder, shipment);
```

The following example shows how to use `CompleteShipment()` to complete a shipment.

```csharp
IOrderRepository orderRepository;
IShipmentProcessor shipmentProcessor;
IList<IShipment> shipments;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
shipmentProcessor.CompleteShipment(purchaseOrder, shipments);
```

The following example shows how to use `ReleaseShipment()` to release a shipment.

```csharp
IOrderRepository orderRepository;
IShipmentProcessor shipmentProcessor;
IList<IShipment> shipments;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
shipmentProcessor.ReleaseShipment(purchaseOrder, shipments);
```

The following example shows how to use `AddShipmentToPicklist()` to add a shipment to a picklist.

```csharp
IOrderRepository orderRepository;
IShipmentProcessor shipmentProcessor;
IShipment shipment;
(…)
var orderGroupId = 123;
var pickListId = 1;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
shipmentProcessor.AddShipmentToPicklist(purchaseOrder, shipment, pickListId);
```

The following example shows how to use `RemoveShipmentFromPicklist()` to remove a shipment from a picklist.

```csharp
IOrderRepository orderRepository;
IShipmentProcessor shipmentProcessor;
IShipment shipment;
(…)
var orderGroupId = 123;
var purchaseOrder = orderRepository.Load<PurchaseOrder>(orderGroupId);
shipmentProcessor.RemoveShipmentFromPicklist(purchaseOrder, shipment);
```

## Process shipment extensions

`IShipmentProcessorExtensions` extends the functionality provided by `IShipmentProcessor`.

The following example shows how to use `CompleteShipment()` to complete a shipment.

```csharp
IShipmentProcessor shipmentProcessor; 
IPurchaseOrder purchaseOrder;
IShipment shipment;
(…)
shipmentProcessor.CompleteShipment(purchaseOrder, shipment);
```

The following example shows how to use `ReleaseShipment()` to release a shipment.

```csharp
IShipmentProcessor shipmentProcessor; 
IPurchaseOrder purchaseOrder;
IShipment shipment;
(…)
shipmentProcessor.ReleaseShipment(purchaseOrder, shipment);
```

The following example shows how to use `CanBePacked()` in `IShipmentExtensions` to determine if a shipment can be packed.

```csharp
IShipment shipment;
(…)
var canBePacked = shipment.CanBePacked();
```

## Process payment plans

`IPaymentPlanProcessor` contains functionality for canceling payment plans.

The following example shows how to use `CancelPaymentPlan()` to cancel a payment plan.

```csharp
IOrderRepository orderRepository;
IPaymentPlanProcessor paymentPlanProcessor;
(…)
var orderGroupId = 123;
var paymentPlan = orderRepository.Load<PaymentPlan>(orderGroupId);
paymentPlanProcessor.CancelPaymentPlan(paymentPlan);
```

## Process payment plan extensions

`IPaymentPlanExtensions` contains functionality for checking payment and cancellation of payment plans.

The following example shows how to use `IsPaid()` to determine if a payment plan is paid.

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var paymentPlan = orderRepository.Load<PaymentPlan>(orderGroupId);
var isPaid = paymentPlan.IsPaid();
```

The following example shows how to use `CanBeCancelled()` to determine whether a payment plan can be canceled.

```csharp
IOrderRepository orderRepository;
(…)
var orderGroupId = 123;
var paymentPlan = orderRepository.Load<PaymentPlan>(orderGroupId);
var canBeCancelled = paymentPlan.CanBeCancelled();
```

## Use APIs instead of CartHelper for order checkout

The `IOrderRepository` API replaces the legacy functionality provided with the `CartHelper` activity workflow. The following provides some guidelines on how to use the API instead.

The legacy cart checkout workflow contained activities that can be called separately by the APIs.

- `ProcessPaymentActivity` – Previously used for processing payments added to a cart. Use `IOrderGroupExtensions.ProcessPayments` instead.
- `CalculateTotalsActivity` – Previously used for calculating order totals. Use `IOrderGroupExtensions.GetTotals()` instead.
- `AdjustInventoryActivity` – Previously used for adjusting line item inventories. Use `IOrderGroupExtensions.AdjustInventoryOrRemoveLineItems()` instead.
- `RecordPromotionUsageActivity` – Previously used to calculate and save promotion usage. Use `IOrderGroupExtensions.ApplyDiscounts()` instead.
- Use `IOrderRepository.SaveAsPurchaseOrder()` to save a cart as a purchase order.
