Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(euclid): eligibility for installments (#11395)
Prajjwal Kumar3c82b5434ee2
diff --git a/config/config.example.toml b/config/config.example.tomlindex 91a88cbc3c..42554806d9 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -608,6 +608,10 @@ bank_redirect.giropay = { connector_list = "globalpay" }card.credit = { connector_list = "cybersource" } # Update Mandate supported payment method type and connector for cardcard.debit = { connector_list = "cybersource" } # Update Mandate supported payment method type and connector for card+[installments.supported_payment_methods]+card.credit = "adyen" # Installment supported payment method type and connector for card+card.debit = "adyen" # Installment supported payment method type and connector for card+# Required fields info used while listing the payment_method_data[required_fields.pay_later] # payment_method = "pay_later"afterpay_clearpay = { fields = { stripe = [ # payment_method_type = afterpay_clearpay, connector = "stripe"diff --git a/config/development.toml b/config/development.tomlindex f4984d5f8b..9124712b77 100644--- a/config/development.toml+++ b/config/development.toml@@ -1202,6 +1202,10 @@ bank_redirect.eps.connector_list = "globalpay,nexinets,aci,multisafepay"card.credit = { connector_list = "cybersource" }card.debit = { connector_list = "cybersource" }+[installments.supported_payment_methods]+card.credit = "adyen"+card.debit = "adyen"+[network_transaction_id_supported_connectors]connector_list = "adyen,archipel,checkout,cybersource,novalnet,nuvei,stripe,worldpay,worldpayvantiv"diff --git a/crates/payment_methods/src/configs/settings.rs b/crates/payment_methods/src/configs/settings.rsindex 9bad38ccad..87b467d9fb 100644--- a/crates/payment_methods/src/configs/settings.rs+++ b/crates/payment_methods/src/configs/settings.rs@@ -94,6 +94,21 @@ pub struct SupportedConnectorsForMandate {#[serde(deserialize_with = "deserialize_hashset")]pub connector_list: HashSet<enums::Connector>,}++#[derive(Debug, Deserialize, Clone, Default)]+pub struct SupportedPaymentMethodsForInstallments(+ pub HashMap<enums::PaymentMethod, SupportedPaymentMethodTypesForInstallments>,+);++#[derive(Debug, Deserialize, Clone, Default)]+pub struct SupportedPaymentMethodTypesForInstallments(+ pub HashMap<enums::PaymentMethodType, SupportedConnectorsForInstallments>,+);++#[derive(Debug, Deserialize, Clone, Default)]+pub struct SupportedConnectorsForInstallments(+ #[serde(deserialize_with = "deserialize_hashset")] pub HashSet<enums::Connector>,+);#[derive(Debug, Deserialize, Clone)]pub struct Mandates {pub supported_payment_methods: SupportedPaymentMethodsForMandate,@@ -105,6 +120,12 @@ pub struct ZeroMandates {pub supported_payment_methods: SupportedPaymentMethodsForMandate,}+#[derive(Debug, Deserialize, Clone, Default)]+#[serde(default)]+pub struct Installments {+ pub supported_payment_methods: SupportedPaymentMethodsForInstallments,+}+fn deserialize_hashset_inner<T>(value: impl AsRef<str>) -> Result<HashSet<T>, String>whereT: Eq + std::str::FromStr + std::hash::Hash,diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rsindex a8fa1f82ef..e7a9dcaea7 100644--- a/crates/router/src/configs/secrets_transformers.rs+++ b/crates/router/src/configs/secrets_transformers.rs@@ -570,6 +570,7 @@ pub(crate) async fn fetch_raw_secrets(oidc,mandates: conf.mandates,zero_mandates: conf.zero_mandates,+ installments: conf.installments,network_transaction_id_supported_connectors: conf.network_transaction_id_supported_connectors,card_only_mit_supported_connectors: conf.card_only_mit_supported_connectors,diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex afe4b67e13..5f0a73466c 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -36,8 +36,8 @@ pub use hyperswitch_interfaces::{use masking::{Maskable, Secret};pub use payment_methods::configs::settings::{BankRedirectConfig, BanksVector, ConnectorBankNames, ConnectorFields, EligiblePaymentMethods,- Mandates, PaymentMethodAuth, PaymentMethodType, RequiredFieldFinal, RequiredFields,- SupportedConnectorsForMandate, SupportedPaymentMethodTypesForMandate,+ Installments, Mandates, PaymentMethodAuth, PaymentMethodType, RequiredFieldFinal,+ RequiredFields, SupportedConnectorsForMandate, SupportedPaymentMethodTypesForMandate,SupportedPaymentMethodsForMandate, ZeroMandates,};use payment_methods::configs::MicroServicesConfig;@@ -117,6 +117,7 @@ pub struct Settings<S: SecretState> {pub cors: CorsSettings,pub mandates: Mandates,pub zero_mandates: ZeroMandates,+ pub installments: Installments,pub network_transaction_id_supported_connectors: NetworkTransactionIdSupportedConnectors,pub card_only_mit_supported_connectors: CardOnlyMitSupportedConnectors,pub list_dispute_supported_connectors: ListDiputeSupportedConnectors,diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rsindex f8fe81c915..c8b8b5cad2 100644--- a/crates/router/src/core/payments/routing.rs+++ b/crates/router/src/core/payments/routing.rs@@ -2143,6 +2143,100 @@ pub async fn perform_cgraph_filtering(Ok(final_selection)}+#[cfg(feature = "v1")]+fn is_installment_payment(payment_data: &routing::PaymentsDslInput<'_>) -> bool {+ payment_data.payment_intent.installment_options.is_some()+}++#[cfg(feature = "v1")]+fn get_payment_method_and_type_for_installment(+ payment_data: &routing::PaymentsDslInput<'_>,+) -> (+ Option<api_enums::PaymentMethod>,+ Option<api_enums::PaymentMethodType>,+) {+ (+ payment_data.payment_attempt.payment_method,+ payment_data.payment_attempt.payment_method_type,+ )+}++#[cfg(feature = "v1")]+fn get_payment_data_for_installments<'a>(+ transaction_data: &'a routing::TransactionData<'a>,+) -> Option<&'a routing::PaymentsDslInput<'a>> {+ match transaction_data {+ routing::TransactionData::Payment(payment_data) => Some(payment_data),+ #[cfg(feature = "payouts")]+ routing::TransactionData::Payout(_) => None,+ }+}++#[cfg(feature = "v1")]+fn get_installment_supported_connectors(+ state: &SessionState,+ transaction_data: &routing::TransactionData<'_>,+) -> Option<Vec<api_enums::RoutableConnectors>> {+ get_payment_data_for_installments(transaction_data)+ .filter(|payment_data| is_installment_payment(payment_data))+ .map(|payment_data| {+ let (payment_method, payment_method_type) =+ get_payment_method_and_type_for_installment(payment_data);++ payment_method+ .zip(payment_method_type)+ .and_then(|(payment_method, payment_method_type)| {+ state+ .conf+ .installments+ .supported_payment_methods+ .0+ .get(&payment_method)+ .and_then(|supported_payment_method_types| {+ supported_payment_method_types.0.get(&payment_method_type)+ })+ .map(|supported_connectors| {+ supported_connectors+ .0+ .iter()+ .filter_map(|connector| {+ api_enums::RoutableConnectors::from_str(+ connector.to_string().as_str(),+ )+ .ok()+ })+ .collect::<Vec<_>>()+ })+ })+ .unwrap_or_default()+ })+}++#[cfg(feature = "v1")]+fn update_eligible_connectors_for_installments(+ state: &SessionState,+ transaction_data: &routing::TransactionData<'_>,+ eligible_connectors: Option<Vec<api_enums::RoutableConnectors>>,+) -> Option<Vec<api_enums::RoutableConnectors>> {+ let installment_supported_connectors =+ get_installment_supported_connectors(state, transaction_data);++ eligible_connectors+ .map(|existing_eligible_connectors| {+ installment_supported_connectors.as_ref().map_or(+ existing_eligible_connectors.clone(),+ |installment_supported_connectors| {+ installment_supported_connectors+ .iter()+ .filter(|connector| existing_eligible_connectors.contains(connector))+ .copied()+ .collect()+ },+ )+ })+ .or(installment_supported_connectors)+}+pub async fn perform_eligibility_analysis(state: &SessionState,key_store: &domain::MerchantKeyStore,@@ -2230,6 +2324,11 @@ pub async fn perform_eligibility_analysis_with_fallback(business_profile: &domain::Profile,) -> RoutingResult<Vec<routing_types::RoutableConnectorChoice>> {logger::debug!("euclid_routing: performing eligibility");++ #[cfg(feature = "v1")]+ let eligible_connectors =+ update_eligible_connectors_for_installments(state, transaction_data, eligible_connectors);+let mut final_selection = perform_eligibility_analysis(state,key_store,