squareup/models/
order_service_charge.rs

1//! Model struct for OrderServiceCharge type
2
3use std::collections::HashMap;
4
5use crate::models::enums::{OrderServiceChargeScope, OrderServiceChargeTreatmentType};
6use serde::{Deserialize, Serialize};
7
8use super::{
9    Money, OrderLineItemAppliedTax,
10    enums::{OrderServiceChargeCalculationPhase, OrderServiceChargeType},
11};
12
13/// Represents a service charge applied to an order.
14#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
15pub struct OrderServiceCharge {
16    /// A unique ID that identifies the service charge only within this order.
17    pub uid: Option<String>,
18    /// The name of the service charge.
19    pub name: Option<String>,
20    /// The catalog object ID referencing the service charge [CatalogObject].
21    pub catalog_object_id: Option<String>,
22    /// The version of the catalog object that this service charge references.
23    pub catalog_version: Option<i64>,
24    /// The service charge percentage as a string representation of a decimal number. For example,
25    /// "7.25" indicates a service charge of 7.25%.
26    ///
27    /// Exactly 1 of `percentage` or `amount_money` should be set.
28    pub percentage: Option<String>,
29    /// The amount of a non-percentage-based service charge.
30    ///
31    /// Exactly one of `percentage` or `amount_money` should be set.
32    pub amount_money: Option<Money>,
33    /// **Read only** The amount of money applied to the order by the service charge, including any
34    /// inclusive tax amounts, as calculated by Square.
35    ///
36    /// For fixed-amount service charges, `applied_money` is equal to `amount_money`.
37    /// For percentage-based service charges, `applied_money` is the money calculated using the
38    /// percentage.
39    pub applied_money: Option<Money>,
40    /// **Read only** The total amount of money to collect for the service charge.
41    ///
42    /// Note: If an inclusive tax is applied to the service charge, `total_money` does not equal
43    /// `applied_money` plus `total_tax_money` because the inclusive tax amount is already included
44    /// in both `applied_money` and `total_tax_money`.
45    pub total_money: Option<Money>,
46    /// **Read only** The total amount of tax money to collect for the service charge.
47    pub total_tax_money: Option<Money>,
48    /// The calculation phase at which to apply the service charge.
49    pub calculation_phase: Option<OrderServiceChargeCalculationPhase>,
50    /// Indicates whether the service charge can be taxed. If set to `true`, order-level taxes
51    /// automatically apply to the service charge. Note that service charges calculated in the
52    /// `TOTAL_PHASE` cannot be marked as taxable.
53    pub taxable: Option<bool>,
54    /// The list of references to the taxes applied to this service charge. Each
55    /// `OrderLineItemAppliedTax` has a `tax_uid` that references the `uid` of a top-level
56    /// `OrderLineItemTax` that is being applied to this service charge. On reads, the amount
57    /// applied is populated.
58    ///
59    /// An `OrderLineItemAppliedTax` is automatically created on every taxable service charge for
60    /// all `ORDER` scoped taxes that are added to the order. `OrderLineItemAppliedTax` records for
61    /// `LineItem` scoped taxes must be added in requests for the tax to apply to any taxable
62    /// service charge. Taxable service charges have the `taxable` field set to `true` and
63    /// calculated in the `SUBTOTAL_PHASE`.
64    ///
65    /// To change the amount of a tax, modify the referenced top-level tax.
66    pub applied_taxes: Option<Vec<OrderLineItemAppliedTax>>,
67    /// Application-defined data attached to this service charge. Metadata fields are intended to
68    /// store descriptive references or associations with an entity in another system or store brief
69    /// information about the object. Square does not process this field; it only stores and returns
70    /// it in relevant API calls. Do not use metadata to store any sensitive information (such as
71    /// personally identifiable information or card details).
72    ///
73    /// Keys written by applications must be 60 characters or less and must be in the character set
74    /// [a-zA-Z0-9_-]. Entries can also include metadata generated by Square. These keys are
75    /// prefixed with a namespace, separated from the key with a ':' character.
76    ///
77    /// Values have a maximum length of 255 characters.
78    ///
79    /// An application can have up to 10 entries per metadata field.
80    ///
81    /// Entries written by applications are private and can only be read or modified by the same
82    /// application.
83    ///
84    /// For more information, see
85    /// [Metadata](https://developer.squareup.com/docs/build-basics/metadata).
86    pub metadata: Option<HashMap<String, String>>,
87    /// **Read only** The type of the service charge.
88    pub r#type: Option<OrderServiceChargeType>,
89    /// **Read only** The treatment type of the service charge.
90    pub treatment_type: Option<OrderServiceChargeTreatmentType>,
91    /// Indicates the level at which the apportioned service charge applies. For ORDER scoped service charges,
92    /// Square generates references in applied_service_charges on all order line items that do not have them.
93    /// For LineItem scoped service charges, the service charge only applies to line items with a service
94    /// charge reference in their applied_service_charges field.
95    ///
96    /// This field is immutable. To change the scope of an apportioned service charge, you must delete the
97    /// apportioned service charge and re-add it as a new apportioned service charge
98    pub scope: Option<OrderServiceChargeScope>,
99}