From e54d3f32b9e559ef8e0fc268fc876adc1afc89a5 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 28 Dec 2022 13:50:51 +0530 Subject: [PATCH] fix(router): updating amount_captured in payment_intent (#251) --- crates/router/src/connector/stripe/transformers.rs | 1 + crates/router/src/core/payments/operations/payment_response.rs | 2 +- crates/router/src/core/payments/transformers.rs | 1 + crates/router/src/core/utils.rs | 2 +- crates/router/src/types.rs | 1 + crates/router/tests/connectors/aci.rs | 2 ++ crates/router/tests/connectors/authorizedotnet.rs | 2 ++ crates/router/tests/connectors/checkout.rs | 2 ++ crates/router/tests/connectors/utils.rs | 1 + 9 files changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 22f711bb91..573bb9df6d 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -399,6 +399,7 @@ impl redirection_data, mandate_reference, }), + amount_captured: Some(item.response.amount_received), ..item.data }) } diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 3e008585b0..12eb7f93c7 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -260,7 +260,7 @@ async fn payment_response_update_tracker( Ok(_) => storage::PaymentIntentUpdate::ResponseUpdate { status: router_data.status.foreign_into(), return_url: router_data.return_url, - amount_captured: None, + amount_captured: router_data.amount_captured, }, }; diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 36df6cdbc3..28d145ee71 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -96,6 +96,7 @@ where connector_meta_data: merchant_connector_account.metadata, request: T::try_from(payment_data.clone())?, response: response.map_or_else(|| Err(types::ErrorResponse::default()), Ok), + amount_captured: payment_data.payment_intent.amount_captured, }; Ok(router_data) diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 85d369930d..6f400af2c0 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -74,7 +74,7 @@ pub async fn construct_refund_router_data<'a, F>( address: PaymentAddress::default(), auth_type: payment_attempt.authentication_type.unwrap_or_default(), connector_meta_data: None, - + amount_captured: payment_intent.amount_captured, request: types::RefundsData { refund_id: refund.refund_id.clone(), payment_method_data, diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 7ab6221cf3..268b99f269 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -76,6 +76,7 @@ pub struct RouterData { pub address: PaymentAddress, pub auth_type: storage_enums::AuthenticationType, pub connector_meta_data: Option, + pub amount_captured: Option, /// Contains flow-specific data required to construct a request and send it to the connector. pub request: Request, diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index 3d417b15d5..d7f004bffb 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -54,6 +54,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { payment_method_id: None, address: PaymentAddress::default(), connector_meta_data: None, + amount_captured: None, } } @@ -93,6 +94,7 @@ fn construct_refund_router_data() -> types::RefundsRouterData { response: Err(types::ErrorResponse::default()), address: PaymentAddress::default(), connector_meta_data: None, + amount_captured: None, } } diff --git a/crates/router/tests/connectors/authorizedotnet.rs b/crates/router/tests/connectors/authorizedotnet.rs index 45b8b18e3d..4b4397f95c 100644 --- a/crates/router/tests/connectors/authorizedotnet.rs +++ b/crates/router/tests/connectors/authorizedotnet.rs @@ -54,6 +54,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { response: Err(types::ErrorResponse::default()), address: PaymentAddress::default(), connector_meta_data: None, + amount_captured: None, } } @@ -92,6 +93,7 @@ fn construct_refund_router_data() -> types::RefundsRouterData { response: Err(types::ErrorResponse::default()), payment_method_id: None, address: PaymentAddress::default(), + amount_captured: None, } } diff --git a/crates/router/tests/connectors/checkout.rs b/crates/router/tests/connectors/checkout.rs index 578a7fab93..ff6942b887 100644 --- a/crates/router/tests/connectors/checkout.rs +++ b/crates/router/tests/connectors/checkout.rs @@ -51,6 +51,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { payment_method_id: None, address: PaymentAddress::default(), connector_meta_data: None, + amount_captured: None, } } @@ -89,6 +90,7 @@ fn construct_refund_router_data() -> types::RefundsRouterData { response: Err(types::ErrorResponse::default()), payment_method_id: None, address: PaymentAddress::default(), + amount_captured: None, } } diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 8997da2b5a..f1a360846a 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -188,5 +188,6 @@ fn generate_data, Res>( payment_method_id: None, address: PaymentAddress::default(), connector_meta_data: None, + amount_captured: None, } }