refactor(required_fields): move pm required fields to pm crate (#7539)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Jagan
2025-04-21 13:26:58 +05:30
committed by GitHub
parent 662e45f003
commit 103a5c182b
12 changed files with 3480 additions and 14515 deletions

View File

@ -1,13 +1,10 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use api_models::{enums, payment_methods::RequiredFieldInfo};
use common_utils::id_type;
#[cfg(feature = "payouts")]
pub mod payout_required_fields;
pub mod payment_connector_required_fields;
impl Default for super::settings::Server {
fn default() -> Self {
Self {
@ -174,206 +171,3 @@ impl Default for super::settings::ApiKeys {
}
}
}
pub fn get_billing_required_fields() -> HashMap<String, RequiredFieldInfo> {
HashMap::from([
(
"billing.address.first_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.first_name".to_string(),
display_name: "billing_first_name".to_string(),
field_type: enums::FieldType::UserBillingName,
value: None,
},
),
(
"billing.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.last_name".to_string(),
display_name: "billing_last_name".to_string(),
field_type: enums::FieldType::UserBillingName,
value: None,
},
),
(
"billing.address.city".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.city".to_string(),
display_name: "city".to_string(),
field_type: enums::FieldType::UserAddressCity,
value: None,
},
),
(
"billing.address.state".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.state".to_string(),
display_name: "state".to_string(),
field_type: enums::FieldType::UserAddressState,
value: None,
},
),
(
"billing.address.zip".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.zip".to_string(),
display_name: "zip".to_string(),
field_type: enums::FieldType::UserAddressPincode,
value: None,
},
),
(
"billing.address.country".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.country".to_string(),
display_name: "country".to_string(),
field_type: enums::FieldType::UserAddressCountry {
options: vec!["ALL".to_string()],
},
value: None,
},
),
(
"billing.address.line1".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.line1".to_string(),
display_name: "line1".to_string(),
field_type: enums::FieldType::UserAddressLine1,
value: None,
},
),
(
"billing.address.line2".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.line2".to_string(),
display_name: "line2".to_string(),
field_type: enums::FieldType::UserAddressLine2,
value: None,
},
),
(
"billing.phone.number".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.phone.number".to_string(),
display_name: "phone_number".to_string(),
field_type: enums::FieldType::UserPhoneNumber,
value: None,
},
),
(
"billing.phone.country_code".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.phone.country_code".to_string(),
display_name: "dialing_code".to_string(),
field_type: enums::FieldType::UserPhoneNumberCountryCode,
value: None,
},
),
(
"billing.email".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.email".to_string(),
display_name: "email".to_string(),
field_type: enums::FieldType::UserEmailAddress,
value: None,
},
),
])
}
pub fn get_shipping_required_fields() -> HashMap<String, RequiredFieldInfo> {
HashMap::from([
(
"shipping.address.first_name".to_string(),
RequiredFieldInfo {
required_field: "shipping.address.first_name".to_string(),
display_name: "shipping_first_name".to_string(),
field_type: enums::FieldType::UserShippingName,
value: None,
},
),
(
"shipping.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "shipping.address.last_name".to_string(),
display_name: "shipping_last_name".to_string(),
field_type: enums::FieldType::UserShippingName,
value: None,
},
),
(
"shipping.address.city".to_string(),
RequiredFieldInfo {
required_field: "shipping.address.city".to_string(),
display_name: "city".to_string(),
field_type: enums::FieldType::UserShippingAddressCity,
value: None,
},
),
(
"shipping.address.state".to_string(),
RequiredFieldInfo {
required_field: "shipping.address.state".to_string(),
display_name: "state".to_string(),
field_type: enums::FieldType::UserShippingAddressState,
value: None,
},
),
(
"shipping.address.zip".to_string(),
RequiredFieldInfo {
required_field: "shipping.address.zip".to_string(),
display_name: "zip".to_string(),
field_type: enums::FieldType::UserShippingAddressPincode,
value: None,
},
),
(
"shipping.address.country".to_string(),
RequiredFieldInfo {
required_field: "shipping.address.country".to_string(),
display_name: "country".to_string(),
field_type: enums::FieldType::UserShippingAddressCountry {
options: vec!["ALL".to_string()],
},
value: None,
},
),
(
"shipping.address.line1".to_string(),
RequiredFieldInfo {
required_field: "shipping.address.line1".to_string(),
display_name: "line1".to_string(),
field_type: enums::FieldType::UserShippingAddressLine1,
value: None,
},
),
(
"shipping.phone.number".to_string(),
RequiredFieldInfo {
required_field: "shipping.phone.number".to_string(),
display_name: "phone_number".to_string(),
field_type: enums::FieldType::UserPhoneNumber,
value: None,
},
),
(
"shipping.phone.country_code".to_string(),
RequiredFieldInfo {
required_field: "shipping.phone.country_code".to_string(),
display_name: "dialing_code".to_string(),
field_type: enums::FieldType::UserPhoneNumberCountryCode,
value: None,
},
),
(
"shipping.email".to_string(),
RequiredFieldInfo {
required_field: "shipping.email".to_string(),
display_name: "email".to_string(),
field_type: enums::FieldType::UserEmailAddress,
value: None,
},
),
])
}

