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
use stripe::{ShippingDetails, Currency}; use util::{Result, List}; use Client; use serde; use std::collections::HashMap; #[derive(Deserialize, Debug)] pub struct Order { pub id: String, pub object: String, pub amount: i64, pub amount_returned: Option<i64>, pub application: Option<String>, pub application_fee: Option<i64>, pub charge: Option<OrderCharge>, pub created: i64, pub currency: Currency, pub customer: String, pub email: String, pub items: Vec<OrderItem>, pub livemode: bool, pub metadata: HashMap<String, String>, pub returns: List<OrderReturn>, pub selected_shipping_method: Option<String>, pub shipping: ShippingDetails, pub shipping_methods: Vec<ShippingMethods>, pub status: OrderStatus, pub status_transitions: OrderTransitions, pub updated: i64 } #[derive(Deserialize, Debug)] pub enum OrderCharge { #[serde(rename = "paid")] Paid, #[serde(rename = "fulfilled")] Fulfilled, #[serde(rename = "refunded")] Refunded } #[derive(Deserialize, Debug)] pub struct DeliveryEstimate { #[serde(rename = "type")] pub delivery_type: DeliveryType, pub latest: Option<String>, pub earliest: Option<String>, pub date: Option<String>, } #[derive(Deserialize, Debug)] pub enum DeliveryType { #[serde(rename = "range")] Range, #[serde(rename = "exact")] Exact } #[derive(Deserialize, Debug)] pub struct ShippingMethods { pub id: String, pub amount: i64, pub currency: Currency, pub delivery_estimate: Option<DeliveryEstimate>, pub description: String } #[derive(Deserialize, Debug)] pub struct OrderTransitions { pub canceled: i64, pub fulfiled: Option<i64>, pub paid: i64, pub returned: Option<i64>, } #[derive(Deserialize, Debug)] pub struct OrderReturn { pub id: String, pub object: String, pub amount: i64, pub created: i64, pub currency: Currency, pub items: Vec<OrderItem>, } #[derive(Default, Serialize, Deserialize, Debug)] pub struct OrderItem { #[serde(skip_serializing)] pub object: String, pub amount: i64, pub currency: Currency, pub description: Option<String>, pub parent: String, pub quantity: Option<i64>, #[serde(rename = "type")] pub item_type: ItemType, } #[derive(Debug, PartialEq, Serialize, Deserialize)] pub enum ItemType { #[serde(rename = "sku")] Sku, #[serde(rename = "tax")] Tax, #[serde(rename = "shipping")] Shipping, #[serde(rename = "discount")] Discount, #[serde(skip_serializing)] Unknown } impl Default for ItemType { fn default() -> ItemType { ItemType::Unknown } } #[derive(Debug, PartialEq, Serialize, Deserialize)] pub enum OrderStatus { #[serde(rename="created")] Created, #[serde(rename="paid")] Paid, #[serde(rename="canceled")] Canceled, #[serde(rename="fulfilled")] Fulfilled, #[serde(rename="returned")] Returned } #[derive(Default, Serialize, Debug)] pub struct OrderParam<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub currency: Option<Currency>, #[serde(skip_serializing_if = "Option::is_none")] pub coupon: Option<&'a str>, #[serde(skip_serializing_if = "Option::is_none")] pub customer: Option<&'a str>, #[serde(skip_serializing_if = "Option::is_none")] pub email: Option<&'a str>, #[serde(skip_serializing_if = "Option::is_none")] pub items: Option<OrderItem>, #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option<HashMap<String, String>>, #[serde(skip_serializing_if = "Option::is_none")] pub shipping: Option<ShippingDetails>, } impl Order { pub fn create<B: serde::Serialize>(client: &Client, param: B) -> Result<Order> { client.post("/orders", param) } pub fn retrieve(client: &Client, id: &str) -> Result<Order> { client.get_empty(&format!("/orders/{}", id)) } pub fn update<B: serde::Serialize>(client: &Client, id: &str, param: B) -> Result<Order> { client.post(&format!("/orders/{}", id), param) } pub fn pay<B: serde::Serialize>(client: &Client, id: &str, param: B) -> Result<Order> { client.post(&format!("/orders/{}/pay", id), param) } pub fn list<B: serde::Serialize>(client: &Client, param: B) -> Result<List<Order>> { client.get("/orders", param) } pub fn return_item<B: serde::Serialize>(client: &Client, id: &str, param: B) -> Result<Order> { client.post(&format!("/orders/{}/returns", id), param) } }