square_api_client/models/order_line_item_discount.rs
1//! Model struct for OrderLineItemDiscount type
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7use super::{
8 enums::{OrderLineItemDiscountScope, OrderLineItemDiscountType},
9 Money,
10};
11
12/// Represents a discount that applies to one or more line items in an order.
13///
14/// Fixed-amount, order-scoped discounts are distributed across all non-zero line item totals. The
15/// amount distributed to each line item is relative to the amount contributed by the item to the
16/// order subtotal.
17#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
18pub struct OrderLineItemDiscount {
19 /// A unique ID that identifies the discount only within this order.
20 pub uid: Option<String>,
21 /// The catalog object ID referencing [CatalogDiscount].
22 pub catalog_object_id: Option<String>,
23 /// The version of the catalog object that this discount references.
24 pub catalog_version: Option<i64>,
25 /// The discount's name.
26 pub name: Option<String>,
27 /// The type of the discount.
28 ///
29 /// Discounts that do not reference a catalog object ID must have a type of `FIXED_PERCENTAGE`
30 /// or `FIXED_AMOUNT`.
31 pub r#type: Option<OrderLineItemDiscountType>,
32 /// The percentage of the discount, as a string representation of a decimal number. A value of
33 /// `7.25` corresponds to a percentage of 7.25%.
34 ///
35 /// `percentage` is not set for amount-based discounts.
36 pub percentage: Option<String>,
37 /// The total declared monetary amount of the discount.
38 ///
39 /// `amount_money` is not set for percentage-based discounts.
40 pub amount_money: Option<Money>,
41 /// The amount of discount actually applied to the line item.
42 ///
43 /// The amount represents the amount of money applied as a line-item scoped discount. When an
44 /// amount-based discount is scoped to the entire order, the value of `applied_money` is
45 /// different than `amount_money` because the total amount of the discount is distributed across
46 /// all line items.
47 pub applied_money: Option<Money>,
48 /// Application-defined data attached to this discount. Metadata fields are intended to store
49 /// descriptive references or associations with an entity in another system or store brief
50 /// information about the object. Square does not process this field; it only stores and returns
51 /// it in relevant API calls. Do not use metadata to store any sensitive information (such as
52 /// personally identifiable information or card details).
53 ///
54 /// Keys written by applications must be 60 characters or less and must be in the character set
55 /// `[a-zA-Z0-9_-]`. Entries can also include metadata generated by Square. These keys are
56 /// prefixed with a namespace, separated from the key with a ':' character.
57 ///
58 /// Values have a maximum length of 255 characters.
59 ///
60 /// An application can have up to 10 entries per metadata field.
61 ///
62 /// Entries written by applications are private and can only be read or modified by the same
63 /// application.
64 ///
65 /// For more information,
66 /// see [Metadata](https://developer.squareup.com/docs/build-basics/metadata).
67 pub metadata: Option<HashMap<String, String>>,
68 /// Indicates the level at which the discount applies. For `ORDER` scoped discounts, Square
69 /// generates references in `applied_discounts` on all order line items that do not have them.
70 /// For `LINE_ITEM` scoped discounts, the discount only applies to line items with a discount
71 /// reference in their `applied_discounts` field.
72 ///
73 /// This field is immutable. To change the scope of a discount, you must delete the discount and
74 /// re-add it as a new discount.
75 pub scope: Option<OrderLineItemDiscountScope>,
76 /// **Read only** The reward IDs corresponding to this discount. The application and
77 /// specification of discounts that have `reward_ids` are completely controlled by the backing
78 /// criteria corresponding to the reward tiers of the rewards that are added to the order
79 /// through the Loyalty API. To manually unapply discounts that are the result of added rewards,
80 /// the rewards must be removed from the order through the Loyalty API.
81 pub reward_ids: Option<Vec<String>>,
82 /// **Read only** The object ID of a [pricing rule](CatalogPricingRule) to be applied
83 /// automatically to this discount. The specification and application of the discounts, to which
84 /// a `pricing_rule_id` is assigned, are completely controlled by the corresponding pricing
85 /// rule.
86 pub pricing_rule_id: Option<String>,
87}