How It Works
Take a deeper look at the Orders API.
The entire Orders API is built around the Order
object. Line items, taxes, discounts, and fulfillments are all defined at the order level.
Line items can be built in two ways:
By referencing a catalog item ID.
By defining the line item ad hoc.
You can define line items by simply referencing a catalog item by its catalog_object_id
. Referencing the catalog_object_id
automatically pulls details about the catalog item into your order and automatically updates your inventory when the order is closed or charged.
You can also create a line item ad hoc (for example, if you do not have a catalog_id
to reference). You need to define line item details, such as the name and price. Note that this does not create a catalog item.
Using existing catalog items means that you can track your inventory and more easily manage your catalog. You should start by setting up your catalog.
Fulfillment orders are a type of order that can track additional fulfillment details required to close the order. Currently, Square supports two types of fulfillment orders:
A shipment order, which can track a customer's address where the order should be shipped.
A pickup order, which can track delivery details, whether the order has been picked up, and other related details.
Fulfillment orders appear in the Square Point of Sale application after they are charged. Note that fulfillment orders must have delay_capture
set to true
.
Taxes and discounts are price modifiers that you can use to modify the total cost of an order or a line item. You have two options for creating line items for your orders:
Referencing catalog object IDs.
Defining line items ad hoc.
You can specify whether the price modifier is a percentage of the total or a sum subtracted from the total. You can apply a discount or tax with an order scope at the order level, where it applies to the entire order total, or with a line item scope at the line item level, where it applies to the individual line item's price.
Each Order
object has a version number to track, which is the most recent version of the order. Orders begin with a version value of 1 and each time an order is updated, the version number gains +1. When issuing an update request, the version is required and it needs to match the latest version number.
This helps protect you from operating on a stale version of an order.
Each object within the Order
object has ID fields to uniquely identify it and to provide a key for specifying one message in a list.
Object IDs can be specified as part of any CreateOrder
or UpdateOrder
request. If left unset, they are generated by the server and included in the response. Any update to an existing field must include the ID on request.
ID fields are limited to 60 characters and are limited to letters, numbers, hyphens, underscores, and periods.
In general, manually creating an order and linking it to a payment involves the following steps:
The application backend gathers order details and builds an
CreateOrder
request object.The application backend sends the
CreateOrder
request object to theCreateOrder
endpoint.The
CreateOrder
endpoint creates anOrder
object and calculates a final purchase price based on the order details.Square returns the
Order
object to the application backend.The application backend extracts the order ID and creates a payment request object using the order ID.
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 newOrder
object to capture any changes that occur.
The Orders API calculates and applies all discounts and taxes as line item price adjustments. Price adjustments defined as the item level are applied directly to the applicable line item and order-level price adjustments are distributed across all line item subtotals.
The final purchase amount is calculated as follows:
Calculate a starting gross price for each line item from the base price and quantity.
Apply item-level percent discounts to the applicable line item totals.
Convert and apply order-level percent discounts to all line item totals.
Convert and distribute order-level fixed-amount discounts to all line item totals. The amount distributed to each line item is relative to the amount that item contributes to the order subtotal.
Apply item-level fixed-amount discounts to the applicable line item totals.
Apply item-level and order-level taxes to all line item totals.
As an example, consider an online order at Raphael's Puppy-Care Emporium for two packages of Tendon pinwheel, one handmade sweater, and three packages of Chewy trainers, which includes the following discounts:
A item-level percent discount on the Tendon pinwheels: "7% OFF — Discontinued item".
A item-level fixed-amount discount on the Tendon pinwheels: "$3.00 OFF — Customer Loyalty Discount".
A item-level fixed-amount discount on the Chewy trainers: "$11.00 OFF — Customer Loyalty Discount".
An order-level percent discount: "12% OFF — National Puppy Day Sale".
An order-level fixed-amount discount: "$55 OFF — Global Sale".
The following taxes apply:
A line-item percent tax on sweaters: "Fair Trade Tax: 5%".
An order-level percent tax: "State Sales Tax: 8.5%"
The Orders API uses "round half to even" rules, known as bankers rounding, to calculate taxes and discounts. Under normal rounding rules, half-values round to the next closest integer. For example:
0.505 becomes 0.51
0.715 becomes 0.72
0.085 becomes 0.09
However, under bankers rounding rules, half-values round to the closest even integer, which has the effect of pulling even numbers down while leaving odd numbers unchanged. For example:
0.505 becomes 0.50 (pulled down from 0.51)
0.715 becomes 0.72 (unchanged from normal rounding)
0.085 becomes 0.08 (pulled down from 0.09)
For more information about rounding at Square, see Understanding Fee Rounding.
The Orders API calculates the gross totals for each line item according to the base price and quantity for the item.
Quantity | Description | Base Price |
Starting Item Total (Quantity * Base Price) |
---|---|---|---|
2 | Chicken Treats — Tendon pinwheel | 15.00 USD | 30.00 USD |
1 | Handmade Sweater — Blue | 50.00 USD | 50.00 USD |
3 | Chicken Treats — Chewy trainers | 12.00 USD | 36.00 USD |
ORDER SUBTOTAL | $116.00 |
The Orders API applies item-level percent discounts to the applicable line items. Note that the Tendon pinwheel line item is the only item to receive 7% off.
Item | Item Amount | Final Amount |
---|---|---|
Chicken Treats — Tendon pinwheel | 30.00 USD | |
7% OFF — Discontinued item
(30.00 x 0.07 = −2.10 USD) |
27.90 USD | |
Tendon pinwheel subtotal | 27.90 USD | |
Handmade Sweater — Blue | 50.00 USD | |
Handmade sweater subtotal | 50.00 USD | |
Chicken Treats — Chewy trainers | 36.00 USD | |
Chewy trainers subtotal | 36.00 USD | |
ORDER SUBTOTAL | 113.90 USD |
The Orders API applies order-level percent discounts to each individual line item. In this example, that means every line item takes 12% off for a National Puppy Day Sale.
Item | Item Amount | Final Amount |
---|---|---|
Chicken Treats — Tendon pinwheel | 27.90 USD | |
12% OFF — National Puppy Day Sale
(27.90 x 0.12 = −3.35 USD) |
24.55 USD | |
Tendon pinwheel subtotal | 24.55 USD | |
Handmade Sweater — Blue | 50.00 USD | |
12% OFF — National Puppy Day Sale
(50.00 x 0.12 = −6.00 USD) |
44.00 USD | |
Handmade sweater subtotal | 44.00 USD | |
Chicken Treats — Chewy trainers | 36.00 USD | |
12% OFF — National Puppy Day Sale
(36.00 x 0.12 = −4.32 USD) |
31.68 USD | |
Chicken treats subtotal | 31.68 USD | |
ORDER SUBTOTAL | 100.23 USD |
Fixed-amount order-level discounts are converted to the equivalent item-level discount based on the relative portion that the line item contributes to the most recent subtotal using the following formula:
In this example, the order-level fixed discount is 55.00 USD and distributed across three line items based on a subtotal of 86.23 USD:
Item | Item Amount | Final Amount |
---|---|---|
Chicken Treats — Tendon pinwheel | 21.55 USD | |
$55 OFF — Global Sales
$$\displaystyle{\left(\frac{21.55}{{86.23}}\right)}\times{55.00}=-{13.75}$$ |
7.80 USD | |
Tendon pinwheel subtotal | 7.80 USD | |
Handmade Sweater — Blue | 44.00 USD | |
$55 OFF — Global Sales
$$\displaystyle{\left(\frac{44.00}{{86.23}}\right)}\times{55.00}=-{28.06}$$ |
15.94 USD | |
Handmade sweater subtotal | 15.94 USD | |
Chicken Treats — Chewy trainers | 20.68 USD | |
$55 OFF — Global Sales
$$\displaystyle{\left(\frac{20.68}{{86.23}}\right)}\times{55.00}=-{13.19}$$ |
7.49 USD | |
Chewy trainers subtotal | 7.49 USD | |
ORDER SUBTOTAL | 31.23 USD |
The Orders API applies item-level fixed-amount discounts to the applicable line items. In this example, that means the Tendon pinwheels and the Chewy trainers receive a fixed-amount discount.
Item | Item Amount | Final Amount |
---|---|---|
Chicken Treats — Tendon pinwheel | 24.55 USD | |
$3.00 OFF — Customer Loyalty Discount (−3.00 USD) | 21.55 USD | |
Chicken Treats subtotal | 21.55 USD | |
Handmade Sweater — Blue | 44.00 USD | |
Handmade sweater subtotal | 44.00 USD | |
Chicken Treats — Chewy trainers | 31.68 USD | |
$11.00 OFF — Customer Loyalty Discount (−11.00 USD) | 20.68 USD | |
Chewy trainers subtotal | 20.68 USD | |
ORDER SUBTOTAL | 86.23 USD |
The last step is to apply all applicable taxes. Item-level taxes are applied first and then order-level taxes are distributed to each line item in the order.
Item | Item Amount | Final Amount |
---|---|---|
Chicken Treats — Tendon pinwheel | 7.80 USD | |
State Sales Tax: 8.5%
$$\displaystyle{\left({7.80}\times{0.085}\right)}=+{0.66}$$ |
8.46 USD | |
Tendon pinwheel subtotal | 8.46 USD | |
Handmade Sweater — Blue | 15.94 USD | |
State Sales Tax: 8.5%
$$\displaystyle{\left({15.94}\times{0.085}\right)}=+{1.35}$$ |
17.29 | |
Handmade sweater subtotal | 17.29 USD | |
Chicken Treats — Chewy trainers | 7.49 USD | |
Fair Trade Tax: 5%
$$\displaystyle{\left({7.49}\times{0.05}\right)}=+{0.37}$$ |
7.86 USD | |
State Sales Tax: 8.5%
$$\displaystyle{\left({7.49}\times{0.085}\right)}=+{0.64}$$ |
8.50 USD | |
Chewy trainers subtotal | 8.50 USD | |
ORDER SUBTOTAL | 34.25 USD |
To calculate order-level taxes and discounts:
Add up the total cost of all order items.
Calculate the tax or discount for that item total.
Distribute the tax or discount proportionally to each item.
If the tax or discount for the total cost of the group equals an odd number, the remainder is applied to one of the items in the group. This way, the total cost of the entire order remains accurate.
For example, suppose you apply a 9.25% sales tax to three dog collars that cost 3.50 USD each:
Red Dog Collar: 3.50 USD with a 9.25% sales tax
Blue Dog Collar: 3.50 USD with a 9.25% sales tax
Yellow Dog Collar: 3.50 USD with a 9.25% sales tax
First, you add up the total cost of the items:
3.50 USD + 3.50 USD + 3.50 USD = 10.50 USD
Next, you calculate the total tax for the combined cost and use bankers rounding to round to the nearest even amount:
10.50 USD x 0.0925 = 0.97125 USD
0.97125 USD rounds to 0.97 USD
Finally, distribute the tax proportionally to each individual item. Because the total tax amount does not divide evenly by the total number of items, apply the remainder (0.01 USD) to one of the items:
Red Dog Collar: 3.50 USD + 0.32 USD = 3.82 USD
Blue Dog Collar: 3.50 USD + 0.32 USD = 3.82 USD
Yellow Dog Collar: 3.50 USD + 0.33 USD = 3.83 USD
Suppose you want to calculate a 15% discount for three dog treats that cost 4.50 USD each:
Dog Cookie: 4.50 USD with a 15% Discount
Dog Bone: 4.50 USD with a 15% Discount
Dog Banana: 4.50 USD with a 15% Discount
First, you add up the total cost of the items:
4.50 USD + 4.50 USD + 4.50 USD = 13.50 USD
Next, you calculate the total discount for the combined cost and use bankers rounding to round to the nearest even amount:
13.50 USD x –0.15 = –2.025 USD
–2.025 USD rounds to –2.02 USD
Finally, distribute the discount proportionally to each individual item. Because the total discount amount does not divide evenly by the total number of items, apply the remainder (–0.01 USD) to one of the items:
Dog Cookie: 4.50 USD – 0.67 USD = 3.83 USD
Dog Bone: 4.50 USD – 0.67 USD = 3.83 USD
Dog Banana: 4.50 USD – 0.68 USD = 3.84 USD
All order details are available through the BatchRetrieveOrders and SearchOrders endpoints.
Fulfillment orders only appear in the Seller Dashboard after they are charged. Note that fulfillment orders must have delay_capture
set to true
.
If you need more assistance, contact Developer Support or ask for help in the Developer Forums.