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(core): conditionally return captures list during payment sync. (#2033)

Hrithikeshc2aa0142ed5a
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index 1da8f9e329..bc8cb0f432 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -2198,6 +2198,8 @@ pub struct PaymentsRetrieveRequest {
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
pub client_secret: Option<String>,
+ /// If enabled provides list of captures linked to latest attempt
+ pub expand_captures: Option<bool>,
/// If enabled provides list of attempts linked to payment intent
pub expand_attempts: Option<bool>,
}
@@ -2597,6 +2599,8 @@ pub struct PaymentRetrieveBody {
pub force_sync: Option<bool>,
/// This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK
pub client_secret: Option<String>,
+ /// If enabled provides list of captures linked to latest attempt
+ pub expand_captures: Option<bool>,
/// If enabled provides list of attempts linked to payment intent
pub expand_attempts: Option<bool>,
}
diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs
index 2132717464..0efb44d9d7 100644
--- a/crates/router/src/compatibility/stripe/payment_intents.rs
+++ b/crates/router/src/compatibility/stripe/payment_intents.rs
@@ -81,6 +81,7 @@ pub async fn payment_intents_retrieve(
merchant_connector_details: None,
client_secret: query_payload.client_secret.clone(),
expand_attempts: None,
+ expand_captures: None,
};
let (auth_type, auth_flow) =
diff --git a/crates/router/src/compatibility/stripe/setup_intents.rs b/crates/router/src/compatibility/stripe/setup_intents.rs
index 119f67148a..a5d24c1581 100644
--- a/crates/router/src/compatibility/stripe/setup_intents.rs
+++ b/crates/router/src/compatibility/stripe/setup_intents.rs
@@ -85,6 +85,7 @@ pub async fn setup_intents_retrieve(
merchant_connector_details: None,
client_secret: query_payload.client_secret.clone(),
expand_attempts: None,
+ expand_captures: None,
};
let (auth_type, auth_flow) =
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index f047715d81..e7784661d6 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -504,6 +504,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {
}),
client_secret: None,
expand_attempts: None,
+ expand_captures: None,
};
payments_core::<api::PSync, api::PaymentsResponse, _, _, _>(
state,
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index 052afd0922..6f9f4f470e 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -274,7 +274,10 @@ async fn get_tracker_for_sync<
.attach_printable_lazy(|| {
format!("Error while retrieving capture list for, merchant_id: {}, payment_id: {payment_id_str}", merchant_account.merchant_id)
})?;
- Some(types::MultipleCaptureData::new_for_sync(captures)?)
+ Some(types::MultipleCaptureData::new_for_sync(
+ captures,
+ request.expand_captures,
+ )?)
} else {
None
};
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index fc77268e0a..3a26b8ee65 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -203,6 +203,21 @@ where
connector_request_reference_id_config: &ConnectorRequestReferenceIdConfig,
connector_http_status_code: Option<u16>,
) -> RouterResponse<Self> {
+ let captures = payment_data
+ .multiple_capture_data
+ .and_then(|multiple_capture_data| {
+ multiple_capture_data
+ .expand_captures
+ .and_then(|should_expand| {
+ should_expand.then_some(
+ multiple_capture_data
+ .get_all_captures()
+ .into_iter()
+ .cloned()
+ .collect(),
+ )
+ })
+ });
payments_to_payments_response(
req,
payment_data.payment_attempt,
@@ -210,15 +225,7 @@ where
payment_data.refunds,
payment_data.disputes,
payment_data.attempts,
- payment_data
- .multiple_capture_data
- .map(|multiple_capture_data| {
- multiple_capture_data
- .get_all_captures()
- .into_iter()
- .cloned()
- .collect()
- }),
+ captures,
payment_data.payment_method_data,
customer,
auth_flow,
diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rs
index 89f6e094d7..7157deffc1 100644
--- a/crates/router/src/core/payments/types.rs
+++ b/crates/router/src/core/payments/types.rs
@@ -12,13 +12,17 @@ pub struct MultipleCaptureData {
// key -> capture_id, value -> Capture
all_captures: HashMap<String, storage::Capture>,
latest_capture: storage::Capture,
+ pub expand_captures: Option<bool>,
_private: Private, // to restrict direct construction of MultipleCaptureData
}
#[derive(Clone, Debug)]
struct Private {}
impl MultipleCaptureData {
- pub fn new_for_sync(captures: Vec<storage::Capture>) -> RouterResult<Self> {
+ pub fn new_for_sync(
+ captures: Vec<storage::Capture>,
+ expand_captures: Option<bool>,
+ ) -> RouterResult<Self> {
let latest_capture = captures
.last()
.ok_or(errors::ApiErrorResponse::InternalServerError)
@@ -32,6 +36,7 @@ impl MultipleCaptureData {
.collect(),
latest_capture,
_private: Private {},
+ expand_captures,
};
Ok(multiple_capture_data)
}
@@ -48,6 +53,7 @@ impl MultipleCaptureData {
.collect(),
latest_capture: new_capture,
_private: Private {},
+ expand_captures: None,
}
}
diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs
index f9d4d59afe..b6baf10e91 100644
--- a/crates/router/src/core/webhooks.rs
+++ b/crates/router/src/core/webhooks.rs
@@ -58,6 +58,7 @@ pub async fn payments_incoming_webhook_flow<W: types::OutgoingWebhookType>(
merchant_connector_details: None,
client_secret: None,
expand_attempts: None,
+ expand_captures: None,
},
services::AuthFlow::Merchant,
consume_or_trigger_flow,
diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rs
index 32de056c1f..d550cfe17a 100644
--- a/crates/router/src/routes/payments.rs
+++ b/crates/router/src/routes/payments.rs
@@ -198,6 +198,7 @@ pub async fn payments_retrieve(
force_sync: json_payload.force_sync.unwrap_or(false),
client_secret: json_payload.client_secret.clone(),
expand_attempts: json_payload.expand_attempts,
+ expand_captures: json_payload.expand_captures,
..Default::default()
};
let (auth_type, auth_flow) =
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index 85a2ad1dbd..15eecf072d 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -8269,6 +8269,11 @@
"description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK",
"nullable": true
},
+ "expand_captures": {
+ "type": "boolean",
+ "description": "If enabled provides list of captures linked to latest attempt",
+ "nullable": true
+ },
"expand_attempts": {
"type": "boolean",
"description": "If enabled provides list of attempts linked to payment intent",
@@ -9447,6 +9452,11 @@
"description": "This is a token which expires after 15 minutes, used from the client to authenticate and create sessions from the SDK",
"nullable": true
},
+ "expand_captures": {
+ "type": "boolean",
+ "description": "If enabled provides list of captures linked to latest attempt",
+ "nullable": true
+ },
"expand_attempts": {
"type": "boolean",
"description": "If enabled provides list of attempts linked to payment intent",