feat(payment_methods): add v2 api for fetching token data (#7629)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sakil Mostak
2025-05-12 19:15:53 +05:30
committed by GitHub
parent 9da96e890c
commit 2cefac5cb3
16 changed files with 486 additions and 16 deletions

View File

@ -990,7 +990,8 @@ pub struct CardDetailsPaymentMethod {
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct NetworkTokenDetailsPaymentMethod {
pub last4_digits: Option<String>,
pub issuer_country: Option<String>,
#[schema(value_type = Option<CountryAlpha2>)]
pub issuer_country: Option<common_enums::CountryAlpha2>,
#[schema(value_type = Option<String>)]
pub network_token_expiry_month: Option<masking::Secret<String>>,
#[schema(value_type = Option<String>)]
@ -1922,6 +1923,90 @@ pub struct CustomerPaymentMethodsListResponse {
pub customer_payment_methods: Vec<CustomerPaymentMethod>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(deny_unknown_fields)]
pub struct GetTokenDataRequest {
/// Indicates the type of token to be fetched
pub token_type: api_enums::TokenDataType,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
impl common_utils::events::ApiEventMetric for GetTokenDataRequest {}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct TokenDataResponse {
/// The unique identifier of the payment method.
#[schema(value_type = String, example = "12345_pm_01926c58bc6e77c09e809964e72af8c8")]
pub payment_method_id: id_type::GlobalPaymentMethodId,
/// token type of the payment method
#[schema(value_type = TokenDataType)]
pub token_type: api_enums::TokenDataType,
/// token details of the payment method
pub token_details: TokenDetailsResponse,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
impl common_utils::events::ApiEventMetric for TokenDataResponse {}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Serialize, ToSchema)]
#[serde(untagged)]
pub enum TokenDetailsResponse {
NetworkTokenDetails(NetworkTokenDetailsResponse),
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct NetworkTokenDetailsResponse {
/// Network token generated against the Card Number
#[schema(value_type = String)]
pub network_token: cards::NetworkToken,
/// Expiry month of the network token
#[schema(value_type = String)]
pub network_token_exp_month: masking::Secret<String>,
/// Expiry year of the network token
#[schema(value_type = String)]
pub network_token_exp_year: masking::Secret<String>,
/// Cryptogram generated by the Network
#[schema(value_type = Option<String>)]
pub cryptogram: Option<masking::Secret<String>>,
/// Issuer of the card
pub card_issuer: Option<String>,
/// Card network of the token
#[schema(value_type = Option<CardNetwork>)]
pub card_network: Option<common_enums::CardNetwork>,
/// Card type of the token
pub card_type: Option<CardType>,
/// Issuing country of the card
#[schema(value_type = Option<CountryAlpha2>)]
pub card_issuing_country: Option<common_enums::CountryAlpha2>,
/// Bank code of the card
pub bank_code: Option<String>,
/// Name of the card holder
#[schema(value_type = Option<String>)]
pub card_holder_name: Option<masking::Secret<String>>,
/// Nick name of the card holder
#[schema(value_type = Option<String>)]
pub nick_name: Option<masking::Secret<String>>,
/// ECI indicator of the card
pub eci: Option<String>,
}
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
#[derive(Debug, serde::Serialize, ToSchema)]
pub struct TotalPaymentMethodCountResponse {