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
// ======================================
// This file was automatically generated.
// ======================================

use crate::ids::IssuingAuthorizationId;
use crate::params::{Expandable, Metadata, Object, Timestamp};
use crate::resources::{
    BalanceTransaction, Currency, IssuingAuthorizationCheck, IssuingAuthorizationMethod,
    IssuingAuthorizationReason, IssuingCard, IssuingCardholder, IssuingTransaction, MerchantData,
};
use serde_derive::{Deserialize, Serialize};

/// The resource representing a Stripe "IssuingAuthorization".
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IssuingAuthorization {
    /// Unique identifier for the object.
    pub id: IssuingAuthorizationId,

    /// Whether the authorization has been approved.
    pub approved: bool,

    /// How the card details were provided.
    ///
    /// One of `keyed_in`, `swipe`, `chip`, `contactless`, or `online`.
    pub authorization_method: IssuingAuthorizationMethod,

    /// The amount that has been authorized.
    ///
    /// This will be `0` when the object is created, and increase after it has been approved.
    pub authorized_amount: i64,

    /// The currency that was presented to the cardholder for the authorization.
    ///
    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
    /// Must be a [supported currency](https://stripe.com/docs/currencies).
    pub authorized_currency: Currency,

    pub balance_transactions: Vec<BalanceTransaction>,

    pub card: IssuingCard,

    /// The cardholder to whom this authorization belongs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cardholder: Option<Expandable<IssuingCardholder>>,

    /// Time at which the object was created.
    ///
    /// Measured in seconds since the Unix epoch.
    pub created: Timestamp,

    /// The amount the authorization is expected to be in `held_currency`.
    ///
    /// When Stripe holds funds from you, this is the amount reserved for the authorization.
    /// This will be `0` when the object is created, and increase after it has been approved.
    /// For multi-currency transactions, `held_amount` can be used to determine the expected exchange rate.
    pub held_amount: i64,

    /// The currency of the [held amount](https://stripe.com/docs/api#issuing_authorization_object-held_amount).
    ///
    /// This will always be the card currency.
    pub held_currency: Currency,

    pub is_held_amount_controllable: bool,

    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
    pub livemode: bool,

    pub merchant_data: MerchantData,

    /// Set of key-value pairs that you can attach to an object.
    ///
    /// This can be useful for storing additional information about the object in a structured format.
    pub metadata: Metadata,

    /// The amount the user is requesting to be authorized.
    ///
    /// This field will only be non-zero during an `issuing.authorization.request` webhook.
    pub pending_authorized_amount: i64,

    /// The additional amount Stripe will hold if the authorization is approved.
    ///
    /// This field will only be non-zero during an `issuing.authorization.request` webhook.
    pub pending_held_amount: i64,

    pub request_history: Vec<IssuingAuthorizationRequest>,

    /// One of `pending`, `reversed`, or `closed`.
    pub status: String,

    pub transactions: Vec<IssuingTransaction>,

    pub verification_data: IssuingAuthorizationVerificationData,

    /// What, if any, digital wallet was used for this authorization.
    ///
    /// One of `apple_pay`, `google_pay`, or `samsung_pay`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub wallet_provider: Option<IssuingAuthorizationWalletProvider>,
}

impl Object for IssuingAuthorization {
    type Id = IssuingAuthorizationId;
    fn id(&self) -> Self::Id {
        self.id.clone()
    }
    fn object(&self) -> &'static str {
        "issuing.authorization"
    }
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IssuingAuthorizationRequest {
    /// Whether this request was approved.
    pub approved: bool,

    /// The amount that was authorized at the time of this request.
    pub authorized_amount: i64,

    /// The currency that was presented to the cardholder for the authorization.
    ///
    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
    /// Must be a [supported currency](https://stripe.com/docs/currencies).
    pub authorized_currency: Currency,

    /// Time at which the object was created.
    ///
    /// Measured in seconds since the Unix epoch.
    pub created: Timestamp,

    /// The amount Stripe held from your account to fund the authorization, if the request was approved.
    pub held_amount: i64,

    /// The currency of the [held amount](https://stripe.com/docs/api#issuing_authorization_object-held_amount).
    pub held_currency: Currency,

    /// One of `authorization_controls`, `card_active`, `card_inactive`, `insufficient_funds`, `account_compliance_disabled`, `account_inactive`, `suspected_fraud`, `webhook_approved`, `webhook_declined`, or `webhook_timeout`.
    pub reason: IssuingAuthorizationReason,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IssuingAuthorizationVerificationData {
    /// One of `match`, `mismatch`, or `not_provided`.
    pub address_line1_check: IssuingAuthorizationCheck,

    /// One of `match`, `mismatch`, or `not_provided`.
    pub address_zip_check: IssuingAuthorizationCheck,

    /// One of `match`, `mismatch`, or `not_provided`.
    pub cvc_check: IssuingAuthorizationCheck,
}

/// An enum representing the possible values of an `IssuingAuthorization`'s `wallet_provider` field.
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum IssuingAuthorizationWalletProvider {
    ApplePay,
    GooglePay,
    SamsungPay,
}

impl IssuingAuthorizationWalletProvider {
    pub fn as_str(self) -> &'static str {
        match self {
            IssuingAuthorizationWalletProvider::ApplePay => "apple_pay",
            IssuingAuthorizationWalletProvider::GooglePay => "google_pay",
            IssuingAuthorizationWalletProvider::SamsungPay => "samsung_pay",
        }
    }
}

impl AsRef<str> for IssuingAuthorizationWalletProvider {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl std::fmt::Display for IssuingAuthorizationWalletProvider {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        self.as_str().fmt(f)
    }
}