diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 1da8f9e32943..bc8cb0f43238 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, /// 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, + /// If enabled provides list of captures linked to latest attempt + pub expand_captures: Option, /// If enabled provides list of attempts linked to payment intent pub expand_attempts: Option, } @@ -2597,6 +2599,8 @@ pub struct PaymentRetrieveBody { pub force_sync: Option, /// 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, + /// If enabled provides list of captures linked to latest attempt + pub expand_captures: Option, /// If enabled provides list of attempts linked to payment intent pub expand_attempts: Option, } diff --git a/crates/router/src/compatibility/stripe/payment_intents.rs b/crates/router/src/compatibility/stripe/payment_intents.rs index 213271746456..0efb44d9d71a 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 119f67148a6d..a5d24c158103 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 f047715d817d..e7784661d61f 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::( state, diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs index 052afd0922f2..6f9f4f470ed6 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 fc77268e0a6b..3a26b8ee656b 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, ) -> RouterResponse { + 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 89f6e094d767..7157deffc117 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, latest_capture: storage::Capture, + pub expand_captures: Option, _private: Private, // to restrict direct construction of MultipleCaptureData } #[derive(Clone, Debug)] struct Private {} impl MultipleCaptureData { - pub fn new_for_sync(captures: Vec) -> RouterResult { + pub fn new_for_sync( + captures: Vec, + expand_captures: Option, + ) -> RouterResult { 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 f9d4d59afe89..b6baf10e913b 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( 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 32de056c1fc6..d550cfe17a47 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 85a2ad1dbda0..15eecf072d13 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",