1. Ordering

Order checkout

The order checkout integration event enables customization of order total calculations, including taxes, shipping costs, fees, and promotion discounts. This feature recognizes that companies often have established requirements and existing relationships with third-party vendors for calculating these costs. Since there is no universal solution for these calculations, the integration provides flexibility to implement business-specific requirements.

Common scenarios

The integration addresses various business needs:

  1. Shipping cost variations:

    • Vendor-specific rates
    • Product type considerations
    • Packaging material requirements
    • Fulfillment-time factors
  2. Promotion management:

    • Item-specific discounts
    • Targeted price adjustments
    • Individual item vs. order-level promotions
  3. Tax handling:

    • Tax-exempt user groups
    • Multiple jurisdiction requirements
    • Special tax rules
    • Custom tax calculations

Integration overview

The integration connects your middleware application through predefined routes, providing control over order total calculations. The process includes:

  1. Cart management:

    • Item selection
    • Configuration options
    • Quantity adjustments
  2. Shipment organization:

    • Ship from address
    • Ship to address
    • Production lead time
    • Customer delivery requirements
    • Inventory availability
    • Fulfillment constraints
  3. Shipping options:

    • Method selection
    • Price comparison
    • Delivery time estimates
    • Service level options
  4. Cost calculations:

    • Tax computation
    • Line item pricing
    • Price break application
    • Promotion processing

Triggering behavior

The integration uses explicit triggering through POST /v1/orders/{direction}/{orderID}/calculate rather than automatic calculation. This approach provides several benefits:

  1. Performance optimization:

    • Prevents redundant calculations
    • Reduces API calls
    • Minimizes third-party service costs
  2. User experience:

    • Faster response times
    • Controlled calculation timing
    • Predictable behavior
  3. Resource management:

    • Efficient service usage
    • Controlled costs
    • Optimized processing

Security verification:

  • Each call includes X-oc-hash header
  • Signature uses integration event hash key
  • Validates serialized JSON payload
  • Uses HMACSHA256 encoding

Standard checkout flow

  1. Cart management:

    • Add items to order
    • Configure item options
    • Set quantities
  2. Address handling:

    • Set shipping addresses
    • Validate locations
    • Configure multiple addresses if needed
  3. Shipping estimation:

    POST /v1/orders/{direction}/{orderID}/estimateshipping
    
    • Retrieves available shipping methods
    • Calculates costs
    • Provides delivery estimates
  4. Method selection:

    • Present options to user
    • Show costs and transit times
    • Allow comparison
  5. Save shipping choices:

    POST /v1/orders/{direction}/{orderID}/shipmethods
    
    json
    {
      "ShipMethodSelections": [
        {
          "ShipEstimateID": "ShipEstimateID",
          "ShipMethodID": "ExampleShipMethod1"
        }
      ]
    }
  6. Calculate totals:

    POST /v1/orders/{direction}/{orderID}/calculate
    
    • Computes all costs
    • Applies promotions
    • Validates totals
  7. Order submission:

    POST /v1/orders/{direction}/{orderID}/submit
    
    • Finalizes order
    • Triggers fulfillment
    • Processes payment

Important notes:

  • Order changes invalidate calculations
  • Recalculation required after changes
  • Changes include:
    • Shipping costs
    • Tax amounts
    • Promotion adjustments
    • Address updates
    • Quantity modifications
    • Unit price changes
    • Cost center updates
    • Order/line item XP changes

Order worksheet

The Order Worksheet serves as a comprehensive record of calculation data:

GET /v1/orders/{direction}/{orderID}/worksheet

Benefits:

  • Detailed cost breakdown
  • Tax calculation history
  • Shipping rate records
  • Promotion application details
  • Fee itemization
  • Historical reference
  • Audit trail
  • Refund calculation support

Implementation

Setup requirements:

  1. Integration configuration:

    • Create OrderCheckout Integration Event Type
    • Configure API Client connection
    • Set OrderCheckoutIntegrationEventID
  2. Endpoint hosting:

    • Implement required routes
    • Handle integration payloads
    • Process calculations
    • Return formatted responses

Standard payload structure:

