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

use stripe::{CardHolders, Object, StripePath, UrlPath, Currency, Address, CardBrand, MerchantCategories};
use std::collections::HashMap;
use {Client, Result, StripeService};
use util::List;

#[derive(Deserialize, Debug)]
pub struct IssuingCard {
    pub id: String,
    pub object: Object,
    pub authorization_controls: AuthorizationControls,
    pub brand: CardBrand,
    pub cardholder: CardHolders,
    pub created: i64,
    pub currency: Currency,
    pub exp_month: i64,
    pub exp_year: i64,
    pub last4: String,
    pub livemode: bool,
    pub metadata: HashMap<String, String>,
    pub name: String,
    pub shipping: IssuingShipping,
    pub status: CardStatus,
    #[serde(rename = "type")]
    pub card_type: CardType,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthorizationControls {
    pub allowed_categories: Option<Vec<MerchantCategories>>,
    pub blocked_categories: Option<Vec<MerchantCategories>>,
    pub currency: Currency,
    pub max_amount: i64,
    pub max_approvals: i64
}

#[derive(Serialize, Deserialize, Debug)]
pub enum CardStatus {
    #[serde(rename = "active")]
    Active,
    #[serde(rename = "inactive")]
    Inactive,
    #[serde(rename = "pending")]
    Pending,
    #[serde(rename = "canceled")]
    Canceled,
    #[serde(rename = "lost")]
    Lost,
    #[serde(rename = "stolen")]
    Stolen
}

#[derive(Deserialize, Debug)]
pub enum CardType {
    #[serde(rename = "virtual")]
    Virtual,
    #[serde(rename = "physical")]
    Physical
}

#[derive(Serialize, Deserialize, Debug)]
pub struct IssuingShipping {
    pub address: Address,
    pub carrier: String,
    pub eta: i64,
    pub name: String,
    pub phone: String,
    pub status: IssuingShippingStatus,
    pub tracking_number: String,
    pub tracking_url: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum IssuingShippingStatus {
    #[serde(rename = "pending")]
    Pending,
    #[serde(rename = "shipped")]
    Shipped,
    #[serde(rename = "delivered")]
    Delivered,
    #[serde(rename = "returned")]
    Returned,
    #[serde(rename = "failure")]
    Failure,
    #[serde(rename = "canceled")]
    Canceled
}

#[derive(Serialize, Deserialize, Debug)]
pub struct IssuingCardParam {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub authorization_controls: Option<AuthorizationControls>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cardholder: Option<CardHolders>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<HashMap<String, String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<CardStatus>,
}

impl StripeService for IssuingCard {
    fn service_path() -> UrlPath { UrlPath::IssuingCard }
}
impl StripeService for IssuingCardParam {
    fn service_path() -> UrlPath { UrlPath::IssuingCard }
}

impl IssuingCard {

    pub fn create<B: serde::Serialize + StripeService>(client: &Client, param: B) -> Result<Self> {
        client.post(Self::service_path(), &StripePath::default(), param)
    }

    pub fn retrieve(client: &Client, id: &str) -> Result<Self> {
        client.get(Self::service_path(), &StripePath::default().param(id), Self::object())
    }

    pub fn retrieve_details(client: &Client, id: &str) -> Result<Self> {
        client.get(Self::service_path(), &StripePath::default().param(id).param("details"), Self::object())
    }

    pub fn update<B: serde::Serialize + StripeService>(client: &Client, id: &str, param: B) -> Result<Self> {
        client.post(Self::service_path(), &StripePath::default().param(id), param)
    }

    pub fn list<B: serde::Serialize + StripeService>(client: &Client, param: B) -> Result<List<Self>> {
        client.get(Self::service_path(), &StripePath::default(), param)
    }

}