1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// This file is auto-generated by oagen. Do not edit.
#[allow(unused_imports)]
use super::*;
#[allow(unused_imports)]
use crate::enums::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(remote = "Self")]
pub struct SdkCreateCouponRequestApplicationJson {
pub code: String,
#[serde(rename = "type")]
pub type_: SdkCreateCouponRequestApplicationJsonType,
/// A decimal discount value of at least 1. Percentage discounts cannot exceed 100; amount discounts use the store currency's major unit. A `subscriptions` coupon cannot take 100% off: that returns `422` on `discount`, so offer a free trial instead.
pub discount: SdkCreateCouponRequestApplicationJsonDiscountOneOf,
pub store_wide: bool,
/// Product IDs the coupon applies to when store_wide is false. Each product you add must sell a variant of the coupon's kind: a subscription plan for a `subscriptions` coupon, or a one-time variant for a `one_time` one. Another product returns `422` on `products`.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub products: Option<Vec<i64>>,
/// Optional variant restrictions. Every variant must belong to a selected product. Products without listed variants remain eligible on all variants. Each variant you add must be of the coupon's kind, a subscription plan or a one-time variant; another returns `422` on `product_variants`.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub product_variants: Option<Vec<i64>>,
#[serde(
skip_serializing_if = "Option::is_none",
default,
deserialize_with = "crate::runtime_schema::present_nullable"
)]
pub limit: Option<Option<i64>>,
/// A future date and time, or null for no expiry.
#[serde(
skip_serializing_if = "Option::is_none",
default,
deserialize_with = "crate::runtime_schema::present_nullable"
)]
pub expires_at: Option<Option<String>>,
/// A decimal minimum amount in the store currency's major unit that the order lines of the coupon's kind must reach, or null for no minimum.
#[serde(
skip_serializing_if = "Option::is_none",
default,
deserialize_with = "crate::runtime_schema::present_nullable"
)]
pub minimum_amount: Option<Option<SdkCreateCouponRequestApplicationJsonDiscountOneOf>>,
/// What the coupon discounts: `one_time` for one-time purchases, or `subscriptions` for the first payments of a subscription plan. A new coupon defaults to `one_time`, and an update that leaves this out keeps the current kind. The coupon only discounts order lines of its kind.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub applies_to: Option<SdkCreateCouponRequestApplicationJsonAppliesTo>,
/// How many payments a `subscriptions` coupon discounts, counting the signup payment as the first, so `3` discounts the signup and the next two renewals. A `subscriptions` coupon needs one, and an update that leaves it out keeps the stored number. Missing on a `subscriptions` coupon, or outside 1 to 36, it returns `422` on `subscription_payments` with `The number of discounted payments must be between 1 and 36.` A `one_time` coupon always stores null here.
#[serde(
skip_serializing_if = "Option::is_none",
default,
deserialize_with = "crate::runtime_schema::present_nullable"
)]
pub subscription_payments: Option<Option<i64>>,
/// Fields returned by a newer API version that are not yet known to this SDK.
#[serde(default, flatten)]
pub additional_properties: std::collections::HashMap<String, serde_json::Value>,
}
impl Serialize for SdkCreateCouponRequestApplicationJson {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
Self::serialize(self, serializer)
}
}
impl<'de> Deserialize<'de> for SdkCreateCouponRequestApplicationJson {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let mut value = serde_json::Value::deserialize(deserializer)?;
crate::runtime_schema::model(&value, "SdkCreateCouponRequestApplicationJson", false)
.map_err(serde::de::Error::custom)?;
crate::runtime_schema::retain_model_fields(
&mut value,
"SdkCreateCouponRequestApplicationJson",
);
Self::deserialize(value).map_err(serde::de::Error::custom)
}
}
impl SdkCreateCouponRequestApplicationJson {
/// Validate the serialized request, including schema constraints and compatibility rules.
pub fn validate_request(&self) -> Result<(), crate::error::Error> {
let value = serde_json::to_value(self)
.map_err(|e| crate::error::Error::Serialization(e.to_string()))?;
crate::runtime_schema::model(&value, "SdkCreateCouponRequestApplicationJson", true)
}
}