rust_woocommerce/models/refunds.rs
1use crate::controllers::refunds::{NoAmount, NoItems, RefundCreate, RefundCreateBuilder};
2
3use super::MetaData;
4use crate::controllers::Entity;
5use chrono::NaiveDateTime;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Refund {
10 /// Unique identifier for the resource.
11 pub id: i32,
12 /// The date the order refund was created, in the site's timezone.
13 pub date_created: NaiveDateTime,
14 /// The date the order refund was created, as GMT.
15 pub date_created_gmt: NaiveDateTime,
16 /// Total refund amount. Optional. If this parameter is provided, it will take precedence over line item totals, even when total of line items does not matches with this amount.
17 pub amount: Option<String>,
18 /// Reason for refund.
19 pub reason: String,
20 /// User ID of user who created the refund.
21 pub refunded_by: i32,
22 /// If the payment was refunded via the API. See api_refund.
23 pub refunded_payment: bool,
24 /// Meta data.
25 pub meta_data: Vec<MetaData>,
26 /// Line items data.
27 pub line_items: Vec<OrderRefundLineItem>,
28 // When true, the payment gateway API is used to generate the refund. Default is true.
29 // pub api_refund: bool,
30 // When true, the selected line items are restocked Default is true.
31 // pub api_restock: bool,
32}
33impl Entity for Refund {
34 fn endpoint() -> String {
35 String::new()
36 }
37
38 fn child_endpoint(parent_id: i32) -> String {
39 format!("orders/{parent_id}/refunds/")
40 }
41}
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct OrderRefundLineItem {
44 /// Item ID
45 pub id: i32,
46 /// Product name.
47 pub name: String,
48 /// Product ID.
49 pub product_id: i32,
50 /// Variation ID, if applicable.
51 pub variation_id: Option<i32>,
52 /// Quantity ordered.
53 pub quantity: i32,
54 /// Tax class of product.
55 pub tax_class: i32,
56 /// Line subtotal (before discounts).
57 pub subtotal: String,
58 /// Line subtotal tax (before discounts).
59 pub subtotal_tax: String,
60 /// Line total (after discounts).
61 pub total: String,
62 /// Line total tax (after discounts).
63 pub total_tax: String,
64 /// Line taxes.
65 pub taxes: Vec<OrderRefundLineItemTaxesProperties>,
66 /// Meta data.
67 pub meta_data: Vec<MetaData>,
68 /// Product SKU.
69 pub sku: String,
70 /// Product price.
71 pub price: String,
72 // The amount to refund for this line item, excluding taxes.
73 // pub refund_total: f64,
74}
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct OrderRefundLineItemTaxesProperties {
77 /// Tax rate ID.
78 pub id: i32,
79 /// Tax total.
80 pub total: String,
81 /// Tax subtotal.
82 pub subtotal: String,
83 // The amount to refund for this tax.
84 // pub refund_total: f64,
85}
86impl Refund {
87 pub fn create() -> RefundCreateBuilder<NoAmount, NoItems> {
88 RefundCreate::builder()
89 }
90}