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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
// ======================================
// This file was automatically generated.
// ======================================
use serde::{Deserialize, Serialize};
use crate::client::{Client, Response};
use crate::ids::RecipientId;
use crate::params::{
Deleted, Expand, Expandable, List, Metadata, Object, Paginable, RangeQuery, Timestamp,
};
use crate::resources::{Account, BankAccount, Card};
/// The resource representing a Stripe "TransferRecipient".
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Recipient {
/// Unique identifier for the object.
pub id: RecipientId,
/// Hash describing the current account on the recipient, if there is one.
#[serde(skip_serializing_if = "Option::is_none")]
pub active_account: Option<BankAccount>,
#[serde(default)]
pub cards: List<Card>,
/// Time at which the object was created.
///
/// Measured in seconds since the Unix epoch.
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<Timestamp>,
/// The default card to use for creating transfers to this recipient.
#[serde(skip_serializing_if = "Option::is_none")]
pub default_card: Option<Expandable<Card>>,
// Always true for a deleted object
#[serde(default)]
pub deleted: bool,
/// An arbitrary string attached to the object.
///
/// Often useful for displaying to users.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
/// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
#[serde(skip_serializing_if = "Option::is_none")]
pub livemode: Option<bool>,
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
#[serde(default)]
pub metadata: Metadata,
/// The ID of the [Custom account](https://stripe.com/docs/connect/custom-accounts) this recipient was migrated to.
///
/// If set, the recipient can no longer be updated, nor can transfers be made to it: use the Custom account instead.
#[serde(skip_serializing_if = "Option::is_none")]
pub migrated_to: Option<Expandable<Account>>,
/// Full, legal name of the recipient.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rolled_back_from: Option<Expandable<Account>>,
/// Type of the recipient, one of `individual` or `corporation`.
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub type_: Option<RecipientType>,
}
impl Recipient {
/// Returns a list of your recipients.
///
/// The recipients are returned sorted by creation date, with the most recently created recipients appearing first.
pub fn list(client: &Client, params: &ListRecipients<'_>) -> Response<List<Recipient>> {
client.get_query("/recipients", ¶ms)
}
/// Creates a new `Recipient` object and verifies the recipient’s identity.
/// Also verifies the recipient’s bank account information or debit card, if either is provided.
pub fn create(client: &Client, params: CreateRecipient<'_>) -> Response<Recipient> {
client.post_form("/recipients", ¶ms)
}
/// Retrieves the details of an existing recipient.
///
/// You need only supply the unique recipient identifier that was returned upon recipient creation.
pub fn retrieve(client: &Client, id: &RecipientId, expand: &[&str]) -> Response<Recipient> {
client.get_query(&format!("/recipients/{}", id), &Expand { expand })
}
/// Updates the specified recipient by setting the values of the parameters passed.
/// Any parameters not provided will be left unchanged.
///
/// If you update the name or tax ID, the identity verification will automatically be rerun.
/// If you update the bank account, the bank account validation will automatically be rerun.
pub fn update(
client: &Client,
id: &RecipientId,
params: UpdateRecipient<'_>,
) -> Response<Recipient> {
client.post_form(&format!("/recipients/{}", id), ¶ms)
}
/// Permanently deletes a recipient.
///
/// It cannot be undone.
pub fn delete(client: &Client, id: &RecipientId) -> Response<Deleted<RecipientId>> {
client.delete(&format!("/recipients/{}", id))
}
}
impl Object for Recipient {
type Id = RecipientId;
fn id(&self) -> Self::Id {
self.id.clone()
}
fn object(&self) -> &'static str {
"recipient"
}
}
/// The parameters for `Recipient::create`.
#[derive(Clone, Debug, Serialize)]
pub struct CreateRecipient<'a> {
/// A U.S.
///
/// Visa or MasterCard debit card (_not_ prepaid) to attach to the recipient.
/// If the debit card is not valid, recipient creation will fail.
/// You can provide either a token, like the ones returned by [Stripe.js](https://stripe.com/docs/js), or a dictionary containing a user's debit card details, with the options described below.
/// Although not all information is required, the extra info helps prevent fraud.
#[serde(skip_serializing_if = "Option::is_none")]
pub card: Option<String>,
/// An arbitrary string which you can attach to a `Recipient` object.
///
/// It is displayed alongside the recipient in the web interface.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<&'a str>,
/// The recipient's email address.
///
/// It is displayed alongside the recipient in the web interface, and can be useful for searching and tracking.
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<&'a str>,
/// Specifies which fields in the response should be expanded.
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
/// The recipient's full, legal name.
///
/// For type `individual`, should be in the format `First Last`, `First Middle Last`, or `First M Last` (no prefixes or suffixes).
/// For `corporation`, the full, incorporated name.
pub name: &'a str,
/// The recipient's tax ID, as a string.
///
/// For type `individual`, the full SSN; for type `corporation`, the full EIN.
#[serde(skip_serializing_if = "Option::is_none")]
pub tax_id: Option<&'a str>,
/// Type of the recipient: either `individual` or `corporation`.
#[serde(rename = "type")]
pub type_: RecipientType,
}
impl<'a> CreateRecipient<'a> {
pub fn new(name: &'a str, type_: RecipientType) -> Self {
CreateRecipient {
card: Default::default(),
description: Default::default(),
email: Default::default(),
expand: Default::default(),
metadata: Default::default(),
name,
tax_id: Default::default(),
type_,
}
}
}
/// The parameters for `Recipient::list`.
#[derive(Clone, Debug, Serialize, Default)]
pub struct ListRecipients<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<RangeQuery<Timestamp>>,
/// A cursor for use in pagination.
///
/// `ending_before` is an object ID that defines your place in the list.
/// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<RecipientId>,
/// Specifies which fields in the response should be expanded.
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
/// A limit on the number of objects to be returned.
///
/// Limit can range between 1 and 100, and the default is 10.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,
/// A cursor for use in pagination.
///
/// `starting_after` is an object ID that defines your place in the list.
/// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<RecipientId>,
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub type_: Option<RecipientType>,
/// Only return recipients that are verified or unverified.
#[serde(skip_serializing_if = "Option::is_none")]
pub verified: Option<bool>,
}
impl<'a> ListRecipients<'a> {
pub fn new() -> Self {
ListRecipients {
created: Default::default(),
ending_before: Default::default(),
expand: Default::default(),
limit: Default::default(),
starting_after: Default::default(),
type_: Default::default(),
verified: Default::default(),
}
}
}
impl Paginable for ListRecipients<'_> {
type O = Recipient;
fn set_last(&mut self, item: Self::O) {
self.starting_after = Some(item.id());
}
}
/// The parameters for `Recipient::update`.
#[derive(Clone, Debug, Serialize, Default)]
pub struct UpdateRecipient<'a> {
/// A U.S.
///
/// Visa or MasterCard debit card (not prepaid) to attach to the recipient.
/// You can provide either a token, like the ones returned by [Stripe.js](https://stripe.com/docs/js), or a dictionary containing a user's debit card details, with the options described below.
/// Passing `card` will create a new card, make it the new recipient default card, and delete the old recipient default (if one exists).
/// If you want to add additional debit cards instead of replacing the existing default, use the [card creation API](https://stripe.com/docs/api#create_card).
/// Whenever you attach a card to a recipient, Stripe will automatically validate the debit card.
#[serde(skip_serializing_if = "Option::is_none")]
pub card: Option<String>,
/// ID of the card to set as the recipient's new default for payouts.
#[serde(skip_serializing_if = "Option::is_none")]
pub default_card: Option<&'a str>,
/// An arbitrary string which you can attach to a `Recipient` object.
///
/// It is displayed alongside the recipient in the web interface.
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<&'a str>,
/// The recipient's email address.
///
/// It is displayed alongside the recipient in the web interface, and can be useful for searching and tracking.
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<&'a str>,
/// Specifies which fields in the response should be expanded.
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
/// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
///
/// This can be useful for storing additional information about the object in a structured format.
/// Individual keys can be unset by posting an empty value to them.
/// All keys can be unset by posting an empty value to `metadata`.
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<Metadata>,
/// The recipient's full, legal name.
///
/// For type `individual`, should be in the format `First Last`, `First Middle Last`, or `First M Last` (no prefixes or suffixes).
/// For `corporation`, the full, incorporated name.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<&'a str>,
/// The recipient's tax ID, as a string.
///
/// For type `individual`, the full SSN; for type `corporation`, the full EIN.
#[serde(skip_serializing_if = "Option::is_none")]
pub tax_id: Option<&'a str>,
}
impl<'a> UpdateRecipient<'a> {
pub fn new() -> Self {
UpdateRecipient {
card: Default::default(),
default_card: Default::default(),
description: Default::default(),
email: Default::default(),
expand: Default::default(),
metadata: Default::default(),
name: Default::default(),
tax_id: Default::default(),
}
}
}
/// An enum representing the possible values of an `ListRecipients`'s `type_` field.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum RecipientType {
Corporation,
Individual,
}
impl RecipientType {
pub fn as_str(self) -> &'static str {
match self {
RecipientType::Corporation => "corporation",
RecipientType::Individual => "individual",
}
}
}
impl AsRef<str> for RecipientType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for RecipientType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for RecipientType {
fn default() -> Self {
Self::Corporation
}
}