diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index d0b171267d..6b5a6d19a5 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -284,7 +284,7 @@ impl PostUpdateTracker, types::CompleteAuthorizeData } } -async fn payment_response_update_tracker( +async fn payment_response_update_tracker( db: &dyn StorageInterface, _payment_id: &api::PaymentIdType, mut payment_data: PaymentData, @@ -428,10 +428,11 @@ async fn payment_response_update_tracker( .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?, None => payment_data.connector_response, }; + let amount = router_data.request.get_capture_amount(); let amount_captured = router_data.amount_captured.or_else(|| { if router_data.status == enums::AttemptStatus::Charged { - Some(payment_data.payment_intent.amount) + amount } else { None } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index aba49974cf..95557c5cda 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -361,13 +361,15 @@ where }) .transpose() .unwrap_or_default(); + let amount_captured = payment_intent.amount_captured.unwrap_or_default(); + let amount_capturable = Some(payment_attempt.amount - amount_captured); services::ApplicationResponse::Json( response .set_payment_id(Some(payment_attempt.payment_id)) .set_merchant_id(Some(payment_attempt.merchant_id)) .set_status(payment_intent.status.foreign_into()) .set_amount(payment_attempt.amount) - .set_amount_capturable(None) + .set_amount_capturable(amount_capturable) .set_amount_received(payment_intent.amount_captured) .set_connector(routed_through) .set_client_secret(payment_intent.client_secret.map(masking::Secret::new)) diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 228a4d7b9a..186dd2791a 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -347,6 +347,34 @@ pub struct AccessTokenRequestData { // Add more keys if required } +pub trait Capturable { + fn get_capture_amount(&self) -> Option { + Some(0) + } +} + +impl Capturable for PaymentsAuthorizeData { + fn get_capture_amount(&self) -> Option { + Some(self.amount) + } +} + +impl Capturable for PaymentsCaptureData { + fn get_capture_amount(&self) -> Option { + Some(self.amount_to_capture) + } +} + +impl Capturable for CompleteAuthorizeData { + fn get_capture_amount(&self) -> Option { + Some(self.amount) + } +} +impl Capturable for VerifyRequestData {} +impl Capturable for PaymentsCancelData {} +impl Capturable for PaymentsSessionData {} +impl Capturable for PaymentsSyncData {} + pub struct AddAccessTokenResult { pub access_token_result: Result, ErrorResponse>, pub connector_supports_access_token: bool,