stripe/model/
promotion_code.rs

1use serde::{Serialize, Deserialize};
2use super::{Coupon, PromotionCodesResourceRestrictions};
3/**A Promotion Code represents a customer-redeemable code for a [coupon](https://stripe.com/docs/api#coupons). It can be used to
4create multiple codes for a single coupon.*/
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6pub struct PromotionCode {
7    ///Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid.
8    pub active: bool,
9    ///The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for each customer.
10    pub code: String,
11    /**A coupon contains information about a percent-off or amount-off discount you
12might want to apply to a customer. Coupons may be applied to [subscriptions](https://stripe.com/docs/api#subscriptions), [invoices](https://stripe.com/docs/api#invoices),
13[checkout sessions](https://stripe.com/docs/api/checkout/sessions), [quotes](https://stripe.com/docs/api#quotes), and more. Coupons do not work with conventional one-off [charges](https://stripe.com/docs/api#create_charge) or [payment intents](https://stripe.com/docs/api/payment_intents).*/
14    pub coupon: Coupon,
15    ///Time at which the object was created. Measured in seconds since the Unix epoch.
16    pub created: i64,
17    ///The customer that this promotion code can be used by.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub customer: Option<serde_json::Value>,
20    ///Date at which the promotion code can no longer be redeemed.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub expires_at: Option<i64>,
23    ///Unique identifier for the object.
24    pub id: String,
25    ///Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
26    pub livemode: bool,
27    ///Maximum number of times this promotion code can be redeemed.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub max_redemptions: Option<i64>,
30    ///Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub metadata: Option<serde_json::Value>,
33    ///String representing the object's type. Objects of the same type share the same value.
34    pub object: String,
35    ///
36    pub restrictions: PromotionCodesResourceRestrictions,
37    ///Number of times this promotion code has been used.
38    pub times_redeemed: i64,
39}
40impl std::fmt::Display for PromotionCode {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
42        write!(f, "{}", serde_json::to_string(self).unwrap())
43    }
44}