View File

@ -224,25 +224,6 @@ impl SecretsHandler for settings::ApplepayMerchantConfigs {
}
}
#[async_trait::async_trait]
impl SecretsHandler for settings::PaymentMethodAuth {
async fn convert_to_raw_secret(
value: SecretStateContainer<Self, SecuredSecret>,
secret_management_client: &dyn SecretManagementInterface,
) -> CustomResult<SecretStateContainer<Self, RawSecret>, SecretsManagementError> {
let payment_method_auth = value.get_inner();
let pm_auth_key = secret_management_client
.get_secret(payment_method_auth.pm_auth_key.clone())
.await?;
Ok(value.transition_state(|payment_method_auth| Self {
pm_auth_key,
..payment_method_auth
}))
}
}
#[async_trait::async_trait]
impl SecretsHandler for settings::KeyManagerConfig {
async fn convert_to_raw_secret(

View File

@ -6,7 +6,7 @@ use std::{
#[cfg(feature = "olap")]
use analytics::{opensearch::OpenSearchConfig, ReportConfig};
use api_models::{enums, payment_methods::RequiredFieldInfo};
use api_models::enums;
use common_utils::{ext_traits::ConfigExt, id_type, types::theme::EmailThemeConfig};
use config::{Environment, File};
use error_stack::ResultExt;
@ -25,6 +25,11 @@ use hyperswitch_interfaces::secrets_interface::secret_state::{
RawSecret, SecretState, SecretStateContainer, SecuredSecret,
};
use masking::Secret;
pub use payment_methods::configs::settings::{
ConnectorFields, EligiblePaymentMethods, Mandates, PaymentMethodAuth, PaymentMethodType,
RequiredFieldFinal, RequiredFields, SupportedConnectorsForMandate,
SupportedPaymentMethodTypesForMandate, SupportedPaymentMethodsForMandate, ZeroMandates,
};
use redis_interface::RedisSettings;
pub use router_env::config::{Log, LogConsole, LogFile, LogTelemetry};
use rust_decimal::Decimal;
@ -416,19 +421,6 @@ pub struct ForexApi {
pub redis_ttl_in_seconds: u32,
}
#[derive(Debug, Deserialize, Clone, Default)]
pub struct PaymentMethodAuth {
pub redis_expiry: i64,
pub pm_auth_key: Secret<String>,
}
#[derive(Debug, Deserialize, Clone, Default)]
#[serde(default)]
pub struct EligiblePaymentMethods {
#[serde(deserialize_with = "deserialize_hashset")]
pub sdk_eligible_payment_methods: HashSet<String>,
}
#[derive(Debug, Deserialize, Clone, Default)]
pub struct DefaultExchangeRates {
pub base_currency: String,
@ -510,17 +502,6 @@ pub struct CorsSettings {
pub allowed_methods: HashSet<String>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct Mandates {
pub supported_payment_methods: SupportedPaymentMethodsForMandate,
pub update_mandate_supported: SupportedPaymentMethodsForMandate,
}
#[derive(Debug, Deserialize, Clone)]
pub struct ZeroMandates {
pub supported_payment_methods: SupportedPaymentMethodsForMandate,
}
#[derive(Debug, Deserialize, Clone, Default)]
pub struct NetworkTransactionIdSupportedConnectors {
#[serde(deserialize_with = "deserialize_hashset")]
@ -545,22 +526,6 @@ pub struct NetworkTokenizationService {
pub check_token_status_url: url::Url,
}
#[derive(Debug, Deserialize, Clone)]
pub struct SupportedPaymentMethodsForMandate(
pub HashMap<enums::PaymentMethod, SupportedPaymentMethodTypesForMandate>,
);
#[derive(Debug, Deserialize, Clone)]
pub struct SupportedPaymentMethodTypesForMandate(
pub HashMap<enums::PaymentMethodType, SupportedConnectorsForMandate>,
);
#[derive(Debug, Deserialize, Clone)]
pub struct SupportedConnectorsForMandate {
#[serde(deserialize_with = "deserialize_hashset")]
pub connector_list: HashSet<enums::Connector>,
}
#[derive(Debug, Deserialize, Clone, Default)]
pub struct PaymentMethodTokenFilter {
#[serde(deserialize_with = "deserialize_hashset")]
@ -647,34 +612,6 @@ pub struct NotAvailableFlows {
#[cfg_attr(feature = "v2", derive(Default))] // Configs are read from the config file in config/payout_required_fields.toml
pub struct PayoutRequiredFields(pub HashMap<enums::PaymentMethod, PaymentMethodType>);
#[derive(Debug, Deserialize, Clone)]
#[cfg_attr(feature = "v2", derive(Default))] // Configs are read from the config file in config/payment_required_fields.toml
pub struct RequiredFields(pub HashMap<enums::PaymentMethod, PaymentMethodType>);
#[derive(Debug, Deserialize, Clone)]
pub struct PaymentMethodType(pub HashMap<enums::PaymentMethodType, ConnectorFields>);
#[derive(Debug, Deserialize, Clone)]
pub struct ConnectorFields {
pub fields: HashMap<enums::Connector, RequiredFieldFinal>,
}
#[cfg(feature = "v1")]
#[derive(Debug, Deserialize, Clone)]
pub struct RequiredFieldFinal {
pub mandate: HashMap<String, RequiredFieldInfo>,
pub non_mandate: HashMap<String, RequiredFieldInfo>,
pub common: HashMap<String, RequiredFieldInfo>,
}
#[cfg(feature = "v2")]
#[derive(Debug, Deserialize, Clone)]
pub struct RequiredFieldFinal {
pub mandate: Option<Vec<RequiredFieldInfo>>,
pub non_mandate: Option<Vec<RequiredFieldInfo>>,
pub common: Option<Vec<RequiredFieldInfo>>,
}
#[derive(Debug, Default, Deserialize, Clone)]
#[serde(default)]
pub struct Secrets {

View File

@ -4,6 +4,9 @@ use std::{
str::FromStr,
};
use ::payment_methods::configs::payment_connector_required_fields::{
get_billing_required_fields, get_shipping_required_fields,
};
#[cfg(all(
any(feature = "v1", feature = "v2"),
not(feature = "payment_methods_v2")
@ -91,10 +94,7 @@ use crate::routes::app::SessionStateInfo;
#[cfg(feature = "payouts")]
use crate::types::domain::types::AsyncLift;
use crate::{
configs::{
defaults::{get_billing_required_fields, get_shipping_required_fields},
settings,
},
configs::settings,
consts as router_consts,
core::{
errors::{self, StorageErrorExt},