json
{
  "ConfigData": {},  // Integration Event configuration
  "Environment": "Sandbox",
  "OrderCloudAccessToken": "eyJhbGciOiJSUzI1NiIsTdHJ5RDVEclEifQ...",
  "OrderWorksheet": {
    "LineItems": [],
    "Order": {},
    "OrderApprovedResponse": {},
    "OrderCalculateResponse": {},
    "OrderPromotions": [],
    "OrderSubmitForApprovalResponse": {},
    "OrderSubmitResponse": {},
    "ShipEstimateResponse": {}
  }
}

Integration endpoints

/ShippingRates

Triggered by: POST v1/orders/{direction}/{orderID}/estimateshipping

Purpose:

  • Calculate shipping options
  • Group items into shipments
  • Provide cost estimates
  • Define delivery timeframes

Response structure:

json
{
  "ShipEstimates": [
    {
      "ID": "ShipEstimateID",
      "SelectedShipMethodID": null,
      "ShipEstimateItems": [
        {
          "LineItemID": "SampleLineItemID",
          "Quantity": 1
        }
      ],
      "ShipMethods": [
        {
          "Cost": 10,
          "ID": "ExampleShipMethod1",
          "Name": "Example Shipping Method 1",
          "EstimatedTransitDays": 5,
          "xp": {}
        },
        {
          "Cost": 8,
          "ID": "ExampleShipMethod2",
          "Name": "Example Shipping Method 2",
          "EstimatedTransitDays": 7,
          "xp": {}
        }
      ],
      "xp": {}
    }
  ],
  "xp": {}
}

/OrderCalculate

Triggered by: POST v1/orders/{direction}/{orderID}/calculate

Purpose:

  • Calculate final totals
  • Apply tax rules
  • Process shipping costs
  • Handle fees
  • Override unit prices
  • Store calculation details

Response structure:

json
{
  "ShippingTotal": 10,
  "TaxTotal": 3,
  "FeeTotal": 0.42,
  "LineItemOverrides": [
    {
      "LineItemID": "SampleLineItemID",
      "UnitPrice": 6.00,
      "PromotionOverrides": [
        {
          "PromotionID": "SamplePromoID",
          "Amount": 3.00
        }
      ]
    }
  ],
  "xp": {
    "TaxBreakdown": {
      "LineItemID": "SampleLineItemID",
      "AvalaraReferenceID": "SampleReferenceID",
      "StateTax": 0.12,
      "CountyTax": 0.22,
      "MunicipalTax": 0
    },
    "FeeBreakdown": [
      {
        "LineItemID": "SampleLineItemID",
        "Name": "Facility Fee",
        "PerQuantity": true,
        "Amount": 0.05
      },
      {
        "LineItemID": "SampleLineItemID",
        "Name": "Tariff",
        "PerQuantity": true,
        "Amount": 0.37
      }
    ]
  }
}

Important: Middleware order updates must occur after sending the response to OrderCloud.

/OrderSubmit

Triggered by: POST v1/orders/{direction}/{orderID}/submit

Purpose:

  • Process final submission
  • Integrate with back-office systems
  • Initialize fulfillment
  • Record external references

Response structure:

json
{
  "xp": {
    "SomeKey": "SomeValue"
  }
}

/OrderSubmitForApproval

Triggered by: POST v1/orders/{direction}/{orderID}/submit

Purpose:

  • Handle approval workflow
  • Process pending orders
  • Notify approvers
  • Track approval status

Response structure:

json
{
  "xp": {
    "SomeKey": "SomeValue"
  }
}

/OrderApproved

Triggered by: POST v1/orders/{direction}/{orderID}/approve

Purpose:

  • Process approved orders
  • Initialize fulfillment
  • Update systems
  • Notify stakeholders

Response structure:

json
{
  "xp": {
    "SomeKey": "SomeValue"
  }
}

How to calculate tax with OrderCloud

Overview

Tax calculation is complex, bordering on overwhelming. Tax rules and regulations with E-Commerce are continually evolving. In the United States each state has jurisdiction over their tax laws creating very different applications of taxes making them even more difficult to manage. Factor in entities outside the US and the complexity grows exponentially. These reasons, but not only these reasons, are why OrderCloud has taken an agnostic approach to tax calculation.

