Skip to content

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

fix(revenue_recovery): fix the invoice_billing__start_at_time which is getting overridden by multiple attempts (#13982)

CHALLA NISHANTH BABU56e4aee07909
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index 5246054a77..0701d73950 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -1582,6 +1582,7 @@ pub struct RevenueRecoveryData {
pub connector_customer_id: String,
pub retry_count: Option<u16>,
pub invoice_next_billing_time: Option<PrimitiveDateTime>,
+ pub invoice_billing_started_at_time: Option<PrimitiveDateTime>,
pub triggered_by: storage_enums::enums::TriggeredBy,
pub card_network: Option<common_enums::CardNetwork>,
pub card_issuer: Option<String>,
@@ -1690,10 +1691,17 @@ where
router_env::logger::error!(?err, "Failed to parse connector string to enum");
errors::api_error_response::ApiErrorResponse::InternalServerError
})?,
- invoice_next_billing_time: self.revenue_recovery_data.invoice_next_billing_time,
- invoice_billing_started_at_time: self
- .revenue_recovery_data
- .invoice_next_billing_time,
+ // Both billing times belong to the invoice rather than to an individual attempt,
+ // so the value recorded first is retained and later webhooks only seed it when it
+ // is still unset.
+ invoice_next_billing_time: revenue_recovery
+ .as_ref()
+ .and_then(|data| data.invoice_next_billing_time)
+ .or(self.revenue_recovery_data.invoice_next_billing_time),
+ invoice_billing_started_at_time: revenue_recovery
+ .as_ref()
+ .and_then(|data| data.invoice_billing_started_at_time)
+ .or(self.revenue_recovery_data.invoice_billing_started_at_time),
billing_connector_payment_method_details,
first_payment_attempt_network_advice_code: first_network_advice_code,
first_payment_attempt_network_decline_code: first_network_decline_code,
diff --git a/crates/router/src/core/payments/operations/payment_attempt_record.rs b/crates/router/src/core/payments/operations/payment_attempt_record.rs
index 22e236fb95..a317c3886e 100644
--- a/crates/router/src/core/payments/operations/payment_attempt_record.rs
+++ b/crates/router/src/core/payments/operations/payment_attempt_record.rs
@@ -202,6 +202,7 @@ impl<F: Send + Clone + Sync>
connector_customer_id: request.connector_customer_id.clone(),
retry_count: request.retry_count,
invoice_next_billing_time: request.invoice_next_billing_time,
+ invoice_billing_started_at_time: request.invoice_billing_started_at_time,
triggered_by: request.triggered_by,
card_network: request.card_network.clone(),
card_issuer: request.card_issuer.clone(),