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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
use stripe::{Address, ExternalAccounts, Currency, MinimumVerification};
use util::{Result, List, Deleted};
use std::collections::HashMap;
use stripe::AccountHolderType;
use serde::Serialize;
use Client;

#[derive(Deserialize, Debug)]
pub struct Account {
    pub id: String,
    pub object: String,
    pub business_logo: Option<String>,
    pub business_name: Option<String>,
    pub business_url: Option<String>,
    pub charges_enabled: bool,
    pub country: String,
    pub debit_negative_balances: Option<bool>,
    pub decline_charge_on: Option<AccountDeclineChargeOn>,
    pub default_currency: Currency,
    pub details_submitted: bool,
    pub display_name: Option<String>,
    pub email: Option<String>,
    pub external_accounts: Option<List<ExternalAccounts>>,
    pub legal_entity: Option<LegalEntity>,
    pub metadata: Option<HashMap<String, String>>,
    pub payout_schedule: Option<PayoutSchedule>,
    pub payout_statement_descriptor: Option<String>,
    pub payouts_enabled: bool,
    pub product_description: Option<String>,
    pub statement_descriptor: Option<String>,
    pub support_address: Option<Address>,
    pub support_email: Option<String>,
    pub support_phone: Option<String>,
    pub support_url: Option<String>,
    pub timezone: String,
    pub tos_acceptance: Option<AccountTosAcceptance>,
    #[serde(rename="type")]
    pub account_type: AccountType,
    pub verification: Option<AccountVerification>

}

#[derive(Deserialize, Debug)]
pub enum AccountType {
    #[serde(rename="standard")]
    STANDARD,
    #[serde(rename="express")]
    EXPRESS,
    #[serde(rename="custom")]
    CUSTOM
}

#[derive(Deserialize, Debug)]
pub struct LegalEntity {
    pub additional_owners: Vec<String>,
    pub address: Address,
    pub business_name: Option<String>,
    pub business_tax_id_provided: bool,
    pub dob: LegalEntityDoB,
    pub first_name: Option<String>,
    pub last_name: Option<String>,
    pub personal_address: Address,
    pub personal_id_number_provided: bool,
    pub ssn_last_4_provided: bool,
    #[serde(rename = "type")]
    pub entity_type: Option<AccountHolderType>,
    pub verification: LegalEntityVerification
}

#[derive(Deserialize, Debug)]
pub struct AdditionalOwners {
    pub address: Address,
    pub dob: LegalEntityDoB,
    pub first_name: Option<String>,
    pub last_name: Option<String>,
    pub maiden_name: Option<String>,
    pub verification: LegalEntityVerification
}

#[derive(Deserialize, Debug)]
pub struct LegalEntityVerification {
    pub details: Option<String>,
    pub details_code: Option<LegalEntityDetailsCode>,
    pub document: Option<String>,
    pub status: LegalEntityVerificationStatus
}

#[derive(Deserialize, Debug)]
pub enum LegalEntityDetailsCode {
    #[serde(rename = "scan_corrupt")]
    ScanCorrupt,
    #[serde(rename = "scan_not_readable")]
    ScanNotReadable,
    #[serde(rename = "scan_failed_greyscale")]
    ScanFailedGreyscale,
    #[serde(rename = "scan_not_uploaded")]
    ScanNotUploaded,
    #[serde(rename = "scan_id_type_not_supported")]
    ScanIdTypeNotSupported,
    #[serde(rename = "scan_id_country_not_supported")]
    ScanIdCountryNotSupported,
    #[serde(rename = "scan_name_mismatch")]
    ScanNameMismatch,
    #[serde(rename = "scan_failed_other")]
    ScanFailedOther,
    #[serde(rename = "failed_keyed_identity")]
    FailedKeyedIdentity,
    #[serde(rename = "failed_other")]
    FailedOther
}

#[derive(Deserialize, Debug)]
pub enum LegalEntityVerificationStatus {
    #[serde(rename = "verified")]
    Verified,
    #[serde(rename = "pending")]
    Pending,
    #[serde(rename = "unverified")]
    Unverified
}

#[derive(Deserialize, Debug)]
pub struct LegalEntityDoB {
    pub day: Option<i16>,
    pub month: Option<i16>,
    pub year: Option<i16>,
}

#[derive(Deserialize, Debug)]
pub struct AccountTosAcceptance {
    pub date: Option<i64>,
    pub iovation_blackbox: Option<String>,
    pub ip: Option<String>,
    pub user_agent: Option<String>,
}

#[derive(Deserialize, Debug)]
pub struct AccountVerification {
    pub disabled_reason: AccountDisabledReason,
    pub due_by: Option<i64>,
    pub fields_needed: Vec<MinimumVerification>,
}

#[derive(Deserialize, Debug)]
pub enum AccountDisabledReason {
    #[serde(rename = "rejected.fraud")]
    RejectedFraud,
    #[serde(rename = "rejected.terms_of_service")]
    RejectedTermsOfService,
    #[serde(rename = "rejected.listed")]
    RejectedListed,
    #[serde(rename = "rejected.other")]
    RejectedOther,
    #[serde(rename = "fields_needed")]
    FieldsNeeded,
    #[serde(rename = "listed")]
    Listed,
    #[serde(rename = "under_review")]
    UnderReview,
    #[serde(rename = "other")]
    Other
}

#[derive(Deserialize, Debug)]
pub struct PayoutSchedule {
    pub delay_days: i64,
    pub interval: String
}

#[derive(Deserialize, Debug)]
pub struct AccountDeclineChargeOn {
    pub avs_failure: bool,
    pub cvc_failure: bool,
}

#[derive(Serialize, Debug)]
pub enum AccountRejectReason {
    #[serde(rename = "fraud")]
    Fraud,
}

#[derive(Deserialize, Debug)]
pub struct LoginLink {
    pub object: String,
    pub created: i64,
    pub url: String
}

//For now, this is for external/connect accounts
impl Account {

    pub fn create<B: Serialize>(client: &Client, param: B) -> Result<Account> {
        client.post("/accounts", param)
    }

    pub fn retrieve(client: &Client, id: &str) -> Result<Account> {
        client.get_empty(&format!("/accounts/{}", id))
    }

    pub fn update<B: Serialize>(client: &Client, id: &str, param: B) -> Result<Account> {
        client.post(&format!("/accounts/{}", id), param)
    }

    pub fn delete(client: &Client, id: &str) -> Result<Deleted> {
        client.delete_empty(&format!("/accounts/{}", id))
    }

    pub fn reject<B: Serialize>(client: &Client, id: &str, param: B) -> Result<Account> {
        client.post(&format!("/accounts/{}/reject", id), param)
    }

    pub fn list<B: Serialize>(client: &Client, param: B) -> Result<List<Account>> {
        client.get("/accounts", param)
    }

}


impl LoginLink {

    pub fn create(client: &Client, account: &str) -> Result<LoginLink> {
        client.post_empty(&format!("/accounts/{}/login_links", account))
    }

}