diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 33e9579d7b..37ae6aaf32 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -1905,6 +1905,9 @@ pub struct PaymentsResponse { /// The business profile that is associated with this payment pub profile_id: Option, + + /// total number of attempts associated with this payment + pub attempt_count: i16, } #[derive(Clone, Debug, serde::Deserialize, ToSchema)] @@ -1970,8 +1973,6 @@ pub struct PaymentListConstraints { pub struct PaymentListResponse { /// The number of payments included in the list pub size: usize, - /// The total number of payment_attempts for intents included in the list - pub attempt_count: i16, // The list of payments response objects pub data: Vec, } diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 1050aab00f..2fc8c76a4d 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -1262,11 +1262,6 @@ pub async fn list_payments( .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; - let attempt_count = payment_intents - .iter() - .map(|intent| intent.attempt_count) - .sum(); - let collected_futures = payment_intents.into_iter().map(|pi| { async { match db @@ -1314,7 +1309,6 @@ pub async fn list_payments( Ok(services::ApplicationResponse::Json( api::PaymentListResponse { size: data.len(), - attempt_count, data, }, )) @@ -1341,15 +1335,12 @@ pub async fn apply_filters_on_payments( .map(|(pi, pa)| (pi, pa.to_storage_model())) .collect(); - let attempt_count = list.iter().map(|item| item.0.attempt_count).sum(); - let data: Vec = list.into_iter().map(ForeignFrom::foreign_from).collect(); Ok(services::ApplicationResponse::Json( api::PaymentListResponse { size: data.len(), - attempt_count, data, }, )) diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index cd39572099..b9b6250abf 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -601,6 +601,7 @@ where .set_connector_metadata(payment_intent.connector_metadata) .set_reference_id(payment_attempt.connector_response_reference_id) .set_profile_id(payment_intent.profile_id) + .set_attempt_count(payment_intent.attempt_count) .to_owned(), headers, )) @@ -658,6 +659,7 @@ where connector_metadata: payment_intent.connector_metadata, allowed_payment_method_types: payment_intent.allowed_payment_method_types, reference_id: payment_attempt.connector_response_reference_id, + attempt_count: payment_intent.attempt_count, ..Default::default() }, headers, @@ -761,6 +763,7 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay capture_method: pa.capture_method, authentication_type: pa.authentication_type, connector_transaction_id: pa.connector_transaction_id, + attempt_count: pi.attempt_count, ..Default::default() } } diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 1fcda76183..0dd862cbe3 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -7708,7 +7708,6 @@ "type": "object", "required": [ "size", - "attempt_count", "data" ], "properties": { @@ -7717,11 +7716,6 @@ "description": "The number of payments included in the list", "minimum": 0.0 }, - "attempt_count": { - "type": "integer", - "format": "int32", - "description": "The total number of payment_attempts for intents included in the list" - }, "data": { "type": "array", "items": { @@ -9028,7 +9022,8 @@ "currency", "payment_method", "business_country", - "business_label" + "business_label", + "attempt_count" ], "properties": { "payment_id": { @@ -9398,6 +9393,11 @@ "type": "string", "description": "The business profile that is associated with this payment", "nullable": true + }, + "attempt_count": { + "type": "integer", + "format": "int32", + "description": "total number of attempts associated with this payment" } } },