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
extern crate serde_json;
use client::Client;
use std::collections::HashMap;
#[derive(Debug)]
pub struct Plan {
}
impl Plan {
pub fn new<S: Into<String>>(
name: S,
amount: i32,
currency_code: S,
interval: S,
interval_count: i32,
trial_days: i32,
limit: Option<i32>,
metadata: Option<HashMap<String, serde_json::Value>>
) -> HashMap<String, serde_json::Value> {
let mut map: HashMap<String, serde_json::Value>;
map = HashMap::new();
map.insert("name".to_string(), json!(name.into()));
map.insert("amount".to_string(), json!(amount));
map.insert("currency_code".to_string(), json!(currency_code.into()));
map.insert("interval".to_string(), json!(interval.into()));
map.insert("interval_count".to_string(), json!(interval_count));
map.insert("trial_days".to_string(), json!(trial_days));
if !limit.is_none() {
map.insert("limit".to_string(), json!(limit));
}
if !metadata.is_none() {
map.insert("metadata".to_string(), json!(metadata));
}
return map;
}
pub fn create(client: &Client, plan: &HashMap<String, serde_json::Value>) -> String {
client.post("/plans", plan)
}
pub fn delete(client: &Client, id: &str) -> String {
client.delete(&format!("/plans/{}", id))
}
pub fn retrieve(client: &Client, id: &str) -> String {
client.get(&format!("/plans/{}", id))
}
pub fn all(
client: &Client,
query_params: Option<HashMap<String, String>>,
limit: Option<String>,
before: Option<String>,
after: Option<String>
) -> String {
client.get_filter("/plans", query_params, limit, before, after)
}
}