use common_types::payments as common_payments_types; use masking::Secret; use serde::{Deserialize, Serialize}; use time::PrimitiveDateTime; use utoipa::ToSchema; use crate::enums as api_enums; #[derive(Default, Debug, Deserialize, Serialize)] pub struct MandateId { pub mandate_id: String, } #[derive(Default, Debug, Deserialize, Serialize, ToSchema)] pub struct MandateRevokedResponse { /// The identifier for mandate pub mandate_id: String, /// The status for mandates #[schema(value_type = MandateStatus)] pub status: api_enums::MandateStatus, /// If there was an error while calling the connectors the code is received here #[schema(example = "E0001")] pub error_code: Option, /// If there was an error while calling the connector the error message is received here #[schema(example = "Failed while verifying the card")] pub error_message: Option, } #[derive(Default, Debug, Deserialize, Serialize, ToSchema, Clone)] pub struct MandateResponse { /// The identifier for mandate pub mandate_id: String, /// The status for mandates #[schema(value_type = MandateStatus)] pub status: api_enums::MandateStatus, /// The identifier for payment method pub payment_method_id: String, /// The payment method pub payment_method: String, /// The payment method type pub payment_method_type: Option, /// The card details for mandate pub card: Option, /// Details about the customer’s acceptance #[schema(value_type = Option)] pub customer_acceptance: Option, } #[derive(Default, Debug, Deserialize, Serialize, ToSchema, Clone)] pub struct MandateCardDetails { /// The last 4 digits of card pub last4_digits: Option, /// The expiry month of card #[schema(value_type = Option)] pub card_exp_month: Option>, /// The expiry year of card #[schema(value_type = Option)] pub card_exp_year: Option>, /// The card holder name #[schema(value_type = Option)] pub card_holder_name: Option>, /// The token from card locker #[schema(value_type = Option)] pub card_token: Option>, /// The card scheme network for the particular card pub scheme: Option, /// The country code in in which the card was issued pub issuer_country: Option, #[schema(value_type = Option)] /// A unique identifier alias to identify a particular card pub card_fingerprint: Option>, /// The first 6 digits of card pub card_isin: Option, /// The bank that issued the card pub card_issuer: Option, /// The network that facilitates payment card transactions #[schema(value_type = Option)] pub card_network: Option, /// The type of the payment card pub card_type: Option, /// The nick_name of the card holder #[schema(value_type = Option)] pub nick_name: Option>, } #[derive(Clone, Debug, Deserialize, ToSchema, Serialize)] #[serde(deny_unknown_fields)] pub struct MandateListConstraints { /// limit on the number of objects to return pub limit: Option, /// offset on the number of objects to return pub offset: Option, /// status of the mandate pub mandate_status: Option, /// connector linked to mandate pub connector: Option, /// The time at which mandate is created #[schema(example = "2022-09-10T10:11:12Z")] pub created_time: Option, /// Time less than the mandate created time #[schema(example = "2022-09-10T10:11:12Z")] #[serde(rename = "created_time.lt")] pub created_time_lt: Option, /// Time greater than the mandate created time #[schema(example = "2022-09-10T10:11:12Z")] #[serde(rename = "created_time.gt")] pub created_time_gt: Option, /// Time less than or equals to the mandate created time #[schema(example = "2022-09-10T10:11:12Z")] #[serde(rename = "created_time.lte")] pub created_time_lte: Option, /// Time greater than or equals to the mandate created time #[schema(example = "2022-09-10T10:11:12Z")] #[serde(rename = "created_time.gte")] pub created_time_gte: Option, } /// Details required for recurring payment #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)] #[serde(tag = "type", content = "data", rename_all = "snake_case")] pub enum RecurringDetails { MandateId(String), PaymentMethodId(String), ProcessorPaymentToken(ProcessorPaymentToken), /// Network transaction ID and Card Details for MIT payments when payment_method_data /// is not stored in the application NetworkTransactionIdAndCardDetails(NetworkTransactionIdAndCardDetails), } /// Processor payment token for MIT payments where payment_method_data is not available #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)] pub struct ProcessorPaymentToken { pub processor_payment_token: String, #[schema(value_type = Option)] pub merchant_connector_id: Option, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)] pub struct NetworkTransactionIdAndCardDetails { /// The card number #[schema(value_type = String, example = "4242424242424242")] pub card_number: cards::CardNumber, /// The card's expiry month #[schema(value_type = String, example = "24")] pub card_exp_month: Secret, /// The card's expiry year #[schema(value_type = String, example = "24")] pub card_exp_year: Secret, /// The card holder's name #[schema(value_type = String, example = "John Test")] pub card_holder_name: Option>, /// The name of the issuer of card #[schema(example = "chase")] pub card_issuer: Option, /// The card network for the card #[schema(value_type = Option, example = "Visa")] pub card_network: Option, #[schema(example = "CREDIT")] pub card_type: Option, #[schema(example = "INDIA")] pub card_issuing_country: Option, #[schema(example = "JP_AMEX")] pub bank_code: Option, /// The card holder's nick name #[schema(value_type = Option, example = "John Test")] pub nick_name: Option>, /// The network transaction ID provided by the card network during a CIT (Customer Initiated Transaction), /// where `setup_future_usage` is set to `off_session`. #[schema(value_type = String)] pub network_transaction_id: Secret, } impl RecurringDetails { pub fn is_network_transaction_id_and_card_details_flow(self) -> bool { matches!(self, Self::NetworkTransactionIdAndCardDetails(_)) } }