stripe/model/discount.rs
1use serde::{Serialize, Deserialize};
2use super::Coupon;
3/**A discount represents the actual application of a [coupon](https://stripe.com/docs/api#coupons) or [promotion code](https://stripe.com/docs/api#promotion_codes).
4It contains information about when the discount began, when it will end, and what it is applied to.
5
6Related guide: [Applying discounts to subscriptions](https://stripe.com/docs/billing/subscriptions/discounts)*/
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8pub struct Discount {
9 ///The Checkout session that this coupon is applied to, if it is applied to a particular session in payment mode. Will not be present for subscription mode.
10 #[serde(skip_serializing_if = "Option::is_none")]
11 pub checkout_session: Option<String>,
12 /**A coupon contains information about a percent-off or amount-off discount you
13might 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),
14[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).*/
15 pub coupon: Coupon,
16 ///The ID of the customer associated with this discount.
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub customer: Option<serde_json::Value>,
19 ///If the coupon has a duration of `repeating`, the date that this discount will end. If the coupon has a duration of `once` or `forever`, this attribute will be null.
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub end: Option<i64>,
22 ///The ID of the discount object. Discounts cannot be fetched by ID. Use `expand[]=discounts` in API calls to expand discount IDs in an array.
23 pub id: String,
24 ///The invoice that the discount's coupon was applied to, if it was applied directly to a particular invoice.
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub invoice: Option<String>,
27 ///The invoice item `id` (or invoice line item `id` for invoice line items of type='subscription') that the discount's coupon was applied to, if it was applied directly to a particular invoice item or invoice line item.
28 #[serde(skip_serializing_if = "Option::is_none")]
29 pub invoice_item: Option<String>,
30 ///String representing the object's type. Objects of the same type share the same value.
31 pub object: String,
32 ///The promotion code applied to create this discount.
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub promotion_code: Option<serde_json::Value>,
35 ///Date that the coupon was applied.
36 pub start: i64,
37 ///The subscription that this coupon is applied to, if it is applied to a particular subscription.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub subscription: Option<String>,
40}
41impl std::fmt::Display for Discount {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
43 write!(f, "{}", serde_json::to_string(self).unwrap())
44 }
45}