recurly/request/
create_subscription_change.rs

1use serde_json::json;
2use crate::model::*;
3use crate::RecurlyClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct CreateSubscriptionChangeRequest<'a> {
8    pub(crate) http_client: &'a RecurlyClient,
9    pub subscription_id: String,
10    pub timeframe: Option<String>,
11    pub plan_id: Option<String>,
12    pub plan_code: Option<String>,
13    pub unit_amount: Option<f64>,
14    pub tax_inclusive: Option<bool>,
15    pub quantity: Option<i64>,
16    pub shipping: Option<SubscriptionChangeShippingCreate>,
17    pub coupon_codes: Option<Vec<String>>,
18    pub add_ons: Option<Vec<SubscriptionAddOnUpdate>>,
19    pub collection_method: Option<String>,
20    pub revenue_schedule_type: Option<String>,
21    pub custom_fields: Option<CustomFields>,
22    pub po_number: Option<String>,
23    pub net_terms: Option<i64>,
24    pub transaction_type: Option<String>,
25    pub billing_info: Option<SubscriptionChangeBillingInfoCreate>,
26    pub ramp_intervals: Option<Vec<SubscriptionRampInterval>>,
27}
28impl<'a> CreateSubscriptionChangeRequest<'a> {
29    pub async fn send(self) -> anyhow::Result<SubscriptionChange> {
30        let mut r = self
31            .http_client
32            .client
33            .post(
34                &format!(
35                    "/subscriptions/{subscription_id}/change", subscription_id = self
36                    .subscription_id
37                ),
38            );
39        if let Some(ref unwrapped) = self.timeframe {
40            r = r.push_json(json!({ "timeframe" : unwrapped }));
41        }
42        if let Some(ref unwrapped) = self.plan_id {
43            r = r.push_json(json!({ "plan_id" : unwrapped }));
44        }
45        if let Some(ref unwrapped) = self.plan_code {
46            r = r.push_json(json!({ "plan_code" : unwrapped }));
47        }
48        if let Some(ref unwrapped) = self.unit_amount {
49            r = r.push_json(json!({ "unit_amount" : unwrapped }));
50        }
51        if let Some(ref unwrapped) = self.tax_inclusive {
52            r = r.push_json(json!({ "tax_inclusive" : unwrapped }));
53        }
54        if let Some(ref unwrapped) = self.quantity {
55            r = r.push_json(json!({ "quantity" : unwrapped }));
56        }
57        if let Some(ref unwrapped) = self.shipping {
58            r = r.push_json(json!({ "shipping" : unwrapped }));
59        }
60        if let Some(ref unwrapped) = self.coupon_codes {
61            r = r.push_json(json!({ "coupon_codes" : unwrapped }));
62        }
63        if let Some(ref unwrapped) = self.add_ons {
64            r = r.push_json(json!({ "add_ons" : unwrapped }));
65        }
66        if let Some(ref unwrapped) = self.collection_method {
67            r = r.push_json(json!({ "collection_method" : unwrapped }));
68        }
69        if let Some(ref unwrapped) = self.revenue_schedule_type {
70            r = r.push_json(json!({ "revenue_schedule_type" : unwrapped }));
71        }
72        if let Some(ref unwrapped) = self.custom_fields {
73            r = r.push_json(json!({ "custom_fields" : unwrapped }));
74        }
75        if let Some(ref unwrapped) = self.po_number {
76            r = r.push_json(json!({ "po_number" : unwrapped }));
77        }
78        if let Some(ref unwrapped) = self.net_terms {
79            r = r.push_json(json!({ "net_terms" : unwrapped }));
80        }
81        if let Some(ref unwrapped) = self.transaction_type {
82            r = r.push_json(json!({ "transaction_type" : unwrapped }));
83        }
84        if let Some(ref unwrapped) = self.billing_info {
85            r = r.push_json(json!({ "billing_info" : unwrapped }));
86        }
87        if let Some(ref unwrapped) = self.ramp_intervals {
88            r = r.push_json(json!({ "ramp_intervals" : unwrapped }));
89        }
90        r = self.http_client.authenticate(r);
91        let res = r.send().await.unwrap().error_for_status();
92        match res {
93            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
94            Err(res) => {
95                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
96                Err(anyhow::anyhow!("{:?}", text))
97            }
98        }
99    }
100    pub fn timeframe(mut self, timeframe: &str) -> Self {
101        self.timeframe = Some(timeframe.to_owned());
102        self
103    }
104    pub fn plan_id(mut self, plan_id: &str) -> Self {
105        self.plan_id = Some(plan_id.to_owned());
106        self
107    }
108    pub fn plan_code(mut self, plan_code: &str) -> Self {
109        self.plan_code = Some(plan_code.to_owned());
110        self
111    }
112    pub fn unit_amount(mut self, unit_amount: f64) -> Self {
113        self.unit_amount = Some(unit_amount);
114        self
115    }
116    pub fn tax_inclusive(mut self, tax_inclusive: bool) -> Self {
117        self.tax_inclusive = Some(tax_inclusive);
118        self
119    }
120    pub fn quantity(mut self, quantity: i64) -> Self {
121        self.quantity = Some(quantity);
122        self
123    }
124    pub fn shipping(mut self, shipping: SubscriptionChangeShippingCreate) -> Self {
125        self.shipping = Some(shipping);
126        self
127    }
128    pub fn coupon_codes(
129        mut self,
130        coupon_codes: impl IntoIterator<Item = impl AsRef<str>>,
131    ) -> Self {
132        self
133            .coupon_codes = Some(
134            coupon_codes.into_iter().map(|s| s.as_ref().to_owned()).collect(),
135        );
136        self
137    }
138    pub fn add_ons(mut self, add_ons: Vec<SubscriptionAddOnUpdate>) -> Self {
139        self.add_ons = Some(add_ons);
140        self
141    }
142    pub fn collection_method(mut self, collection_method: &str) -> Self {
143        self.collection_method = Some(collection_method.to_owned());
144        self
145    }
146    pub fn revenue_schedule_type(mut self, revenue_schedule_type: &str) -> Self {
147        self.revenue_schedule_type = Some(revenue_schedule_type.to_owned());
148        self
149    }
150    pub fn custom_fields(mut self, custom_fields: CustomFields) -> Self {
151        self.custom_fields = Some(custom_fields);
152        self
153    }
154    pub fn po_number(mut self, po_number: &str) -> Self {
155        self.po_number = Some(po_number.to_owned());
156        self
157    }
158    pub fn net_terms(mut self, net_terms: i64) -> Self {
159        self.net_terms = Some(net_terms);
160        self
161    }
162    pub fn transaction_type(mut self, transaction_type: &str) -> Self {
163        self.transaction_type = Some(transaction_type.to_owned());
164        self
165    }
166    pub fn billing_info(
167        mut self,
168        billing_info: SubscriptionChangeBillingInfoCreate,
169    ) -> Self {
170        self.billing_info = Some(billing_info);
171        self
172    }
173    pub fn ramp_intervals(
174        mut self,
175        ramp_intervals: Vec<SubscriptionRampInterval>,
176    ) -> Self {
177        self.ramp_intervals = Some(ramp_intervals);
178        self
179    }
180}