square_api_client/models/order.rs
1//! Model struct for Order type
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7use super::{
8 enums::OrderState, DateTime, Money, OrderFulfillment, OrderLineItem, OrderLineItemDiscount,
9 OrderLineItemTax, OrderMoneyAmounts, OrderPricingOptions, OrderReturn, OrderReward,
10 OrderRoundingAdjustment, OrderServiceCharge, OrderSource, Refund, Tender,
11};
12
13/// Contains all information related to a single order to process with Square, including line items
14/// that specify the products to purchase.
15///
16/// `Order` objects also include information about any associated tenders, refunds, and returns.
17///
18/// All Connect V2 Transactions have all been converted to Orders including all associated
19/// itemization data.
20#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
21pub struct Order {
22 /// **Read only** The order's unique ID.
23 pub id: Option<String>,
24 /// The ID of the seller location that this order is associated with.
25 pub location_id: Option<String>,
26 /// A client-specified ID to associate an entity in another system with this order.
27 pub reference_id: Option<String>,
28 /// The origination details of the order.
29 pub source: Option<OrderSource>,
30 /// The ID of the [Customer] associated with the order.
31 ///
32 /// **IMPORTANT:** You should specify a `customer_id` if you want the corresponding payment
33 /// transactions to be explicitly linked to the customer in the Seller Dashboard. If this field
34 /// is omitted, the `customer_id` assigned to any underlying `Payment` objects is ignored and
35 /// might result in the creation of new [instant
36 /// profiles](https://developer.squareup.com/docs/customers-api/what-it-does#instant-profiles).
37 pub customer_id: Option<String>,
38 /// The line items included in the order.
39 pub line_items: Option<Vec<OrderLineItem>>,
40 /// The list of all taxes associated with the order.
41 ///
42 /// Taxes can be scoped to either `ORDER` or `LINE_ITEM`. For taxes with `LINE_ITEM` scope, an
43 /// `OrderLineItemAppliedTax` must be added to each line item that the tax applies to. For taxes
44 /// with `ORDER` scope, the server generates an `OrderLineItemAppliedTax` for every line item.
45 ///
46 /// On reads, each tax in the list includes the total amount of that tax applied to the order.
47 ///
48 /// **IMPORTANT:** If `LINE_ITEM` scope is set on any taxes in this field, using the deprecated
49 /// `line_items.taxes` field results in an error. Use `line_items.applied_taxes` instead.
50 pub taxes: Option<Vec<OrderLineItemTax>>,
51 /// The list of all discounts associated with the order.
52 ///
53 /// Discounts can be scoped to either `ORDER` or `LINE_ITEM`. For discounts scoped to
54 /// `LINE_ITEM`, an `OrderLineItemAppliedDiscount` must be added to each line item that the
55 /// discount applies to. For discounts with `ORDER` scope, the server generates an
56 /// `OrderLineItemAppliedDiscount` for every line item.
57 ///
58 /// **IMPORTANT:** If `LINE_ITEM` scope is set on any discounts in this field, using the
59 /// deprecated `line_items.discounts` field results in an error. Use
60 /// `line_items.applied_discounts` instead.
61 pub discounts: Option<Vec<OrderLineItemDiscount>>,
62 /// A list of service charges applied to the order.
63 pub service_charges: Option<Vec<OrderServiceCharge>>,
64 /// Details about order fulfillment.
65 ///
66 /// Orders can only be created with at most one fulfillment. However, orders returned by the API
67 /// might contain multiple fulfillments.
68 pub fulfillments: Option<Vec<OrderFulfillment>>,
69 /// **Read only** A collection of items from sale orders being returned in this one. Normally
70 /// part of an itemized return or exchange. There is exactly one `Return` object per sale
71 /// `Order` being referenced.
72 pub returns: Option<Vec<OrderReturn>>,
73 /// **Read only** A collection of various money amounts.
74 pub return_amounts: Option<OrderMoneyAmounts>,
75 /// **Read only** A collection of various money amounts.
76 pub net_amounts: Option<OrderMoneyAmounts>,
77 /// **Read only** A rounding adjustment of the money being returned. Commonly used to apply cash
78 /// rounding when the minimum unit of the account is smaller than the lowest physical
79 /// denomination of the currency.
80 pub rounding_adjustment: Option<OrderRoundingAdjustment>,
81 /// **Read only** The tenders that were used to pay for the order.
82 pub tenders: Option<Vec<Tender>>,
83 /// **Read only** The refunds that are part of this order.
84 pub refunds: Option<Vec<Refund>>,
85 /// Application-defined data attached to this order. Metadata fields are intended to store
86 /// descriptive references or associations with an entity in another system or store brief
87 /// information about the object. Square does not process this field; it only stores and returns
88 /// it in relevant API calls. Do not use metadata to store any sensitive information (such as
89 /// personally identifiable information or card details).
90 ///
91 /// Keys written by applications must be 60 characters or less and must be in the character set
92 /// `[a-zA-Z0-9_-]`. Entries can also include metadata generated by Square. These keys are
93 /// prefixed with a namespace, separated from the key with a ':' character.
94 ///
95 /// Values have a maximum length of 255 characters.
96 ///
97 /// An application can have up to 10 entries per metadata field.
98 ///
99 /// Entries written by applications are private and can only be read or modified by the same
100 /// application.
101 ///
102 /// For more information,
103 /// see [Metadata](https://developer.squareup.com/docs/build-basics/metadata).
104 pub metadata: Option<HashMap<String, String>>,
105 /// **Read only** The timestamp for when the order was created.
106 pub created_at: Option<DateTime>,
107 /// **Read only** The timestamp for when the order was last updated.
108 pub updated_at: Option<DateTime>,
109 /// **Read only** The timestamp for when the order reached a terminal [state](OrderState).
110 pub closed_at: Option<DateTime>,
111 /// The current state of the order.
112 pub state: Option<OrderState>,
113 /// The version number, which is incremented each time an update is committed to the order.
114 /// Orders not created through the API do not include a version number and therefore cannot be
115 /// updated.
116 ///
117 /// [Read more about working with
118 /// versions](https://developer.squareup.com/docs/orders-api/manage-orders#update-orders).
119 pub version: Option<i32>,
120 /// **Read only** The total amount of money to collect for the order.
121 pub total_money: Option<Money>,
122 /// **Read only** The total amount of tax money to collect for the order.
123 pub total_tax_money: Option<Money>,
124 /// **Read only** The total amount of discount money to collect for the order.
125 pub total_discount_money: Option<Money>,
126 /// **Read only** The total amount of tip money to collect for the order.
127 pub total_tip_money: Option<Money>,
128 /// **Read only** The total amount of money collected in service charges for the order.
129 ///
130 /// Note: `total_service_charge_money` is the sum of `applied_money` fields for each individual
131 /// service charge. Therefore, `total_service_charge_money` only includes inclusive tax amounts,
132 /// not additive tax amounts.
133 pub total_service_charge_money: Option<Money>,
134 /// A short-term identifier for the order (such as a customer first name, table number, or
135 /// auto-generated order number that resets daily). For orders created in Square Point of Sale,
136 /// the `ticket_name` is printed on in-person tickets and stubs. It converts to the
137 /// `kitchen_printing.name` field in the bill cart feature details.
138 pub ticket_name: Option<String>,
139 /// Pricing options for an order. The options affect how the order's price is calculated. They
140 /// can be used, for example, to apply automatic price adjustments that are based on
141 /// preconfigured [pricing rules](CatalogPricingRule).
142 pub pricing_options: Option<OrderPricingOptions>,
143 /// **Read only** A set-like list of Rewards that have been added to the Order.
144 pub rewards: Option<Vec<OrderReward>>,
145}