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(payments): add card installment support with plan configuration and interest calculation (#11381)
Ayush Anand28de993abe54
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 1d0904874a..4361a7014c 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -20915,6 +20915,33 @@"connected"]},+ "InstallmentData": {+ "type": "object",+ "description": "Installment selection made by the customer during payment confirmation.",+ "required": [+ "number_of_installments",+ "billing_frequency"+ ],+ "properties": {+ "number_of_installments": {+ "type": "integer",+ "format": "int32",+ "description": "Number of installments chosen by the customer",+ "minimum": 0+ },+ "billing_frequency": {+ "$ref": "#/components/schemas/BillingFrequency"+ },+ "installment_interest": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MinorUnit"+ }+ ],+ "nullable": true+ }+ }+ },"InstallmentOption": {"type": "object","description": "Installment options grouped by payment method",@@ -20955,7 +20982,26 @@"interest_rate": {"type": "number","format": "double",- "description": "Interest rate applied per installment as a percentage"+ "description": "Interest rate per installment as a percentage max 2 decimal places\n"+ }+ }+ },+ "InstallmentRequest": {+ "type": "object",+ "description": "Installment selection sent by the customer during payment confirmation.",+ "required": [+ "number_of_installments",+ "billing_frequency"+ ],+ "properties": {+ "number_of_installments": {+ "type": "integer",+ "format": "int32",+ "description": "Number of installments chosen by the customer",+ "minimum": 0+ },+ "billing_frequency": {+ "$ref": "#/components/schemas/BillingFrequency"}}},@@ -28372,6 +28418,14 @@},"description": "Installment payment options grouped by payment method. When provided, the payment is treated as an installment payment.","nullable": true+ },+ "installment_data": {+ "allOf": [+ {+ "$ref": "#/components/schemas/InstallmentRequest"+ }+ ],+ "nullable": true}}},@@ -28908,6 +28962,14 @@},"description": "Installment payment options grouped by payment method. When provided, the payment is treated as an installment payment.","nullable": true+ },+ "installment_data": {+ "allOf": [+ {+ "$ref": "#/components/schemas/InstallmentRequest"+ }+ ],+ "nullable": true}}},@@ -29644,6 +29706,14 @@},"description": "Installment payment options associated with this payment, grouped by payment method","nullable": true+ },+ "installment_data": {+ "allOf": [+ {+ "$ref": "#/components/schemas/InstallmentData"+ }+ ],+ "nullable": true}}},@@ -30533,6 +30603,14 @@},"description": "Installment payment options grouped by payment method. When provided, the payment is treated as an installment payment.","nullable": true+ },+ "installment_data": {+ "allOf": [+ {+ "$ref": "#/components/schemas/InstallmentRequest"+ }+ ],+ "nullable": true}},"additionalProperties": false@@ -31295,6 +31373,14 @@},"description": "Installment payment options associated with this payment, grouped by payment method","nullable": true+ },+ "installment_data": {+ "allOf": [+ {+ "$ref": "#/components/schemas/InstallmentData"+ }+ ],+ "nullable": true}}},@@ -31989,6 +32075,14 @@},"description": "Installment payment options grouped by payment method. When provided, the payment is treated as an installment payment.","nullable": true+ },+ "installment_data": {+ "allOf": [+ {+ "$ref": "#/components/schemas/InstallmentRequest"+ }+ ],+ "nullable": true}}},diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex ce1a4c68d8..d9c8758bb1 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -2,7 +2,7 @@use std::fmt;use std::{collections::{HashMap, HashSet},- num::NonZeroI64,+ num::{NonZeroI64, NonZeroU8},};pub mod additional_info;pub mod trait_impls;@@ -1101,6 +1101,29 @@ impl AmountDetailsUpdate {self.tax_on_surcharge}}++/// Installment selection sent by the customer during payment confirmation.+#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel)]+#[smithy(namespace = "com.hyperswitch.smithy.types")]+pub struct InstallmentRequest {+ /// Number of installments chosen by the customer+ #[schema(value_type = u8)]+ pub number_of_installments: NonZeroU8,+ /// Billing frequency for the chosen installment plan+ #[schema(value_type = BillingFrequency)]+ pub billing_frequency: common_payments_types::BillingFrequency,+}++impl From<InstallmentRequest> for common_payments_types::InstallmentData {+ fn from(data: InstallmentRequest) -> Self {+ Self {+ number_of_installments: data.number_of_installments,+ billing_frequency: data.billing_frequency,+ installment_interest: None,+ }+ }+}+#[cfg(feature = "v1")]#[derive(Default,@@ -1563,6 +1586,9 @@ pub struct PaymentsRequest {/// Installment payment options grouped by payment method. When provided, the payment is treated as an installment payment.#[schema(value_type = Option<Vec<InstallmentOption>>)]pub installment_options: Option<Vec<common_types::payments::InstallmentOption>>,++ /// Installment data selected by the customer during payment confirmation. This is used to specify the chosen number of installments and billing frequency.+ pub installment_data: Option<InstallmentRequest>,}#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, ToSchema, SmithyModel)]@@ -7692,6 +7718,10 @@ pub struct PaymentsResponse {/// Installment payment options associated with this payment, grouped by payment method#[schema(value_type = Option<Vec<InstallmentOption>>)]pub installment_options: Option<Vec<common_types::payments::InstallmentOption>>,++ /// Installment selection confirmed by the customer for this payment+ #[schema(value_type = Option<InstallmentData>)]+ pub installment_data: Option<common_types::payments::InstallmentData>,}#[cfg(feature = "v1")]diff --git a/crates/common_types/src/payments.rs b/crates/common_types/src/payments.rsindex 52c7f2ee7e..840c87980d 100644--- a/crates/common_types/src/payments.rs+++ b/crates/common_types/src/payments.rs@@ -1,10 +1,12 @@//! Payment related types--use std::collections::{HashMap, HashSet};+use std::{+ collections::{HashMap, HashSet},+ num::NonZeroU8,+};use common_enums::enums;use common_utils::{- date_time, errors, events, ext_traits::OptionExt, impl_to_sql_from_sql_json, pii,+ consts, date_time, errors, events, ext_traits::OptionExt, impl_to_sql_from_sql_json, pii,types::MinorUnit,};use diesel::{@@ -1254,53 +1256,125 @@ pub enum BillingFrequency {Month,}-/// A non-empty list of installment counts where each value is >= 2 and all values are unique.+/// A non-empty list of unique installment counts.#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]-#[serde(try_from = "Vec<u8>", into = "Vec<u8>")]-pub struct InstallmentCounts(Vec<u8>);+#[serde(try_from = "Vec<NonZeroU8>")]+pub struct InstallmentCounts(Vec<NonZeroU8>);impl InstallmentCounts {- fn validate_not_empty(counts: &[u8]) -> std::result::Result<(), errors::ValidationError> {- (!counts.is_empty())- .then_some(())- .ok_or_else(|| errors::ValidationError::InvalidValue {+ /// Check if this `InstallmentCounts` contains the given count.+ pub fn contains(&self, count: NonZeroU8) -> bool {+ self.0.contains(&count)+ }++ fn validate_not_empty(counts: &[NonZeroU8]) -> Result<(), errors::ValidationError> {+ (!counts.is_empty()).then_some(()).ok_or_else(|| {+ error_stack::report!(errors::ValidationError::InvalidValue {message: "number_of_installments must not be empty.".to_string(),})+ })}- fn validate_values(counts: &[u8]) -> std::result::Result<(), errors::ValidationError> {+ fn validate_unique(counts: &[NonZeroU8]) -> Result<(), errors::ValidationError> {counts.iter().try_fold(HashSet::new(), |mut seen, &n| {- (n >= 1)- .then_some(())- .ok_or_else(|| errors::ValidationError::InvalidValue {- message: "each value in number_of_installments must be at least 1."- .to_string(),- })?;seen.insert(n).then_some(seen).ok_or_else(|| {- errors::ValidationError::InvalidValue {+ error_stack::report!(errors::ValidationError::InvalidValue {message: "number_of_installments must contain unique values.".to_string(),- }+ })})}).map(|_| ())}}-impl TryFrom<Vec<u8>> for InstallmentCounts {- type Error = errors::ValidationError;+impl TryFrom<Vec<NonZeroU8>> for InstallmentCounts {+ type Error = Report<errors::ValidationError>;- fn try_from(counts: Vec<u8>) -> std::result::Result<Self, Self::Error> {+ fn try_from(counts: Vec<NonZeroU8>) -> Result<Self, errors::ValidationError> {Self::validate_not_empty(&counts)?;- Self::validate_values(&counts)?;+ Self::validate_unique(&counts)?;Ok(Self(counts))}}-impl From<InstallmentCounts> for Vec<u8> {- fn from(c: InstallmentCounts) -> Self {- c.0+/// An interest rate with at most 2 decimal places.+/// Serializes and deserializes as a plain float (e.g. `2.5`).+#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq)]+#[serde(try_from = "f64")]+pub struct InstallmentInterestRate(f64);++impl InstallmentInterestRate {+ /// apply the interest rate to amount and ceil the result+ pub fn apply_and_ceil_result(+ &self,+ amount: MinorUnit,+ ) -> errors::CustomResult<MinorUnit, errors::InstallmentInterestRateError> {+ let max_amount = i64::MAX / 10000;+ let amount = amount.get_amount_as_i64();+ if amount > max_amount {+ // value gets rounded off after i64::MAX/10000+ Err(error_stack::report!(+ errors::InstallmentInterestRateError::UnableToApplyInterestRate+ ))+ .attach_printable(format!(+ "Cannot calculate interest rate for amount greater than {max_amount}",+ ))+ } else {+ let amount_f64 = amount+ .to_string()+ .parse::<f64>()+ .change_context(errors::InstallmentInterestRateError::UnableToApplyInterestRate)+ .attach_printable("Failed to parse amount as f64")?;+ let ceiled = (amount_f64 * (self.0 / 100.0)).ceil();+ let result = ceiled+ .to_string()+ .parse::<i64>()+ .change_context(errors::InstallmentInterestRateError::UnableToApplyInterestRate)+ .attach_printable("Failed to parse ceiled result as i64")?;+ Ok(MinorUnit::new(result))+ }+ }++ fn is_valid_precision_length(value: &str) -> bool {+ if value.contains('.') {+ // if string has '.' then take the decimal part and verify precision length+ match value.split('.').next_back() {+ Some(decimal_part) => {+ decimal_part.trim_end_matches('0').len()+ <= usize::from(consts::INSTALLMENT_INTEREST_RATE_PRECISION_LENGTH)+ }+ // will never be None+ None => false,+ }+ } else {+ // if there is no '.' then it is a whole number with no decimal part. So return true+ true+ }+ }++ fn is_non_negative(rate: f64) -> bool {+ rate >= 0.0+ }+}++impl TryFrom<f64> for InstallmentInterestRate {+ type Error = Report<errors::ValidationError>;++ fn try_from(rate: f64) -> Result<Self, errors::ValidationError> {+ Self::is_non_negative(rate).then_some(()).ok_or_else(|| {+ error_stack::report!(errors::ValidationError::InvalidValue {+ message: "interest_rate must not be negative.".to_string(),+ })+ })?;+ Self::is_valid_precision_length(&rate.to_string())+ .then_some(Self(rate))+ .ok_or_else(|| {+ error_stack::report!(errors::ValidationError::InvalidValue {+ message: "interest_rate must have at most 2 decimal places.".to_string(),+ })+ })}}@@ -1312,8 +1386,10 @@ pub struct InstallmentOptionData {pub number_of_installments: InstallmentCounts,/// Billing frequency for each installment cyclepub billing_frequency: BillingFrequency,- /// Interest rate applied per installment as a percentage- pub interest_rate: f64,+ /// Interest rate per installment as a percentage max 2 decimal places+ ///+ #[schema(value_type = f64)]+ pub interest_rate: InstallmentInterestRate,}/// Installment options grouped by payment method@@ -1341,6 +1417,30 @@ pub struct InstallmentOption {pub struct InstallmentOptions(pub Vec<InstallmentOption>);impl_to_sql_from_sql_json!(InstallmentOptions);+/// Installment selection made by the customer during payment confirmation.+#[derive(+ Debug,+ Clone,+ serde::Serialize,+ serde::Deserialize,+ ToSchema,+ PartialEq,+ Eq,+ FromSqlRow,+ AsExpression,+)]+#[diesel(sql_type = Jsonb)]+pub struct InstallmentData {+ /// Number of installments chosen by the customer+ #[schema(value_type = u8)]+ pub number_of_installments: NonZeroU8,+ /// Billing frequency for the chosen installment plan+ pub billing_frequency: BillingFrequency,+ /// Total interest amount applied for this installment plan+ pub installment_interest: Option<MinorUnit>,+}+impl_to_sql_from_sql_json!(InstallmentData);+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq, SmithyModel,)]diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rsindex db4b6c64ea..715e18cee7 100644--- a/crates/common_utils/src/consts.rs+++ b/crates/common_utils/src/consts.rs@@ -46,6 +46,9 @@ pub fn default_payouts_list_limit() -> u32 {/// surcharge percentage maximum precision lengthpub const SURCHARGE_PERCENTAGE_PRECISION_LENGTH: u8 = 2;+/// installment interest rate maximum precision length+pub const INSTALLMENT_INTEREST_RATE_PRECISION_LENGTH: u8 = 2;+/// Header Key for application overhead of a requestpub const X_HS_LATENCY: &str = "x-hs-latency";diff --git a/crates/common_utils/src/errors.rs b/crates/common_utils/src/errors.rsindex 54d047afcd..07abe2334f 100644--- a/crates/common_utils/src/errors.rs+++ b/crates/common_utils/src/errors.rs@@ -142,6 +142,14 @@ pub enum PercentageError {},}+/// Error type for installment interest rate operations+#[derive(Debug, Clone, thiserror::Error, PartialEq)]+pub enum InstallmentInterestRateError {+ /// Error occurred while applying interest rate to amount+ #[error("Failed to apply interest rate to amount")]+ UnableToApplyInterestRate,+}+/// Allows [error_stack::Report] to change between error contexts/// using the dependent [ErrorSwitch] trait to define relations & mappings between traitspub trait ReportSwitchExt<T, U> {diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rsindex be84ed26f4..d400c7d245 100644--- a/crates/diesel_models/src/payment_attempt.rs+++ b/crates/diesel_models/src/payment_attempt.rs@@ -163,6 +163,7 @@ pub struct PaymentAttempt {pub encrypted_payment_method_data: Option<common_utils::encryption::Encryption>,pub error_details: Option<ErrorDetails>,pub retry_type: Option<storage_enums::RetryType>,+ pub installment_data: Option<common_types::payments::InstallmentData>,#[diesel(deserialize_as = RequiredFromNullable<storage_enums::PaymentMethod>)]pub payment_method_type_v2: storage_enums::PaymentMethod,pub connector_payment_id: Option<ConnectorTransactionId>,@@ -294,6 +295,7 @@ pub struct PaymentAttempt {pub error_details: Option<ErrorDetails>,/// Indicates the type of retry for this payment attempt (None for initial attempt)pub retry_type: Option<storage_enums::RetryType>,+ pub installment_data: Option<common_types::payments::InstallmentData>,}#[cfg(feature = "v1")]@@ -539,6 +541,7 @@ pub struct PaymentAttemptNew {pub error_details: Option<ErrorDetails>,/// Indicates the type of retry for this payment attempt (None for initial attempt)pub retry_type: Option<storage_enums::RetryType>,+ pub installment_data: Option<common_types::payments::InstallmentData>,}#[cfg(feature = "v1")]@@ -614,6 +617,7 @@ pub enum PaymentAttemptUpdate {customer_acceptance: Option<pii::SecretSerdeValue>,shipping_cost: Option<MinorUnit>,order_tax_amount: Option<MinorUnit>,+ installment_data: Option<common_types::payments::InstallmentData>,connector_mandate_detail: Option<ConnectorMandateReferenceId>,tokenization: Option<common_enums::Tokenization>,card_discovery: Option<storage_enums::CardDiscovery>,@@ -1135,6 +1139,7 @@ impl PaymentAttemptUpdateInternal {encrypted_payment_method_data: source.encrypted_payment_method_data,error_details: source.error_details,retry_type: source.retry_type,+ installment_data: source.installment_data,}}}@@ -1195,6 +1200,7 @@ pub struct PaymentAttemptUpdateInternal {pub tokenization: Option<common_enums::Tokenization>,pub shipping_cost: Option<MinorUnit>,pub order_tax_amount: Option<MinorUnit>,+ pub installment_data: Option<common_types::payments::InstallmentData>,pub connector_mandate_detail: Option<ConnectorMandateReferenceId>,pub processor_transaction_data: Option<String>,pub card_discovery: Option<common_enums::CardDiscovery>,@@ -1234,6 +1240,12 @@ impl PaymentAttemptUpdateInternal {+ update_internal.order_tax_amount.or(source.order_tax_amount)+ .unwrap_or(MinorUnit::new(0))+ + update_internal+ .installment_data+ .as_ref()+ .or(source.installment_data.as_ref())+ .and_then(|d| d.installment_interest).unwrap_or(MinorUnit::new(0)),);update_internal.card_network = update_internal@@ -1412,6 +1424,7 @@ impl PaymentAttemptUpdate {request_extended_authorization,authorized_amount,error_details,+ installment_data,} = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source);PaymentAttempt {amount: amount.unwrap_or(source.amount),@@ -1468,6 +1481,7 @@ impl PaymentAttemptUpdate {card_network: card_network.or(source.card_network),shipping_cost: shipping_cost.or(source.shipping_cost),order_tax_amount: order_tax_amount.or(source.order_tax_amount),+ installment_data: installment_data.or(source.installment_data),processor_transaction_data: processor_transaction_data.or(source.processor_transaction_data),connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail),@@ -2857,6 +2871,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -2931,6 +2946,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -2966,6 +2982,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {customer_acceptance,shipping_cost,order_tax_amount,+ installment_data,connector_mandate_detail,tokenization,card_discovery,@@ -3042,6 +3059,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential,request_extended_authorization,authorized_amount: None,+ installment_data,encrypted_payment_method_data: None,error_details: None,},@@ -3119,6 +3137,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {authorized_amount: None,encrypted_payment_method_data: None,error_details: None,+ installment_data: None,},PaymentAttemptUpdate::RejectUpdate {status,@@ -3195,6 +3214,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {authorized_amount: None,encrypted_payment_method_data: None,error_details: None,+ installment_data: None,},PaymentAttemptUpdate::BlocklistUpdate {status,@@ -3271,6 +3291,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {authorized_amount: None,encrypted_payment_method_data: None,error_details: None,+ installment_data: None,},PaymentAttemptUpdate::ConnectorMandateDetailUpdate {connector_mandate_detail,@@ -3346,6 +3367,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {authorized_amount: None,encrypted_payment_method_data: None,error_details: None,+ installment_data: None,},PaymentAttemptUpdate::PaymentMethodDetailsUpdate {payment_method_id,@@ -3420,6 +3442,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {authorized_amount: None,encrypted_payment_method_data: None,error_details: None,+ installment_data: None,},PaymentAttemptUpdate::ResponseUpdate {status,@@ -3530,6 +3553,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {authorized_amount,encrypted_payment_method_data,error_details,+ installment_data: None,}}PaymentAttemptUpdate::ErrorUpdate {@@ -3626,6 +3650,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data,error_details,}@@ -3698,6 +3723,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -3780,6 +3806,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -3869,6 +3896,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details,}@@ -3955,6 +3983,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,}@@ -4031,6 +4060,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -4106,6 +4136,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -4190,6 +4221,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,}@@ -4265,6 +4297,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -4342,6 +4375,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},@@ -4429,6 +4463,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,}@@ -4504,6 +4539,7 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {is_stored_credential: None,request_extended_authorization: None,authorized_amount: None,+ installment_data: None,encrypted_payment_method_data: None,error_details: None,},diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 3444fc0dd8..450d39eb2d 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -1142,6 +1142,7 @@ diesel::table! {error_details -> Nullable<Jsonb>,#[max_length = 64]retry_type -> Nullable<Varchar>,+ installment_data -> Nullable<Jsonb>,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 1f11713e7a..736290cd84 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -1086,6 +1086,7 @@ diesel::table! {error_details -> Nullable<Jsonb>,#[max_length = 64]retry_type -> Nullable<Varchar>,+ installment_data -> Nullable<Jsonb>,payment_method_type_v2 -> Nullable<Varchar>,#[max_length = 128]connector_payment_id -> Nullable<Varchar>,diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rsindex 99f6707a72..df62e70e8f 100644--- a/crates/diesel_models/src/user/sample_data.rs+++ b/crates/diesel_models/src/user/sample_data.rs@@ -321,6 +321,7 @@ impl PaymentAttemptBatchNew {tokenization: self.tokenization,error_details: None,retry_type: None,+ installment_data: None,}}}diff --git a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rsindex 0d78f35321..69c5298c11 100644--- a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs@@ -1,4 +1,4 @@-use std::{ops::Deref, str::FromStr};+use std::{num::NonZeroU8, ops::Deref, str::FromStr};#[cfg(feature = "payouts")]use api_models::payouts::{self, PayoutMethodData};@@ -370,6 +370,7 @@ pub struct AdyenPaymentRequest<'a> {metadata: Option<serde_json::Value>,platform_chargeback_logic: Option<AdyenPlatformChargeBackLogicMetadata>,application_info: Option<ApplicationInfo>,+ installments: Option<AdyenInstallments>,}#[derive(Debug, Clone, Serialize, Deserialize)]@@ -749,6 +750,11 @@ pub struct Amount {pub value: MinorUnit,}+#[derive(Debug, Clone, Serialize)]+pub struct AdyenInstallments {+ value: NonZeroU8,+}+#[derive(Debug, Clone, Serialize)]#[serde(untagged)]pub enum PaymentMethod<'a> {@@ -2197,6 +2203,18 @@ fn get_amount_data(item: &AdyenRouterData<&PaymentsAuthorizeRouterData>) -> Amou}}+fn get_installment_details(+ item: &AdyenRouterData<&PaymentsAuthorizeRouterData>,+) -> Option<AdyenInstallments> {+ item.router_data+ .request+ .installment_details+ .as_ref()+ .map(|d| AdyenInstallments {+ value: d.number_of_installments,+ })+}+pub fn get_address_info(address: Option<&hyperswitch_domain_models::address::Address>,) -> Option<Result<Address, error_stack::Report<errors::ConnectorError>>> {@@ -3309,6 +3327,7 @@ impl.map(filter_adyen_metadata),platform_chargeback_logic,application_info,+ installments: None,})}}@@ -3358,6 +3377,7 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &Card)> for AdyenPget_address_info(item.router_data.get_optional_shipping()).and_then(Result::ok);let telephone_number = item.router_data.get_optional_billing_phone_number();let application_info = get_application_info(item);+ let installments = get_installment_details(item);let mpi_data =if let Some(auth_data) = value.0.router_data.request.authentication_data.as_ref() {@@ -3445,6 +3465,7 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &Card)> for AdyenP.map(filter_adyen_metadata),platform_chargeback_logic,application_info,+ installments,})}}@@ -3538,6 +3559,7 @@ impl.clone().map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,};Ok(request)@@ -3621,6 +3643,7 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &VoucherData)>.map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,};Ok(request)@@ -3746,6 +3769,7 @@ impl.map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,};Ok(request)@@ -3829,6 +3853,7 @@ impl.clone().map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,};Ok(request)@@ -3917,6 +3942,7 @@ impl.clone().map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,})}@@ -4088,6 +4114,7 @@ impl TryFrom<(&AdyenRouterData<&PaymentsAuthorizeRouterData>, &WalletData)>.clone().map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,})}@@ -4183,6 +4210,7 @@ impl.clone().map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,})}@@ -4272,6 +4300,7 @@ impl.clone().map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,})}@@ -6860,6 +6889,7 @@ impl.clone().map(filter_adyen_metadata),platform_chargeback_logic,+ installments: None,application_info,})}diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rsindex 350d151fa9..24f8aa4bcd 100644--- a/crates/hyperswitch_connectors/src/utils.rs+++ b/crates/hyperswitch_connectors/src/utils.rs@@ -7563,6 +7563,7 @@ pub(crate) fn convert_setup_mandate_router_data_to_authorize_router_data(.clone(),rrn: None,feature_metadata: None,+ installment_details: None,}}diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rsindex d76e9d86dd..3e2f5c94f3 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs@@ -1427,6 +1427,8 @@ pub struct PaymentAttempt {pub error_details: Option<PaymentAttemptErrorDetails>,/// Indicates the type of retry for this payment attempt (None for initial attempt)pub retry_type: Option<storage_enums::RetryType>,+ /// Installment data selected by the customer (number of installments and billing frequency)+ pub installment_data: Option<common_types::payments::InstallmentData>,}#[cfg(feature = "v1")]@@ -1442,6 +1444,8 @@ pub struct NetAmount {surcharge_amount: Option<MinorUnit>,/// tax on surcharge amounttax_on_surcharge: Option<MinorUnit>,+ /// Installment interest amount for installment payments+ installment_interest: Option<MinorUnit>,}#[cfg(feature = "v1")]@@ -1452,6 +1456,7 @@ impl NetAmount {order_tax_amount: Option<MinorUnit>,surcharge_amount: Option<MinorUnit>,tax_on_surcharge: Option<MinorUnit>,+ installment_interest: Option<MinorUnit>,) -> Self {Self {order_amount,@@ -1459,6 +1464,7 @@ impl NetAmount {order_tax_amount,surcharge_amount,tax_on_surcharge,+ installment_interest,}}@@ -1482,6 +1488,10 @@ impl NetAmount {self.tax_on_surcharge}+ pub fn get_installment_interest(&self) -> Option<MinorUnit> {+ self.installment_interest+ }+pub fn get_total_surcharge_amount(&self) -> Option<MinorUnit> {self.surcharge_amount.map(|surcharge_amount| surcharge_amount + self.tax_on_surcharge.unwrap_or_default())@@ -1493,6 +1503,7 @@ impl NetAmount {+ self.order_tax_amount.unwrap_or_default()+ self.surcharge_amount.unwrap_or_default()+ self.tax_on_surcharge.unwrap_or_default()+ + self.installment_interest.unwrap_or_default()}pub fn get_additional_amount(&self) -> MinorUnit {@@ -1517,6 +1528,10 @@ impl NetAmount {self.tax_on_surcharge = surcharge_details.map(|details| details.tax_on_surcharge_amount);}+ pub fn set_installment_interest(&mut self, installment_interest: Option<MinorUnit>) {+ self.installment_interest = installment_interest;+ }+pub fn from_payments_request(payments_request: &api_models::payments::PaymentsRequest,order_amount: MinorUnit,@@ -1533,6 +1548,7 @@ impl NetAmount {order_tax_amount: payments_request.order_tax_amount,surcharge_amount,tax_on_surcharge,+ installment_interest: None,}}@@ -1567,12 +1583,15 @@ impl NetAmount {payment_attempt.net_amount.get_tax_on_surcharge()})});+ let installment_interest = payment_attempt+ .and_then(|payment_attempt| payment_attempt.net_amount.get_installment_interest());Self {order_amount,shipping_cost,order_tax_amount,surcharge_amount,tax_on_surcharge,+ installment_interest,}})}@@ -1937,6 +1956,7 @@ pub enum PaymentAttemptUpdate {client_source: Option<String>,client_version: Option<String>,customer_acceptance: Option<pii::SecretSerdeValue>,+ installment_data: Option<common_types::payments::InstallmentData>,connector_mandate_detail: Option<ConnectorMandateReferenceId>,tokenization: Option<common_enums::Tokenization>,card_discovery: Option<common_enums::CardDiscovery>,@@ -2246,6 +2266,7 @@ impl PaymentAttemptUpdate {client_source,client_version,customer_acceptance,+ installment_data,connector_mandate_detail,tokenization,card_discovery,@@ -2286,6 +2307,7 @@ impl PaymentAttemptUpdate {customer_acceptance,shipping_cost: net_amount.get_shipping_cost(),order_tax_amount: net_amount.get_order_tax_amount(),+ installment_data,connector_mandate_detail,tokenization,card_discovery,@@ -2865,6 +2887,7 @@ impl behaviour::Conversion for PaymentAttempt {card_network,order_tax_amount: self.net_amount.get_order_tax_amount(),shipping_cost: self.net_amount.get_shipping_cost(),+ installment_data: self.installment_data,connector_mandate_detail: self.connector_mandate_detail,tokenization: self.tokenization,request_extended_authorization: self.request_extended_authorization,@@ -2937,6 +2960,10 @@ impl behaviour::Conversion for PaymentAttempt {storage_model.order_tax_amount,storage_model.surcharge_amount,storage_model.tax_amount,+ storage_model+ .installment_data+ .as_ref()+ .and_then(|d| d.installment_interest),),currency: storage_model.currency,save_to_locker: storage_model.save_to_locker,@@ -3019,6 +3046,7 @@ impl behaviour::Conversion for PaymentAttempt {encrypted_payment_method_data,error_details: storage_model.error_details.map(Into::into),retry_type: storage_model.retry_type,+ installment_data: storage_model.installment_data,})}.await@@ -3118,6 +3146,7 @@ impl behaviour::Conversion for PaymentAttempt {encrypted_payment_method_data: self.encrypted_payment_method_data.map(Encryption::from),error_details: self.error_details.map(Into::into),retry_type: self.retry_type,+ installment_data: self.installment_data,})}}@@ -3301,6 +3330,7 @@ impl behaviour::Conversion for PaymentAttempt {encrypted_payment_method_data: None,error_details: None,retry_type: None,+ installment_data: None,})}diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rsindex ef0054c04e..9b7f960b71 100644--- a/crates/hyperswitch_domain_models/src/router_request_types.rs+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs@@ -104,6 +104,7 @@ pub struct PaymentsAuthorizeData {Option<common_types::payments::PartnerMerchantIdentifierDetails>,pub rrn: Option<String>,pub feature_metadata: Option<api_models::payments::FeatureMetadata>,+ pub installment_details: Option<common_types::payments::InstallmentData>,}#[derive(Debug, Clone, Serialize)]diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex e43460c123..cdf5b77e36 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -304,6 +304,8 @@ Never share your secret api keys. Keep them guarded and secure.common_types::payments::MerchantApplicationDetails,common_types::payments::InstallmentOption,common_types::payments::InstallmentOptionData,+ common_types::payments::InstallmentData,+ api_models::payments::InstallmentRequest,common_types::payments::BillingFrequency,common_types::connector_webhook_configuration::WebhookSetupCapabilities,common_types::connector_webhook_configuration::WebhookConfigType,diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex a9716bf6b9..c1adc48332 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -2219,6 +2219,76 @@ whereOk(())}+/// Calculates the total installment interest to be added to the order amount.+#[cfg(feature = "v1")]+pub fn calculate_installment_interest(+ order_amount: MinorUnit,+ interest_rate: common_types::payments::InstallmentInterestRate,+) -> RouterResult<MinorUnit> {+ interest_rate+ .apply_and_ceil_result(order_amount)+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to calculate installment interest")+}++#[cfg(feature = "v1")]+#[instrument(skip_all)]+fn populate_installment_details<F>(payment_data: &mut PaymentData<F>) -> RouterResult<()>+where+ F: Send + Clone,+{+ if let Some(selected_installment) = payment_data.payment_attempt.installment_data.clone() {+ // Customer sent installment_data but merchant never configured installment_options+ let installment_options = payment_data+ .payment_intent+ .installment_options+ .as_ref()+ .ok_or_else(|| {+ report!(errors::ApiErrorResponse::InvalidRequestData {+ message: "Installment options are not configured for this payment".to_string(),+ })+ })?;++ if let Some(payment_method) = &payment_data.payment_attempt.payment_method.clone() {+ let installment_option_data = installment_options+ .iter()+ .find(|opt| opt.payment_method == *payment_method)+ .and_then(|option| {+ option.installments.iter().find(|data| {+ data.number_of_installments+ .contains(selected_installment.number_of_installments)+ && data.billing_frequency == selected_installment.billing_frequency+ })+ })+ .ok_or_else(|| {+ report!(errors::ApiErrorResponse::InvalidRequestData {+ message: format!(+ "No installment plan found for {} installments with {:?} billing frequency",+ selected_installment.number_of_installments,+ selected_installment.billing_frequency,+ ),+ })+ })?;++ let total_interest = calculate_installment_interest(+ payment_data.payment_attempt.net_amount.get_order_amount(),+ installment_option_data.interest_rate,+ )?;++ payment_data+ .payment_attempt+ .net_amount+ .set_installment_interest(Some(total_interest));++ if let Some(installment_data) = payment_data.payment_attempt.installment_data.as_mut() {+ installment_data.installment_interest = Some(total_interest);+ }+ }+ }++ Ok(())+}+#[inline]pub fn get_connector_data(connectors: &mut IntoIter<api::ConnectorRoutingData>,@@ -11699,6 +11769,9 @@ pub trait OperationSessionGetters<F> {#[cfg(feature = "v1")]fn get_is_manual_retry_enabled(&self) -> Option<bool>;++ #[cfg(feature = "v1")]+ fn get_installment_details(&self) -> Option<&common_types::payments::InstallmentData>;}pub trait OperationSessionSetters<F> {@@ -11942,6 +12015,10 @@ impl<F: Clone> OperationSessionGetters<F> for PaymentData<F> {self.is_manual_retry_enabled}+ fn get_installment_details(&self) -> Option<&common_types::payments::InstallmentData> {+ self.payment_attempt.installment_data.as_ref()+ }+// #[cfg(feature = "v2")]// fn get_capture_method(&self) -> Option<enums::CaptureMethod> {// Some(self.payment_intent.capture_method)diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 08569dbcd9..3e4272251a 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -13,11 +13,12 @@ use api_models::{mandates::RecurringDetails,payments::{additional_info::{self as payment_additional_types},- RequestSurchargeDetails,+ InstallmentRequest, RequestSurchargeDetails,},};use base64::Engine;use common_enums::{enums::ExecutionMode, ConnectorType};+use common_types::payments::InstallmentOption;#[cfg(feature = "v2")]use common_utils::id_type::GenerateId;use common_utils::{@@ -4230,6 +4231,22 @@ pub(crate) fn validate_payment_status_against_not_allowed_statuses(})}+pub(crate) fn validate_installment_data_in_create(+ installment_options: &Option<Vec<InstallmentOption>>,+ installment_data: &Option<InstallmentRequest>,+) -> Result<(), errors::ApiErrorResponse> {+ utils::when(+ installment_options.is_some() || installment_data.is_some(),+ || {+ Err(errors::ApiErrorResponse::InvalidRequestData {+ message:+ "installment_options and installment_data are not supported when confirm is true."+ .to_string(),+ })+ },+ )+}+#[instrument(skip_all)]pub(crate) fn validate_pm_or_token_given(payment_method: &Option<api_enums::PaymentMethod>,@@ -5158,6 +5175,7 @@ impl AttemptType {is_overcapture_enabled: None,error_details: None,retry_type: Some(enums::RetryType::ManualRetry),+ installment_data: None,}}diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex da3b01b0f3..c14f1209f2 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -45,8 +45,8 @@ use crate::{payments::{self, helpers, operations,operations::payment_confirm::unified_authentication_service::ThreeDsMetaData,- populate_surcharge_details, CustomerDetails, OperationSessionSetters, PaymentAddress,- PaymentData,+ populate_installment_details, populate_surcharge_details, CustomerDetails,+ OperationSessionGetters, OperationSessionSetters, PaymentAddress, PaymentData,},three_ds_decision_rule,unified_authentication_service::{@@ -890,6 +890,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>_ => None,});+ payment_attempt.installment_data = request.installment_data.clone().map(Into::into);+let payment_data = PaymentData {flow: PhantomData,payment_intent,@@ -1329,6 +1331,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forconnector_data: &api::ConnectorData,) -> CustomResult<(), errors::ApiErrorResponse> {populate_surcharge_details(state, payment_data).await?;+ populate_installment_details(payment_data)?;payment_data.payment_attempt.request_extended_authorization = payment_data.payment_intent.get_request_extended_authorization_bool_if_connector_supports(@@ -2422,6 +2425,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for};let card_discovery = payment_data.get_card_discovery_for_card_payment_method();+ let installment_data = payment_data.get_installment_details().cloned();let is_stored_credential = helpers::is_stored_credential(&payment_data.recurring_details,&payment_data.pm_token,@@ -2473,6 +2477,10 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for.get_order_tax_amount(),surcharge_amount,tax_amount,+ payment_data+ .payment_attempt+ .net_amount+ .get_installment_interest(),),connector_mandate_detail: payment_data@@ -2491,6 +2499,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for.payment_attempt.request_extended_authorization,tokenization: payment_data.payment_attempt.get_tokenization_strategy(),+ installment_data,},storage_scheme,&cloned_key_store,diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex 53175e9831..d289c3b8e9 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -1165,6 +1165,13 @@ impl<F: Send + Clone + Sync> ValidateRequest<F, api::PaymentsRequest, PaymentDaterr.change_context(errors::ApiErrorResponse::InvalidRequestData { message })})?;+ if request.confirm.unwrap_or(false) {+ helpers::validate_installment_data_in_create(+ &request.installment_options,+ &request.installment_data,+ )?;+ }+if request.confirm.unwrap_or(false) {helpers::validate_pm_or_token_given(&request.payment_method,@@ -1553,6 +1560,7 @@ impl PaymentCreate {encrypted_payment_method_data: None,error_details: None,retry_type: None,+ installment_data: None,},additional_pm_data,diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex 16c34ca715..8ada2284e5 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -798,6 +798,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsIncrementalAuNone,None,None,+ None,),amount_capturable: incremental_authorization_details.total_amount,},diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rsindex c57a53b62a..548a5a0801 100644--- a/crates/router/src/core/payments/operations/payment_update.rs+++ b/crates/router/src/core/payments/operations/payment_update.rs@@ -499,6 +499,10 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>});payment_intent.shipping_cost = request.shipping_cost.or(payment_intent.shipping_cost);+ payment_intent.installment_options = request+ .installment_options+ .clone()+ .or(payment_intent.installment_options);payment_attempt.net_amount.set_order_tax_amount(request.order_tax_amount.or(order_tax_amount));@@ -918,6 +922,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for.get_order_tax_amount(),surcharge_amount,tax_amount,+ None,),shipping_cost: payment_data.payment_intent.shipping_cost,order_tax_amount: payment_datadiff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rsindex d3d3bdf424..ac32d71973 100644--- a/crates/router/src/core/payments/retry.rs+++ b/crates/router/src/core/payments/retry.rs@@ -855,6 +855,7 @@ pub fn make_new_auto_retry_payment_attempt(is_overcapture_enabled: Default::default(),error_details: Default::default(),retry_type: Some(storage_enums::RetryType::AutoRetry),+ installment_data: Default::default(),}}diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex 23b429e82b..4084621c5c 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -492,6 +492,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(partner_merchant_identifier_details: None,rrn,feature_metadata: None,+ installment_details: None,};let connector_mandate_request_reference_id = payment_data.payment_attempt@@ -4140,6 +4141,7 @@ wherepartner_merchant_identifier_details: payment_intent.partner_merchant_identifier_details,payment_method_tokenization_details,installment_options: payment_intent.installment_options,+ installment_data: payment_data.get_installment_details().cloned(),connector_response_metadata,};@@ -4457,6 +4459,7 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Paypartner_merchant_identifier_details: pi.partner_merchant_identifier_details,payment_method_tokenization_details: None,installment_options: pi.installment_options,+ installment_data: pa.installment_data,}}}@@ -4824,6 +4827,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthorizpartner_merchant_identifier_details: None,rrn,feature_metadata: None,+ installment_details: None,})}}@@ -5091,6 +5095,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz.partner_merchant_identifier_details,rrn,feature_metadata,+ installment_details: payment_data.payment_attempt.installment_data.clone(),})}}diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rsindex cd6e470ac5..aa040122e0 100644--- a/crates/router/src/db/events.rs+++ b/crates/router/src/db/events.rs@@ -1530,6 +1530,7 @@ mod tests {payment_method_tokenization_details: None,error_details: None,installment_options: None,+ installment_data: None,state_metadata: None,connector_response_metadata: None,};diff --git a/crates/router/src/types.rs b/crates/router/src/types.rsindex 7c0bb96fc7..3b14a34604 100644--- a/crates/router/src/types.rs+++ b/crates/router/src/types.rs@@ -1335,6 +1335,7 @@ impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData {.clone(),rrn: None,feature_metadata: None,+ installment_details: None,}}}diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rsindex cfa8c58110..e5a9e16157 100644--- a/crates/router/src/types/api/verify_connector.rs+++ b/crates/router/src/types/api/verify_connector.rs@@ -76,6 +76,7 @@ impl VerifyConnectorData {partner_merchant_identifier_details: None,rrn: None,feature_metadata: None,+ installment_details: None,}}diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rsindex 1e90e930fe..32e1b2e1dd 100644--- a/crates/router/src/types/storage/payment_attempt.rs+++ b/crates/router/src/types/storage/payment_attempt.rs@@ -243,6 +243,7 @@ mod tests {encrypted_payment_method_data: Default::default(),error_details: Default::default(),retry_type: Default::default(),+ installment_data: Default::default(),};let store = state@@ -362,6 +363,7 @@ mod tests {encrypted_payment_method_data: Default::default(),error_details: Default::default(),retry_type: Default::default(),+ installment_data: Default::default(),};let store = state.stores@@ -495,6 +497,7 @@ mod tests {encrypted_payment_method_data: Default::default(),error_details: Default::default(),retry_type: Default::default(),+ installment_data: Default::default(),};let store = state.storesdiff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rsindex ab2f8988a9..780582f117 100644--- a/crates/router/tests/connectors/utils.rs+++ b/crates/router/tests/connectors/utils.rs@@ -1024,6 +1024,7 @@ impl Default for PaymentAuthorizeType {partner_merchant_identifier_details: None,rrn: None,feature_metadata: None,+ installment_details: None,};Self(data)}diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rsindex 263112c93d..e14d989fca 100644--- a/crates/router/tests/payments.rs+++ b/crates/router/tests/payments.rs@@ -481,6 +481,7 @@ async fn payments_create_core() {payment_method_tokenization_details: None,error_details: None,installment_options: None,+ installment_data: None,state_metadata: None,connector_response_metadata: None,};@@ -782,6 +783,7 @@ async fn payments_create_core_adyen_no_redirect() {payment_method_tokenization_details: None,error_details: None,installment_options: None,+ installment_data: None,state_metadata: None,connector_response_metadata: None,},diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rsindex 2dc8e01b1a..d0c2cec148 100644--- a/crates/router/tests/payments2.rs+++ b/crates/router/tests/payments2.rs@@ -241,6 +241,7 @@ async fn payments_create_core() {payment_method_tokenization_details: None,error_details: None,installment_options: None,+ installment_data: None,state_metadata: None,connector_response_metadata: None,};@@ -551,6 +552,7 @@ async fn payments_create_core_adyen_no_redirect() {payment_method_tokenization_details: None,error_details: None,installment_options: None,+ installment_data: None,state_metadata: None,connector_response_metadata: None,},diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rsindex 3943bc3391..1a2e18646d 100644--- a/crates/storage_impl/src/mock_db/payment_attempt.rs+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs@@ -249,6 +249,7 @@ impl PaymentAttemptInterface for MockDb {encrypted_payment_method_data: payment_attempt.encrypted_payment_method_data,error_details: payment_attempt.error_details,retry_type: payment_attempt.retry_type,+ installment_data: payment_attempt.installment_data,};payment_attempts.push(payment_attempt.clone());Ok(payment_attempt)diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rsindex feb14b5d99..8efddcf4ea 100644--- a/crates/storage_impl/src/payments/payment_attempt.rs+++ b/crates/storage_impl/src/payments/payment_attempt.rs@@ -847,6 +847,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {.encrypted_payment_method_data.clone(),retry_type: payment_attempt.retry_type,+ installment_data: payment_attempt.installment_data.clone(),};let field = format!("pa_{}", created_attempt.attempt_id);diff --git a/migrations/2026-02-24-000001_add_installment_data_to_payment_attempt/down.sql b/migrations/2026-02-24-000001_add_installment_data_to_payment_attempt/down.sqlnew file mode 100644index 0000000000..2f18b9ea24--- /dev/null+++ b/migrations/2026-02-24-000001_add_installment_data_to_payment_attempt/down.sql@@ -0,0 +1,2 @@+ALTER TABLE payment_attempt+DROP COLUMN IF EXISTS installment_data;diff --git a/migrations/2026-02-24-000001_add_installment_data_to_payment_attempt/up.sql b/migrations/2026-02-24-000001_add_installment_data_to_payment_attempt/up.sqlnew file mode 100644index 0000000000..b663644f5f--- /dev/null+++ b/migrations/2026-02-24-000001_add_installment_data_to_payment_attempt/up.sql@@ -0,0 +1,2 @@+ALTER TABLE payment_attempt+ADD COLUMN IF NOT EXISTS installment_data JSONB;