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

feat(router): add `attempt_count` in list payments response (#1990)

Sai Harsha Vardhanf0cc0fba1684
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index c8d8b6de5e..cbb2055260 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -1963,6 +1963,8 @@ 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<PaymentsResponse>,
}
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 95b3a32d50..e888f1f2fb 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -1269,6 +1269,11 @@ 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
@@ -1316,6 +1321,7 @@ pub async fn list_payments(
Ok(services::ApplicationResponse::Json(
api::PaymentListResponse {
size: data.len(),
+ attempt_count,
data,
},
))
@@ -1342,12 +1348,15 @@ 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<api::PaymentsResponse> =
list.into_iter().map(ForeignFrom::foreign_from).collect();
Ok(services::ApplicationResponse::Json(
api::PaymentListResponse {
size: data.len(),
+ attempt_count,
data,
},
))
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index 0e28a1e70d..e94c91ea03 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -7683,6 +7683,7 @@
"type": "object",
"required": [
"size",
+ "attempt_count",
"data"
],
"properties": {
@@ -7691,6 +7692,11 @@
"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": {
@@ -10119,11 +10125,6 @@
"format": "int64",
"description": "The total number of refunds in the list"
},
- "total_count": {
- "type": "integer",
- "format": "int64",
- "description": "The total number of refunds in the list"
- },
"data": {
"type": "array",
"items": {