use crate::ids::IssuingCardId;
use crate::params::{Expandable, Metadata, Object, Timestamp};
use crate::resources::{
Address, CardBrand, Currency, IssuingCardholder, MerchantCategory, SpendingLimit,
};
use serde_derive::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IssuingCard {
pub id: IssuingCardId,
pub authorization_controls: IssuingCardAuthorizationControls,
pub brand: CardBrand,
#[serde(skip_serializing_if = "Option::is_none")]
pub cardholder: Option<IssuingCardholder>,
pub created: Timestamp,
pub currency: Currency,
pub exp_month: i64,
pub exp_year: i64,
pub last4: String,
pub livemode: bool,
pub metadata: Metadata,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub replacement_for: Option<Expandable<IssuingCard>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub replacement_reason: Option<IssuingCardReplacementReason>,
#[serde(skip_serializing_if = "Option::is_none")]
pub shipping: Option<IssuingCardShipping>,
pub status: IssuingCardStatus,
#[serde(rename = "type")]
pub type_: IssuingCardType,
}
impl Object for IssuingCard {
type Id = IssuingCardId;
fn id(&self) -> Self::Id {
self.id.clone()
}
fn object(&self) -> &'static str {
"issuing.card"
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IssuingCardAuthorizationControls {
#[serde(skip_serializing_if = "Option::is_none")]
pub allowed_categories: Option<Vec<MerchantCategory>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub blocked_categories: Option<Vec<MerchantCategory>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<Currency>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_amount: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_approvals: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub spending_limits: Option<Vec<SpendingLimit>>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IssuingCardShipping {
pub address: Address,
#[serde(skip_serializing_if = "Option::is_none")]
pub carrier: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub eta: Option<Timestamp>,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<IssuingCardShippingStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tracking_number: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tracking_url: Option<String>,
#[serde(rename = "type")]
pub type_: IssuingCardShippingType,
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum IssuingCardReplacementReason {
Damage,
Expiration,
Loss,
Theft,
}
impl IssuingCardReplacementReason {
pub fn as_str(&self) -> &'static str {
match self {
IssuingCardReplacementReason::Damage => "damage",
IssuingCardReplacementReason::Expiration => "expiration",
IssuingCardReplacementReason::Loss => "loss",
IssuingCardReplacementReason::Theft => "theft",
}
}
}
impl AsRef<str> for IssuingCardReplacementReason {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for IssuingCardReplacementReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum IssuingCardShippingStatus {
Canceled,
Delivered,
Failure,
Pending,
Returned,
Shipped,
}
impl IssuingCardShippingStatus {
pub fn as_str(&self) -> &'static str {
match self {
IssuingCardShippingStatus::Canceled => "canceled",
IssuingCardShippingStatus::Delivered => "delivered",
IssuingCardShippingStatus::Failure => "failure",
IssuingCardShippingStatus::Pending => "pending",
IssuingCardShippingStatus::Returned => "returned",
IssuingCardShippingStatus::Shipped => "shipped",
}
}
}
impl AsRef<str> for IssuingCardShippingStatus {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for IssuingCardShippingStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum IssuingCardShippingType {
Bulk,
Individual,
}
impl IssuingCardShippingType {
pub fn as_str(&self) -> &'static str {
match self {
IssuingCardShippingType::Bulk => "bulk",
IssuingCardShippingType::Individual => "individual",
}
}
}
impl AsRef<str> for IssuingCardShippingType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for IssuingCardShippingType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum IssuingCardStatus {
Active,
Canceled,
Inactive,
Lost,
Pending,
Stolen,
}
impl IssuingCardStatus {
pub fn as_str(&self) -> &'static str {
match self {
IssuingCardStatus::Active => "active",
IssuingCardStatus::Canceled => "canceled",
IssuingCardStatus::Inactive => "inactive",
IssuingCardStatus::Lost => "lost",
IssuingCardStatus::Pending => "pending",
IssuingCardStatus::Stolen => "stolen",
}
}
}
impl AsRef<str> for IssuingCardStatus {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for IssuingCardStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum IssuingCardType {
Physical,
Virtual,
}
impl IssuingCardType {
pub fn as_str(&self) -> &'static str {
match self {
IssuingCardType::Physical => "physical",
IssuingCardType::Virtual => "virtual",
}
}
}
impl AsRef<str> for IssuingCardType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for IssuingCardType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}