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 retry_type to PaymentAttempt and related schema updates (#11084)
Ayush Anand205a342042f9
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex 371cc9c39b..118cfd373d 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -10537,6 +10537,28 @@ pub enum StorageType {Persistent,}+/// Represents the type of retry for a payment attempt+#[derive(+ Clone,+ Copy,+ Debug,+ Eq,+ Hash,+ PartialEq,+ serde::Deserialize,+ serde::Serialize,+ strum::Display,+ strum::EnumString,+ ToSchema,+)]+#[router_derive::diesel_enum(storage_type = "text")]+#[serde(rename_all = "snake_case")]+#[strum(serialize_all = "snake_case")]+pub enum RetryType {+ ManualRetry,+ AutoRetry,+}+#[derive(Debug, serde::Serialize, Clone, strum::EnumString, strum::Display)]#[serde(rename_all = "snake_case")]#[strum(ascii_case_insensitive)]diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rsindex 02694a7717..e23cbe57c2 100644--- a/crates/diesel_models/src/payment_attempt.rs+++ b/crates/diesel_models/src/payment_attempt.rs@@ -162,6 +162,7 @@ pub struct PaymentAttempt {pub tokenization: Option<common_enums::Tokenization>,pub encrypted_payment_method_data: Option<common_utils::encryption::Encryption>,pub error_details: Option<ErrorDetails>,+ pub retry_type: Option<storage_enums::RetryType>,#[diesel(deserialize_as = RequiredFromNullable<storage_enums::PaymentMethod>)]pub payment_method_type_v2: storage_enums::PaymentMethod,pub connector_payment_id: Option<ConnectorTransactionId>,@@ -291,6 +292,8 @@ pub struct PaymentAttempt {pub tokenization: Option<common_enums::Tokenization>,pub encrypted_payment_method_data: Option<common_utils::encryption::Encryption>,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>,}#[cfg(feature = "v1")]@@ -442,6 +445,7 @@ pub struct PaymentAttemptNew {pub amount_captured: Option<MinorUnit>,pub encrypted_payment_method_data: Option<common_utils::encryption::Encryption>,pub error_details: Option<ErrorDetails>,+ pub retry_type: Option<storage_enums::RetryType>,}#[cfg(feature = "v1")]@@ -533,6 +537,8 @@ pub struct PaymentAttemptNew {pub tokenization: Option<common_enums::Tokenization>,pub encrypted_payment_method_data: Option<common_utils::encryption::Encryption>,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>,}#[cfg(feature = "v1")]@@ -1127,6 +1133,7 @@ impl PaymentAttemptUpdateInternal {amount_captured: amount_captured.or(source.amount_captured),encrypted_payment_method_data: source.encrypted_payment_method_data,error_details: source.error_details,+ retry_type: source.retry_type,}}}diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex 3890954941..70f2fdf516 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -1136,6 +1136,8 @@ diesel::table! {tokenization -> Nullable<Varchar>,encrypted_payment_method_data -> Nullable<Bytea>,error_details -> Nullable<Jsonb>,+ #[max_length = 64]+ retry_type -> Nullable<Varchar>,}}diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rsindex 1d71f5416b..9702c44637 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -1080,6 +1080,8 @@ diesel::table! {tokenization -> Nullable<Varchar>,encrypted_payment_method_data -> Nullable<Bytea>,error_details -> Nullable<Jsonb>,+ #[max_length = 64]+ retry_type -> Nullable<Varchar>,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 917521bf33..99f6707a72 100644--- a/crates/diesel_models/src/user/sample_data.rs+++ b/crates/diesel_models/src/user/sample_data.rs@@ -320,6 +320,7 @@ impl PaymentAttemptBatchNew {authorized_amount: self.authorized_amount,tokenization: self.tokenization,error_details: None,+ retry_type: None,}}}diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rsindex b07ce4cfb8..62ddae7560 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs@@ -1382,6 +1382,8 @@ pub struct PaymentAttempt {pub encrypted_payment_method_data: Option<Encryptable<pii::SecretSerdeValue>>,/// Complete error details containing unified, issuer, and connector-level error informationpub error_details: Option<PaymentAttemptErrorDetails>,+ /// Indicates the type of retry for this payment attempt (None for initial attempt)+ pub retry_type: Option<storage_enums::RetryType>,}#[cfg(feature = "v1")]@@ -2798,6 +2800,7 @@ impl behaviour::Conversion for PaymentAttempt {is_stored_credential: self.is_stored_credential,authorized_amount: self.authorized_amount,encrypted_payment_method_data: self.encrypted_payment_method_data.map(Encryption::from),+ retry_type: self.retry_type,})}@@ -2925,6 +2928,7 @@ impl behaviour::Conversion for PaymentAttempt {authorized_amount: storage_model.authorized_amount,encrypted_payment_method_data,error_details: storage_model.error_details.map(Into::into),+ retry_type: storage_model.retry_type,})}.await@@ -3023,6 +3027,7 @@ impl behaviour::Conversion for PaymentAttempt {authorized_amount: self.authorized_amount,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,})}}@@ -3205,6 +3210,7 @@ impl behaviour::Conversion for PaymentAttempt {amount_captured,encrypted_payment_method_data: None,error_details: None,+ retry_type: None,})}@@ -3496,6 +3502,7 @@ impl behaviour::Conversion for PaymentAttempt {amount_captured: amount_details.amount_captured,encrypted_payment_method_data: None,error_details: None,+ retry_type: None,})}}diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex f251728089..6b213b0356 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -4953,7 +4953,7 @@ impl AttemptType {// Logic to override the fields with data provided in the request should be done after this if required.// In case if fields are not overridden by the request then they contain the same data that was in the previous attempt provided it is populated in this function.#[inline(always)]- fn make_new_payment_attempt(+ fn make_new_manual_retry_payment_attempt(payment_method_data: Option<&api_models::payments::PaymentMethodData>,old_payment_attempt: PaymentAttempt,new_attempt_count: i16,@@ -5059,6 +5059,7 @@ impl AttemptType {debit_routing_savings: None,is_overcapture_enabled: None,error_details: None,+ retry_type: Some(enums::RetryType::ManualRetry),}}@@ -5092,7 +5093,7 @@ impl AttemptType {Self::New => {let db = &*state.store;let new_attempt_count = fetched_payment_intent.attempt_count + 1;- let new_payment_attempt_to_insert = Self::make_new_payment_attempt(+ let new_payment_attempt_to_insert = Self::make_new_manual_retry_payment_attempt(request.payment_method_data.as_ref()diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex b9187a32a1..b48238032c 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -1410,6 +1410,7 @@ impl PaymentCreate {is_overcapture_enabled: None,encrypted_payment_method_data: None,error_details: None,+ retry_type: None,},additional_pm_data,diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rsindex 6b9211021d..990135ef95 100644--- a/crates/router/src/core/payments/retry.rs+++ b/crates/router/src/core/payments/retry.rs@@ -506,7 +506,7 @@ whereD: payments::OperationSessionGetters<F> + payments::OperationSessionSetters<F> + Send + Sync,{let new_attempt_count = payment_data.get_payment_intent().attempt_count + 1;- let new_payment_attempt = make_new_payment_attempt(+ let new_payment_attempt = make_new_auto_retry_payment_attempt(connector,payment_data.get_payment_attempt().clone(),new_attempt_count,@@ -753,7 +753,7 @@ where#[cfg(feature = "v1")]#[instrument(skip_all)]-pub fn make_new_payment_attempt(+pub fn make_new_auto_retry_payment_attempt(connector: String,old_payment_attempt: storage::PaymentAttempt,new_attempt_count: i16,@@ -847,6 +847,7 @@ pub fn make_new_payment_attempt(debit_routing_savings: Default::default(),is_overcapture_enabled: Default::default(),error_details: Default::default(),+ retry_type: Some(storage_enums::RetryType::AutoRetry),}}diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rsindex bf7cc10483..1e90e930fe 100644--- a/crates/router/src/types/storage/payment_attempt.rs+++ b/crates/router/src/types/storage/payment_attempt.rs@@ -242,6 +242,7 @@ mod tests {connector_transaction_id: Default::default(),encrypted_payment_method_data: Default::default(),error_details: Default::default(),+ retry_type: Default::default(),};let store = state@@ -360,6 +361,7 @@ mod tests {connector_transaction_id: Default::default(),encrypted_payment_method_data: Default::default(),error_details: Default::default(),+ retry_type: Default::default(),};let store = state.stores@@ -492,6 +494,7 @@ mod tests {connector_transaction_id: Default::default(),encrypted_payment_method_data: Default::default(),error_details: Default::default(),+ retry_type: Default::default(),};let store = state.storesdiff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rsindex 8713c03752..3943bc3391 100644--- a/crates/storage_impl/src/mock_db/payment_attempt.rs+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs@@ -248,6 +248,7 @@ impl PaymentAttemptInterface for MockDb {tokenization: payment_attempt.tokenization,encrypted_payment_method_data: payment_attempt.encrypted_payment_method_data,error_details: payment_attempt.error_details,+ retry_type: payment_attempt.retry_type,};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 a14e528d8d..feb14b5d99 100644--- a/crates/storage_impl/src/payments/payment_attempt.rs+++ b/crates/storage_impl/src/payments/payment_attempt.rs@@ -846,6 +846,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {encrypted_payment_method_data: payment_attempt.encrypted_payment_method_data.clone(),+ retry_type: payment_attempt.retry_type,};let field = format!("pa_{}", created_attempt.attempt_id);diff --git a/migrations/2026-01-29-100000_add_retry_type_to_payment_attempt/down.sql b/migrations/2026-01-29-100000_add_retry_type_to_payment_attempt/down.sqlnew file mode 100644index 0000000000..fd04a794a5--- /dev/null+++ b/migrations/2026-01-29-100000_add_retry_type_to_payment_attempt/down.sql@@ -0,0 +1,2 @@+-- Remove retry_type column from payment_attempt table+ALTER TABLE payment_attempt DROP COLUMN IF EXISTS retry_type;diff --git a/migrations/2026-01-29-100000_add_retry_type_to_payment_attempt/up.sql b/migrations/2026-01-29-100000_add_retry_type_to_payment_attempt/up.sqlnew file mode 100644index 0000000000..4bd8b343f4--- /dev/null+++ b/migrations/2026-01-29-100000_add_retry_type_to_payment_attempt/up.sql@@ -0,0 +1,2 @@+-- Add retry_type column to payment_attempt table+ALTER TABLE payment_attempt ADD COLUMN retry_type VARCHAR(64);