Our 20 years of e-commerce solution experience has informed us of the rules and regulations challenges, but also the customer solution challenges they face with ERP integration and business relationship management with technology vendors. There are dozens of tax services employed throughout our customer base and we've helped each of them become tightly integrated into the online shopping experience for them.

This guide is designed to be an overview of how we support tax calculation integration and management with some focus on a particular vendor we recommend highly, Avalara.

Integration events

Integration events are a feature of the OrderCloud platform. In particular, we'll focus on the OrderCheckout Integration event. It was designed to help coordinate the process of the customer checkout. Calculating the values for shipping, tax, inventory and promotions have many data points that can be adjusted in a number of ways. Each time one of the key data points is changed the relevant calculations need to be performed and orchestrating that from the front end application (UI) is cumbersome and fraught with peril. The OrderCheckout Integration event is here to help.

The event acts much like a webhook from a technical perspective. The ability to validate the webhook hash is present for security. However, these events can be manually triggered:

The Calculate an Order event has the property to provide the TaxTotal to be applied to the Order. The property is a number/float and doesn't have any restrictions on the value other than the data type. This is important because we are always asked "how do you support different currencies". OrderCloud is agnostic to currency as well. In fact, we have some customers that use reward points as currency for payments. So, if you need to support the Japanese Yen or the British Pound it's not a problem.

Tax service integration

As mentioned above, calculating tax is complex. Tackling this yourself isn't a good idea. That's why vendors like Avalara, Vertex and TaxJar exist. At Sitecore, we don't want to force you into a solution so we designed a simple and secure method for integrating your preferred tax vendor into your e-commerce solution.

The generally recommended workflow for integrating a tax calculation vendor into your commerce solution is simple:

  1. Trigger the OrderCalculate Integration Event that is configured to point to your Middleware
  2. Middleware receives the request
  3. Middleware requests and is granted a token with the OverrideTax scoped role
  4. Middleware calls to the configured Tax vendor for calculation passing along all relevant data points
  5. Middleware receives the response from the Tax Vendor
  6. Middleware responds to the OrderCloud Integration event with the TaxTotal populated

The OrderCheckout calculate event is a recommended solution, but it's not the only opportunity to provide tax calculation for your Order. You can simply call out to your tax vendor and apply the tax cost directly to your Order. To apply the tax cost to your Order you must have the scope "OverrideTax" granted in your token request. We refer to this security profile role as an "elevated" role. Generally it is granted to a middleware implementation rather than the user that is shopping your site. This prevents any illegitimate activity on the Order from occurring.

Every tax vendor has different configurations and data models. For example, Avalara needs a tax and item code for each line item or product. You also may need to manage a number of entities for your customers and suppliers in order to identify the proper tax jurisdiction. This is another area where OrderCloud is flexible for your needs. If you have properties on a Product, or LineItem that are specific to your tax integration implementation you can use our Extended Properties (xp) to define them. There may be a number of data points, or properties, you need to reference in order to fulfill the integration event. This is where the payload of the Integration Event is important. OrderCloud sends, as the request payload, an Order Worksheet that is essentially a hydrated model of a number of concerns related to the Order. Information about the User, their organization and Order properties for the LineItems, Products and Pricing.

Integration flow

International considerations

All this information still leaves us with the question of how to support regional localization. Primarily this is a concern with the tax vendor. Avalara, for example, supports a great number of localities very elegantly. From a development perspective the same API endpoints needed to perform tax calculation with US entities is used. The configuration of the data is the key to having the accurate Value Added Tax (VAT) returned for your integration.

You may need to address some configuration items in your data model. For example, specifying the currency of the transaction. This information should be configured on the User or Buyer model that is provided in the Order Worksheet. For Japan, you can specify "JPY" which is the currency code for the Japanese Yen. If you simply apply the property locale information and the currency to the same transaction API endpoint at Avalara you will get the right calculation to apply to your OrderCloud TaxTotal field.

If you have suggestions for improving this article, let us know!