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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
use crate::config::{Client, Response};
use crate::ids::{PlanId, SubscriptionId, SubscriptionItemId};
use crate::params::{Deleted, Expand, List, Metadata, Object, Timestamp};
use crate::resources::{Plan, SubscriptionItemBillingThresholds, TaxRate};
use serde_derive::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SubscriptionItem {
pub id: SubscriptionItemId,
#[serde(skip_serializing_if = "Option::is_none")]
pub billing_thresholds: Option<SubscriptionItemBillingThresholds>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<Timestamp>,
#[serde(default)]
pub deleted: bool,
#[serde(default)]
pub metadata: Metadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub plan: Option<Plan>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quantity: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tax_rates: Option<Vec<TaxRate>>,
}
impl SubscriptionItem {
pub fn list(
client: &Client,
params: ListSubscriptionItems<'_>,
) -> Response<List<SubscriptionItem>> {
client.get_query("/subscription_items", ¶ms)
}
pub fn retrieve(
client: &Client,
id: &SubscriptionItemId,
expand: &[&str],
) -> Response<SubscriptionItem> {
client.get_query(&format!("/subscription_items/{}", id), &Expand { expand })
}
pub fn update(
client: &Client,
id: &SubscriptionItemId,
params: UpdateSubscriptionItem<'_>,
) -> Response<SubscriptionItem> {
client.post_form(&format!("/subscription_items/{}", id), ¶ms)
}
pub fn delete(
client: &Client,
id: &SubscriptionItemId,
) -> Response<Deleted<SubscriptionItemId>> {
client.delete(&format!("/subscription_items/{}", id))
}
}
impl Object for SubscriptionItem {
type Id = SubscriptionItemId;
fn id(&self) -> Self::Id {
self.id.clone()
}
fn object(&self) -> &'static str {
"subscription_item"
}
}
#[derive(Clone, Debug, Serialize)]
pub struct ListSubscriptionItems<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<SubscriptionItemId>,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<SubscriptionItemId>,
pub subscription: SubscriptionId,
}
impl<'a> ListSubscriptionItems<'a> {
pub fn new(subscription: SubscriptionId) -> Self {
ListSubscriptionItems {
ending_before: Default::default(),
expand: Default::default(),
limit: Default::default(),
starting_after: Default::default(),
subscription,
}
}
}
#[derive(Clone, Debug, Serialize, Default)]
pub struct UpdateSubscriptionItem<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub billing_thresholds: Option<SubscriptionItemBillingThresholds>,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
#[serde(skip_serializing_if = "Option::is_none")]
pub plan: Option<PlanId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prorate: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub proration_date: Option<Timestamp>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quantity: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tax_rates: Option<Vec<String>>,
}
impl<'a> UpdateSubscriptionItem<'a> {
pub fn new() -> Self {
UpdateSubscriptionItem {
billing_thresholds: Default::default(),
expand: Default::default(),
metadata: Default::default(),
plan: Default::default(),
prorate: Default::default(),
proration_date: Default::default(),
quantity: Default::default(),
tax_rates: Default::default(),
}
}
}