Take a deeper look at the Orders API.
Each order is represented by an Order object. An Order
provides detailed information about a commerce-related event, such as a sale, fulfillment, return, or exchange.
An Order
also provides access to additional data that can be found in other Square APIs. For example, you can use the fields within an Order
to:
- Determine the customer's name and address from the Customers API.
- Look up item variations (such as sizes or colors) from the Catalog API.
- Retrieve detailed payment data from the Payments API.
An OrderLineItem contains details about an item, such as its name, quantity, base price, and price adjustments (discounts, service charges, and taxes). Within an Order
, the line_items
array contains the OrderLineItem
objects for that order.
There are two ways to define an OrderLineItem
:
Specify a catalog item ID - If you've already set up your catalog, you can provide a valid
catalog_object_id
in theOrderLineItem
. This automatically populates the item with product details from the Catalog API. It also automatically updates your inventory when theOrder
is closed or charged.Define the line item ad hoc - If you don't have a
catalog_object_id
to reference, you can define theOrderLineItem
details manually.
A Fulfillment lets you track additional details that are required to close the order. Within an Order
, the fulfillments
array contains all the Fulfillment
objects for the order.
There are three types of Fulfillment
:
SHIPMENT
- A shipping carrier ships the fulfillment to a recipient.PICKUP
- A recipient picks up the fulfillment at a physical location.DELIVERY
- A courier delivers the fulfillment to the recipient.
For more information, see Manage Order Fulfillments.
Note
If you use the Orders API to create a fulfillment order, the order appears in the Square Point of Sale application after it is charged. The order payment must be approved with delayed capture. For more information, see Using the Orders API (PayOrder endpoint).
You can specify one or more price adjustments to modify the total cost of an order or individual line items. Price adjustments are defined at the Order
level. They can then be applied to the order as a whole or to individual items in the order.
There are three types of price adjustments:
Discounts - A discount is defined by an OrderLineItemDiscount object in the
discounts
array of theOrder
. You can scope anOrderLineItemDiscount
so that it can apply to the entire order or to one or more line items.Service charges - A service charge is defined by an OrderServiceCharge object in the
service_charges
array of theOrder
. AnOrderServiceCharge
can be based on the total amount of the order or apportioned based on the individual items in the order.Taxes - A tax is defined by an OrderLineItemTax object in the
taxes
array of theOrder
. You can scope anOrderLineItemTax
so it can apply to the entire order or to one or more line items.
Every Order
object has a read-only id
field, which contains a system-generated unique identifier for the order (for example, 7j32iSjnCZFuTwFA06Jy5fDKb0GZY).
The embedded objects within an Order
have uid
fields (unique IDs) to distinguish individual objects from each other. For example, suppose an order's taxes
array contains two elements for sales taxes: one for the city and one for the state. You could set the uid
for the first element to CITYTAX
and the uid
for the second element to STATETAX
.
If you don't provide values for the unique ID fields, the Orders API generates unique values for them and returns them in the API responses.
Note
ID fields are limited to 60 characters and limited to letters, numbers, hyphens, underscores, and periods.
Orders can be created by Square products such as Square Point of Sale or the Reader SDK integration. Orders can also be created manually using the CreateOrder endpoint.
At a high level, your application can manually create an order using the following steps:
- The application gathers information about the order and builds an Order object.
- The application sends the
Order
to the CreateOrder endpoint. - The
CreateOrder
endpoint determines the initial item totals, discounts, service charges, and taxes. - The
CreateOrder
endpoint returns the updatedOrder
to the application.
Important
Managing the order state is critical to ensure that customers are properly charged. When an Order
object is created, Square takes a snapshot of the state of the objects included and uses that snapshot to process the transaction. Even if the price of the item changes before the transaction completes, the Orders API uses that original price to calculate the total.
You should create Order
objects immediately before processing the transaction. Otherwise, you need to create a new Order
object to capture any changes that occur.
All order details are available through the BatchRetrieveOrders and SearchOrders endpoints.
Fulfillment orders only appear in the Square Dashboard after they're charged. Note that fulfillment orders must have delay_capture
set to true
.