rust_woocommerce/models/
orders.rs

1use crate::controllers::orders::{CreateOrderBuilder, UpdateOrderBuilder};
2
3use super::{
4    customers::{Billing, Shipping},
5    data::CurrencyISO,
6    MetaData,
7};
8use crate::controllers::Entity;
9use crate::TaxStatus;
10use chrono::NaiveDateTime;
11use serde::{Deserialize, Serialize};
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct Order {
15    /// Unique identifier for the resource.
16    pub id: i32,
17    /// Parent order ID.
18    pub parent_id: Option<i32>,
19    /// Order number.
20    pub number: String,
21    /// Order key.
22    pub order_key: String,
23    /// Shows where the order was created.
24    pub created_via: String,
25    /// Version of WooCommerce which last updated the order.
26    pub version: String,
27    /// Order status.
28    pub status: OrderStatus,
29    /// Currency the order was created with, in ISO format.
30    pub currency: CurrencyISO,
31    /// The date the order was created, in the site's timezone.
32    pub date_created: Option<NaiveDateTime>,
33    /// The date the order was created, as GMT.    
34    pub date_created_gmt: Option<NaiveDateTime>,
35    ///The date the order was last modified, in the site's timezone.
36    pub date_modified: Option<NaiveDateTime>,
37    /// The date the order was last modified, as GMT
38    pub date_modified_gmt: Option<NaiveDateTime>,
39    /// Total discount amount for the order.
40    pub discount_total: String,
41    /// Total discount tax amount for the order.
42    pub discount_tax: String,
43    /// Total shipping amount for the order.
44    pub shipping_total: String,
45    /// Total shipping tax amount for the order.
46    pub shipping_tax: String,
47    /// Sum of line item taxes only.
48    pub cart_tax: String,
49    /// Grand total.
50    pub total: String,
51    /// Sum of all taxes.
52    pub total_tax: String,
53    /// True the prices included tax during checkout.
54    pub prices_include_tax: bool,
55    /// User ID who owns the order. 0 for guests. Default is 0.
56    pub customer_id: i32,
57    /// Customer's IP address.
58    pub customer_ip_address: String,
59    /// User agent of the customer.
60    pub customer_user_agent: String,
61    /// Note left by customer during checkout.
62    pub customer_note: String,
63    /// Billing address.
64    pub billing: Billing,
65    /// Shipping address.
66    pub shipping: Shipping,
67    /// Payment method ID.
68    pub payment_method: String,
69    /// Payment method title.
70    pub payment_method_title: String,
71    /// Unique transaction ID.
72    pub transaction_id: String,
73    /// The date the order was paid, in the site's timezone.
74    pub date_paid: Option<NaiveDateTime>,
75    /// The date the order was paid, as GMT.
76    pub date_paid_gmt: Option<NaiveDateTime>,
77    /// The date the order was completed, in the site's timezone.
78    pub date_completed: Option<NaiveDateTime>,
79    /// The date the order was completed, as GMT.
80    pub date_completed_gmt: Option<NaiveDateTime>,
81    /// MD5 hash of cart items to ensure orders are not modified.
82    pub cart_hash: String,
83    /// Meta data.
84    pub meta_data: Vec<MetaData>,
85    /// Line items data.
86    pub line_items: Vec<OrderLineItemProperties>,
87    /// Tax lines data.
88    pub tax_lines: Vec<OrderTaxLineProperties>,
89    /// Shipping lines data.
90    pub shipping_lines: Vec<ShippingLineProperties>,
91    /// Fee lines data.
92    pub fee_lines: Vec<OrderFeeLineProperties>,
93    /// Coupons line data.
94    pub coupon_lines: Vec<OrderCouponLineProperties>,
95    /// List of refunds.
96    pub refunds: Vec<OrderRefundProperties>,
97    // Define if the order is paid. It will set the status to processing and reduce stock items. Default is false.
98    // pub set_paid: bool,
99}
100impl Order {
101    pub fn create() -> CreateOrderBuilder {
102        CreateOrderBuilder::default()
103    }
104    pub fn update() -> UpdateOrderBuilder {
105        UpdateOrderBuilder::default()
106    }
107}
108impl Entity for Order {
109    fn endpoint() -> String {
110        String::from("orders/")
111    }
112    fn child_endpoint(parent_id: i32) -> String {
113        let _ = parent_id;
114        String::new()
115    }
116}
117#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
118#[serde(rename_all = "kebab-case")]
119pub enum OrderStatus {
120    #[default]
121    Pending,
122    Processing,
123    OnHold,
124    Completed,
125    Cancelled,
126    Refunded,
127    Failed,
128    Trash,
129    Draft,
130}
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct OrderLineItemProperties {
133    /// Item ID.
134    pub id: i32,
135    /// Product name.
136    pub name: String,
137    /// Product ID.
138    pub product_id: i32,
139    /// Variation ID, if applicable.
140    pub variation_id: Option<i32>,
141    /// Quantity ordered.
142    pub quantity: i32,
143    /// Slug of the tax class of product.
144    pub tax_class: String,
145    /// Line subtotal (before discounts).
146    pub subtotal: String,
147    /// Line subtotal tax (before discounts).
148    pub subtotal_tax: String,
149    /// Line total (after discounts).
150    pub total: String,
151    /// Line total tax (after discounts).
152    pub total_tax: String,
153    /// Line taxes.
154    pub taxes: Vec<OrderTax>,
155    /// Meta data.
156    pub meta_data: Vec<MetaData>,
157    /// Product SKU.
158    pub sku: Option<String>,
159    /// Product price.
160    pub price: f64,
161}
162#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct OrderTaxLineProperties {
164    /// Item ID.
165    pub id: i32,
166    /// Tax rate code.
167    pub rate_code: String,
168    /// Tax rate ID.
169    pub rate_id: String,
170    /// Tax rate label.
171    pub label: String,
172    /// Show if is a compound tax rate.
173    pub compound: bool,
174    /// Tax total (not including shipping taxes).
175    pub tax_total: String,
176    /// Shipping tax total.
177    pub shipping_tax_total: String,
178    /// Meta data.
179    pub meta_data: Vec<MetaData>,
180}
181#[derive(Debug, Clone, Serialize, Deserialize)]
182pub struct ShippingLineProperties {
183    /// Item ID.
184    pub id: i32,
185    /// Shipping method name.
186    pub method_title: String,
187    /// Shipping method ID.
188    pub method_id: String,
189    /// Line total (after discounts).
190    pub total: String,
191    /// Line total tax (after discounts).
192    pub total_tax: String,
193    /// Line taxes.
194    pub taxes: Vec<OrderTax>,
195    /// Meta data.
196    pub meta_data: Vec<MetaData>,
197}
198#[derive(Debug, Clone, Serialize, Deserialize)]
199pub struct OrderFeeLineProperties {
200    /// Item ID.
201    pub id: i32,
202    /// Fee name.
203    pub name: String,
204    /// Tax class of fee.
205    pub tax_class: String,
206    /// Tax status of fee. Options: taxable and none.
207    pub tax_status: TaxStatus,
208    /// Line total (after discounts).
209    pub total: String,
210    /// Line total tax (after discounts).
211    pub total_tax: String,
212    /// Line taxes.
213    pub taxes: Vec<OrderTax>,
214    /// Meta data.
215    pub meta_data: Vec<MetaData>,
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize)]
219pub struct OrderCouponLineProperties {
220    /// Item ID.
221    pub id: i32,
222    /// Coupon code.
223    pub code: String,
224    /// Discount total.
225    pub discount: String,
226    /// Discount total tax.
227    pub discount_tax: String,
228    /// Meta data.
229    pub meta_data: Vec<MetaData>,
230}
231#[derive(Debug, Clone, Serialize, Deserialize)]
232pub struct OrderRefundProperties {
233    /// Refund ID.
234    pub id: i32,
235    /// Refund reason.
236    pub reason: String,
237    /// Refund total.
238    pub total: String,
239}
240
241#[derive(Debug, Clone, Serialize, Deserialize)]
242pub struct OrderTax {
243    /// Item ID.
244    pub id: i32,
245    /// Tax rate code.
246    pub rate_code: String,
247    /// Tax rate ID.
248    pub rate_id: String,
249    /// Tax rate label.
250    pub label: String,
251    /// Show if is a compound tax rate.
252    pub compound: bool,
253    /// Tax total (not including shipping taxes).
254    pub tax_total: String,
255    /// Shipping tax total.
256    pub shipping_tax_total: String,
257    /// Meta data.
258    pub meta_data: Vec<MetaData>,
259}