mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 17:47:54 +08:00
feat: store encrypted extended card info in redis (#4493)
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use common_utils::{
|
||||
consts,
|
||||
crypto::{Encryptable, OptionalEncryptableName},
|
||||
pii,
|
||||
};
|
||||
@ -1099,8 +1100,47 @@ pub struct ExtendedCardInfoChoice {
|
||||
|
||||
impl common_utils::events::ApiEventMetric for ExtendedCardInfoChoice {}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct ExtendedCardInfoConfig {
|
||||
/// Merchant public key
|
||||
#[schema(value_type = String)]
|
||||
pub public_key: Secret<String>,
|
||||
pub ttl_in_secs: u16,
|
||||
/// TTL for extended card info
|
||||
#[schema(default = 900, maximum = 3600, value_type = u16)]
|
||||
#[serde(default)]
|
||||
pub ttl_in_secs: TtlForExtendedCardInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, Clone)]
|
||||
pub struct TtlForExtendedCardInfo(u16);
|
||||
|
||||
impl Default for TtlForExtendedCardInfo {
|
||||
fn default() -> Self {
|
||||
Self(consts::DEFAULT_TTL_FOR_EXTENDED_CARD_INFO)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for TtlForExtendedCardInfo {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let value = u16::deserialize(deserializer)?;
|
||||
|
||||
// Check if value exceeds the maximum allowed
|
||||
if value > consts::MAX_TTL_FOR_EXTENDED_CARD_INFO {
|
||||
Err(serde::de::Error::custom(
|
||||
"ttl_in_secs must be less than or equal to 3600 (1hr)",
|
||||
))
|
||||
} else {
|
||||
Ok(Self(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for TtlForExtendedCardInfo {
|
||||
type Target = u16;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
@ -916,6 +916,58 @@ pub struct Card {
|
||||
pub nick_name: Option<Secret<String>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||
pub struct ExtendedCardInfo {
|
||||
/// The card number
|
||||
#[schema(value_type = String, example = "4242424242424242")]
|
||||
pub card_number: CardNumber,
|
||||
|
||||
/// The card's expiry month
|
||||
#[schema(value_type = String, example = "24")]
|
||||
pub card_exp_month: Secret<String>,
|
||||
|
||||
/// The card's expiry year
|
||||
#[schema(value_type = String, example = "24")]
|
||||
pub card_exp_year: Secret<String>,
|
||||
|
||||
/// The card holder's name
|
||||
#[schema(value_type = String, example = "John Test")]
|
||||
pub card_holder_name: Option<Secret<String>>,
|
||||
|
||||
/// The name of the issuer of card
|
||||
#[schema(example = "chase")]
|
||||
pub card_issuer: Option<String>,
|
||||
|
||||
/// The card network for the card
|
||||
#[schema(value_type = Option<CardNetwork>, example = "Visa")]
|
||||
pub card_network: Option<api_enums::CardNetwork>,
|
||||
|
||||
#[schema(example = "CREDIT")]
|
||||
pub card_type: Option<String>,
|
||||
|
||||
#[schema(example = "INDIA")]
|
||||
pub card_issuing_country: Option<String>,
|
||||
|
||||
#[schema(example = "JP_AMEX")]
|
||||
pub bank_code: Option<String>,
|
||||
}
|
||||
|
||||
impl From<Card> for ExtendedCardInfo {
|
||||
fn from(value: Card) -> Self {
|
||||
Self {
|
||||
card_number: value.card_number,
|
||||
card_exp_month: value.card_exp_month,
|
||||
card_exp_year: value.card_exp_year,
|
||||
card_holder_name: value.card_holder_name,
|
||||
card_issuer: value.card_issuer,
|
||||
card_network: value.card_network,
|
||||
card_type: value.card_type,
|
||||
card_issuing_country: value.card_issuing_country,
|
||||
bank_code: value.bank_code,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GetAddressFromPaymentMethodData for Card {
|
||||
fn get_billing_address(&self) -> Option<Address> {
|
||||
// Create billing address if first_name is some or if it is not ""
|
||||
|
||||
Reference in New Issue
Block a user