From e5b3cb70b89e07a7dab7e4664c2733130dbe3d16 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 9 Dec 2024 15:48:19 +0530 Subject: [PATCH 01/64] feat(router): add always_request_overcapture to business_profile --- crates/api_models/src/admin.rs | 24 +++++++++++++++ crates/common_utils/src/id_type/merchant.rs | 5 ++++ crates/diesel_models/src/business_profile.rs | 11 +++++++ crates/diesel_models/src/schema.rs | 1 + crates/diesel_models/src/schema_v2.rs | 1 + .../src/business_profile.rs | 29 +++++++++++++++++++ crates/router/src/core/admin.rs | 4 +++ crates/router/src/types/api/admin.rs | 3 ++ .../down.sql | 1 + .../up.sql | 1 + 10 files changed, 80 insertions(+) create mode 100644 migrations/2024-12-09-072648_add_always_request_overcapture/down.sql create mode 100644 migrations/2024-12-09-072648_add_always_request_overcapture/up.sql diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index 53ce86789665..a20242e363e3 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -1970,6 +1970,10 @@ pub struct ProfileCreate { /// Indicates if click to pay is enabled or not. #[serde(default)] pub is_click_to_pay_enabled: bool, + + /// Indicates if the overcapture is always requested or not. + #[serde(default)] + pub always_request_overcapture: bool, } #[nutype::nutype( @@ -2082,6 +2086,10 @@ pub struct ProfileCreate { /// Indicates if click to pay is enabled or not. #[schema(default = false, example = false)] pub is_click_to_pay_enabled: bool, + + /// Indicates if the overcapture is always requested or not. + #[schema(default = false, example = false)] + pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -2214,6 +2222,10 @@ pub struct ProfileResponse { /// Indicates if click to pay is enabled or not. #[schema(default = false, example = false)] pub is_click_to_pay_enabled: bool, + + /// Indicates if the overcapture is always requested or not. + #[schema(default = false, example = false)] + pub always_request_overcapture: bool, } #[cfg(feature = "v2")] @@ -2333,6 +2345,10 @@ pub struct ProfileResponse { /// Indicates if click to pay is enabled or not. #[schema(default = false, example = false)] pub is_click_to_pay_enabled: bool, + + /// Indicates if the overcapture is always requested or not. + #[schema(default = false, example = false)] + pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -2459,6 +2475,10 @@ pub struct ProfileUpdate { /// Indicates if click to pay is enabled or not. #[schema(default = false, example = false)] pub is_click_to_pay_enabled: Option, + + /// Indicates if the overcapture is always requested or not. + #[schema(default = false, example = false)] + pub always_request_overcapture: Option, } #[cfg(feature = "v2")] @@ -2566,6 +2586,10 @@ pub struct ProfileUpdate { /// Indicates if click to pay is enabled or not. #[schema(default = false, example = false)] pub is_click_to_pay_enabled: Option, + + /// Indicates if the overcapture is always requested or not. + #[schema(default = false, example = false)] + pub always_request_overcapture: bool, } #[derive(Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)] diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rs index 08b80249ae34..036a1204279a 100644 --- a/crates/common_utils/src/id_type/merchant.rs +++ b/crates/common_utils/src/id_type/merchant.rs @@ -108,6 +108,11 @@ impl MerchantId { format!("max_auto_retries_enabled_{}", self.get_string_repr()) } + /// get_should_always_enable_overcapture key + pub fn get_should_always_enable_overcapture(&self) -> String { + format!("should_always_enable_overcapture_{}", self.get_string_repr()) + } + /// get_requires_cvv_key pub fn get_requires_cvv_key(&self) -> String { format!("{}_requires_cvv", self.get_string_repr()) diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index 484a1c0c699e..788f91d878f9 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -58,6 +58,7 @@ pub struct Profile { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -102,6 +103,7 @@ pub struct ProfileNew { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -143,6 +145,7 @@ pub struct ProfileUpdateInternal { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: Option, + pub always_request_overcapture: Option, } #[cfg(feature = "v1")] @@ -183,6 +186,7 @@ impl ProfileUpdateInternal { is_auto_retries_enabled, max_auto_retries_enabled, is_click_to_pay_enabled, + always_request_overcapture, } = self; Profile { profile_id: source.profile_id, @@ -244,6 +248,8 @@ impl ProfileUpdateInternal { max_auto_retries_enabled: max_auto_retries_enabled.or(source.max_auto_retries_enabled), is_click_to_pay_enabled: is_click_to_pay_enabled .unwrap_or(source.is_click_to_pay_enabled), + always_request_overcapture: always_request_overcapture + .unwrap_or(source.always_request_overcapture), } } } @@ -299,6 +305,7 @@ pub struct Profile { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } impl Profile { @@ -358,6 +365,7 @@ pub struct ProfileNew { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } #[cfg(feature = "v2")] @@ -401,6 +409,7 @@ pub struct ProfileUpdateInternal { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: Option, + pub always_request_overcapture: bool, } #[cfg(feature = "v2")] @@ -509,6 +518,8 @@ impl ProfileUpdateInternal { max_auto_retries_enabled: max_auto_retries_enabled.or(source.max_auto_retries_enabled), is_click_to_pay_enabled: is_click_to_pay_enabled .unwrap_or(source.is_click_to_pay_enabled), + always_request_overcapture: always_request_overcapture + .unwrap_or(source.always_request_overcapture), } } } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index c30562de9913..fede91ae292c 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -214,6 +214,7 @@ diesel::table! { is_auto_retries_enabled -> Nullable, max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, + always_request_overcapture -> Bool, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 12bb19c0a7f1..c530b7d3e9ad 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -222,6 +222,7 @@ diesel::table! { is_auto_retries_enabled -> Nullable, max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, + always_request_overcapture -> Bool, } } diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs index 433353b2f813..61e58ceeddcd 100644 --- a/crates/hyperswitch_domain_models/src/business_profile.rs +++ b/crates/hyperswitch_domain_models/src/business_profile.rs @@ -59,6 +59,7 @@ pub struct Profile { pub is_auto_retries_enabled: bool, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -100,6 +101,7 @@ pub struct ProfileSetter { pub is_auto_retries_enabled: bool, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -148,6 +150,7 @@ impl From for Profile { is_auto_retries_enabled: value.is_auto_retries_enabled, max_auto_retries_enabled: value.max_auto_retries_enabled, is_click_to_pay_enabled: value.is_click_to_pay_enabled, + always_request_overcapture: value.always_request_overcapture } } } @@ -198,6 +201,7 @@ pub struct ProfileGeneralUpdate { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: Option, + pub always_request_overcapture: Option } #[cfg(feature = "v1")] @@ -261,6 +265,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled, max_auto_retries_enabled, is_click_to_pay_enabled, + always_request_overcapture, } = *update; Self { @@ -299,6 +304,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled, max_auto_retries_enabled, is_click_to_pay_enabled, + always_request_overcapture } } ProfileUpdate::RoutingAlgorithmUpdate { @@ -339,6 +345,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::DynamicRoutingAlgorithmUpdate { dynamic_routing_algorithm, @@ -377,6 +384,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::ExtendedCardInfoUpdate { is_extended_card_info_enabled, @@ -415,6 +423,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::ConnectorAgnosticMitUpdate { is_connector_agnostic_mit_enabled, @@ -453,6 +462,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::NetworkTokenizationUpdate { is_network_tokenization_enabled, @@ -491,6 +501,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, } } @@ -548,6 +559,7 @@ impl super::behaviour::Conversion for Profile { is_auto_retries_enabled: Some(self.is_auto_retries_enabled), max_auto_retries_enabled: self.max_auto_retries_enabled, is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, }) } @@ -617,6 +629,7 @@ impl super::behaviour::Conversion for Profile { is_auto_retries_enabled: item.is_auto_retries_enabled.unwrap_or(false), max_auto_retries_enabled: item.max_auto_retries_enabled, is_click_to_pay_enabled: item.is_click_to_pay_enabled, + always_request_overcapture: item.always_request_overcapture, }) } .await @@ -670,6 +683,7 @@ impl super::behaviour::Conversion for Profile { is_auto_retries_enabled: Some(self.is_auto_retries_enabled), max_auto_retries_enabled: self.max_auto_retries_enabled, is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, }) } } @@ -715,6 +729,7 @@ pub struct Profile { pub version: common_enums::ApiVersion, pub is_network_tokenization_enabled: bool, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } #[cfg(feature = "v2")] @@ -756,6 +771,7 @@ pub struct ProfileSetter { pub is_tax_connector_enabled: bool, pub is_network_tokenization_enabled: bool, pub is_click_to_pay_enabled: bool, + pub always_request_overcapture: bool, } #[cfg(feature = "v2")] @@ -804,6 +820,7 @@ impl From for Profile { version: consts::API_VERSION, is_network_tokenization_enabled: value.is_network_tokenization_enabled, is_click_to_pay_enabled: value.is_click_to_pay_enabled, + always_request_overcapture: value.always_request_overcapture, } } } @@ -855,6 +872,7 @@ pub struct ProfileGeneralUpdate { pub order_fulfillment_time_origin: Option, pub is_network_tokenization_enabled: Option, pub is_click_to_pay_enabled: Option, + pub always_request_overcapture: Option, } #[cfg(feature = "v2")] @@ -914,6 +932,7 @@ impl From for ProfileUpdateInternal { order_fulfillment_time_origin, is_network_tokenization_enabled, is_click_to_pay_enabled, + always_request_overcapture, } = *update; Self { profile_name, @@ -953,6 +972,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled, + always_request_overcapture, } } ProfileUpdate::RoutingAlgorithmUpdate { @@ -995,6 +1015,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::ExtendedCardInfoUpdate { is_extended_card_info_enabled, @@ -1035,6 +1056,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::ConnectorAgnosticMitUpdate { is_connector_agnostic_mit_enabled, @@ -1075,6 +1097,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::DefaultRoutingFallbackUpdate { default_fallback_routing, @@ -1115,6 +1138,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::NetworkTokenizationUpdate { is_network_tokenization_enabled, @@ -1155,6 +1179,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, ProfileUpdate::CollectCvvDuringPaymentUpdate { should_collect_cvv_during_payment, @@ -1195,6 +1220,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: None, + always_request_overcapture: None, }, } } @@ -1255,6 +1281,7 @@ impl super::behaviour::Conversion for Profile { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, }) } @@ -1324,6 +1351,7 @@ impl super::behaviour::Conversion for Profile { version: item.version, is_network_tokenization_enabled: item.is_network_tokenization_enabled, is_click_to_pay_enabled: item.is_click_to_pay_enabled, + always_request_overcapture: item.always_request_overcapture, }) } .await @@ -1380,6 +1408,7 @@ impl super::behaviour::Conversion for Profile { is_auto_retries_enabled: None, max_auto_retries_enabled: None, is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, }) } } diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 40ed4e755210..31630db35804 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -3694,6 +3694,7 @@ impl ProfileCreateBridge for api::ProfileCreate { is_auto_retries_enabled: self.is_auto_retries_enabled.unwrap_or_default(), max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from), is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, })) } @@ -3802,6 +3803,7 @@ impl ProfileCreateBridge for api::ProfileCreate { is_tax_connector_enabled: self.is_tax_connector_enabled, is_network_tokenization_enabled: self.is_network_tokenization_enabled, is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, })) } } @@ -4052,6 +4054,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate { is_auto_retries_enabled: self.is_auto_retries_enabled, max_auto_retries_enabled: self.max_auto_retries_enabled.map(i16::from), is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, }, ))) } @@ -4149,6 +4152,7 @@ impl ProfileUpdateBridge for api::ProfileUpdate { .always_collect_shipping_details_from_wallet_connector, is_network_tokenization_enabled: self.is_network_tokenization_enabled, is_click_to_pay_enabled: self.is_click_to_pay_enabled, + always_request_overcapture: self.always_request_overcapture, }, ))) } diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs index 7207f63aa0fc..6a99851ddb4c 100644 --- a/crates/router/src/types/api/admin.rs +++ b/crates/router/src/types/api/admin.rs @@ -175,6 +175,7 @@ impl ForeignTryFrom for ProfileResponse { is_auto_retries_enabled: item.is_auto_retries_enabled, max_auto_retries_enabled: item.max_auto_retries_enabled, is_click_to_pay_enabled: item.is_click_to_pay_enabled, + always_request_overcapture: item.always_request_overcapture, }) } } @@ -243,6 +244,7 @@ impl ForeignTryFrom for ProfileResponse { is_tax_connector_enabled: item.is_tax_connector_enabled, is_network_tokenization_enabled: item.is_network_tokenization_enabled, is_click_to_pay_enabled: item.is_click_to_pay_enabled, + always_request_overcapture: item.always_request_overcapture, }) } } @@ -370,5 +372,6 @@ pub async fn create_profile_from_merchant_account( is_auto_retries_enabled: request.is_auto_retries_enabled.unwrap_or_default(), max_auto_retries_enabled: request.max_auto_retries_enabled.map(i16::from), is_click_to_pay_enabled: request.is_click_to_pay_enabled, + always_request_overcapture: request.always_request_overcapture, })) } diff --git a/migrations/2024-12-09-072648_add_always_request_overcapture/down.sql b/migrations/2024-12-09-072648_add_always_request_overcapture/down.sql new file mode 100644 index 000000000000..1aae471f86f4 --- /dev/null +++ b/migrations/2024-12-09-072648_add_always_request_overcapture/down.sql @@ -0,0 +1 @@ +ALTER TABLE business_profile DROP COLUMN IF EXISTS always_request_overcapture; \ No newline at end of file diff --git a/migrations/2024-12-09-072648_add_always_request_overcapture/up.sql b/migrations/2024-12-09-072648_add_always_request_overcapture/up.sql new file mode 100644 index 000000000000..1a5555cc773a --- /dev/null +++ b/migrations/2024-12-09-072648_add_always_request_overcapture/up.sql @@ -0,0 +1 @@ +ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS always_request_overcapture BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file From 86091fda6a0ddea0e4a7d9559251ffbd6d81cb4e Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 12 Dec 2024 00:19:41 +0530 Subject: [PATCH 02/64] feat(core): add field request_overcapture to payment_intent --- crates/api_models/src/payments.rs | 15 +++++++++++ crates/common_enums/src/enums.rs | 10 +++++++ crates/common_enums/src/transformers.rs | 19 ++++++++++++++ crates/diesel_models/src/payment_intent.rs | 26 +++++++++++++++++++ crates/diesel_models/src/schema.rs | 1 + crates/diesel_models/src/schema_v2.rs | 1 + .../hyperswitch_domain_models/src/payments.rs | 5 ++++ .../src/payments/payment_intent.rs | 23 ++++++++++++++++ .../payments/operations/payment_confirm.rs | 1 + .../payments/operations/payment_create.rs | 2 ++ .../payments/operations/payment_update.rs | 6 +++++ .../operations/payment_update_intent.rs | 3 +++ .../router/src/core/payments/transformers.rs | 1 + crates/router/src/utils/user/sample_data.rs | 1 + .../down.sql | 1 + .../up.sql | 1 + 16 files changed, 116 insertions(+) create mode 100644 migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/down.sql create mode 100644 migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/up.sql diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 6a7f7148bd3a..0856caa31a47 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -227,6 +227,10 @@ pub struct PaymentsCreateIntentRequest { #[schema(value_type = Option)] pub request_external_three_ds_authentication: Option, + + /// Whether to perform overcapture (if applicable) + #[schema(value_type = Option)] + pub request_overcapture: Option, } #[cfg(feature = "v2")] @@ -388,6 +392,10 @@ pub struct PaymentsUpdateIntentRequest { #[schema(value_type = Option)] pub request_external_three_ds_authentication: Option, + + /// Whether to perform overcapture (if applicable) + #[schema(value_type = Option)] + pub request_overcapture: Option, } #[derive(Debug, serde::Serialize, Clone, ToSchema)] @@ -516,6 +524,10 @@ pub struct PaymentsIntentResponse { /// Whether to perform external authentication (if applicable) #[schema(value_type = External3dsAuthenticationRequest)] pub request_external_three_ds_authentication: common_enums::External3dsAuthenticationRequest, + + /// Whether to perform overcapture (if applicable) + #[schema(value_type = OverCaptureRequest)] + pub request_overcapture: common_enums::OverCaptureRequest, } #[cfg(feature = "v2")] @@ -1013,6 +1025,9 @@ pub struct PaymentsRequest { /// Choose what kind of sca exemption is required for this payment #[schema(value_type = Option)] pub psd2_sca_exemption_type: Option, + + /// Whether to request overcapture on this payment + pub request_overcapture: Option, } #[cfg(feature = "v1")] diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 23e2f285cf34..d3fc47753e6f 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -3326,6 +3326,16 @@ pub enum External3dsAuthenticationRequest { Skip, } +/// Whether overcapture is requested or not +#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] +pub enum OverCaptureRequest { + /// Request for overcapture + Enable, + /// Skip overcapture + #[default] + Skip, +} + /// Whether payment link is requested to be enabled or not for this transaction #[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] pub enum EnablePaymentLinkRequest { diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index 7611ae127ee7..6ed16765602c 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -2021,6 +2021,25 @@ impl super::External3dsAuthenticationRequest { } } +impl From> for super::OverCaptureRequest { + fn from(value: Option) -> Self { + match value { + Some(true) => Self::Enable, + _ => Self::Skip, + } + } +} + +/// Get the boolean value of the `OverCaptureRequest`. +impl super::OverCaptureRequest { + pub fn as_bool(&self) -> bool { + match self { + Self::Enable => true, + Self::Skip => false, + } + } +} + impl super::EnablePaymentLinkRequest { pub fn as_bool(&self) -> bool { match self { diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs index b29da50d0a7d..618fd240d4a3 100644 --- a/crates/diesel_models/src/payment_intent.rs +++ b/crates/diesel_models/src/payment_intent.rs @@ -73,6 +73,7 @@ pub struct PaymentIntent { pub payment_link_config: Option, pub id: common_utils::id_type::GlobalPaymentId, pub psd2_sca_exemption_type: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -138,6 +139,7 @@ pub struct PaymentIntent { pub tax_details: Option, pub skip_external_tax_calculation: Option, pub psd2_sca_exemption_type: Option, + pub request_overcapture: Option, } #[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression, PartialEq)] @@ -292,6 +294,7 @@ pub struct PaymentIntentNew { pub enable_payment_link: Option, pub apply_mit_exemption: Option, pub id: common_utils::id_type::GlobalPaymentId, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -358,6 +361,7 @@ pub struct PaymentIntentNew { pub tax_details: Option, pub skip_external_tax_calculation: Option, pub psd2_sca_exemption_type: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -465,6 +469,7 @@ pub struct PaymentIntentUpdateFields { pub customer_details: Option, pub merchant_order_reference_id: Option, pub is_payment_processor_token_flow: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -497,6 +502,7 @@ pub struct PaymentIntentUpdateFields { pub shipping_details: Option, pub is_payment_processor_token_flow: Option, pub tax_details: Option, + pub request_overcapture: Option, } // TODO: uncomment fields as necessary @@ -537,6 +543,7 @@ pub struct PaymentIntentUpdateInternal { pub frm_metadata: Option, pub request_external_three_ds_authentication: Option, pub updated_by: String, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -580,6 +587,7 @@ pub struct PaymentIntentUpdateInternal { pub shipping_details: Option, pub is_payment_processor_token_flow: Option, pub tax_details: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -622,6 +630,7 @@ impl PaymentIntentUpdate { shipping_details, is_payment_processor_token_flow, tax_details, + request_overcapture, } = self.into(); PaymentIntent { amount: amount.unwrap_or(source.amount), @@ -667,6 +676,7 @@ impl PaymentIntentUpdate { is_payment_processor_token_flow: is_payment_processor_token_flow .or(source.is_payment_processor_token_flow), tax_details: tax_details.or(source.tax_details), + request_overcapture: request_overcapture.or(source.request_overcapture), ..source } } @@ -716,6 +726,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::Update(value) => Self { amount: Some(value.amount), @@ -755,6 +766,7 @@ impl From for PaymentIntentUpdateInternal { authorization_count: None, is_payment_processor_token_flow: value.is_payment_processor_token_flow, tax_details: None, + request_overcapture: value.request_overcapture, }, PaymentIntentUpdate::PaymentCreateUpdate { return_url, @@ -801,6 +813,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::PGStatusUpdate { status, @@ -843,6 +856,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::MerchantStatusUpdate { status, @@ -886,6 +900,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::ResponseUpdate { // amount, @@ -937,6 +952,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate { active_attempt_id, @@ -979,6 +995,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::StatusAndAttemptUpdate { status, @@ -1022,6 +1039,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::ApproveUpdate { status, @@ -1064,6 +1082,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::RejectUpdate { status, @@ -1106,6 +1125,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::SurchargeApplicableUpdate { surcharge_applicable, @@ -1147,6 +1167,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::IncrementalAuthorizationAmountUpdate { amount } => Self { amount: Some(amount), @@ -1185,6 +1206,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::AuthorizationCountUpdate { authorization_count, @@ -1225,6 +1247,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::CompleteAuthorizeUpdate { shipping_address_id, @@ -1265,6 +1288,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::ManualUpdate { status, updated_by } => Self { status, @@ -1303,6 +1327,7 @@ impl From for PaymentIntentUpdateInternal { shipping_details: None, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture: None, }, PaymentIntentUpdate::SessionResponseUpdate { tax_details, @@ -1346,6 +1371,7 @@ impl From for PaymentIntentUpdateInternal { merchant_order_reference_id: None, shipping_details, is_payment_processor_token_flow: None, + request_overcapture: None, }, } } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index fede91ae292c..713b3d6bce6a 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -966,6 +966,7 @@ diesel::table! { tax_details -> Nullable, skip_external_tax_calculation -> Nullable, psd2_sca_exemption_type -> Nullable, + request_overcapture -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index c530b7d3e9ad..36886b7569b2 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -929,6 +929,7 @@ diesel::table! { #[max_length = 64] id -> Varchar, psd2_sca_exemption_type -> Nullable, + request_overcapture -> Nullable, } } diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs index 9e6477fa26ba..fab325ae81c2 100644 --- a/crates/hyperswitch_domain_models/src/payments.rs +++ b/crates/hyperswitch_domain_models/src/payments.rs @@ -106,6 +106,7 @@ pub struct PaymentIntent { pub tax_details: Option, pub skip_external_tax_calculation: Option, pub psd2_sca_exemption_type: Option, + pub request_overcapture: Option, } impl PaymentIntent { @@ -362,6 +363,8 @@ pub struct PaymentIntent { pub payment_link_config: Option, /// The straight through routing algorithm id that is used for this payment. This overrides the default routing algorithm that is configured in business profile. pub routing_algorithm_id: Option, + /// Denotes whether to request for overcapture + pub request_overcapture: common_enums::OverCaptureRequest, } #[cfg(feature = "v2")] @@ -501,6 +504,8 @@ impl PaymentIntent { .payment_link_config .map(ApiModelToDieselModelConvertor::convert_from), routing_algorithm_id: request.routing_algorithm_id, + request_overcapture: request.request_overcapture + .unwrap_or_default(), }) } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index 9b6b6fe55720..c252d084d883 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -164,6 +164,7 @@ pub struct PaymentIntentUpdateFields { // updated_by is set internally, field not present in request pub updated_by: String, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -196,6 +197,7 @@ pub struct PaymentIntentUpdateFields { pub shipping_details: Option>>, pub is_payment_processor_token_flow: Option, pub tax_details: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -345,6 +347,7 @@ pub struct PaymentIntentUpdateInternal { pub shipping_details: Option>>, pub is_payment_processor_token_flow: Option, pub tax_details: Option, + pub request_overcapture: Option, } // This conversion is used in the `update_payment_intent` function @@ -390,6 +393,7 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata: None, request_external_three_ds_authentication: None, updated_by, + request_overcapture: None, }, PaymentIntentUpdate::ConfirmIntentPostUpdate { status, updated_by } => Self { @@ -426,6 +430,7 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata: None, request_external_three_ds_authentication: None, updated_by, + request_overcapture: None, }, PaymentIntentUpdate::SyncUpdate { status, updated_by } => Self { status: Some(status), @@ -461,6 +466,7 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata: None, request_external_three_ds_authentication: None, updated_by, + request_overcapture: None, }, PaymentIntentUpdate::UpdateIntent(boxed_intent) => { let PaymentIntentUpdateFields { @@ -494,6 +500,7 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata, request_external_three_ds_authentication, updated_by, + request_overcapture, } = *boxed_intent; Self { status: None, @@ -537,6 +544,7 @@ impl From for diesel_models::PaymentIntentUpdateInternal { request_external_three_ds_authentication.map(|val| val.as_bool()), updated_by, + request_overcapture: request_overcapture.map(|val| val.as_bool()), } } } @@ -584,6 +592,7 @@ impl From for PaymentIntentUpdateInternal { merchant_order_reference_id: value.merchant_order_reference_id, shipping_details: value.shipping_details, is_payment_processor_token_flow: value.is_payment_processor_token_flow, + request_overcapture: value.request_overcapture, ..Default::default() }, PaymentIntentUpdate::PaymentCreateUpdate { @@ -817,6 +826,7 @@ impl From for DieselPaymentIntentUpdate { shipping_details: value.shipping_details.map(Encryption::from), is_payment_processor_token_flow: value.is_payment_processor_token_flow, tax_details: value.tax_details, + request_overcapture: value.request_overcapture, })) } PaymentIntentUpdate::PaymentCreateUpdate { @@ -973,6 +983,7 @@ impl From for diesel_models::PaymentIntentUpdateInt shipping_details, is_payment_processor_token_flow, tax_details, + request_overcapture, } = value; Self { amount, @@ -1011,6 +1022,7 @@ impl From for diesel_models::PaymentIntentUpdateInt shipping_details: shipping_details.map(Encryption::from), is_payment_processor_token_flow, tax_details, + request_overcapture, } } } @@ -1268,6 +1280,7 @@ impl behaviour::Conversion for PaymentIntent { customer_present, routing_algorithm_id, payment_link_config, + request_overcapture, } = self; Ok(DieselPaymentIntent { skip_external_tax_calculation: Some(amount_details.get_external_tax_action_as_bool()), @@ -1338,6 +1351,9 @@ impl behaviour::Conversion for PaymentIntent { payment_link_config, routing_algorithm_id, psd2_sca_exemption_type: None, + request_overcapture: Some( + request_overcapture.as_bool(), + ), }) } async fn convert_back( @@ -1463,6 +1479,7 @@ impl behaviour::Conversion for PaymentIntent { customer_present: storage_model.customer_present.into(), payment_link_config: storage_model.payment_link_config, routing_algorithm_id: storage_model.routing_algorithm_id, + request_overcapture: storage_model.request_overcapture.into(), }) } .await @@ -1535,6 +1552,9 @@ impl behaviour::Conversion for PaymentIntent { tax_details: amount_details.tax_details, enable_payment_link: Some(self.enable_payment_link.as_bool()), apply_mit_exemption: Some(self.apply_mit_exemption.as_bool()), + request_overcapture: Some( + self.request_overcapture.as_bool(), + ), }) } } @@ -1600,6 +1620,7 @@ impl behaviour::Conversion for PaymentIntent { tax_details: self.tax_details, skip_external_tax_calculation: self.skip_external_tax_calculation, psd2_sca_exemption_type: self.psd2_sca_exemption_type, + request_overcapture: self.request_overcapture, }) } @@ -1688,6 +1709,7 @@ impl behaviour::Conversion for PaymentIntent { organization_id: storage_model.organization_id, skip_external_tax_calculation: storage_model.skip_external_tax_calculation, psd2_sca_exemption_type: storage_model.psd2_sca_exemption_type, + request_overcapture: storage_model.request_overcapture, }) } .await @@ -1751,6 +1773,7 @@ impl behaviour::Conversion for PaymentIntent { tax_details: self.tax_details, skip_external_tax_calculation: self.skip_external_tax_calculation, psd2_sca_exemption_type: self.psd2_sca_exemption_type, + request_overcapture: self.request_overcapture, }) } } diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 67829f1fb732..50f73a311273 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -1469,6 +1469,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen shipping_details, is_payment_processor_token_flow, tax_details: None, + request_overcapture: None, })), &m_key_store, storage_scheme, diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 3bd5b9abcdde..1550794018c5 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1488,6 +1488,8 @@ impl PaymentCreate { tax_details: None, skip_external_tax_calculation, psd2_sca_exemption_type: request.psd2_sca_exemption_type, + request_overcapture: request.request_overcapture, + }) } diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 61a52e7dfb58..1442d12bf048 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -391,6 +391,10 @@ impl GetTracker, api::PaymentsRequest> for Pa .request_external_three_ds_authentication .or(payment_intent.request_external_three_ds_authentication); + payment_intent.request_overcapture = request + .request_overcapture + .or(payment_intent.request_overcapture); + payment_intent.merchant_order_reference_id = request .merchant_order_reference_id .clone() @@ -884,6 +888,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen let metadata = payment_data.payment_intent.metadata.clone(); let frm_metadata = payment_data.payment_intent.frm_metadata.clone(); let session_expiry = payment_data.payment_intent.session_expiry; + let request_overcapture = payment_data.payment_intent.request_overcapture; let merchant_order_reference_id = payment_data .payment_intent .merchant_order_reference_id @@ -923,6 +928,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen shipping_details, is_payment_processor_token_flow: None, tax_details: None, + request_overcapture, })), key_store, storage_scheme, diff --git a/crates/router/src/core/payments/operations/payment_update_intent.rs b/crates/router/src/core/payments/operations/payment_update_intent.rs index f8ce03d558e9..5c364191e4c4 100644 --- a/crates/router/src/core/payments/operations/payment_update_intent.rs +++ b/crates/router/src/core/payments/operations/payment_update_intent.rs @@ -169,6 +169,7 @@ impl GetTracker, PaymentsUpda session_expiry, frm_metadata, request_external_three_ds_authentication, + request_overcapture, } = request.clone(); let batch_encrypted_data = domain_types::crypto_operation( @@ -267,6 +268,7 @@ impl GetTracker, PaymentsUpda routing_algorithm_id: routing_algorithm_id.or(payment_intent.routing_algorithm_id), allowed_payment_method_types: allowed_payment_method_types .or(payment_intent.allowed_payment_method_types), + request_overcapture: request_overcapture.unwrap_or(payment_intent.request_overcapture), ..payment_intent }; @@ -344,6 +346,7 @@ impl UpdateTracker, PaymentsUpdateIn request_external_three_ds_authentication: Some( intent.request_external_three_ds_authentication, ), + request_overcapture: Some(intent.request_overcapture), updated_by: intent.updated_by, tax_details: intent.amount_details.tax_details, })); diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 6e277ed460f0..c09c4b207f42 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -1136,6 +1136,7 @@ where request_external_three_ds_authentication: payment_intent .request_external_three_ds_authentication .clone(), + request_overcapture: payment_intent.request_overcapture.clone(), }, vec![], ))) diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs index 600d610e428d..042008bb3188 100644 --- a/crates/router/src/utils/user/sample_data.rs +++ b/crates/router/src/utils/user/sample_data.rs @@ -275,6 +275,7 @@ pub async fn generate_sample_data( tax_details: None, skip_external_tax_calculation: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; let (connector_transaction_id, connector_transaction_data) = ConnectorTransactionId::form_id_and_data(attempt_id.clone()); diff --git a/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/down.sql b/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/down.sql new file mode 100644 index 000000000000..8a7552029b6a --- /dev/null +++ b/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/down.sql @@ -0,0 +1 @@ +ALTER TABLE payment_intent DROP COLUMN IF EXISTS request_overcapture; \ No newline at end of file diff --git a/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/up.sql b/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/up.sql new file mode 100644 index 000000000000..ed3b1d019d55 --- /dev/null +++ b/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/up.sql @@ -0,0 +1 @@ +ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN; \ No newline at end of file From 48d2eff1c9adb6cf01c696f3ae1731baa5ee6151 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 12 Dec 2024 00:21:11 +0530 Subject: [PATCH 03/64] fix(clippy_v2): make always_request_overcapture optional in ProfileUpdateInternal and ProfileUpdate --- crates/api_models/src/admin.rs | 2 +- crates/diesel_models/src/business_profile.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index a20242e363e3..732438e967f8 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -2589,7 +2589,7 @@ pub struct ProfileUpdate { /// Indicates if the overcapture is always requested or not. #[schema(default = false, example = false)] - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[derive(Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)] diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index 788f91d878f9..72676d2a2553 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -409,7 +409,7 @@ pub struct ProfileUpdateInternal { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: Option, - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[cfg(feature = "v2")] @@ -452,6 +452,7 @@ impl ProfileUpdateInternal { is_auto_retries_enabled, max_auto_retries_enabled, is_click_to_pay_enabled, + always_request_overcapture } = self; Profile { id: source.id, From 2f49343a905368982a34968e22917b6c83ab7d91 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 12 Dec 2024 00:22:20 +0530 Subject: [PATCH 04/64] chore: generate openapi_spec --- api-reference-v2/openapi_spec.json | 48 ++++++++++++++++++++++++++++-- crates/openapi/src/openapi_v2.rs | 1 + 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index 64949c3812b6..89d323be9025 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -12061,6 +12061,14 @@ } } }, + "OverCaptureRequest": { + "type": "string", + "description": "Whether overcapture is requested or not", + "enum": [ + "Enable", + "Skip" + ] + }, "PayLaterData": { "oneOf": [ { @@ -14444,6 +14452,14 @@ } ], "nullable": true + }, + "request_overcapture": { + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureRequest" + } + ], + "nullable": true } }, "additionalProperties": false @@ -15157,7 +15173,8 @@ "payment_link_enabled", "request_incremental_authorization", "expires_on", - "request_external_three_ds_authentication" + "request_external_three_ds_authentication", + "request_overcapture" ], "properties": { "id": { @@ -15319,6 +15336,9 @@ }, "request_external_three_ds_authentication": { "$ref": "#/components/schemas/External3dsAuthenticationRequest" + }, + "request_overcapture": { + "$ref": "#/components/schemas/OverCaptureRequest" } }, "additionalProperties": false @@ -16206,6 +16226,14 @@ } ], "nullable": true + }, + "request_overcapture": { + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureRequest" + } + ], + "nullable": true } }, "additionalProperties": false @@ -17555,7 +17583,8 @@ "type": "object", "required": [ "profile_name", - "is_click_to_pay_enabled" + "is_click_to_pay_enabled", + "always_request_overcapture" ], "properties": { "profile_name": { @@ -17719,6 +17748,12 @@ "description": "Indicates if click to pay is enabled or not.", "default": false, "example": false + }, + "always_request_overcapture": { + "type": "boolean", + "description": "Indicates if the overcapture is always requested or not.", + "default": false, + "example": false } }, "additionalProperties": false @@ -17752,7 +17787,8 @@ "is_tax_connector_enabled", "is_network_tokenization_enabled", "should_collect_cvv_during_payment", - "is_click_to_pay_enabled" + "is_click_to_pay_enabled", + "always_request_overcapture" ], "properties": { "merchant_id": { @@ -17938,6 +17974,12 @@ "description": "Indicates if click to pay is enabled or not.", "default": false, "example": false + }, + "always_request_overcapture": { + "type": "boolean", + "description": "Indicates if the overcapture is always requested or not.", + "default": false, + "example": false } } }, diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs index ba2975349c0f..061e4a529609 100644 --- a/crates/openapi/src/openapi_v2.rs +++ b/crates/openapi/src/openapi_v2.rs @@ -512,6 +512,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::enums::EnablePaymentLinkRequest, api_models::enums::RequestIncrementalAuthorization, api_models::enums::External3dsAuthenticationRequest, + api_models::enums::OverCaptureRequest, api_models::enums::TaxCalculationOverride, api_models::enums::SurchargeCalculationOverride, api_models::payments::FrmMessage, From 4ad3cd38b09449a5fc66dab43e976abedb03fd73 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 07:10:52 +0000 Subject: [PATCH 05/64] chore: run formatter --- crates/common_utils/src/id_type/merchant.rs | 5 ++++- crates/diesel_models/src/business_profile.rs | 2 +- crates/hyperswitch_domain_models/src/business_profile.rs | 6 +++--- crates/hyperswitch_domain_models/src/payments.rs | 3 +-- .../src/payments/payment_intent.rs | 8 ++------ .../router/src/core/payments/operations/payment_create.rs | 1 - 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rs index 036a1204279a..13e722da6f95 100644 --- a/crates/common_utils/src/id_type/merchant.rs +++ b/crates/common_utils/src/id_type/merchant.rs @@ -110,7 +110,10 @@ impl MerchantId { /// get_should_always_enable_overcapture key pub fn get_should_always_enable_overcapture(&self) -> String { - format!("should_always_enable_overcapture_{}", self.get_string_repr()) + format!( + "should_always_enable_overcapture_{}", + self.get_string_repr() + ) } /// get_requires_cvv_key diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index 72676d2a2553..0061ea5844c7 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -452,7 +452,7 @@ impl ProfileUpdateInternal { is_auto_retries_enabled, max_auto_retries_enabled, is_click_to_pay_enabled, - always_request_overcapture + always_request_overcapture, } = self; Profile { id: source.id, diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs index 61e58ceeddcd..b8c00128fa1f 100644 --- a/crates/hyperswitch_domain_models/src/business_profile.rs +++ b/crates/hyperswitch_domain_models/src/business_profile.rs @@ -150,7 +150,7 @@ impl From for Profile { is_auto_retries_enabled: value.is_auto_retries_enabled, max_auto_retries_enabled: value.max_auto_retries_enabled, is_click_to_pay_enabled: value.is_click_to_pay_enabled, - always_request_overcapture: value.always_request_overcapture + always_request_overcapture: value.always_request_overcapture, } } } @@ -201,7 +201,7 @@ pub struct ProfileGeneralUpdate { pub is_auto_retries_enabled: Option, pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: Option, - pub always_request_overcapture: Option + pub always_request_overcapture: Option, } #[cfg(feature = "v1")] @@ -304,7 +304,7 @@ impl From for ProfileUpdateInternal { is_auto_retries_enabled, max_auto_retries_enabled, is_click_to_pay_enabled, - always_request_overcapture + always_request_overcapture, } } ProfileUpdate::RoutingAlgorithmUpdate { diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs index fab325ae81c2..4e19ccdc40ed 100644 --- a/crates/hyperswitch_domain_models/src/payments.rs +++ b/crates/hyperswitch_domain_models/src/payments.rs @@ -504,8 +504,7 @@ impl PaymentIntent { .payment_link_config .map(ApiModelToDieselModelConvertor::convert_from), routing_algorithm_id: request.routing_algorithm_id, - request_overcapture: request.request_overcapture - .unwrap_or_default(), + request_overcapture: request.request_overcapture.unwrap_or_default(), }) } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index c252d084d883..aa626dfcfb06 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -1351,9 +1351,7 @@ impl behaviour::Conversion for PaymentIntent { payment_link_config, routing_algorithm_id, psd2_sca_exemption_type: None, - request_overcapture: Some( - request_overcapture.as_bool(), - ), + request_overcapture: Some(request_overcapture.as_bool()), }) } async fn convert_back( @@ -1552,9 +1550,7 @@ impl behaviour::Conversion for PaymentIntent { tax_details: amount_details.tax_details, enable_payment_link: Some(self.enable_payment_link.as_bool()), apply_mit_exemption: Some(self.apply_mit_exemption.as_bool()), - request_overcapture: Some( - self.request_overcapture.as_bool(), - ), + request_overcapture: Some(self.request_overcapture.as_bool()), }) } } diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 1550794018c5..5ff44176221b 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1489,7 +1489,6 @@ impl PaymentCreate { skip_external_tax_calculation, psd2_sca_exemption_type: request.psd2_sca_exemption_type, request_overcapture: request.request_overcapture, - }) } From 2b7c16501b213cdd2896e4e5a49cb8ec03fb08bb Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 12 Dec 2024 07:14:41 +0000 Subject: [PATCH 06/64] docs(openapi): re-generate OpenAPI specification --- api-reference/openapi_spec.json | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 3f3ffc17a183..036d04e0da71 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -17091,6 +17091,11 @@ } ], "nullable": true + }, + "request_overcapture": { + "type": "boolean", + "description": "Whether to request overcapture on this payment", + "nullable": true } } }, @@ -17469,6 +17474,11 @@ } ], "nullable": true + }, + "request_overcapture": { + "type": "boolean", + "description": "Whether to request overcapture on this payment", + "nullable": true } } }, @@ -18671,6 +18681,11 @@ } ], "nullable": true + }, + "request_overcapture": { + "type": "boolean", + "description": "Whether to request overcapture on this payment", + "nullable": true } }, "additionalProperties": false @@ -19712,6 +19727,11 @@ } ], "nullable": true + }, + "request_overcapture": { + "type": "boolean", + "description": "Whether to request overcapture on this payment", + "nullable": true } } }, @@ -21673,6 +21693,10 @@ "is_click_to_pay_enabled": { "type": "boolean", "description": "Indicates if click to pay is enabled or not." + }, + "always_request_overcapture": { + "type": "boolean", + "description": "Indicates if the overcapture is always requested or not." } }, "additionalProperties": false @@ -21706,7 +21730,8 @@ "is_tax_connector_enabled", "is_network_tokenization_enabled", "is_auto_retries_enabled", - "is_click_to_pay_enabled" + "is_click_to_pay_enabled", + "always_request_overcapture" ], "properties": { "merchant_id": { @@ -21909,6 +21934,12 @@ "description": "Indicates if click to pay is enabled or not.", "default": false, "example": false + }, + "always_request_overcapture": { + "type": "boolean", + "description": "Indicates if the overcapture is always requested or not.", + "default": false, + "example": false } } }, From 251ccc1d61c076ad5b0b78510c8782580b1a13ad Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Sun, 15 Dec 2024 13:25:40 +0530 Subject: [PATCH 07/64] feat(router): add parameters to payment_attepmt and router data --- crates/diesel_models/Cargo.toml | 2 +- crates/diesel_models/src/lib.rs | 2 + crates/diesel_models/src/payment_attempt.rs | 100 ++++++++++++++++++ crates/diesel_models/src/schema.rs | 3 + crates/diesel_models/src/schema_v2.rs | 3 + crates/diesel_models/src/user/sample_data.rs | 6 ++ .../src/payments/payment_attempt.rs | 37 +++++++ .../src/router_data.rs | 2 + .../src/core/authentication/transformers.rs | 1 + .../core/fraud_check/flows/checkout_flow.rs | 1 + .../fraud_check/flows/fulfillment_flow.rs | 1 + .../core/fraud_check/flows/record_return.rs | 1 + .../src/core/fraud_check/flows/sale_flow.rs | 1 + .../fraud_check/flows/transaction_flow.rs | 1 + crates/router/src/core/mandate/utils.rs | 1 + crates/router/src/core/payments/helpers.rs | 5 + .../payments/operations/payment_confirm.rs | 8 +- .../payments/operations/payment_create.rs | 5 + .../payments/operations/payment_response.rs | 2 + .../payments/operations/payment_update.rs | 7 +- crates/router/src/core/payments/retry.rs | 6 ++ .../router/src/core/payments/transformers.rs | 2 + crates/router/src/core/utils.rs | 10 +- crates/router/src/core/webhooks/utils.rs | 1 + .../router/src/services/conversion_impls.rs | 1 + crates/router/src/types.rs | 2 + .../router/src/types/api/verify_connector.rs | 1 + crates/router/src/utils/user/sample_data.rs | 3 + crates/router/tests/connectors/mifinity.rs | 1 + .../src/mock_db/payment_attempt.rs | 3 + .../src/payments/payment_attempt.rs | 15 +++ .../down.sql | 3 + .../up.sql | 3 + 33 files changed, 236 insertions(+), 4 deletions(-) create mode 100644 migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql create mode 100644 migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql diff --git a/crates/diesel_models/Cargo.toml b/crates/diesel_models/Cargo.toml index 120a606d58b5..f6e44acdafa0 100644 --- a/crates/diesel_models/Cargo.toml +++ b/crates/diesel_models/Cargo.toml @@ -17,7 +17,7 @@ payment_methods_v2 = [] [dependencies] async-bb8-diesel = { git = "https://github.com/jarnura/async-bb8-diesel", rev = "53b4ab901aab7635c8215fd1c2d542c8db443094" } -diesel = { version = "2.2.3", features = ["postgres", "serde_json", "time", "64-column-tables"] } +diesel = { version = "2.2.3", features = ["postgres", "serde_json", "time", "128-column-tables"] } error-stack = "0.4.1" rustc-hash = "1.1.0" serde = { version = "1.0.197", features = ["derive"] } diff --git a/crates/diesel_models/src/lib.rs b/crates/diesel_models/src/lib.rs index d07f84aa65e2..23de55cf04a4 100644 --- a/crates/diesel_models/src/lib.rs +++ b/crates/diesel_models/src/lib.rs @@ -1,3 +1,5 @@ +#![recursion_limit = "128"] + pub mod address; pub mod api_keys; pub mod blocklist_lookup; diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 6ddc26d49bdb..bd3df31f3469 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -94,6 +94,9 @@ pub struct PaymentAttempt { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -172,6 +175,9 @@ pub struct PaymentAttempt { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -278,6 +284,9 @@ pub struct PaymentAttemptNew { pub payment_method_subtype: storage_enums::PaymentMethodType, pub id: id_type::GlobalAttemptId, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -351,6 +360,9 @@ pub struct PaymentAttemptNew { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -374,6 +386,8 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, + overcapture_applied: Option, + maximum_capturable_amount: Option, }, UpdateTrackers { payment_token: Option, @@ -423,6 +437,8 @@ pub enum PaymentAttemptUpdate { shipping_cost: Option, order_tax_amount: Option, connector_mandate_detail: Option, + overcapture_applied: Option, + maximum_capturable_amount: Option, }, VoidUpdate { status: storage_enums::AttemptStatus, @@ -471,6 +487,8 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, + overcapture_applied: Option, + maximum_capturable_amount: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -791,6 +809,9 @@ pub struct PaymentAttemptUpdateInternal { // client_version: Option, // customer_acceptance: Option, // card_network: Option, + // pub request_overcapture: Option, + // pub overcapture_applied: Option, + // pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -848,6 +869,9 @@ pub struct PaymentAttemptUpdateInternal { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -1031,6 +1055,9 @@ impl PaymentAttemptUpdate { order_tax_amount, connector_transaction_data, connector_mandate_detail, + request_overcapture, + overcapture_applied, + maximum_capturable_amount, } = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source); PaymentAttempt { amount: amount.unwrap_or(source.amount), @@ -1089,6 +1116,9 @@ impl PaymentAttemptUpdate { connector_transaction_data: connector_transaction_data .or(source.connector_transaction_data), connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail), + request_overcapture: request_overcapture.or(source.request_overcapture), + overcapture_applied: overcapture_applied.or(source.overcapture_applied), + maximum_capturable_amount: maximum_capturable_amount.or(source.maximum_capturable_amount), ..source } } @@ -2088,6 +2118,8 @@ impl From for PaymentAttemptUpdateInternal { fingerprint_id, updated_by, payment_method_billing_address_id, + overcapture_applied, + maximum_capturable_amount, } => Self { amount: Some(amount), currency: Some(currency), @@ -2141,6 +2173,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied, + maximum_capturable_amount, }, PaymentAttemptUpdate::AuthenticationTypeUpdate { authentication_type, @@ -2197,6 +2232,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::ConfirmUpdate { amount, @@ -2232,6 +2270,8 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost, order_tax_amount, connector_mandate_detail, + overcapture_applied, + maximum_capturable_amount, } => Self { amount: Some(amount), currency: Some(currency), @@ -2284,6 +2324,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount, connector_transaction_data: None, connector_mandate_detail, + request_overcapture: None, + overcapture_applied, + maximum_capturable_amount, }, PaymentAttemptUpdate::VoidUpdate { status, @@ -2341,6 +2384,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::RejectUpdate { status, @@ -2399,6 +2445,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::BlocklistUpdate { status, @@ -2457,6 +2506,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::ConnectorMandateDetailUpdate { connector_mandate_detail, @@ -2513,6 +2565,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::PaymentMethodDetailsUpdate { payment_method_id, @@ -2569,6 +2624,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::ResponseUpdate { status, @@ -2592,6 +2650,8 @@ impl From for PaymentAttemptUpdateInternal { payment_method_data, charge_id, connector_mandate_detail, + overcapture_applied, + maximum_capturable_amount, } => { let (connector_transaction_id, connector_transaction_data) = connector_transaction_id @@ -2650,6 +2710,9 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail, + request_overcapture: None, + overcapture_applied, + maximum_capturable_amount, } } PaymentAttemptUpdate::ErrorUpdate { @@ -2723,6 +2786,10 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, + } } PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self { @@ -2777,6 +2844,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::UpdateTrackers { payment_token, @@ -2839,6 +2909,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::UnresolvedResponseUpdate { status, @@ -2908,6 +2981,9 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::PreprocessingUpdate { @@ -2976,6 +3052,9 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::CaptureUpdate { @@ -3034,6 +3113,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::AmountToCaptureUpdate { status, @@ -3091,6 +3173,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::ConnectorResponse { authentication_data, @@ -3157,6 +3242,9 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { @@ -3214,6 +3302,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::AuthenticationUpdate { status, @@ -3273,6 +3364,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::ManualUpdate { status, @@ -3341,6 +3435,9 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::PostSessionTokensUpdate { @@ -3398,6 +3495,9 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, } } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 713b3d6bce6a..06b546455a02 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -885,6 +885,9 @@ diesel::table! { #[max_length = 512] connector_transaction_data -> Nullable, connector_mandate_detail -> Nullable, + request_overcapture -> Nullable, + overcapture_applied -> Nullable, + maximum_capturable_amount -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 36886b7569b2..360782b4a995 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -855,6 +855,9 @@ diesel::table! { shipping_cost -> Nullable, order_tax_amount -> Nullable, connector_mandate_detail -> Nullable, + request_overcapture -> Nullable, + overcapture_applied -> Nullable, + maximum_capturable_amount -> Nullable, } } diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs index cfc9e1c4c8ed..1ba073d0a0a9 100644 --- a/crates/diesel_models/src/user/sample_data.rs +++ b/crates/diesel_models/src/user/sample_data.rs @@ -203,6 +203,9 @@ pub struct PaymentAttemptBatchNew { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -282,6 +285,9 @@ impl PaymentAttemptBatchNew { shipping_cost: self.shipping_cost, order_tax_amount: self.order_tax_amount, connector_mandate_detail: self.connector_mandate_detail, + request_overcapture: self.request_overcapture, + overcapture_applied: self.overcapture_applied, + maximum_capturable_amount: self.maximum_capturable_amount, } } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 591ccc4ff981..0b89ab57f149 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -320,6 +320,10 @@ pub struct PaymentAttempt { pub id: id_type::GlobalAttemptId, /// The connector mandate details which are stored temporarily pub connector_mandate_detail: Option, + /// This is based on Payment Request and the configuration of the merchant in the business profile + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } impl PaymentAttempt { @@ -508,6 +512,9 @@ pub struct PaymentAttempt { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -753,6 +760,9 @@ pub struct PaymentAttemptNew { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, + pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -774,6 +784,8 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, + overcapture_applied: Option, + maximum_capturable_amount: Option, }, UpdateTrackers { payment_token: Option, @@ -819,6 +831,8 @@ pub enum PaymentAttemptUpdate { client_version: Option, customer_acceptance: Option, connector_mandate_detail: Option, + overcapture_applied: Option, + maximum_capturable_amount: Option, }, RejectUpdate { status: storage_enums::AttemptStatus, @@ -867,6 +881,8 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, + overcapture_applied: Option, + maximum_capturable_amount: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -971,6 +987,8 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, + overcapture_applied, + maximum_capturable_amount, } => DieselPaymentAttemptUpdate::Update { amount: net_amount.get_order_amount(), currency, @@ -989,6 +1007,8 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, + overcapture_applied, + maximum_capturable_amount, }, Self::UpdateTrackers { payment_token, @@ -1071,6 +1091,8 @@ impl PaymentAttemptUpdate { client_version, customer_acceptance, connector_mandate_detail, + overcapture_applied, + maximum_capturable_amount } => DieselPaymentAttemptUpdate::ConfirmUpdate { amount: net_amount.get_order_amount(), currency, @@ -1105,6 +1127,8 @@ impl PaymentAttemptUpdate { shipping_cost: net_amount.get_shipping_cost(), order_tax_amount: net_amount.get_order_tax_amount(), connector_mandate_detail, + overcapture_applied, + maximum_capturable_amount }, Self::VoidUpdate { status, @@ -1137,6 +1161,8 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, + overcapture_applied, + maximum_capturable_amount, } => DieselPaymentAttemptUpdate::ResponseUpdate { status, connector, @@ -1159,6 +1185,8 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, + overcapture_applied, + maximum_capturable_amount, }, Self::UnresolvedResponseUpdate { status, @@ -1455,6 +1483,9 @@ impl behaviour::Conversion for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, + request_overcapture: self.request_overcapture, + overcapture_applied: self.overcapture_applied, + maximum_capturable_amount: self.maximum_capturable_amount, }) } @@ -1536,6 +1567,9 @@ impl behaviour::Conversion for PaymentAttempt { profile_id: storage_model.profile_id, organization_id: storage_model.organization_id, connector_mandate_detail: storage_model.connector_mandate_detail, + request_overcapture: storage_model.request_overcapture, + overcapture_applied: storage_model.overcapture_applied, + maximum_capturable_amount: storage_model.maximum_capturable_amount, }) } .await @@ -1618,6 +1652,9 @@ impl behaviour::Conversion for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, + request_overcapture: self.request_overcapture, + overcapture_applied: self.overcapture_applied, + maximum_capturable_amount: self.maximum_capturable_amount, }) } } diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index a3867ce3e62a..145fba94bf2a 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -89,6 +89,8 @@ pub struct RouterData { /// Contains the type of sca exemption required for the transaction pub psd2_sca_exemption_type: Option, + + pub request_overcapture: Option, } // Different patterns of authentication. diff --git a/crates/router/src/core/authentication/transformers.rs b/crates/router/src/core/authentication/transformers.rs index c4b35d527980..666c855362a0 100644 --- a/crates/router/src/core/authentication/transformers.rs +++ b/crates/router/src/core/authentication/transformers.rs @@ -191,6 +191,7 @@ pub fn construct_router_data( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type, + request_overcapture: None, }) } diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs index 84ba1f26a5d1..1487c9e2e29a 100644 --- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs +++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs @@ -162,6 +162,7 @@ impl ConstructFlowSpecificData( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs index 6e29d01c81fb..286ca9992cad 100644 --- a/crates/router/src/core/fraud_check/flows/record_return.rs +++ b/crates/router/src/core/fraud_check/flows/record_return.rs @@ -130,6 +130,7 @@ impl ConstructFlowSpecificData( header_payload: router_data.header_payload, connector_mandate_request_reference_id: router_data.connector_mandate_request_reference_id, psd2_sca_exemption_type: router_data.psd2_sca_exemption_type, + request_overcapture: router_data.request_overcapture, } } @@ -4153,6 +4155,9 @@ impl AttemptType { organization_id: old_payment_attempt.organization_id, profile_id: old_payment_attempt.profile_id, connector_mandate_detail: None, + request_overcapture: old_payment_attempt.request_overcapture, + overcapture_applied: None, + maximum_capturable_amount: None, } } diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 50f73a311273..89fbf6edaf89 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -396,6 +396,10 @@ impl GetTracker, api::PaymentsRequest> for Pa payment_attempt.capture_method = request.capture_method.or(payment_attempt.capture_method); + payment_attempt.request_overcapture = request + .request_overcapture + .or(Some(business_profile.always_request_overcapture)); + payment_attempt.customer_acceptance = request .customer_acceptance .clone() @@ -1344,7 +1348,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen async move { m_db.update_payment_attempt_with_attempt_id( m_payment_data_payment_attempt, - storage::PaymentAttemptUpdate::ConfirmUpdate { + storage::PaymentAttemptUpdate::ConfirmUpdate { // Should we remove todooo currency: payment_data.currency, status: attempt_status, payment_method, @@ -1386,6 +1390,8 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen connector_mandate_detail: payment_data .payment_attempt .connector_mandate_detail, + maximum_capturable_amount: None, + overcapture_applied: None, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 5ff44176221b..e8b761bc401f 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -541,6 +541,8 @@ impl GetTracker, api::PaymentsRequest> for Pa } let amount = payment_attempt.get_total_amount().into(); + payment_attempt.request_overcapture = request.request_overcapture.or(Some(business_profile.always_request_overcapture)); // todoooo + payment_attempt.connector_mandate_detail = Some(DieselConnectorMandateReferenceId::foreign_from( api_models::payments::ConnectorMandateReferenceId::new( @@ -1280,6 +1282,9 @@ impl PaymentCreate { organization_id: organization_id.clone(), profile_id, connector_mandate_detail: None, + request_overcapture: request.request_overcapture, + overcapture_applied: None, + maximum_capturable_amount: None, }, additional_pm_data, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index d77236c8a2bc..3a756062fe79 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1733,6 +1733,8 @@ async fn payment_response_update_tracker( .payment_attempt .connector_mandate_detail .clone(), + overcapture_applied: None, // todooooooo + maximum_capturable_amount: None, }), ), }; diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 1442d12bf048..0cd25de7381a 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -442,6 +442,9 @@ impl GetTracker, api::PaymentsRequest> for Pa id: profile_id.get_string_repr().to_owned(), })?; + payment_attempt.request_overcapture = request.request_overcapture.or(Some(business_profile.always_request_overcapture)); + + let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) }); @@ -797,7 +800,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen .store .update_payment_attempt_with_attempt_id( payment_data.payment_attempt, - storage::PaymentAttemptUpdate::Update { + storage::PaymentAttemptUpdate::Update { //should we remove todooo currency: payment_data.currency, status: get_attempt_status(), authentication_type: None, @@ -820,6 +823,8 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen surcharge_amount, tax_amount, ), + maximum_capturable_amount: None, + overcapture_applied: None, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index fed28b680110..903a25077f67 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -467,6 +467,8 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; #[cfg(feature = "v1")] @@ -654,6 +656,10 @@ pub fn make_new_payment_attempt( charge_id: Default::default(), customer_acceptance: Default::default(), connector_mandate_detail: Default::default(), + request_overcapture: old_payment_attempt.request_overcapture, + overcapture_applied: Default::default(), + maximum_capturable_amount: Default::default(), + } } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index c09c4b207f42..321d05964127 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -168,6 +168,7 @@ where header_payload: None, connector_mandate_request_reference_id, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } @@ -848,6 +849,7 @@ where header_payload, connector_mandate_request_reference_id, psd2_sca_exemption_type: payment_data.payment_intent.psd2_sca_exemption_type, + request_overcapture: payment_data.payment_attempt.request_overcapture, }; Ok(router_data) diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 62f1425d4d3c..f4de2d148565 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -216,6 +216,7 @@ pub async fn construct_payout_router_data<'a, F>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) @@ -364,8 +365,8 @@ pub async fn construct_refund_router_data<'a, F>( charges, integrity_object: None, refund_status: refund.refund_status, - }, + }, response: Ok(types::RefundsResponseData { connector_refund_id: connector_refund_id.unwrap_or_default(), refund_status: refund.refund_status, @@ -397,6 +398,7 @@ pub async fn construct_refund_router_data<'a, F>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) @@ -709,6 +711,7 @@ pub async fn construct_accept_dispute_router_data<'a>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } @@ -806,6 +809,7 @@ pub async fn construct_submit_evidence_router_data<'a>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } @@ -909,6 +913,7 @@ pub async fn construct_upload_file_router_data<'a>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } @@ -1032,6 +1037,7 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data<'a, F: Clone header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } @@ -1132,6 +1138,7 @@ pub async fn construct_defend_dispute_router_data<'a>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } @@ -1226,6 +1233,7 @@ pub async fn construct_retrieve_file_router_data<'a>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs index f1e84b2226a7..5add0849aed7 100644 --- a/crates/router/src/core/webhooks/utils.rs +++ b/crates/router/src/core/webhooks/utils.rs @@ -124,6 +124,7 @@ pub async fn construct_webhook_router_data<'a>( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) } diff --git a/crates/router/src/services/conversion_impls.rs b/crates/router/src/services/conversion_impls.rs index 6ac934cd2fd7..22b4b83d37b8 100644 --- a/crates/router/src/services/conversion_impls.rs +++ b/crates/router/src/services/conversion_impls.rs @@ -78,6 +78,7 @@ fn get_default_router_data( header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, } } diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 9e7fc4e204f2..43c2efee4c10 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -953,6 +953,7 @@ impl ForeignFrom<(&RouterData, T2) .connector_mandate_request_reference_id .clone(), psd2_sca_exemption_type: data.psd2_sca_exemption_type, + request_overcapture: data.request_overcapture, } } } @@ -1019,6 +1020,7 @@ impl header_payload: data.header_payload.clone(), connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, } } } diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs index c368a3fb37d0..300b733eb44e 100644 --- a/crates/router/src/types/api/verify_connector.rs +++ b/crates/router/src/types/api/verify_connector.rs @@ -119,6 +119,7 @@ impl VerifyConnectorData { header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, } } } diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs index 042008bb3188..62b880e1f666 100644 --- a/crates/router/src/utils/user/sample_data.rs +++ b/crates/router/src/utils/user/sample_data.rs @@ -361,6 +361,9 @@ pub async fn generate_sample_data( order_tax_amount: None, connector_transaction_data, connector_mandate_detail: None, + request_overcapture: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; let refund = if refunds_count < number_of_refunds && !is_failed_payment { diff --git a/crates/router/tests/connectors/mifinity.rs b/crates/router/tests/connectors/mifinity.rs index 89349be07bb2..a04480b63b4c 100644 --- a/crates/router/tests/connectors/mifinity.rs +++ b/crates/router/tests/connectors/mifinity.rs @@ -1,3 +1,4 @@ + use masking::Secret; use router::types::{self, domain, storage::enums}; use test_utils::connector_auth; diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs index 0415625f7ebb..c41e9cdf4725 100644 --- a/crates/storage_impl/src/mock_db/payment_attempt.rs +++ b/crates/storage_impl/src/mock_db/payment_attempt.rs @@ -195,6 +195,9 @@ impl PaymentAttemptInterface for MockDb { organization_id: payment_attempt.organization_id, profile_id: payment_attempt.profile_id, connector_mandate_detail: payment_attempt.connector_mandate_detail, + request_overcapture: payment_attempt.request_overcapture, + overcapture_applied: payment_attempt.overcapture_applied, + maximum_capturable_amount: payment_attempt.maximum_capturable_amount, }; payment_attempts.push(payment_attempt.clone()); Ok(payment_attempt) diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 06c7fefe85fa..5f8b00bc6629 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -564,6 +564,9 @@ impl PaymentAttemptInterface for KVRouterStore { organization_id: payment_attempt.organization_id.clone(), profile_id: payment_attempt.profile_id.clone(), connector_mandate_detail: payment_attempt.connector_mandate_detail.clone(), + request_overcapture: payment_attempt.request_overcapture, + overcapture_applied: payment_attempt.overcapture_applied, + maximum_capturable_amount: payment_attempt.maximum_capturable_amount, }; let field = format!("pa_{}", created_attempt.attempt_id); @@ -1511,6 +1514,9 @@ impl DataModelExt for PaymentAttempt { shipping_cost: self.net_amount.get_shipping_cost(), order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, + request_overcapture: self.request_overcapture, + overcapture_applied: self.overcapture_applied, + maximum_capturable_amount: self.maximum_capturable_amount, } } @@ -1587,6 +1593,9 @@ impl DataModelExt for PaymentAttempt { organization_id: storage_model.organization_id, profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, + request_overcapture: storage_model.request_overcapture, + overcapture_applied: storage_model.overcapture_applied, + maximum_capturable_amount: storage_model.maximum_capturable_amount, } } } @@ -1670,6 +1679,9 @@ impl DataModelExt for PaymentAttemptNew { shipping_cost: self.net_amount.get_shipping_cost(), order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, + request_overcapture: self.request_overcapture, + overcapture_applied: self.overcapture_applied, + maximum_capturable_amount: self.maximum_capturable_amount, } } @@ -1742,6 +1754,9 @@ impl DataModelExt for PaymentAttemptNew { organization_id: storage_model.organization_id, profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, + request_overcapture: storage_model.request_overcapture, + overcapture_applied: storage_model.overcapture_applied, + maximum_capturable_amount: storage_model.maximum_capturable_amount, } } } diff --git a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql new file mode 100644 index 000000000000..0107daec739b --- /dev/null +++ b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE payment_attempt DROP COLUMN IF EXISTS request_overcapture; +ALTER TABLE payment_attempt DROP COLUMN IF EXISTS overcapture_applied; +ALTER TABLE payment_attempt DROP COLUMN IF EXISTS maximum_capturable_amount; diff --git a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql new file mode 100644 index 000000000000..1322f79b0c51 --- /dev/null +++ b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN; +ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS overcapture_applied BOOLEAN; +ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS maximum_capturable_amount BIGINT; \ No newline at end of file From 0af1c04e4ddd5cc0c59dc59900e34ffc17541381 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Sun, 15 Dec 2024 17:38:24 +0530 Subject: [PATCH 08/64] feat(router): add fields to PaymentResponse --- connector-template/transformers.rs | 2 ++ crates/api_models/src/payments.rs | 6 ++++++ crates/diesel_models/src/lib.rs | 2 -- .../src/connectors/airwallex/transformers.rs | 4 ++++ .../src/connectors/amazonpay/transformers.rs | 2 ++ .../src/connectors/bambora/transformers.rs | 12 +++++++++++ .../connectors/bamboraapac/transformers.rs | 8 ++++++++ .../src/connectors/billwerk/transformers.rs | 2 ++ .../src/connectors/bitpay/transformers.rs | 2 ++ .../src/connectors/boku/transformers.rs | 2 ++ .../src/connectors/cashtocode/transformers.rs | 4 ++++ .../src/connectors/coinbase/transformers.rs | 2 ++ .../src/connectors/cryptopay/transformers.rs | 2 ++ .../connectors/deutschebank/transformers.rs | 8 ++++++++ .../connectors/digitalvirgo/transformers.rs | 4 ++++ .../src/connectors/dlocal/transformers.rs | 8 ++++++++ .../src/connectors/elavon/transformers.rs | 6 ++++++ .../src/connectors/fiserv/transformers.rs | 4 ++++ .../src/connectors/fiservemea/transformers.rs | 2 ++ .../src/connectors/fiuu/transformers.rs | 18 +++++++++++++++++ .../src/connectors/forte/transformers.rs | 8 ++++++++ .../src/connectors/globepay/transformers.rs | 4 ++++ .../src/connectors/gocardless/transformers.rs | 6 ++++++ .../src/connectors/helcim/transformers.rs | 10 ++++++++++ .../src/connectors/inespay/transformers.rs | 2 ++ .../src/connectors/jpmorgan/transformers.rs | 2 ++ .../src/connectors/mollie/transformers.rs | 2 ++ .../connectors/multisafepay/transformers.rs | 2 ++ .../src/connectors/nexinets/transformers.rs | 4 ++++ .../src/connectors/nexixpay/transformers.rs | 14 +++++++++++++ .../src/connectors/nomupay/transformers.rs | 2 ++ .../src/connectors/novalnet/transformers.rs | 8 ++++++++ .../src/connectors/payeezy/transformers.rs | 2 ++ .../src/connectors/payu/transformers.rs | 8 ++++++++ .../src/connectors/powertranz/transformers.rs | 2 ++ .../src/connectors/prophetpay/transformers.rs | 8 ++++++++ .../src/connectors/rapyd/transformers.rs | 2 ++ .../src/connectors/razorpay/transformers.rs | 4 ++++ .../src/connectors/redsys/transformers.rs | 2 ++ .../src/connectors/shift4/transformers.rs | 4 ++++ .../src/connectors/square/transformers.rs | 2 ++ .../src/connectors/stax/transformers.rs | 2 ++ .../src/connectors/thunes/transformers.rs | 2 ++ .../src/connectors/tsys/transformers.rs | 4 ++++ .../src/connectors/volt/transformers.rs | 6 ++++++ .../src/connectors/worldline/transformers.rs | 4 ++++ .../src/connectors/worldpay.rs | 6 ++++++ .../src/connectors/worldpay/transformers.rs | 2 ++ .../src/connectors/xendit/transformers.rs | 2 ++ .../src/connectors/zen/transformers.rs | 4 ++++ .../src/connectors/zsl/transformers.rs | 4 ++++ .../src/router_data.rs | 4 ++++ .../src/router_response_types.rs | 9 +++++++++ .../router/src/connector/aci/transformers.rs | 2 ++ .../src/connector/adyen/transformers.rs | 19 ++++++++++++++++++ .../connector/authorizedotnet/transformers.rs | 8 ++++++++ .../connector/bankofamerica/transformers.rs | 8 ++++++++ crates/router/src/connector/bluesnap.rs | 2 ++ .../src/connector/bluesnap/transformers.rs | 2 ++ .../src/connector/braintree/transformers.rs | 18 +++++++++++++++++ .../src/connector/checkout/transformers.rs | 8 ++++++++ .../src/connector/cybersource/transformers.rs | 12 +++++++++++ .../src/connector/datatrans/transformers.rs | 4 ++++ .../connector/dummyconnector/transformers.rs | 2 ++ .../src/connector/globalpay/transformers.rs | 3 +++ .../src/connector/iatapay/transformers.rs | 4 ++++ .../src/connector/itaubank/transformers.rs | 4 ++++ .../src/connector/klarna/transformers.rs | 6 ++++++ .../src/connector/mifinity/transformers.rs | 10 ++++++++++ .../router/src/connector/nmi/transformers.rs | 14 +++++++++++++ .../router/src/connector/noon/transformers.rs | 2 ++ .../src/connector/nuvei/transformers.rs | 2 ++ .../src/connector/opayo/transformers.rs | 2 ++ .../src/connector/opennode/transformers.rs | 2 ++ .../src/connector/paybox/transformers.rs | 10 ++++++++++ .../src/connector/payme/transformers.rs | 8 ++++++++ crates/router/src/connector/paypal.rs | 4 ++++ .../src/connector/paypal/transformers.rs | 20 +++++++++++++++++++ .../src/connector/placetopay/transformers.rs | 2 ++ .../src/connector/plaid/transformers.rs | 4 ++++ .../src/connector/stripe/transformers.rs | 8 ++++++++ .../src/connector/trustpay/transformers.rs | 10 ++++++++++ .../src/connector/wellsfargo/transformers.rs | 8 ++++++++ .../wellsfargopayout/transformers.rs | 2 ++ .../payments/operations/payment_create.rs | 6 +++++- .../payments/operations/payment_response.rs | 6 ++++-- crates/router/src/core/payments/retry.rs | 6 ++++-- .../router/src/core/payments/transformers.rs | 6 ++++++ .../src/types/storage/payment_attempt.rs | 7 +++++++ crates/router/tests/connectors/utils.rs | 3 +++ 90 files changed, 484 insertions(+), 7 deletions(-) diff --git a/connector-template/transformers.rs b/connector-template/transformers.rs index b508596cbc08..8d26b881e529 100644 --- a/connector-template/transformers.rs +++ b/connector-template/transformers.rs @@ -139,6 +139,8 @@ impl TryFrom, + + /// Whether the payment is overcaptureable or not + pub overcapture_applied: Option, + + /// Maximum capturable amount + pub maximum_capturable_amount: Option, } // Serialize is implemented because, this will be serialized in the api events. diff --git a/crates/diesel_models/src/lib.rs b/crates/diesel_models/src/lib.rs index 23de55cf04a4..d07f84aa65e2 100644 --- a/crates/diesel_models/src/lib.rs +++ b/crates/diesel_models/src/lib.rs @@ -1,5 +1,3 @@ -#![recursion_limit = "128"] - pub mod address; pub mod api_keys; pub mod blocklist_lookup; diff --git a/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs b/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs index 97c9ed4d36a4..9a720aa00948 100644 --- a/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs @@ -583,6 +583,8 @@ impl TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -594,6 +600,8 @@ impl connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -629,6 +637,8 @@ impl connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -664,6 +674,8 @@ impl connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs b/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs index f4399d105c5d..bfd4136b0f11 100644 --- a/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs @@ -314,6 +314,8 @@ impl connector_response_reference_id: Some(connector_transaction_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -486,6 +488,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -632,6 +636,8 @@ impl connector_response_reference_id: Some(connector_transaction_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -911,6 +917,8 @@ impl connector_response_reference_id: Some(connector_transaction_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs b/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs index 05b9abae0515..23b61fbbc269 100644 --- a/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs @@ -292,6 +292,8 @@ impl TryFrom TryFrom TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs b/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs index 7a70d97a102c..06c04b0f2770 100644 --- a/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs @@ -275,6 +275,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ) } @@ -308,6 +310,8 @@ impl TryFrom TryFrom .or(Some(item.response.data.id)), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; match amount_captured_in_minor_units { diff --git a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs index 328940d83aee..799451bb5d44 100644 --- a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs @@ -337,6 +337,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -385,6 +387,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -588,6 +592,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -647,6 +653,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: if item.response.rc == "0" { common_enums::AttemptStatus::Charged diff --git a/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs b/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs index a9408e4e1c52..74ea4e7dbfb8 100644 --- a/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs @@ -168,6 +168,8 @@ impl TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: Some(response.ssl_txn_id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } } @@ -392,6 +394,8 @@ impl TryFrom> for PaymentsSyn connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -451,6 +455,8 @@ impl TryFrom> connector_response_reference_id: Some(response.ssl_txn_id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } } diff --git a/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs b/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs index f4084525410e..b26f04905f8b 100644 --- a/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs @@ -386,6 +386,8 @@ impl TryFrom TryFrom TryFrom connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -794,6 +796,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -850,6 +854,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -896,6 +902,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Self { @@ -915,6 +923,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }); Self { response, @@ -1164,6 +1174,8 @@ impl TryFrom> for PaymentsSy connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -1225,6 +1237,8 @@ impl TryFrom> for PaymentsSy connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -1394,6 +1408,8 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -1505,6 +1521,8 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok(Self { status, diff --git a/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs b/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs index 2583f47058bf..540a3ef286c8 100644 --- a/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs @@ -309,6 +309,8 @@ impl TryFrom TryFrom> connector_response_reference_id: Some(item.response.transaction_id.to_string()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), amount_captured: None, ..item.data @@ -489,6 +495,8 @@ impl TryFrom TryFrom TryFrom mandate_reference: Box::new(mandate_reference), network_txn_id: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: AttemptStatus::Charged, ..item.data @@ -686,6 +688,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -717,6 +721,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs b/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs index 4a8ddf68df9a..d3b5ae47b38e 100644 --- a/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs @@ -388,6 +388,8 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -439,6 +441,8 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -488,6 +492,8 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -568,6 +574,8 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -625,6 +633,8 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data diff --git a/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs index 296d76546c84..e1f8134eba01 100644 --- a/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs @@ -136,6 +136,8 @@ impl TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: Some(item.response.operation.order_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -830,6 +832,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -849,6 +853,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -972,6 +978,8 @@ impl connector_response_reference_id: Some(item.response.operation.order_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1144,6 +1152,8 @@ impl connector_response_reference_id: Some(item.response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1202,6 +1212,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1265,6 +1277,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs index bea8b607daea..de641ff1a735 100644 --- a/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs @@ -136,6 +136,8 @@ impl TryFrom TryFrom connector_response_reference_id: transaction_id.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1088,6 +1092,8 @@ impl connector_response_reference_id: transaction_id.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1257,6 +1263,8 @@ impl connector_response_reference_id: transaction_id.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs b/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs index 49188803c4f6..2c6598ea086a 100644 --- a/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs @@ -448,6 +448,8 @@ impl TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -412,6 +414,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -460,6 +464,8 @@ impl TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -807,6 +809,8 @@ impl TryFrom TryFrom TryFrom TryFrom PaymentsResponseDa connector_response_reference_id: Some(connector_response.transaction_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } @@ -276,6 +278,8 @@ fn get_payments_sync_response( ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } diff --git a/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs b/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs index 61cf91c87cb8..28cf5e33dcf1 100644 --- a/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs @@ -285,6 +285,8 @@ impl TryFrom TryFrom TryFrom TryFrom> connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -635,6 +637,8 @@ impl TryFrom for Wo connector_response_reference_id: optional_correlation_id, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..data.clone() }) @@ -531,6 +533,8 @@ impl ConnectorIntegration for Wor connector_response_reference_id: optional_correlation_id, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..data.clone() }) @@ -632,6 +636,8 @@ impl ConnectorIntegration fo connector_response_reference_id: optional_correlation_id, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..data.clone() }) diff --git a/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs index ec23b520a200..2c5f295f187d 100644 --- a/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs @@ -729,6 +729,8 @@ impl connector_response_reference_id: optional_correlation_id.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), (Some(reason), _) => Err(ErrorResponse { code: worldpay_status.to_string(), diff --git a/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs b/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs index c9d4cd2583c2..5daad7f15b8a 100644 --- a/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs @@ -136,6 +136,8 @@ impl TryFrom TryFrom TryFrom TryFrom { let attempt_status = self.status; let connector_payment_id = match resource_id { @@ -579,6 +581,8 @@ impl TrackerPostUpdateObjects { let attempt_status = self.status; let connector_payment_id = match resource_id { diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs index 89eb7f9b3cdb..f1816d7a65f5 100644 --- a/crates/hyperswitch_domain_models/src/router_response_types.rs +++ b/crates/hyperswitch_domain_models/src/router_response_types.rs @@ -27,6 +27,8 @@ pub enum PaymentsResponseData { connector_response_reference_id: Option, incremental_authorization_allowed: Option, charge_id: Option, + overcapture_applied: Option, + maximum_capturable_amount: Option, }, MultipleCaptureResponse { // pending_capture_id_list: Vec, @@ -164,6 +166,8 @@ impl PaymentsResponseData { connector_response_reference_id: auth_connector_response_reference_id, incremental_authorization_allowed: auth_incremental_auth_allowed, charge_id: auth_charge_id, + overcapture_applied: auth_overcapture_applied, + maximum_capturable_amount: auth_maximum_capturable_amount, }, Self::TransactionResponse { resource_id: capture_resource_id, @@ -174,6 +178,8 @@ impl PaymentsResponseData { connector_response_reference_id: capture_connector_response_reference_id, incremental_authorization_allowed: capture_incremental_auth_allowed, charge_id: capture_charge_id, + overcapture_applied: _, + maximum_capturable_amount: _, }, ) => Ok(Self::TransactionResponse { resource_id: capture_resource_id.clone(), @@ -199,6 +205,9 @@ impl PaymentsResponseData { incremental_authorization_allowed: (*capture_incremental_auth_allowed) .or(*auth_incremental_auth_allowed), charge_id: capture_charge_id.clone().or(auth_charge_id.clone()), + overcapture_applied: auth_overcapture_applied + .clone(), + maximum_capturable_amount: auth_maximum_capturable_amount.clone(), }), _ => Err(ApiErrorResponse::NotSupported { message: "Invalid Flow ".to_owned(), diff --git a/crates/router/src/connector/aci/transformers.rs b/crates/router/src/connector/aci/transformers.rs index 3e25799c02e6..f4693e73ff16 100644 --- a/crates/router/src/connector/aci/transformers.rs +++ b/crates/router/src/connector/aci/transformers.rs @@ -772,6 +772,8 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index 16cab2fda470..a30b803b6207 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -1555,6 +1555,7 @@ impl TryFrom<&AdyenRouterData<&types::PaymentsAuthorizeRouterData>> for AdyenPay fn try_from( item: &AdyenRouterData<&types::PaymentsAuthorizeRouterData>, ) -> Result { + println!("$$$$$4request_overcapture: {:?}", item.router_data.request_overcapture); match item .router_data .request @@ -3361,6 +3362,8 @@ impl TryFrom> connector_response_reference_id: Some(item.response.reference), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -3396,6 +3399,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), payment_method_balance: Some(types::PaymentMethodBalance { currency: item.response.balance.currency, @@ -3466,6 +3471,8 @@ pub fn get_adyen_response( connector_response_reference_id: Some(response.merchant_reference), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3533,6 +3540,8 @@ pub fn get_webhook_response( connector_response_reference_id: Some(response.merchant_reference_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3609,6 +3618,8 @@ pub fn get_redirection_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3670,6 +3681,8 @@ pub fn get_present_to_shopper_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3730,6 +3743,8 @@ pub fn get_qr_code_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3773,6 +3788,8 @@ pub fn get_redirection_error_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) @@ -4140,6 +4157,8 @@ impl TryFrom> connector_response_reference_id: Some(item.response.reference), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), amount_captured: Some(0), ..item.data diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs index 9698b4ac5d83..9c5d90902c7a 100644 --- a/crates/router/src/connector/authorizedotnet/transformers.rs +++ b/crates/router/src/connector/authorizedotnet/transformers.rs @@ -408,6 +408,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -1143,6 +1145,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), }, ..item.data @@ -1216,6 +1220,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), }, ..item.data @@ -1541,6 +1547,8 @@ impl connector_response_reference_id: Some(transaction.transaction_id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: payment_status, ..item.data diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 71cc006700e4..3894fbc348ed 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -427,6 +427,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), }, connector_response, @@ -1533,6 +1535,8 @@ fn get_payment_response( ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } } @@ -1846,6 +1850,8 @@ impl .unwrap_or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), connector_response, ..item.data @@ -1865,6 +1871,8 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/bluesnap.rs b/crates/router/src/connector/bluesnap.rs index dc508a3491d6..a6793871755c 100644 --- a/crates/router/src/connector/bluesnap.rs +++ b/crates/router/src/connector/bluesnap.rs @@ -752,6 +752,8 @@ impl ConnectorIntegration connector_response_reference_id: Some(item.response.transaction_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/braintree/transformers.rs b/crates/router/src/connector/braintree/transformers.rs index 00624ce0f9b1..e24330f3938d 100644 --- a/crates/router/src/connector/braintree/transformers.rs +++ b/crates/router/src/connector/braintree/transformers.rs @@ -451,6 +451,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -474,6 +476,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -627,6 +631,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -650,6 +656,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -710,6 +718,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -775,6 +785,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -1283,6 +1295,8 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -1393,6 +1407,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -1498,6 +1514,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs index cd758fffb690..6e7750c8d448 100644 --- a/crates/router/src/connector/checkout/transformers.rs +++ b/crates/router/src/connector/checkout/transformers.rs @@ -701,6 +701,8 @@ impl TryFrom> ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -754,6 +756,8 @@ impl TryFrom> ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -830,6 +834,8 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: response.into(), ..item.data @@ -931,6 +937,8 @@ impl TryFrom> connector_response_reference_id: item.response.reference, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status, amount_captured, diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 7ce98d3d5a34..693f94210b1a 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -2576,6 +2576,8 @@ fn get_payment_response( ), incremental_authorization_allowed, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } } @@ -2673,6 +2675,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -3081,6 +3085,8 @@ impl connector_response_reference_id, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -3338,6 +3344,8 @@ impl mandate_status == enums::AttemptStatus::Authorized, ), charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), }, connector_response, @@ -3467,6 +3475,8 @@ impl .unwrap_or(Some(item.response.id)), incremental_authorization_allowed, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -3485,6 +3495,8 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/datatrans/transformers.rs b/crates/router/src/connector/datatrans/transformers.rs index 7d52e64b4b7c..87bea907d072 100644 --- a/crates/router/src/connector/datatrans/transformers.rs +++ b/crates/router/src/connector/datatrans/transformers.rs @@ -301,6 +301,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } }; @@ -419,6 +421,8 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/dummyconnector/transformers.rs b/crates/router/src/connector/dummyconnector/transformers.rs index 79caa3d0a767..0f3f779f8806 100644 --- a/crates/router/src/connector/dummyconnector/transformers.rs +++ b/crates/router/src/connector/dummyconnector/transformers.rs @@ -260,6 +260,8 @@ impl TryFrom types::PaymentsResponseData::TransactionResponse { @@ -401,6 +403,8 @@ fn get_iatpay_response( connector_response_reference_id: connector_response_reference_id.clone(), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }, }; diff --git a/crates/router/src/connector/itaubank/transformers.rs b/crates/router/src/connector/itaubank/transformers.rs index 127f8526afe4..2e8b678323e8 100644 --- a/crates/router/src/connector/itaubank/transformers.rs +++ b/crates/router/src/connector/itaubank/transformers.rs @@ -288,6 +288,8 @@ impl connector_response_reference_id: Some(item.response.txid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -376,6 +378,8 @@ impl connector_response_reference_id: Some(item.response.txid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rs index 803dc4a428d2..27566a39aa7a 100644 --- a/crates/router/src/connector/klarna/transformers.rs +++ b/crates/router/src/connector/klarna/transformers.rs @@ -270,6 +270,8 @@ impl TryFrom> connector_response_reference_id: Some(item.response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status: enums::AttemptStatus::foreign_from(( item.response.fraud_status, @@ -395,6 +397,8 @@ impl .or(Some(item.response.order_id)), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -472,6 +476,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), status, ..item.data diff --git a/crates/router/src/connector/mifinity/transformers.rs b/crates/router/src/connector/mifinity/transformers.rs index 1e2c420c767b..0daa44c230ab 100644 --- a/crates/router/src/connector/mifinity/transformers.rs +++ b/crates/router/src/connector/mifinity/transformers.rs @@ -269,6 +269,8 @@ impl connector_response_reference_id: Some(trace_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -284,6 +286,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -353,6 +357,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -368,6 +374,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -384,6 +392,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 4c33f0200172..2a6a94c6dd4e 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -213,6 +213,8 @@ impl connector_response_reference_id: Some(item.response.transactionid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::AuthenticationPending, ), @@ -367,6 +369,8 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method @@ -751,6 +755,8 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::CaptureInitiated, ), @@ -846,6 +852,8 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::Charged, ), @@ -903,6 +911,8 @@ impl TryFrom> connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method @@ -954,6 +964,8 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::VoidInitiated, ), @@ -1005,6 +1017,8 @@ impl TryFrom connector_response_reference_id, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } }, diff --git a/crates/router/src/connector/nuvei/transformers.rs b/crates/router/src/connector/nuvei/transformers.rs index 121ec1d7b7ce..f5d03a798415 100644 --- a/crates/router/src/connector/nuvei/transformers.rs +++ b/crates/router/src/connector/nuvei/transformers.rs @@ -1627,6 +1627,8 @@ where connector_response_reference_id: response.order_id, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }, ..item.data diff --git a/crates/router/src/connector/opayo/transformers.rs b/crates/router/src/connector/opayo/transformers.rs index f55aa4325b06..8e2e8b0bb8e1 100644 --- a/crates/router/src/connector/opayo/transformers.rs +++ b/crates/router/src/connector/opayo/transformers.rs @@ -152,6 +152,8 @@ impl connector_response_reference_id: Some(item.response.transaction_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/opennode/transformers.rs b/crates/router/src/connector/opennode/transformers.rs index 1e8239d377bb..30a07865f719 100644 --- a/crates/router/src/connector/opennode/transformers.rs +++ b/crates/router/src/connector/opennode/transformers.rs @@ -145,6 +145,8 @@ impl connector_response_reference_id: item.response.data.order_id, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } else { Ok(types::PaymentsResponseData::TransactionUnresolvedResponse { diff --git a/crates/router/src/connector/paybox/transformers.rs b/crates/router/src/connector/paybox/transformers.rs index 80e3e0ef0752..8b0030079ab5 100644 --- a/crates/router/src/connector/paybox/transformers.rs +++ b/crates/router/src/connector/paybox/transformers.rs @@ -693,6 +693,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), amount_captured: None, ..item.data @@ -764,6 +766,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -793,6 +797,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -838,6 +844,8 @@ impl TryFrom connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/payme/transformers.rs b/crates/router/src/connector/payme/transformers.rs index 7b6b67c8408e..beb9bba5e39e 100644 --- a/crates/router/src/connector/payme/transformers.rs +++ b/crates/router/src/connector/payme/transformers.rs @@ -260,6 +260,8 @@ impl TryFrom<&PaymePaySaleResponse> for types::PaymentsResponseData { connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) } } @@ -327,6 +329,8 @@ impl From<&SaleQuery> for types::PaymentsResponseData { connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } } @@ -547,6 +551,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -1124,6 +1130,8 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; Ok(Self { diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs index 375853e27a02..8fcd08fbb3e3 100644 --- a/crates/router/src/connector/paypal.rs +++ b/crates/router/src/connector/paypal.rs @@ -1227,6 +1227,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..data.clone() }) @@ -1278,6 +1280,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..data.clone() }) diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs index 11e01b78e134..0e48d64ff759 100644 --- a/crates/router/src/connector/paypal/transformers.rs +++ b/crates/router/src/connector/paypal/transformers.rs @@ -607,6 +607,8 @@ impl connector_response_reference_id: Some(info_response.id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1840,6 +1842,8 @@ impl .or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1965,6 +1969,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -2020,6 +2026,8 @@ impl ), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -2073,6 +2081,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -2111,6 +2121,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -2164,6 +2176,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -2233,6 +2247,8 @@ impl .or(Some(item.response.supplementary_data.related_ids.order_id)), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -2574,6 +2590,8 @@ impl TryFrom> .or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), amount_captured: Some(amount_captured), ..item.data @@ -2626,6 +2644,8 @@ impl .or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/placetopay/transformers.rs b/crates/router/src/connector/placetopay/transformers.rs index d809b9e770d8..72c0d213f41f 100644 --- a/crates/router/src/connector/placetopay/transformers.rs +++ b/crates/router/src/connector/placetopay/transformers.rs @@ -275,6 +275,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/plaid/transformers.rs b/crates/router/src/connector/plaid/transformers.rs index 29d4db1297f8..c2a85f684e69 100644 --- a/crates/router/src/connector/plaid/transformers.rs +++ b/crates/router/src/connector/plaid/transformers.rs @@ -315,6 +315,8 @@ impl connector_response_reference_id: Some(item.response.payment_id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }, ..item.data @@ -401,6 +403,8 @@ impl TryFrom connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; @@ -2711,6 +2713,8 @@ impl connector_response_reference_id: Some(item.response.id.clone()), incremental_authorization_allowed: None, charge_id, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; @@ -2791,6 +2795,8 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }) }; @@ -3496,6 +3502,8 @@ impl TryFrom .unwrap_or(Some(item.response.id)), incremental_authorization_allowed, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -2178,6 +2184,8 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/wellsfargopayout/transformers.rs b/crates/router/src/connector/wellsfargopayout/transformers.rs index 135cb5f53cbf..95adab56f753 100644 --- a/crates/router/src/connector/wellsfargopayout/transformers.rs +++ b/crates/router/src/connector/wellsfargopayout/transformers.rs @@ -141,6 +141,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index e8b761bc401f..2d17547b0c1d 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -323,6 +323,7 @@ impl GetTracker, api::PaymentsRequest> for Pa &payment_method_info, merchant_key_store, profile_id, + &business_profile, &customer_acceptance, ) .await?; @@ -1099,6 +1100,7 @@ impl PaymentCreate { payment_method_info: &Option, _key_store: &domain::MerchantKeyStore, profile_id: common_utils::id_type::ProfileId, + business_profile: &domain::Profile, customer_acceptance: &Option, ) -> RouterResult<( storage::PaymentAttemptNew, @@ -1134,6 +1136,8 @@ impl PaymentCreate { .transpose()? .flatten(); + let request_overcapture = request.request_overcapture.or(Some(business_profile.always_request_overcapture)); + if additional_pm_data.is_none() { // If recurring payment is made using payment_method_id, then fetch payment_method_data from retrieved payment_method object additional_pm_data = payment_method_info.as_ref().and_then(|pm_info| { @@ -1282,7 +1286,7 @@ impl PaymentCreate { organization_id: organization_id.clone(), profile_id, connector_mandate_detail: None, - request_overcapture: request.request_overcapture, + request_overcapture, overcapture_applied: None, maximum_capturable_amount: None, }, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 3a756062fe79..6bb40b942292 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1532,6 +1532,8 @@ async fn payment_response_update_tracker( connector_response_reference_id, incremental_authorization_allowed, charge_id, + overcapture_applied, + maximum_capturable_amount, .. } => { payment_data @@ -1733,8 +1735,8 @@ async fn payment_response_update_tracker( .payment_attempt .connector_mandate_detail .clone(), - overcapture_applied: None, // todooooooo - maximum_capturable_amount: None, + overcapture_applied, + maximum_capturable_amount, }), ), }; diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 903a25077f67..41bd87323c7c 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -421,6 +421,8 @@ where connector_metadata, redirection_data, charge_id, + overcapture_applied, + maximum_capturable_amount, .. }) => { let encoded_data = payment_data.get_payment_attempt().encoded_data.clone(); @@ -467,8 +469,8 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_applied, + maximum_capturable_amount, }; #[cfg(feature = "v1")] diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 321d05964127..450816f69b77 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -716,6 +716,8 @@ where connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }); let additional_data = PaymentAdditionalData { @@ -2081,6 +2083,8 @@ where order_tax_amount, connector_mandate_id, shipping_cost: payment_intent.shipping_cost, + overcapture_applied: payment_attempt.overcapture_applied, + maximum_capturable_amount: payment_attempt.maximum_capturable_amount, }; services::ApplicationResponse::JsonWithHeaders((payments_response, headers)) @@ -2338,6 +2342,8 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay order_tax_amount: None, connector_mandate_id:None, shipping_cost: None, + overcapture_applied: pa.overcapture_applied, + maximum_capturable_amount: pa.maximum_capturable_amount, } } } diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index 0291374d54f6..3c30df9ad2ae 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -217,6 +217,9 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), + request_overcapture: Default::default(), + overcapture_applied: Default::default(), + maximum_capturable_amount: Default::default(), }; let store = state @@ -301,6 +304,8 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), + overcapture_applied: Default::default(), + maximum_capturable_amount: Default::default(), }; let store = state .stores @@ -398,6 +403,8 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), + overcapture_applied: Default::default(), + maximum_capturable_amount: Default::default(), }; let store = state .stores diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index c08139ae6fe0..c8ffb78f5238 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -549,6 +549,7 @@ pub trait ConnectorActions: Connector { header_payload: None, connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, } } @@ -1121,6 +1122,8 @@ pub fn get_connector_metadata( connector_response_reference_id: _, incremental_authorization_allowed: _, charge_id: _, + overcapture_applied: _, + maximum_capturable_amount: _, }) => connector_metadata, _ => None, } From c3e7343630f5e4f47ac3653a799985eb578f6ab8 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:27:06 +0000 Subject: [PATCH 09/64] chore: run formatter --- crates/diesel_models/src/payment_attempt.rs | 24 +++++++++---------- .../src/connectors/bambora/transformers.rs | 4 ++-- .../connectors/bamboraapac/transformers.rs | 8 +++---- .../src/connectors/billwerk/transformers.rs | 2 +- .../src/connectors/cashtocode/transformers.rs | 2 +- .../connectors/deutschebank/transformers.rs | 8 +++---- .../src/connectors/dlocal/transformers.rs | 2 +- .../src/connectors/elavon/transformers.rs | 4 ++-- .../src/connectors/fiuu/transformers.rs | 18 +++++++------- .../src/connectors/globepay/transformers.rs | 4 ++-- .../connectors/multisafepay/transformers.rs | 2 +- .../src/connectors/nexixpay/transformers.rs | 4 ++-- .../src/connectors/novalnet/transformers.rs | 8 +++---- .../src/connectors/paybox/transformers.rs | 10 ++++---- .../src/connectors/prophetpay/transformers.rs | 6 ++--- .../src/connectors/rapyd/transformers.rs | 2 +- .../src/connectors/razorpay/transformers.rs | 2 +- .../src/connectors/tsys/transformers.rs | 4 ++-- .../src/connectors/volt/transformers.rs | 4 ++-- .../src/connectors/worldpay.rs | 4 ++-- .../src/connectors/zen/transformers.rs | 2 +- .../src/connectors/zsl/transformers.rs | 4 ++-- .../src/payments/payment_attempt.rs | 4 ++-- .../src/router_data.rs | 4 ++-- .../src/router_response_types.rs | 7 +++--- .../src/connector/adyen/transformers.rs | 5 +++- .../src/connector/globalpay/transformers.rs | 3 +-- .../src/connector/iatapay/transformers.rs | 2 +- .../src/connector/mifinity/transformers.rs | 10 ++++---- .../router/src/connector/nmi/transformers.rs | 14 +++++------ .../router/src/connector/noon/transformers.rs | 2 +- .../src/connector/nuvei/transformers.rs | 2 +- .../src/connector/payme/transformers.rs | 6 ++--- .../src/connector/plaid/transformers.rs | 2 +- .../src/connector/trustpay/transformers.rs | 4 ++-- .../payments/operations/payment_confirm.rs | 3 ++- .../payments/operations/payment_create.rs | 8 +++++-- .../payments/operations/payment_response.rs | 2 +- .../payments/operations/payment_update.rs | 12 ++++++---- crates/router/src/core/payments/retry.rs | 1 - crates/router/src/core/utils.rs | 1 - crates/router/tests/connectors/mifinity.rs | 1 - .../src/payments/payment_attempt.rs | 4 ++-- 43 files changed, 115 insertions(+), 110 deletions(-) diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index bd3df31f3469..ea2ff63d9c93 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -1118,7 +1118,8 @@ impl PaymentAttemptUpdate { connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail), request_overcapture: request_overcapture.or(source.request_overcapture), overcapture_applied: overcapture_applied.or(source.overcapture_applied), - maximum_capturable_amount: maximum_capturable_amount.or(source.maximum_capturable_amount), + maximum_capturable_amount: maximum_capturable_amount + .or(source.maximum_capturable_amount), ..source } } @@ -2711,8 +2712,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail, request_overcapture: None, - overcapture_applied, - maximum_capturable_amount, + overcapture_applied, + maximum_capturable_amount, } } PaymentAttemptUpdate::ErrorUpdate { @@ -2787,9 +2788,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, - + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self { @@ -2982,8 +2982,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::PreprocessingUpdate { @@ -3243,8 +3243,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { @@ -3436,8 +3436,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_applied: None, + maximum_capturable_amount: None, } } PaymentAttemptUpdate::PostSessionTokensUpdate { diff --git a/crates/hyperswitch_connectors/src/connectors/bambora/transformers.rs b/crates/hyperswitch_connectors/src/connectors/bambora/transformers.rs index 97f940a23d2f..cc328e40e825 100644 --- a/crates/hyperswitch_connectors/src/connectors/bambora/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/bambora/transformers.rs @@ -480,7 +480,7 @@ impl TryFrom TryFrom incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -489,7 +489,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -637,7 +637,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -918,7 +918,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs b/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs index 23b61fbbc269..088b41c7dd6c 100644 --- a/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs @@ -293,7 +293,7 @@ impl TryFrom incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ) } diff --git a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs index de4ab4446d80..aa3d0d1cae9b 100644 --- a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs @@ -353,7 +353,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -406,7 +406,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -620,7 +620,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -695,7 +695,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs index c6ac660f43ab..c38767ae146c 100644 --- a/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/dlocal/transformers.rs @@ -337,7 +337,7 @@ impl TryFrom incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) } } @@ -456,7 +456,7 @@ impl TryFrom> incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) } } diff --git a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs index 35e83cc3836d..57ae5117827d 100644 --- a/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs @@ -759,7 +759,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -797,7 +797,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -855,7 +855,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) }; Ok(Self { @@ -903,7 +903,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) }; Self { @@ -924,7 +924,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }); Self { response, @@ -1197,7 +1197,7 @@ impl TryFrom> for PaymentsSy incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -1260,7 +1260,7 @@ impl TryFrom> for PaymentsSy incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -1431,7 +1431,7 @@ impl TryFrom> incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }; Ok(Self { status, @@ -1544,7 +1544,7 @@ impl TryFrom> incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }; Ok(Self { status, diff --git a/crates/hyperswitch_connectors/src/connectors/globepay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/globepay/transformers.rs index d91219abc377..9d2f77097313 100644 --- a/crates/hyperswitch_connectors/src/connectors/globepay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/globepay/transformers.rs @@ -222,7 +222,7 @@ impl TryFrom TryFrom TryFrom incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -854,7 +854,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs b/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs index 3940f0313024..eb3117b64cdd 100644 --- a/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/novalnet/transformers.rs @@ -603,7 +603,7 @@ impl TryFrom incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1093,7 +1093,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -1264,7 +1264,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs index e1c767e0227c..bdb5b0940028 100644 --- a/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs @@ -701,7 +701,7 @@ impl TryFrom TryFrom TryFrom TryFrom incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/hyperswitch_connectors/src/connectors/prophetpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/prophetpay/transformers.rs index acf087d432af..d1253e03a79c 100644 --- a/crates/hyperswitch_connectors/src/connectors/prophetpay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/prophetpay/transformers.rs @@ -415,7 +415,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -465,7 +465,7 @@ impl TryFrom TryFrom TryFrom TryFrom PaymentsResponseDa incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, } } @@ -279,7 +279,7 @@ fn get_payments_sync_response( incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, } } diff --git a/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs b/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs index 28cf5e33dcf1..2b84e0f1488b 100644 --- a/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs @@ -364,7 +364,7 @@ impl TryFrom TryFrom for Wo incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..data.clone() }) @@ -637,7 +637,7 @@ impl ConnectorIntegration fo incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..data.clone() }) diff --git a/crates/hyperswitch_connectors/src/connectors/zen/transformers.rs b/crates/hyperswitch_connectors/src/connectors/zen/transformers.rs index a0051a022e5f..4b4d54e9db00 100644 --- a/crates/hyperswitch_connectors/src/connectors/zen/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/zen/transformers.rs @@ -951,7 +951,7 @@ fn get_zen_response( incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }; Ok((status, error, payment_response_data)) } diff --git a/crates/hyperswitch_connectors/src/connectors/zsl/transformers.rs b/crates/hyperswitch_connectors/src/connectors/zsl/transformers.rs index 1a23c825f9f9..a5b5cb9bdbd0 100644 --- a/crates/hyperswitch_connectors/src/connectors/zsl/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/zsl/transformers.rs @@ -336,7 +336,7 @@ impl TryFrom TryFrom DieselPaymentAttemptUpdate::ConfirmUpdate { amount: net_amount.get_order_amount(), currency, @@ -1128,7 +1128,7 @@ impl PaymentAttemptUpdate { order_tax_amount: net_amount.get_order_tax_amount(), connector_mandate_detail, overcapture_applied, - maximum_capturable_amount + maximum_capturable_amount, }, Self::VoidUpdate { status, diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index b39f82264bf1..be91e9e8f705 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -465,7 +465,7 @@ impl incremental_authorization_allowed, charge_id, overcapture_applied, - maximum_capturable_amount, + maximum_capturable_amount, } => { let attempt_status = self.status; let connector_payment_id = match resource_id { @@ -583,7 +583,7 @@ impl TrackerPostUpdateObjects { let attempt_status = self.status; let connector_payment_id = match resource_id { diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs index f1816d7a65f5..19fcfbda34b8 100644 --- a/crates/hyperswitch_domain_models/src/router_response_types.rs +++ b/crates/hyperswitch_domain_models/src/router_response_types.rs @@ -167,7 +167,7 @@ impl PaymentsResponseData { incremental_authorization_allowed: auth_incremental_auth_allowed, charge_id: auth_charge_id, overcapture_applied: auth_overcapture_applied, - maximum_capturable_amount: auth_maximum_capturable_amount, + maximum_capturable_amount: auth_maximum_capturable_amount, }, Self::TransactionResponse { resource_id: capture_resource_id, @@ -179,7 +179,7 @@ impl PaymentsResponseData { incremental_authorization_allowed: capture_incremental_auth_allowed, charge_id: capture_charge_id, overcapture_applied: _, - maximum_capturable_amount: _, + maximum_capturable_amount: _, }, ) => Ok(Self::TransactionResponse { resource_id: capture_resource_id.clone(), @@ -205,8 +205,7 @@ impl PaymentsResponseData { incremental_authorization_allowed: (*capture_incremental_auth_allowed) .or(*auth_incremental_auth_allowed), charge_id: capture_charge_id.clone().or(auth_charge_id.clone()), - overcapture_applied: auth_overcapture_applied - .clone(), + overcapture_applied: auth_overcapture_applied.clone(), maximum_capturable_amount: auth_maximum_capturable_amount.clone(), }), _ => Err(ApiErrorResponse::NotSupported { diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index a30b803b6207..fd20c9fb5520 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -1555,7 +1555,10 @@ impl TryFrom<&AdyenRouterData<&types::PaymentsAuthorizeRouterData>> for AdyenPay fn try_from( item: &AdyenRouterData<&types::PaymentsAuthorizeRouterData>, ) -> Result { - println!("$$$$$4request_overcapture: {:?}", item.router_data.request_overcapture); + println!( + "$$$$$4request_overcapture: {:?}", + item.router_data.request_overcapture + ); match item .router_data .request diff --git a/crates/router/src/connector/globalpay/transformers.rs b/crates/router/src/connector/globalpay/transformers.rs index 1e5c3a4851ad..2e7ec8fb182e 100644 --- a/crates/router/src/connector/globalpay/transformers.rs +++ b/crates/router/src/connector/globalpay/transformers.rs @@ -283,8 +283,7 @@ fn get_payment_response( incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, - + maximum_capturable_amount: None, }), } } diff --git a/crates/router/src/connector/iatapay/transformers.rs b/crates/router/src/connector/iatapay/transformers.rs index 392da01b0d95..df2c27daedd4 100644 --- a/crates/router/src/connector/iatapay/transformers.rs +++ b/crates/router/src/connector/iatapay/transformers.rs @@ -404,7 +404,7 @@ fn get_iatpay_response( incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }, }; diff --git a/crates/router/src/connector/mifinity/transformers.rs b/crates/router/src/connector/mifinity/transformers.rs index 0daa44c230ab..9bd7f405864f 100644 --- a/crates/router/src/connector/mifinity/transformers.rs +++ b/crates/router/src/connector/mifinity/transformers.rs @@ -270,7 +270,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -287,7 +287,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -358,7 +358,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -375,7 +375,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), @@ -393,7 +393,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 2a6a94c6dd4e..42ffa4da3201 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -214,7 +214,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::AuthenticationPending, ), @@ -370,7 +370,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method @@ -756,7 +756,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::CaptureInitiated, ), @@ -853,7 +853,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::Charged, ), @@ -912,7 +912,7 @@ impl TryFrom> incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method @@ -965,7 +965,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), enums::AttemptStatus::VoidInitiated, ), @@ -1018,7 +1018,7 @@ impl TryFrom incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) } }, diff --git a/crates/router/src/connector/nuvei/transformers.rs b/crates/router/src/connector/nuvei/transformers.rs index f5d03a798415..0eddb269dff4 100644 --- a/crates/router/src/connector/nuvei/transformers.rs +++ b/crates/router/src/connector/nuvei/transformers.rs @@ -1628,7 +1628,7 @@ where incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) }, ..item.data diff --git a/crates/router/src/connector/payme/transformers.rs b/crates/router/src/connector/payme/transformers.rs index beb9bba5e39e..23f943281258 100644 --- a/crates/router/src/connector/payme/transformers.rs +++ b/crates/router/src/connector/payme/transformers.rs @@ -261,7 +261,7 @@ impl TryFrom<&PaymePaySaleResponse> for types::PaymentsResponseData { incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) } } @@ -330,7 +330,7 @@ impl From<&SaleQuery> for types::PaymentsResponseData { incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, } } } @@ -552,7 +552,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/plaid/transformers.rs b/crates/router/src/connector/plaid/transformers.rs index c2a85f684e69..cfa3bf22076d 100644 --- a/crates/router/src/connector/plaid/transformers.rs +++ b/crates/router/src/connector/plaid/transformers.rs @@ -316,7 +316,7 @@ impl incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }) }, ..item.data diff --git a/crates/router/src/connector/trustpay/transformers.rs b/crates/router/src/connector/trustpay/transformers.rs index d6670a01354d..eac9d759971c 100644 --- a/crates/router/src/connector/trustpay/transformers.rs +++ b/crates/router/src/connector/trustpay/transformers.rs @@ -768,7 +768,7 @@ fn handle_bank_redirects_response( incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }; Ok((status, error, payment_response_data)) } @@ -804,7 +804,7 @@ fn handle_bank_redirects_error_response( incremental_authorization_allowed: None, charge_id: None, overcapture_applied: None, - maximum_capturable_amount: None, + maximum_capturable_amount: None, }; Ok((status, error, payment_response_data)) } diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 38d173eb360e..35f215cc749d 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -1442,7 +1442,8 @@ impl UpdateTracker, api::PaymentsRequest> for async move { m_db.update_payment_attempt_with_attempt_id( m_payment_data_payment_attempt, - storage::PaymentAttemptUpdate::ConfirmUpdate { // Should we remove todooo + storage::PaymentAttemptUpdate::ConfirmUpdate { + // Should we remove todooo currency: payment_data.currency, status: attempt_status, payment_method, diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index ce5fa5573d0b..a5344a75bb3a 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -542,7 +542,9 @@ impl GetTracker, api::PaymentsRequest> } let amount = payment_attempt.get_total_amount().into(); - payment_attempt.request_overcapture = request.request_overcapture.or(Some(business_profile.always_request_overcapture)); // todoooo + payment_attempt.request_overcapture = request + .request_overcapture + .or(Some(business_profile.always_request_overcapture)); // todoooo payment_attempt.connector_mandate_detail = Some(DieselConnectorMandateReferenceId::foreign_from( @@ -1142,7 +1144,9 @@ impl PaymentCreate { .transpose()? .flatten(); - let request_overcapture = request.request_overcapture.or(Some(business_profile.always_request_overcapture)); + let request_overcapture = request + .request_overcapture + .or(Some(business_profile.always_request_overcapture)); if additional_pm_data.is_none() { // If recurring payment is made using payment_method_id, then fetch payment_method_data from retrieved payment_method object diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 8208b45def0a..164baa7bf0e8 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1533,7 +1533,7 @@ async fn payment_response_update_tracker( incremental_authorization_allowed, charge_id, overcapture_applied, - maximum_capturable_amount, + maximum_capturable_amount, .. } => { payment_data diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index d401c6dfe0ad..78760f0e07f5 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -442,8 +442,9 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - payment_attempt.request_overcapture = request.request_overcapture.or(Some(business_profile.always_request_overcapture)); - + payment_attempt.request_overcapture = request + .request_overcapture + .or(Some(business_profile.always_request_overcapture)); let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) @@ -801,7 +802,8 @@ impl UpdateTracker, api::PaymentsRequest> for .store .update_payment_attempt_with_attempt_id( payment_data.payment_attempt, - storage::PaymentAttemptUpdate::Update { //should we remove todooo + storage::PaymentAttemptUpdate::Update { + //should we remove todooo currency: payment_data.currency, status: get_attempt_status(), authentication_type: None, @@ -824,8 +826,8 @@ impl UpdateTracker, api::PaymentsRequest> for surcharge_amount, tax_amount, ), - maximum_capturable_amount: None, - overcapture_applied: None, + maximum_capturable_amount: None, + overcapture_applied: None, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index edc0bb80e399..63b5ffde45cd 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -661,7 +661,6 @@ pub fn make_new_payment_attempt( request_overcapture: old_payment_attempt.request_overcapture, overcapture_applied: Default::default(), maximum_capturable_amount: Default::default(), - } } diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 69c4dbaac2a6..3831f029461c 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -366,7 +366,6 @@ pub async fn construct_refund_router_data<'a, F>( split_refunds, integrity_object: None, refund_status: refund.refund_status, - }, response: Ok(types::RefundsResponseData { connector_refund_id: connector_refund_id.unwrap_or_default(), diff --git a/crates/router/tests/connectors/mifinity.rs b/crates/router/tests/connectors/mifinity.rs index a04480b63b4c..89349be07bb2 100644 --- a/crates/router/tests/connectors/mifinity.rs +++ b/crates/router/tests/connectors/mifinity.rs @@ -1,4 +1,3 @@ - use masking::Secret; use router::types::{self, domain, storage::enums}; use test_utils::connector_auth; diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 5f8b00bc6629..13815c4f6339 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -565,8 +565,8 @@ impl PaymentAttemptInterface for KVRouterStore { profile_id: payment_attempt.profile_id.clone(), connector_mandate_detail: payment_attempt.connector_mandate_detail.clone(), request_overcapture: payment_attempt.request_overcapture, - overcapture_applied: payment_attempt.overcapture_applied, - maximum_capturable_amount: payment_attempt.maximum_capturable_amount, + overcapture_applied: payment_attempt.overcapture_applied, + maximum_capturable_amount: payment_attempt.maximum_capturable_amount, }; let field = format!("pa_{}", created_attempt.attempt_id); From 1c1510f6062002d71468cf7dfd0d0396ae0802e3 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 08:30:11 +0000 Subject: [PATCH 10/64] docs(openapi): re-generate OpenAPI specification --- api-reference-v2/openapi_spec.json | 26 ++++++++++++++++++++++++++ api-reference/openapi_spec.json | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index d59a20df6273..165d2dc9090c 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -15174,6 +15174,19 @@ "type": "string", "description": "Connector Identifier for the payment method", "nullable": true + }, + "overcapture_applied": { + "type": "boolean", + "description": "Whether the payment is overcaptureable or not", + "nullable": true + }, + "maximum_capturable_amount": { + "allOf": [ + { + "$ref": "#/components/schemas/MinorUnit" + } + ], + "nullable": true } } }, @@ -16078,6 +16091,19 @@ "type": "string", "description": "Connector Identifier for the payment method", "nullable": true + }, + "overcapture_applied": { + "type": "boolean", + "description": "Whether the payment is overcaptureable or not", + "nullable": true + }, + "maximum_capturable_amount": { + "allOf": [ + { + "$ref": "#/components/schemas/MinorUnit" + } + ], + "nullable": true } } }, diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 5ad284455d66..60221ce726e8 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -18208,6 +18208,19 @@ "type": "string", "description": "Connector Identifier for the payment method", "nullable": true + }, + "overcapture_applied": { + "type": "boolean", + "description": "Whether the payment is overcaptureable or not", + "nullable": true + }, + "maximum_capturable_amount": { + "allOf": [ + { + "$ref": "#/components/schemas/MinorUnit" + } + ], + "nullable": true } } }, @@ -19449,6 +19462,19 @@ "type": "string", "description": "Connector Identifier for the payment method", "nullable": true + }, + "overcapture_applied": { + "type": "boolean", + "description": "Whether the payment is overcaptureable or not", + "nullable": true + }, + "maximum_capturable_amount": { + "allOf": [ + { + "$ref": "#/components/schemas/MinorUnit" + } + ], + "nullable": true } } }, From 702da2d64b09629b0efca331c277373f702617e1 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 19 Dec 2024 18:30:10 +0530 Subject: [PATCH 11/64] refactor(router): Remove fields from PaymentAttemptUpdate --- crates/diesel_models/src/payment_attempt.rs | 16 ++++------------ .../transformers.rs | 2 ++ .../src/payments/payment_attempt.rs | 12 ------------ .../core/payments/operations/payment_confirm.rs | 2 -- .../core/payments/operations/payment_update.rs | 2 -- .../core/unified_authentication_service/utils.rs | 1 + 6 files changed, 7 insertions(+), 28 deletions(-) diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index ea2ff63d9c93..2059cd16df47 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -386,8 +386,6 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - overcapture_applied: Option, - maximum_capturable_amount: Option, }, UpdateTrackers { payment_token: Option, @@ -437,8 +435,6 @@ pub enum PaymentAttemptUpdate { shipping_cost: Option, order_tax_amount: Option, connector_mandate_detail: Option, - overcapture_applied: Option, - maximum_capturable_amount: Option, }, VoidUpdate { status: storage_enums::AttemptStatus, @@ -2119,8 +2115,6 @@ impl From for PaymentAttemptUpdateInternal { fingerprint_id, updated_by, payment_method_billing_address_id, - overcapture_applied, - maximum_capturable_amount, } => Self { amount: Some(amount), currency: Some(currency), @@ -2175,8 +2169,8 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied, - maximum_capturable_amount, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::AuthenticationTypeUpdate { authentication_type, @@ -2271,8 +2265,6 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost, order_tax_amount, connector_mandate_detail, - overcapture_applied, - maximum_capturable_amount, } => Self { amount: Some(amount), currency: Some(currency), @@ -2326,8 +2318,8 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail, request_overcapture: None, - overcapture_applied, - maximum_capturable_amount, + overcapture_applied: None, + maximum_capturable_amount: None, }, PaymentAttemptUpdate::VoidUpdate { status, diff --git a/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs b/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs index 6a9347dbeed7..ec47ce1f06bf 100644 --- a/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/unified_authentication_service/transformers.rs @@ -150,6 +150,8 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, + maximum_capturable_amount: None, + overcapture_applied: None, }), ..item.data }) diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 81a944497590..c32cb98e53cb 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -784,8 +784,6 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - overcapture_applied: Option, - maximum_capturable_amount: Option, }, UpdateTrackers { payment_token: Option, @@ -831,8 +829,6 @@ pub enum PaymentAttemptUpdate { client_version: Option, customer_acceptance: Option, connector_mandate_detail: Option, - overcapture_applied: Option, - maximum_capturable_amount: Option, }, RejectUpdate { status: storage_enums::AttemptStatus, @@ -987,8 +983,6 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, - overcapture_applied, - maximum_capturable_amount, } => DieselPaymentAttemptUpdate::Update { amount: net_amount.get_order_amount(), currency, @@ -1007,8 +1001,6 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, - overcapture_applied, - maximum_capturable_amount, }, Self::UpdateTrackers { payment_token, @@ -1091,8 +1083,6 @@ impl PaymentAttemptUpdate { client_version, customer_acceptance, connector_mandate_detail, - overcapture_applied, - maximum_capturable_amount, } => DieselPaymentAttemptUpdate::ConfirmUpdate { amount: net_amount.get_order_amount(), currency, @@ -1127,8 +1117,6 @@ impl PaymentAttemptUpdate { shipping_cost: net_amount.get_shipping_cost(), order_tax_amount: net_amount.get_order_tax_amount(), connector_mandate_detail, - overcapture_applied, - maximum_capturable_amount, }, Self::VoidUpdate { status, diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 35f215cc749d..0b6d92e5d38b 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -1485,8 +1485,6 @@ impl UpdateTracker, api::PaymentsRequest> for connector_mandate_detail: payment_data .payment_attempt .connector_mandate_detail, - maximum_capturable_amount: None, - overcapture_applied: None, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 78760f0e07f5..d08a5e9da79e 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -826,8 +826,6 @@ impl UpdateTracker, api::PaymentsRequest> for surcharge_amount, tax_amount, ), - maximum_capturable_amount: None, - overcapture_applied: None, }, storage_scheme, ) diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs index e0d10251049a..aeef696d5b2a 100644 --- a/crates/router/src/core/unified_authentication_service/utils.rs +++ b/crates/router/src/core/unified_authentication_service/utils.rs @@ -168,5 +168,6 @@ pub fn construct_uas_router_data( connector_mandate_request_reference_id: None, authentication_id, psd2_sca_exemption_type: None, + request_overcapture: None, }) } From 36412666056611b35fc01a6808eb0af1fbf1ef6c Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 19 Dec 2024 18:31:08 +0530 Subject: [PATCH 12/64] refactor(router): add overcapture validation to validate_amount_to_capture --- crates/router/src/core/payments/helpers.rs | 24 ++++++++++++------- .../payments/operations/payment_capture.rs | 8 +++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index e3cb7246a09c..08b644325a55 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2601,15 +2601,23 @@ pub(crate) fn validate_status_with_capture_method( pub(crate) fn validate_amount_to_capture( amount: i64, amount_to_capture: Option, + is_overcapture_applied: Option, + maximum_capturable_amount: Option, ) -> RouterResult<()> { - utils::when( - amount_to_capture.is_some() && (Some(amount) < amount_to_capture), - || { - Err(report!(errors::ApiErrorResponse::InvalidRequestData { - message: "amount_to_capture is greater than amount".to_string() - })) - }, - ) + if let Some(amount_to_capture) = amount_to_capture { + utils::when( + (amount < amount_to_capture) + || !(is_overcapture_applied == Some(true) + && maximum_capturable_amount >= Some(amount_to_capture)), + || { + Err(report!(errors::ApiErrorResponse::InvalidRequestData { + message: "amount_to_capture is greater than amount".to_string() + })) + }, + ) + } else { + Ok(()) + } } #[cfg(feature = "v1")] diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index f8d304bcb79c..0f0861c7e498 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -100,6 +100,10 @@ impl GetTracker, api::Paymen request .amount_to_capture .map(|capture_amount| capture_amount.get_amount_as_i64()), + payment_attempt.overcapture_applied, + payment_attempt + .maximum_capturable_amount + .map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64()), )?; helpers::validate_capture_method(capture_method)?; @@ -112,6 +116,10 @@ impl GetTracker, api::Paymen helpers::validate_amount_to_capture( payment_attempt.amount_capturable.get_amount_as_i64(), Some(amount_to_capture.get_amount_as_i64()), + payment_attempt.overcapture_applied, + payment_attempt + .maximum_capturable_amount + .map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64()), )?; let previous_captures = db From b54e293c94d4c3323589824aa2bb124adb498265 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 23 Dec 2024 10:53:23 +0530 Subject: [PATCH 13/64] refactor(core): change the struct of overcapture request data --- crates/common_utils/src/types.rs | 29 ++++ crates/diesel_models/src/enums.rs | 1 + crates/diesel_models/src/payment_attempt.rs | 131 ++++++------------ crates/diesel_models/src/schema.rs | 4 +- crates/diesel_models/src/schema_v2.rs | 4 +- crates/diesel_models/src/user/sample_data.rs | 8 +- .../src/payments/payment_attempt.rs | 56 +++++--- .../hyperswitch_interfaces/src/integrity.rs | 1 + .../src/connector/stripe/transformers.rs | 83 ++++++++--- crates/router/src/core/payments/helpers.rs | 20 +-- .../payments/operations/payment_capture.rs | 10 +- .../payments/operations/payment_confirm.rs | 24 +++- .../payments/operations/payment_create.rs | 17 ++- .../payments/operations/payment_response.rs | 25 +++- .../payments/operations/payment_update.rs | 25 +++- crates/router/src/core/payments/retry.rs | 19 ++- .../router/src/core/payments/transformers.rs | 22 ++- crates/router/src/core/utils.rs | 17 +++ crates/router/src/types.rs | 11 +- crates/router/src/utils/user/sample_data.rs | 4 +- .../src/mock_db/payment_attempt.rs | 4 +- .../src/payments/payment_attempt.rs | 28 ++-- .../down.sql | 11 +- .../up.sql | 5 +- 24 files changed, 342 insertions(+), 217 deletions(-) diff --git a/crates/common_utils/src/types.rs b/crates/common_utils/src/types.rs index 0d39841fe09b..a1213670a1e6 100644 --- a/crates/common_utils/src/types.rs +++ b/crates/common_utils/src/types.rs @@ -1403,6 +1403,35 @@ pub struct BrowserInformation { #[cfg(feature = "v2")] crate::impl_to_sql_from_sql_json!(BrowserInformation); + +/// Overcapture Data +#[derive( + ToSchema, + Debug, + Clone, + serde::Deserialize, + serde::Serialize, + Eq, + PartialEq, + diesel::AsExpression, +)] +#[diesel(sql_type = Jsonb)] +pub struct OvercaptureData { + /// Whether overcapture is requested + pub request_overcapture: Option, + + /// Whether overcapture is applied + pub overcapture_applied: Option, + + /// Maximum capturable amount + pub maximum_capturable_amount: Option, + + /// Overcaptured amount + pub overcaptured_amount: Option, +} + +crate::impl_to_sql_from_sql_json!(OvercaptureData); + /// Domain type for connector_transaction_id /// Maximum length for connector's transaction_id can be 128 characters in HS DB. /// In case connector's use an identifier whose length exceeds 128 characters, diff --git a/crates/diesel_models/src/enums.rs b/crates/diesel_models/src/enums.rs index 19f3bf0a3823..595637d429d4 100644 --- a/crates/diesel_models/src/enums.rs +++ b/crates/diesel_models/src/enums.rs @@ -325,3 +325,4 @@ pub enum UserRoleVersion { V1, V2, } + diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 2059cd16df47..87f159bdf2f9 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -94,9 +94,7 @@ pub struct PaymentAttempt { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -175,9 +173,7 @@ pub struct PaymentAttempt { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -284,9 +280,7 @@ pub struct PaymentAttemptNew { pub payment_method_subtype: storage_enums::PaymentMethodType, pub id: id_type::GlobalAttemptId, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -360,9 +354,7 @@ pub struct PaymentAttemptNew { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -386,6 +378,7 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, + overcapture_details: Option, }, UpdateTrackers { payment_token: Option, @@ -435,6 +428,7 @@ pub enum PaymentAttemptUpdate { shipping_cost: Option, order_tax_amount: Option, connector_mandate_detail: Option, + overcapture_details: Option, }, VoidUpdate { status: storage_enums::AttemptStatus, @@ -483,8 +477,7 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, - overcapture_applied: Option, - maximum_capturable_amount: Option, + overcapture_details: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -865,13 +858,12 @@ pub struct PaymentAttemptUpdateInternal { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] impl PaymentAttemptUpdateInternal { + // to think about todooo pub fn populate_derived_fields(self, source: &PaymentAttempt) -> Self { let mut update_internal = self; update_internal.net_amount = Some( @@ -891,6 +883,13 @@ impl PaymentAttemptUpdateInternal { + update_internal .order_tax_amount .or(source.order_tax_amount) + .unwrap_or(MinorUnit::new(0)) + + update_internal + .overcapture_details + .as_ref() + .and_then(|data| data.overcaptured_amount) + .or(source.overcapture_details.as_ref() + .and_then(|data| data.overcaptured_amount)) .unwrap_or(MinorUnit::new(0)), ); update_internal.card_network = update_internal @@ -1051,9 +1050,7 @@ impl PaymentAttemptUpdate { order_tax_amount, connector_transaction_data, connector_mandate_detail, - request_overcapture, - overcapture_applied, - maximum_capturable_amount, + overcapture_details, } = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source); PaymentAttempt { amount: amount.unwrap_or(source.amount), @@ -1112,10 +1109,7 @@ impl PaymentAttemptUpdate { connector_transaction_data: connector_transaction_data .or(source.connector_transaction_data), connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail), - request_overcapture: request_overcapture.or(source.request_overcapture), - overcapture_applied: overcapture_applied.or(source.overcapture_applied), - maximum_capturable_amount: maximum_capturable_amount - .or(source.maximum_capturable_amount), + overcapture_details: overcapture_details.or(source.overcapture_details), ..source } } @@ -2115,6 +2109,7 @@ impl From for PaymentAttemptUpdateInternal { fingerprint_id, updated_by, payment_method_billing_address_id, + overcapture_details, } => Self { amount: Some(amount), currency: Some(currency), @@ -2168,9 +2163,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details, }, PaymentAttemptUpdate::AuthenticationTypeUpdate { authentication_type, @@ -2227,9 +2220,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::ConfirmUpdate { amount, @@ -2265,6 +2256,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost, order_tax_amount, connector_mandate_detail, + overcapture_details, } => Self { amount: Some(amount), currency: Some(currency), @@ -2317,9 +2309,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount, connector_transaction_data: None, connector_mandate_detail, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details, }, PaymentAttemptUpdate::VoidUpdate { status, @@ -2377,9 +2367,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::RejectUpdate { status, @@ -2438,9 +2426,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::BlocklistUpdate { status, @@ -2499,9 +2485,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::ConnectorMandateDetailUpdate { connector_mandate_detail, @@ -2558,9 +2542,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::PaymentMethodDetailsUpdate { payment_method_id, @@ -2617,9 +2599,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::ResponseUpdate { status, @@ -2643,8 +2623,7 @@ impl From for PaymentAttemptUpdateInternal { payment_method_data, charge_id, connector_mandate_detail, - overcapture_applied, - maximum_capturable_amount, + overcapture_details, } => { let (connector_transaction_id, connector_transaction_data) = connector_transaction_id @@ -2703,9 +2682,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail, - request_overcapture: None, - overcapture_applied, - maximum_capturable_amount, + overcapture_details } } PaymentAttemptUpdate::ErrorUpdate { @@ -2779,9 +2756,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, } } PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self { @@ -2836,9 +2811,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::UpdateTrackers { payment_token, @@ -2901,9 +2874,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::UnresolvedResponseUpdate { status, @@ -2973,9 +2944,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, } } PaymentAttemptUpdate::PreprocessingUpdate { @@ -3044,9 +3013,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, } } PaymentAttemptUpdate::CaptureUpdate { @@ -3105,9 +3072,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::AmountToCaptureUpdate { status, @@ -3165,9 +3130,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::ConnectorResponse { authentication_data, @@ -3234,9 +3197,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, } } PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { @@ -3294,9 +3255,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::AuthenticationUpdate { status, @@ -3356,9 +3315,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, PaymentAttemptUpdate::ManualUpdate { status, @@ -3427,9 +3384,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, } } PaymentAttemptUpdate::PostSessionTokensUpdate { @@ -3487,9 +3442,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }, } } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 28822027e4f8..cf40e10f1531 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -887,9 +887,7 @@ diesel::table! { #[max_length = 512] connector_transaction_data -> Nullable, connector_mandate_detail -> Nullable, - request_overcapture -> Nullable, - overcapture_applied -> Nullable, - maximum_capturable_amount -> Nullable, + overcapture_details -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 7cebcb8d3423..fdf42647d9ee 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -857,9 +857,7 @@ diesel::table! { shipping_cost -> Nullable, order_tax_amount -> Nullable, connector_mandate_detail -> Nullable, - request_overcapture -> Nullable, - overcapture_applied -> Nullable, - maximum_capturable_amount -> Nullable, + overcapture_details -> Nullable, } } diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs index 1ba073d0a0a9..dd83fc4de5da 100644 --- a/crates/diesel_models/src/user/sample_data.rs +++ b/crates/diesel_models/src/user/sample_data.rs @@ -203,9 +203,7 @@ pub struct PaymentAttemptBatchNew { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -285,9 +283,7 @@ impl PaymentAttemptBatchNew { shipping_cost: self.shipping_cost, order_tax_amount: self.order_tax_amount, connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, - overcapture_applied: self.overcapture_applied, - maximum_capturable_amount: self.maximum_capturable_amount, + overcapture_details: self.overcapture_details, } } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index c32cb98e53cb..a982bed7a0fb 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -512,9 +512,7 @@ pub struct PaymentAttempt { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option } #[cfg(feature = "v1")] @@ -530,6 +528,8 @@ pub struct NetAmount { surcharge_amount: Option, /// tax on surcharge amount tax_on_surcharge: Option, + /// overcaptured amount + overcaptured_amount: Option, } #[cfg(feature = "v1")] @@ -540,6 +540,7 @@ impl NetAmount { order_tax_amount: Option, surcharge_amount: Option, tax_on_surcharge: Option, + overcaptured_amount: Option, ) -> Self { Self { order_amount, @@ -547,6 +548,7 @@ impl NetAmount { order_tax_amount, surcharge_amount, tax_on_surcharge, + overcaptured_amount, } } @@ -575,12 +577,17 @@ impl NetAmount { .map(|surcharge_amount| surcharge_amount + self.tax_on_surcharge.unwrap_or_default()) } + pub fn get_overcaptured_amount(&self) -> Option { + self.overcaptured_amount + } + pub fn get_total_amount(&self) -> MinorUnit { self.order_amount + self.shipping_cost.unwrap_or_default() + self.order_tax_amount.unwrap_or_default() + self.surcharge_amount.unwrap_or_default() + self.tax_on_surcharge.unwrap_or_default() + + self.overcaptured_amount.unwrap_or_default() } pub fn set_order_amount(&mut self, order_amount: MinorUnit) { @@ -601,6 +608,10 @@ impl NetAmount { self.tax_on_surcharge = surcharge_details.map(|details| details.tax_on_surcharge_amount); } + pub fn set_overcaptured_amount(&mut self, overcaptured_amount: MinorUnit) { + self.overcaptured_amount = Some(overcaptured_amount); + } + pub fn from_payments_request( payments_request: &api_models::payments::PaymentsRequest, order_amount: MinorUnit, @@ -617,6 +628,7 @@ impl NetAmount { order_tax_amount: None, surcharge_amount, tax_on_surcharge, + overcaptured_amount: None, } } @@ -651,12 +663,17 @@ impl NetAmount { payment_attempt.net_amount.get_tax_on_surcharge() }) }); + let overcaptured_amount = payment_attempt.and_then(|payment_attempt| { + payment_attempt.net_amount.get_overcaptured_amount() + }); + Self { order_amount, shipping_cost, order_tax_amount, surcharge_amount, tax_on_surcharge, + overcaptured_amount, } }) } @@ -760,9 +777,7 @@ pub struct PaymentAttemptNew { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -784,6 +799,7 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, + overcapture_details: Option, }, UpdateTrackers { payment_token: Option, @@ -829,6 +845,7 @@ pub enum PaymentAttemptUpdate { client_version: Option, customer_acceptance: Option, connector_mandate_detail: Option, + overcapture_details: Option, }, RejectUpdate { status: storage_enums::AttemptStatus, @@ -877,8 +894,7 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, - overcapture_applied: Option, - maximum_capturable_amount: Option, + overcapture_details: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -983,6 +999,7 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, + overcapture_details, } => DieselPaymentAttemptUpdate::Update { amount: net_amount.get_order_amount(), currency, @@ -1001,6 +1018,7 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, + overcapture_details, }, Self::UpdateTrackers { payment_token, @@ -1083,6 +1101,7 @@ impl PaymentAttemptUpdate { client_version, customer_acceptance, connector_mandate_detail, + overcapture_details, } => DieselPaymentAttemptUpdate::ConfirmUpdate { amount: net_amount.get_order_amount(), currency, @@ -1117,6 +1136,7 @@ impl PaymentAttemptUpdate { shipping_cost: net_amount.get_shipping_cost(), order_tax_amount: net_amount.get_order_tax_amount(), connector_mandate_detail, + overcapture_details }, Self::VoidUpdate { status, @@ -1149,8 +1169,7 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, - overcapture_applied, - maximum_capturable_amount, + overcapture_details, } => DieselPaymentAttemptUpdate::ResponseUpdate { status, connector, @@ -1173,8 +1192,7 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, - overcapture_applied, - maximum_capturable_amount, + overcapture_details, }, Self::UnresolvedResponseUpdate { status, @@ -1471,9 +1489,7 @@ impl behaviour::Conversion for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, - overcapture_applied: self.overcapture_applied, - maximum_capturable_amount: self.maximum_capturable_amount, + overcapture_details: self.overcapture_details, }) } @@ -1490,6 +1506,7 @@ impl behaviour::Conversion for PaymentAttempt { let connector_transaction_id = storage_model .get_optional_connector_transaction_id() .cloned(); + let overcaptured_amount = storage_model.overcapture_details.as_ref().and_then(|overcapture_data|overcapture_data.overcaptured_amount.clone()); Ok::>(Self { payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, @@ -1501,6 +1518,7 @@ impl behaviour::Conversion for PaymentAttempt { storage_model.order_tax_amount, storage_model.surcharge_amount, storage_model.tax_amount, + overcaptured_amount, ), currency: storage_model.currency, save_to_locker: storage_model.save_to_locker, @@ -1555,9 +1573,7 @@ impl behaviour::Conversion for PaymentAttempt { profile_id: storage_model.profile_id, organization_id: storage_model.organization_id, connector_mandate_detail: storage_model.connector_mandate_detail, - request_overcapture: storage_model.request_overcapture, - overcapture_applied: storage_model.overcapture_applied, - maximum_capturable_amount: storage_model.maximum_capturable_amount, + overcapture_details: storage_model.overcapture_details, }) } .await @@ -1640,9 +1656,7 @@ impl behaviour::Conversion for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, - overcapture_applied: self.overcapture_applied, - maximum_capturable_amount: self.maximum_capturable_amount, + overcapture_details: self.overcapture_details, }) } } diff --git a/crates/hyperswitch_interfaces/src/integrity.rs b/crates/hyperswitch_interfaces/src/integrity.rs index 43d7f4b31754..05ee2c540ee5 100644 --- a/crates/hyperswitch_interfaces/src/integrity.rs +++ b/crates/hyperswitch_interfaces/src/integrity.rs @@ -267,6 +267,7 @@ impl FlowIntegrity for CaptureIntegrityObject { .capture_amount .zip(req_integrity_object.capture_amount) .map(|(res_amount, req_amount)| { + println!("$$$$ res_amount: {}, req_amount: {}", res_amount, req_amount); if res_amount != req_amount { mismatched_fields.push(format_mismatch( "capture_amount", diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 96c5af2832af..9e39dc6d18d2 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -232,6 +232,8 @@ pub struct StripeCardData { pub payment_method_auth_type: Option, #[serde(rename = "payment_method_options[card][network]")] pub payment_method_data_card_preferred_network: Option, + #[serde(rename = "payment_method_options[card][request_overcapture]")] + pub payment_method_data_card_request_overcapture: Option, } #[derive(Debug, Eq, PartialEq, Serialize)] pub struct StripePayLaterData { @@ -239,6 +241,12 @@ pub struct StripePayLaterData { pub payment_method_data_type: StripePaymentMethodType, } +#[derive(Debug, Eq, PartialEq, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum StripeOvercaptureRequest { + IfAvailable +} + #[derive(Debug, Eq, PartialEq, Serialize)] pub struct TokenRequest { #[serde(flatten)] @@ -1144,6 +1152,7 @@ fn create_stripe_payment_method( payment_method_token: Option, is_customer_initiated_mandate_payment: Option, billing_address: StripeBillingAddress, + is_overcapture_requested: Option, ) -> Result< ( StripePaymentMethodData, @@ -1159,7 +1168,7 @@ fn create_stripe_payment_method( enums::AuthenticationType::NoThreeDs => Auth3ds::Automatic, }; Ok(( - StripePaymentMethodData::try_from((card_details, payment_method_auth_type))?, + StripePaymentMethodData::try_from((card_details, payment_method_auth_type, is_overcapture_requested))?, Some(StripePaymentMethodType::Card), billing_address, )) @@ -1377,10 +1386,10 @@ fn get_stripe_card_network(card_network: common_enums::CardNetwork) -> Option for StripePaymentMethodData { +impl TryFrom<(&domain::Card, Auth3ds, Option)> for StripePaymentMethodData { type Error = errors::ConnectorError; fn try_from( - (card, payment_method_auth_type): (&domain::Card, Auth3ds), + (card, payment_method_auth_type, is_overcapture_requested): (&domain::Card, Auth3ds, Option), ) -> Result { Ok(Self::Card(StripeCardData { payment_method_data_type: StripePaymentMethodType::Card, @@ -1393,6 +1402,10 @@ impl TryFrom<(&domain::Card, Auth3ds)> for StripePaymentMethodData { .card_network .clone() .and_then(get_stripe_card_network), + payment_method_data_card_request_overcapture: match is_overcapture_requested { + Some(true) => Some(StripeOvercaptureRequest::IfAvailable), + _ => None + } })) } } @@ -1750,6 +1763,7 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntent .card_network .clone() .and_then(get_stripe_card_network), + payment_method_data_card_request_overcapture: None, }), domain::payments::PaymentMethodData::CardRedirect(_) | domain::payments::PaymentMethodData::Wallet(_) @@ -1792,7 +1806,8 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntent Some(connector_util::PaymentsAuthorizeRequestData::is_customer_initiated_mandate_payment( &item.request, )), - billing_address + billing_address, + item.request_overcapture, )?; validate_shipping_address_against_payment_method( @@ -2062,6 +2077,7 @@ impl TryFrom<&types::TokenizationRouterData> for TokenRequest { item.payment_method_token.clone(), None, StripeBillingAddress::default(), + item.request_overcapture, )?; Ok(Self { token_data: payment_data.0, @@ -2256,6 +2272,22 @@ pub struct StripeAdditionalCardDetails { checks: Option, three_d_secure: Option, network_transaction_id: Option, + overcapture: Option +} + + +#[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] +pub struct StripeOvercaptureResponse { + status: Option, + maximum_amount_capturable: Option, +} + + +#[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum StripeOvercaptureStatus { + Available, + UnAvailable, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] @@ -2469,18 +2501,7 @@ impl //Note: we might have to call retrieve_setup_intent to get the network_transaction_id in case its not sent in PaymentIntentResponse // Or we identify the mandate txns before hand and always call SetupIntent in case of mandate payment call - let network_txn_id = match item.response.latest_charge.as_ref() { - Some(StripeChargeEnum::ChargeObject(charge_object)) => charge_object - .payment_method_details - .as_ref() - .and_then(|payment_method_details| match payment_method_details { - StripePaymentMethodDetailsResponse::Card { card } => { - card.network_transaction_id.clone() - } - _ => None, - }), - _ => None, - }; + let (network_txn_id, overcapture_applied, maximum_capturable_amount) = extract_charge_details(item.response.latest_charge.as_ref()); let connector_metadata = get_connector_metadata(item.response.next_action.as_ref(), item.response.amount)?; @@ -2511,8 +2532,8 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_applied, + maximum_capturable_amount, }) }; @@ -3790,7 +3811,7 @@ impl enums::AuthenticationType::ThreeDs => Auth3ds::Any, enums::AuthenticationType::NoThreeDs => Auth3ds::Automatic, }; - Ok(Self::try_from((ccard, payment_method_auth_type))?) + Ok(Self::try_from((ccard, payment_method_auth_type, None))?) } domain::PaymentMethodData::PayLater(_) => Ok(Self::PayLater(StripePayLaterData { payment_method_data_type: pm_type, @@ -4088,6 +4109,30 @@ fn get_transaction_metadata( meta_data } +fn extract_charge_details( + latest_charge: Option<&StripeChargeEnum> +) -> (Option, Option, Option) { + match latest_charge { + Some(StripeChargeEnum::ChargeObject(charge_object)) => charge_object + .payment_method_details + .as_ref() + .and_then(|payment_method_details| match payment_method_details { + StripePaymentMethodDetailsResponse::Card { card } => { + let overcapture_applied = card.overcapture.as_ref().and_then(|overcapture| match overcapture.status.clone() { + Some(StripeOvercaptureStatus::Available) => Some(true), + Some(StripeOvercaptureStatus::UnAvailable) => Some(false), + None => None + }); + let maximum_capturable_amount = card.overcapture.as_ref().and_then(|overcapture| overcapture.maximum_amount_capturable); + Some((card.network_transaction_id.clone(), overcapture_applied, maximum_capturable_amount)) + } + _ => None, + }) + .unwrap_or((None, None, None)), + _ => (None, None, None), + } +} + impl ForeignTryFrom<(&Option, u16, String)> for types::PaymentsResponseData { type Error = types::ErrorResponse; fn foreign_try_from( diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 08b644325a55..ee6d4cdda531 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2601,14 +2601,16 @@ pub(crate) fn validate_status_with_capture_method( pub(crate) fn validate_amount_to_capture( amount: i64, amount_to_capture: Option, - is_overcapture_applied: Option, - maximum_capturable_amount: Option, + overcapture_details: Option<&common_utils::types::OvercaptureData>, ) -> RouterResult<()> { - if let Some(amount_to_capture) = amount_to_capture { + let (is_overcapture_applied, maximum_capturable_amount) = overcapture_details.map(|overcapture_data| + (overcapture_data.overcapture_applied, overcapture_data.maximum_capturable_amount.map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64())) + ).unwrap_or((None, None)); + + if let Some(true) = amount_to_capture.map(|req_amount_to_capture|(amount < req_amount_to_capture)) { utils::when( - (amount < amount_to_capture) - || !(is_overcapture_applied == Some(true) - && maximum_capturable_amount >= Some(amount_to_capture)), + !(is_overcapture_applied == Some(true) + && maximum_capturable_amount >= amount_to_capture), || { Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "amount_to_capture is greater than amount".to_string() @@ -3510,6 +3512,7 @@ mod tests { tax_details: None, skip_external_tax_calculation: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; let req_cs = Some("1".to_string()); assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent).is_ok()); @@ -3649,6 +3652,7 @@ mod tests { tax_details: None, skip_external_tax_calculation: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; let req_cs = Some("1".to_string()); assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent).is_err()) @@ -4182,9 +4186,7 @@ impl AttemptType { organization_id: old_payment_attempt.organization_id, profile_id: old_payment_attempt.profile_id, connector_mandate_detail: None, - request_overcapture: old_payment_attempt.request_overcapture, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: old_payment_attempt.overcapture_details, } } diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 0f0861c7e498..294079f67e79 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -100,10 +100,7 @@ impl GetTracker, api::Paymen request .amount_to_capture .map(|capture_amount| capture_amount.get_amount_as_i64()), - payment_attempt.overcapture_applied, - payment_attempt - .maximum_capturable_amount - .map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64()), + payment_attempt.overcapture_details.as_ref(), )?; helpers::validate_capture_method(capture_method)?; @@ -116,10 +113,7 @@ impl GetTracker, api::Paymen helpers::validate_amount_to_capture( payment_attempt.amount_capturable.get_amount_as_i64(), Some(amount_to_capture.get_amount_as_i64()), - payment_attempt.overcapture_applied, - payment_attempt - .maximum_capturable_amount - .map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64()), + payment_attempt.overcapture_details.as_ref(), )?; let previous_captures = db diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 0b6d92e5d38b..bc97ff7543ba 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -402,9 +402,23 @@ impl GetTracker, api::PaymentsRequest> payment_attempt.capture_method = request.capture_method.or(payment_attempt.capture_method); - payment_attempt.request_overcapture = request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)); + match (payment_attempt.overcapture_details.clone(), request.request_overcapture) { + (Some(mut overcapture_data), Some(request_overcapture)) => { + overcapture_data.request_overcapture = Some(request_overcapture); + + }, + (None, Some(request_overcapture)) => { + payment_attempt.overcapture_details = Some( + common_utils::types::OvercaptureData { + request_overcapture: Some(request_overcapture), + overcapture_applied: None, + maximum_capturable_amount: None, + overcaptured_amount: None, + } + ); + }, + _ => () + }; payment_attempt.customer_acceptance = request .customer_acceptance @@ -1259,6 +1273,7 @@ impl UpdateTracker, api::PaymentsRequest> for let browser_info = payment_data.payment_attempt.browser_info.clone(); let frm_message = payment_data.frm_message.clone(); let capture_method = payment_data.payment_attempt.capture_method; + let overcapture_details = payment_data.payment_attempt.overcapture_details.clone(); let default_status_result = ( storage_enums::IntentStatus::Processing, @@ -1443,7 +1458,6 @@ impl UpdateTracker, api::PaymentsRequest> for m_db.update_payment_attempt_with_attempt_id( m_payment_data_payment_attempt, storage::PaymentAttemptUpdate::ConfirmUpdate { - // Should we remove todooo currency: payment_data.currency, status: attempt_status, payment_method, @@ -1481,10 +1495,12 @@ impl UpdateTracker, api::PaymentsRequest> for .get_order_tax_amount(), surcharge_amount, tax_amount, + None, ), connector_mandate_detail: payment_data .payment_attempt .connector_mandate_detail, + overcapture_details, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index a5344a75bb3a..54af425c8b2f 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -542,10 +542,6 @@ impl GetTracker, api::PaymentsRequest> } let amount = payment_attempt.get_total_amount().into(); - payment_attempt.request_overcapture = request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)); // todoooo - payment_attempt.connector_mandate_detail = Some(DieselConnectorMandateReferenceId::foreign_from( api_models::payments::ConnectorMandateReferenceId::new( @@ -1144,9 +1140,14 @@ impl PaymentCreate { .transpose()? .flatten(); - let request_overcapture = request + let overcapture_details = Some(common_utils::types::OvercaptureData { + request_overcapture: request .request_overcapture - .or(Some(business_profile.always_request_overcapture)); + .or(Some(business_profile.always_request_overcapture)), + overcapture_applied: None, + maximum_capturable_amount: None, + overcaptured_amount: None, + }); if additional_pm_data.is_none() { // If recurring payment is made using payment_method_id, then fetch payment_method_data from retrieved payment_method object @@ -1296,9 +1297,7 @@ impl PaymentCreate { organization_id: organization_id.clone(), profile_id, connector_mandate_detail: None, - request_overcapture, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details, }, additional_pm_data, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 164baa7bf0e8..4e5baa1b300d 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -417,6 +417,7 @@ impl PostUpdateTracker, types::PaymentsIncrementalAu None, None, None, + None, ), amount_capturable: incremental_authorization_details.total_amount, }, @@ -867,6 +868,11 @@ impl PostUpdateTracker, types::PaymentsCaptureData> where F: 'b + Send, { + let net_amount = payment_data.payment_attempt.net_amount.get_total_amount(); + let overcapture_applied = payment_data.payment_attempt.overcapture_details.as_ref().and_then(|overcapture_data|overcapture_data.overcapture_applied.clone()); + core_utils::get_overcaptured_amount(overcapture_applied, router_data.amount_captured.map(MinorUnit::new), net_amount) + .map(|overcaptured_amount| payment_data.payment_attempt.net_amount.set_overcaptured_amount(overcaptured_amount)); + payment_data = Box::pin(payment_response_update_tracker( db, payment_data, @@ -1422,7 +1428,7 @@ async fn payment_response_update_tracker( error_reason: Some(err.reason), amount_capturable: router_data .request - .get_amount_capturable(&payment_data, status) + .get_amount_capturable(&payment_data, status, None) .map(MinorUnit::new), updated_by: storage_scheme.to_string(), unified_code: Some(Some(unified_code)), @@ -1568,6 +1574,16 @@ async fn payment_response_update_tracker( None }; + let overcapture_details = match payment_data.payment_attempt.overcapture_details.clone() { + Some(mut overcapture_details) => { + overcapture_details.overcapture_applied = overcapture_applied; + overcapture_details.maximum_capturable_amount = maximum_capturable_amount; + overcapture_details.overcaptured_amount = payment_data.payment_attempt.net_amount.get_overcaptured_amount(); + Some(overcapture_details) + } + None => None, + }; + // incase of success, update error code and error message let error_status = if router_data.status == enums::AttemptStatus::Charged { @@ -1669,6 +1685,7 @@ async fn payment_response_update_tracker( payment_data.payment_attempt.connector.clone(), payment_data.payment_attempt.merchant_id.clone(), ); + let (capture_updates, payment_attempt_update) = match payment_data .multiple_capture_data { @@ -1714,6 +1731,7 @@ async fn payment_response_update_tracker( .get_amount_capturable( &payment_data, updated_attempt_status, + maximum_capturable_amount, ) .map(MinorUnit::new), payment_method_id, @@ -1735,12 +1753,12 @@ async fn payment_response_update_tracker( .payment_attempt .connector_mandate_detail .clone(), - overcapture_applied, - maximum_capturable_amount, + overcapture_details, }), ), }; + (capture_updates, payment_attempt_update) } types::PaymentsResponseData::TransactionUnresolvedResponse { @@ -2478,3 +2496,4 @@ fn get_total_amount_captured( } } } + diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index d08a5e9da79e..a595581ad97e 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -442,9 +442,24 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - payment_attempt.request_overcapture = request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)); + match (payment_attempt.overcapture_details.clone(), request.request_overcapture) { + (Some(mut overcapture_data), Some(request_overcapture)) => { + overcapture_data.request_overcapture = Some(request_overcapture); + + }, + (None, Some(request_overcapture)) => { + payment_attempt.overcapture_details = Some( + common_utils::types::OvercaptureData { + request_overcapture: Some(request_overcapture), + overcapture_applied: None, + maximum_capturable_amount: None, + overcaptured_amount: None, + } + ); + }, + _ => () + }; + let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) @@ -785,6 +800,7 @@ impl UpdateTracker, api::PaymentsRequest> for let payment_experience = payment_data.payment_attempt.payment_experience; let amount_to_capture = payment_data.payment_attempt.amount_to_capture; let capture_method = payment_data.payment_attempt.capture_method; + let overcapture_details = payment_data.payment_attempt.overcapture_details.clone(); let payment_method_billing_address_id = payment_data .payment_attempt .payment_method_billing_address_id @@ -803,7 +819,6 @@ impl UpdateTracker, api::PaymentsRequest> for .update_payment_attempt_with_attempt_id( payment_data.payment_attempt, storage::PaymentAttemptUpdate::Update { - //should we remove todooo currency: payment_data.currency, status: get_attempt_status(), authentication_type: None, @@ -825,7 +840,9 @@ impl UpdateTracker, api::PaymentsRequest> for None, surcharge_amount, tax_amount, + None, ), + overcapture_details, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 63b5ffde45cd..9fe6159e8547 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -16,6 +16,7 @@ use crate::{ flows::{ConstructFlowSpecificData, Feature}, operations, }, + utils::get_overcaptured_amount, }, db::StorageInterface, routes::{ @@ -393,6 +394,7 @@ where FData: Send, D: payments::OperationSessionGetters + payments::OperationSessionSetters + Send + Sync, { + let new_attempt_count = payment_data.get_payment_intent().attempt_count + 1; let new_payment_attempt = make_new_payment_attempt( connector, @@ -434,6 +436,16 @@ where .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not parse the connector response")?; + let overcapture_details = match payment_data.get_payment_attempt().overcapture_details.clone() { + Some(mut overcapture_details) => { + overcapture_details.overcapture_applied = overcapture_applied; + overcapture_details.maximum_capturable_amount = maximum_capturable_amount; + overcapture_details.overcaptured_amount = get_overcaptured_amount(overcapture_applied, router_data.amount_captured.map(MinorUnit::new), payment_data.get_payment_attempt().net_amount.get_total_amount()); + Some(overcapture_details) + } + None => None, + }; + let payment_attempt_update = storage::PaymentAttemptUpdate::ResponseUpdate { status: router_data.status, connector: None, @@ -469,8 +481,7 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, - overcapture_applied, - maximum_capturable_amount, + overcapture_details, }; #[cfg(feature = "v1")] @@ -658,9 +669,7 @@ pub fn make_new_payment_attempt( charge_id: Default::default(), customer_acceptance: Default::default(), connector_mandate_detail: Default::default(), - request_overcapture: old_payment_attempt.request_overcapture, - overcapture_applied: Default::default(), - maximum_capturable_amount: Default::default(), + overcapture_details: old_payment_attempt.overcapture_details, } } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 5331356c4019..4f7340cc4125 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -789,6 +789,9 @@ where crate::logger::debug!("unified address details {:?}", unified_address); + let request_overcapture = payment_data.payment_attempt.overcapture_details.as_ref() + .and_then(|ovecapture_data|ovecapture_data.request_overcapture); + router_data = types::RouterData { flow: PhantomData, merchant_id: merchant_account.get_id().clone(), @@ -858,7 +861,7 @@ where connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: payment_data.payment_intent.psd2_sca_exemption_type, - request_overcapture: payment_data.payment_attempt.request_overcapture, + request_overcapture, }; Ok(router_data) @@ -1974,6 +1977,11 @@ where }) }); + let (overcapture_applied, maximum_capturable_amount) = payment_attempt.overcapture_details + .as_ref() + .map(|overcapture_data| (overcapture_data.overcapture_applied.clone(), overcapture_data.maximum_capturable_amount.clone())) + .unwrap_or((None, None)); + let connector_transaction_id = payment_attempt .get_connector_payment_id() .map(ToString::to_string); @@ -2086,8 +2094,8 @@ where order_tax_amount, connector_mandate_id, shipping_cost: payment_intent.shipping_cost, - overcapture_applied: payment_attempt.overcapture_applied, - maximum_capturable_amount: payment_attempt.maximum_capturable_amount, + overcapture_applied, + maximum_capturable_amount, }; services::ApplicationResponse::JsonWithHeaders((payments_response, headers)) @@ -2344,8 +2352,12 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay order_tax_amount: None, connector_mandate_id:None, shipping_cost: None, - overcapture_applied: pa.overcapture_applied, - maximum_capturable_amount: pa.maximum_capturable_amount, + overcapture_applied: pa.overcapture_details.as_ref().and_then(|overcapture_data| + overcapture_data.overcapture_applied.clone() + ), + maximum_capturable_amount: pa.overcapture_details.as_ref().and_then(|overcapture_data| + overcapture_data.maximum_capturable_amount.clone() + ), } } } diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 3831f029461c..def38b70275f 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -451,6 +451,23 @@ pub fn validate_uuid(uuid: String, key: &str) -> Result, + amount_captured: Option, + net_amount: MinorUnit, +) -> Option { + match overcapture_applied.zip(amount_captured) { + Some((true, orginal_amount_captured)) => { + if net_amount < orginal_amount_captured{ + Some(orginal_amount_captured - net_amount) + } else { + None + } + }, + _ => None +} +} + #[cfg(test)] mod tests { #![allow(clippy::expect_used)] diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 8f11fcb6900f..6ba70ed40d69 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -254,6 +254,7 @@ pub trait Capturable { &self, _payment_data: &PaymentData, _attempt_status: common_enums::AttemptStatus, + _maximum_capturable_amount: Option, ) -> Option where F: Clone, @@ -280,6 +281,7 @@ impl Capturable for PaymentsAuthorizeData { &self, payment_data: &PaymentData, attempt_status: common_enums::AttemptStatus, + maximum_capturable_amount: Option, ) -> Option where F: Clone, @@ -302,7 +304,7 @@ impl Capturable for PaymentsAuthorizeData { | common_enums::IntentStatus::PartiallyCapturedAndCapturable => None, } }, - common_enums::CaptureMethod::Manual => Some(payment_data.payment_attempt.get_total_amount().get_amount_as_i64()), + common_enums::CaptureMethod::Manual => maximum_capturable_amount.or( Some(payment_data.payment_attempt.get_total_amount())).map(|amount_capturable|amount_capturable.get_amount_as_i64()), // In case of manual multiple, amount capturable must be inferred from all captures. common_enums::CaptureMethod::ManualMultiple | // Scheduled capture is not supported as of now @@ -323,6 +325,7 @@ impl Capturable for PaymentsCaptureData { &self, _payment_data: &PaymentData, attempt_status: common_enums::AttemptStatus, + _maximum_capturable_amount: Option, ) -> Option where F: Clone, @@ -361,6 +364,7 @@ impl Capturable for CompleteAuthorizeData { &self, payment_data: &PaymentData, attempt_status: common_enums::AttemptStatus, + maximum_capturable_amount: Option, ) -> Option where F: Clone, @@ -385,7 +389,7 @@ impl Capturable for CompleteAuthorizeData { | common_enums::IntentStatus::PartiallyCapturedAndCapturable => None, } }, - common_enums::CaptureMethod::Manual => Some(payment_data.payment_attempt.get_total_amount().get_amount_as_i64()), + common_enums::CaptureMethod::Manual =>maximum_capturable_amount.or(Some(payment_data.payment_attempt.get_total_amount())).map(|amount_capturable| amount_capturable.get_amount_as_i64()), // In case of manual multiple, amount capturable must be inferred from all captures. common_enums::CaptureMethod::ManualMultiple | // Scheduled capture is not supported as of now @@ -413,6 +417,7 @@ impl Capturable for PaymentsCancelData { &self, _payment_data: &PaymentData, attempt_status: common_enums::AttemptStatus, + _maximum_capturable_amount: Option, ) -> Option where F: Clone, @@ -441,6 +446,7 @@ impl Capturable for PaymentsIncrementalAuthorizationData { &self, _payment_data: &PaymentData, _attempt_status: common_enums::AttemptStatus, + _maximum_capturable_amount: Option, ) -> Option where F: Clone, @@ -479,6 +485,7 @@ impl Capturable for PaymentsSyncData { &self, _payment_data: &PaymentData, attempt_status: common_enums::AttemptStatus, + _maximum_capturable_amount: Option, ) -> Option where F: Clone, diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs index f870f6484984..3c121506a6ae 100644 --- a/crates/router/src/utils/user/sample_data.rs +++ b/crates/router/src/utils/user/sample_data.rs @@ -361,9 +361,7 @@ pub async fn generate_sample_data( order_tax_amount: None, connector_transaction_data, connector_mandate_detail: None, - request_overcapture: None, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_details: None, }; let refund = if refunds_count < number_of_refunds && !is_failed_payment { diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs index c41e9cdf4725..a949f940ff54 100644 --- a/crates/storage_impl/src/mock_db/payment_attempt.rs +++ b/crates/storage_impl/src/mock_db/payment_attempt.rs @@ -195,9 +195,7 @@ impl PaymentAttemptInterface for MockDb { organization_id: payment_attempt.organization_id, profile_id: payment_attempt.profile_id, connector_mandate_detail: payment_attempt.connector_mandate_detail, - request_overcapture: payment_attempt.request_overcapture, - overcapture_applied: payment_attempt.overcapture_applied, - maximum_capturable_amount: payment_attempt.maximum_capturable_amount, + overcapture_details: payment_attempt.overcapture_details, }; payment_attempts.push(payment_attempt.clone()); Ok(payment_attempt) diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 13815c4f6339..f36f99befe09 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -564,9 +564,7 @@ impl PaymentAttemptInterface for KVRouterStore { organization_id: payment_attempt.organization_id.clone(), profile_id: payment_attempt.profile_id.clone(), connector_mandate_detail: payment_attempt.connector_mandate_detail.clone(), - request_overcapture: payment_attempt.request_overcapture, - overcapture_applied: payment_attempt.overcapture_applied, - maximum_capturable_amount: payment_attempt.maximum_capturable_amount, + overcapture_details: payment_attempt.overcapture_details.clone(), }; let field = format!("pa_{}", created_attempt.attempt_id); @@ -1514,9 +1512,7 @@ impl DataModelExt for PaymentAttempt { shipping_cost: self.net_amount.get_shipping_cost(), order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, - overcapture_applied: self.overcapture_applied, - maximum_capturable_amount: self.maximum_capturable_amount, + overcapture_details: self.overcapture_details, } } @@ -1524,6 +1520,8 @@ impl DataModelExt for PaymentAttempt { let connector_transaction_id = storage_model .get_optional_connector_transaction_id() .cloned(); + let overcaptured_amount = storage_model.overcapture_details.as_ref() + .and_then(|overcapture_data|overcapture_data.overcaptured_amount.clone()); Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( storage_model.amount, @@ -1531,6 +1529,7 @@ impl DataModelExt for PaymentAttempt { storage_model.order_tax_amount, storage_model.surcharge_amount, storage_model.tax_amount, + overcaptured_amount, ), payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, @@ -1593,9 +1592,7 @@ impl DataModelExt for PaymentAttempt { organization_id: storage_model.organization_id, profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, - request_overcapture: storage_model.request_overcapture, - overcapture_applied: storage_model.overcapture_applied, - maximum_capturable_amount: storage_model.maximum_capturable_amount, + overcapture_details: storage_model.overcapture_details, } } } @@ -1679,13 +1676,15 @@ impl DataModelExt for PaymentAttemptNew { shipping_cost: self.net_amount.get_shipping_cost(), order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, - overcapture_applied: self.overcapture_applied, - maximum_capturable_amount: self.maximum_capturable_amount, + overcapture_details: self.overcapture_details, } } fn from_storage_model(storage_model: Self::StorageModel) -> Self { + let overcapture_amount = storage_model.overcapture_details.as_ref().and_then( + |overcapture_data| overcapture_data.overcaptured_amount.clone() + ); + Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( storage_model.amount, @@ -1693,6 +1692,7 @@ impl DataModelExt for PaymentAttemptNew { storage_model.order_tax_amount, storage_model.surcharge_amount, storage_model.tax_amount, + overcapture_amount, ), payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, @@ -1754,9 +1754,7 @@ impl DataModelExt for PaymentAttemptNew { organization_id: storage_model.organization_id, profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, - request_overcapture: storage_model.request_overcapture, - overcapture_applied: storage_model.overcapture_applied, - maximum_capturable_amount: storage_model.maximum_capturable_amount, + overcapture_details: storage_model.overcapture_details, } } } diff --git a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql index 0107daec739b..f0cc9d1b51f5 100644 --- a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql +++ b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql @@ -1,3 +1,8 @@ -ALTER TABLE payment_attempt DROP COLUMN IF EXISTS request_overcapture; -ALTER TABLE payment_attempt DROP COLUMN IF EXISTS overcapture_applied; -ALTER TABLE payment_attempt DROP COLUMN IF EXISTS maximum_capturable_amount; +ALTER TABLE payment_attempt +DROP COLUMN IF EXISTS request_overcapture; + +ALTER TABLE payment_attempt +DROP COLUMN IF EXISTS overcapture_applied; + +ALTER TABLE payment_attempt +DROP COLUMN IF EXISTS maximum_capturable_amount; \ No newline at end of file diff --git a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql index 1322f79b0c51..76adac0ffe96 100644 --- a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql +++ b/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql @@ -1,3 +1,2 @@ -ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN; -ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS overcapture_applied BOOLEAN; -ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS maximum_capturable_amount BIGINT; \ No newline at end of file +ALTER TABLE payment_attempt +ADD COLUMN IF NOT EXISTS overcapture_details JSONB DEFAULT NULL; \ No newline at end of file From bd8d0a0b4b6bcf4264af44aeab91f9396f04e44f Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 23 Dec 2024 10:56:41 +0530 Subject: [PATCH 14/64] chore: remove logger --- crates/hyperswitch_interfaces/src/integrity.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/hyperswitch_interfaces/src/integrity.rs b/crates/hyperswitch_interfaces/src/integrity.rs index 05ee2c540ee5..43d7f4b31754 100644 --- a/crates/hyperswitch_interfaces/src/integrity.rs +++ b/crates/hyperswitch_interfaces/src/integrity.rs @@ -267,7 +267,6 @@ impl FlowIntegrity for CaptureIntegrityObject { .capture_amount .zip(req_integrity_object.capture_amount) .map(|(res_amount, req_amount)| { - println!("$$$$ res_amount: {}, req_amount: {}", res_amount, req_amount); if res_amount != req_amount { mismatched_fields.push(format_mismatch( "capture_amount", From a4617b6c8f4f8f08fc28559a249fb57815d1d057 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 23 Dec 2024 15:37:30 +0530 Subject: [PATCH 15/64] fix(connector): rename StripeOvercaptureStatus values --- .../src/connector/stripe/transformers.rs | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 9e39dc6d18d2..0cb7fb9e8c12 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -2287,7 +2287,7 @@ pub struct StripeOvercaptureResponse { #[serde(rename_all = "snake_case")] pub enum StripeOvercaptureStatus { Available, - UnAvailable, + Unavailable, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] @@ -2501,7 +2501,20 @@ impl //Note: we might have to call retrieve_setup_intent to get the network_transaction_id in case its not sent in PaymentIntentResponse // Or we identify the mandate txns before hand and always call SetupIntent in case of mandate payment call - let (network_txn_id, overcapture_applied, maximum_capturable_amount) = extract_charge_details(item.response.latest_charge.as_ref()); + let network_txn_id = match item.response.latest_charge.as_ref() { + Some(StripeChargeEnum::ChargeObject(charge_object)) => charge_object + .payment_method_details + .as_ref() + .and_then(|payment_method_details| match payment_method_details { + StripePaymentMethodDetailsResponse::Card { card } => { + card.network_transaction_id.clone() + } + _ => None, + }), + _ => None, + }; + + let (overcapture_applied, maximum_capturable_amount) = extract_overcapture_response(item.response.latest_charge.as_ref()); let connector_metadata = get_connector_metadata(item.response.next_action.as_ref(), item.response.amount)?; @@ -2725,6 +2738,9 @@ impl }), _ => None, }; + + let (overcapture_applied, maximum_capturable_amount) = extract_overcapture_response(item.response.latest_charge.as_ref()); + let charge_id = item .response .latest_charge @@ -2742,8 +2758,8 @@ impl connector_response_reference_id: Some(item.response.id.clone()), incremental_authorization_allowed: None, charge_id, - overcapture_applied: None, - maximum_capturable_amount: None, + overcapture_applied, + maximum_capturable_amount, }) }; @@ -4109,9 +4125,9 @@ fn get_transaction_metadata( meta_data } -fn extract_charge_details( +fn extract_overcapture_response( latest_charge: Option<&StripeChargeEnum> -) -> (Option, Option, Option) { +) -> (Option, Option) { match latest_charge { Some(StripeChargeEnum::ChargeObject(charge_object)) => charge_object .payment_method_details @@ -4120,16 +4136,16 @@ fn extract_charge_details( StripePaymentMethodDetailsResponse::Card { card } => { let overcapture_applied = card.overcapture.as_ref().and_then(|overcapture| match overcapture.status.clone() { Some(StripeOvercaptureStatus::Available) => Some(true), - Some(StripeOvercaptureStatus::UnAvailable) => Some(false), - None => None + Some(StripeOvercaptureStatus::Unavailable) => Some(false), + None => None, }); let maximum_capturable_amount = card.overcapture.as_ref().and_then(|overcapture| overcapture.maximum_amount_capturable); - Some((card.network_transaction_id.clone(), overcapture_applied, maximum_capturable_amount)) + Some((overcapture_applied, maximum_capturable_amount)) } _ => None, }) - .unwrap_or((None, None, None)), - _ => (None, None, None), + .unwrap_or((None, None)), + _ => (None, None), } } From e7e8f38744d5176b26d584883f223b5fc31c477b Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 23 Dec 2024 16:00:42 +0530 Subject: [PATCH 16/64] chore: resolve conflicts --- .../src/connectors/jpmorgan/transformers.rs | 6 ++++++ crates/router/src/connector/klarna/transformers.rs | 8 ++++++++ crates/router/src/core/relay/utils.rs | 1 + 3 files changed, 15 insertions(+) diff --git a/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs b/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs index 7fc6f48464b0..4e58b80667ca 100644 --- a/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/jpmorgan/transformers.rs @@ -450,6 +450,8 @@ impl TryFrom connector_response_reference_id: Some(item.response.transaction_id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) @@ -714,6 +718,8 @@ impl connector_response_reference_id: Some(item.response.transaction_id.clone()), incremental_authorization_allowed: None, charge_id: None, + overcapture_applied: None, + maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rs index 70dc6254720a..0c1cd8e9c485 100644 --- a/crates/router/src/connector/klarna/transformers.rs +++ b/crates/router/src/connector/klarna/transformers.rs @@ -390,6 +390,8 @@ impl TryFrom> connector_response_reference_id: Some(response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, + maximum_capturable_amount: None, + overcapture_applied: None, }), status: enums::AttemptStatus::foreign_from(( response.fraud_status.clone(), @@ -413,6 +415,8 @@ impl TryFrom> connector_response_reference_id: Some(response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, + maximum_capturable_amount: None, + overcapture_applied: None, }), status: enums::AttemptStatus::foreign_from(( response.status.clone(), @@ -576,6 +580,8 @@ impl .or(Some(response.order_id.clone())), incremental_authorization_allowed: None, charge_id: None, + maximum_capturable_amount: None, + overcapture_applied: None, }), ..item.data }), @@ -595,6 +601,8 @@ impl connector_response_reference_id: Some(response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, + maximum_capturable_amount: None, + overcapture_applied: None, }), ..item.data }), diff --git a/crates/router/src/core/relay/utils.rs b/crates/router/src/core/relay/utils.rs index 0753be1ec435..a648d66e434b 100644 --- a/crates/router/src/core/relay/utils.rs +++ b/crates/router/src/core/relay/utils.rs @@ -133,6 +133,7 @@ pub async fn construct_relay_refund_router_data<'a, F>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) From e87b8d631d5d61b45b980882ede4e8f5a2a3e515 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 23 Dec 2024 16:14:54 +0530 Subject: [PATCH 17/64] chore: fix formatting errors --- crates/diesel_models/src/enums.rs | 1 - crates/diesel_models/src/payment_attempt.rs | 10 ++-- .../src/payments/payment_attempt.rs | 14 +++--- .../src/connector/klarna/transformers.rs | 6 +-- .../src/connector/stripe/transformers.rs | 49 ++++++++++++------- crates/router/src/core/payments/helpers.rs | 19 +++++-- .../payments/operations/payment_confirm.rs | 28 +++++------ .../payments/operations/payment_create.rs | 4 +- .../payments/operations/payment_response.rs | 45 +++++++++++------ .../payments/operations/payment_update.rs | 37 +++++++------- crates/router/src/core/payments/retry.rs | 16 ++++-- .../router/src/core/payments/transformers.rs | 29 ++++++----- crates/router/src/core/utils.rs | 16 +++--- .../src/payments/payment_attempt.rs | 13 +++-- 14 files changed, 173 insertions(+), 114 deletions(-) diff --git a/crates/diesel_models/src/enums.rs b/crates/diesel_models/src/enums.rs index e27e3d43114c..ec6e91a2ecb0 100644 --- a/crates/diesel_models/src/enums.rs +++ b/crates/diesel_models/src/enums.rs @@ -326,4 +326,3 @@ pub enum UserRoleVersion { V1, V2, } - diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 014e98a0a066..c28349452914 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -280,7 +280,7 @@ pub struct PaymentAttemptNew { pub payment_method_subtype: storage_enums::PaymentMethodType, pub id: id_type::GlobalAttemptId, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -888,8 +888,10 @@ impl PaymentAttemptUpdateInternal { .overcapture_details .as_ref() .and_then(|data| data.overcaptured_amount) - .or(source.overcapture_details.as_ref() - .and_then(|data| data.overcaptured_amount)) + .or(source + .overcapture_details + .as_ref() + .and_then(|data| data.overcaptured_amount)) .unwrap_or(MinorUnit::new(0)), ); update_internal.card_network = update_internal @@ -2682,7 +2684,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail, - overcapture_details + overcapture_details, } } PaymentAttemptUpdate::ErrorUpdate { diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 04f10b77e20e..99f9b74f963e 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -594,7 +594,7 @@ pub struct PaymentAttempt { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub overcapture_details: Option + pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -745,9 +745,8 @@ impl NetAmount { payment_attempt.net_amount.get_tax_on_surcharge() }) }); - let overcaptured_amount = payment_attempt.and_then(|payment_attempt| { - payment_attempt.net_amount.get_overcaptured_amount() - }); + let overcaptured_amount = payment_attempt + .and_then(|payment_attempt| payment_attempt.net_amount.get_overcaptured_amount()); Self { order_amount, @@ -1219,7 +1218,7 @@ impl PaymentAttemptUpdate { shipping_cost: net_amount.get_shipping_cost(), order_tax_amount: net_amount.get_order_tax_amount(), connector_mandate_detail, - overcapture_details + overcapture_details, }, Self::VoidUpdate { status, @@ -1602,7 +1601,10 @@ impl behaviour::Conversion for PaymentAttempt { let connector_transaction_id = storage_model .get_optional_connector_transaction_id() .cloned(); - let overcaptured_amount = storage_model.overcapture_details.as_ref().and_then(|overcapture_data|overcapture_data.overcaptured_amount.clone()); + let overcaptured_amount = storage_model + .overcapture_details + .as_ref() + .and_then(|overcapture_data| overcapture_data.overcaptured_amount.clone()); Ok::>(Self { payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rs index 0c1cd8e9c485..0f6007cd3513 100644 --- a/crates/router/src/connector/klarna/transformers.rs +++ b/crates/router/src/connector/klarna/transformers.rs @@ -416,7 +416,7 @@ impl TryFrom> incremental_authorization_allowed: None, charge_id: None, maximum_capturable_amount: None, - overcapture_applied: None, + overcapture_applied: None, }), status: enums::AttemptStatus::foreign_from(( response.status.clone(), @@ -581,7 +581,7 @@ impl incremental_authorization_allowed: None, charge_id: None, maximum_capturable_amount: None, - overcapture_applied: None, + overcapture_applied: None, }), ..item.data }), @@ -602,7 +602,7 @@ impl incremental_authorization_allowed: None, charge_id: None, maximum_capturable_amount: None, - overcapture_applied: None, + overcapture_applied: None, }), ..item.data }), diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index d9cd03a72cf2..5682d2c2f4ed 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -244,7 +244,7 @@ pub struct StripePayLaterData { #[derive(Debug, Eq, PartialEq, Serialize)] #[serde(rename_all = "snake_case")] pub enum StripeOvercaptureRequest { - IfAvailable + IfAvailable, } #[derive(Debug, Eq, PartialEq, Serialize)] @@ -1169,7 +1169,11 @@ fn create_stripe_payment_method( enums::AuthenticationType::NoThreeDs => Auth3ds::Automatic, }; Ok(( - StripePaymentMethodData::try_from((card_details, payment_method_auth_type, is_overcapture_requested))?, + StripePaymentMethodData::try_from(( + card_details, + payment_method_auth_type, + is_overcapture_requested, + ))?, Some(StripePaymentMethodType::Card), billing_address, )) @@ -1390,7 +1394,11 @@ fn get_stripe_card_network(card_network: common_enums::CardNetwork) -> Option)> for StripePaymentMethodData { type Error = errors::ConnectorError; fn try_from( - (card, payment_method_auth_type, is_overcapture_requested): (&domain::Card, Auth3ds, Option), + (card, payment_method_auth_type, is_overcapture_requested): ( + &domain::Card, + Auth3ds, + Option, + ), ) -> Result { Ok(Self::Card(StripeCardData { payment_method_data_type: StripePaymentMethodType::Card, @@ -1403,10 +1411,10 @@ impl TryFrom<(&domain::Card, Auth3ds, Option)> for StripePaymentMethodData .card_network .clone() .and_then(get_stripe_card_network), - payment_method_data_card_request_overcapture: match is_overcapture_requested { - Some(true) => Some(StripeOvercaptureRequest::IfAvailable), - _ => None - } + payment_method_data_card_request_overcapture: match is_overcapture_requested { + Some(true) => Some(StripeOvercaptureRequest::IfAvailable), + _ => None, + }, })) } } @@ -2282,17 +2290,15 @@ pub struct StripeAdditionalCardDetails { checks: Option, three_d_secure: Option, network_transaction_id: Option, - overcapture: Option + overcapture: Option, } - #[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] pub struct StripeOvercaptureResponse { status: Option, maximum_amount_capturable: Option, } - #[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] #[serde(rename_all = "snake_case")] pub enum StripeOvercaptureStatus { @@ -2524,7 +2530,8 @@ impl _ => None, }; - let (overcapture_applied, maximum_capturable_amount) = extract_overcapture_response(item.response.latest_charge.as_ref()); + let (overcapture_applied, maximum_capturable_amount) = + extract_overcapture_response(item.response.latest_charge.as_ref()); let connector_metadata = get_connector_metadata(item.response.next_action.as_ref(), item.response.amount)?; @@ -2749,7 +2756,8 @@ impl _ => None, }; - let (overcapture_applied, maximum_capturable_amount) = extract_overcapture_response(item.response.latest_charge.as_ref()); + let (overcapture_applied, maximum_capturable_amount) = + extract_overcapture_response(item.response.latest_charge.as_ref()); let charge_id = item .response @@ -4136,7 +4144,7 @@ fn get_transaction_metadata( } fn extract_overcapture_response( - latest_charge: Option<&StripeChargeEnum> + latest_charge: Option<&StripeChargeEnum>, ) -> (Option, Option) { match latest_charge { Some(StripeChargeEnum::ChargeObject(charge_object)) => charge_object @@ -4144,12 +4152,17 @@ fn extract_overcapture_response( .as_ref() .and_then(|payment_method_details| match payment_method_details { StripePaymentMethodDetailsResponse::Card { card } => { - let overcapture_applied = card.overcapture.as_ref().and_then(|overcapture| match overcapture.status.clone() { - Some(StripeOvercaptureStatus::Available) => Some(true), - Some(StripeOvercaptureStatus::Unavailable) => Some(false), - None => None, + let overcapture_applied = card.overcapture.as_ref().and_then(|overcapture| { + match overcapture.status.clone() { + Some(StripeOvercaptureStatus::Available) => Some(true), + Some(StripeOvercaptureStatus::Unavailable) => Some(false), + None => None, + } }); - let maximum_capturable_amount = card.overcapture.as_ref().and_then(|overcapture| overcapture.maximum_amount_capturable); + let maximum_capturable_amount = card + .overcapture + .as_ref() + .and_then(|overcapture| overcapture.maximum_amount_capturable); Some((overcapture_applied, maximum_capturable_amount)) } _ => None, diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 4c929ff11252..6a6785f53e73 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2611,14 +2611,23 @@ pub(crate) fn validate_amount_to_capture( amount_to_capture: Option, overcapture_details: Option<&common_utils::types::OvercaptureData>, ) -> RouterResult<()> { - let (is_overcapture_applied, maximum_capturable_amount) = overcapture_details.map(|overcapture_data| - (overcapture_data.overcapture_applied, overcapture_data.maximum_capturable_amount.map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64())) - ).unwrap_or((None, None)); + let (is_overcapture_applied, maximum_capturable_amount) = overcapture_details + .map(|overcapture_data| { + ( + overcapture_data.overcapture_applied, + overcapture_data + .maximum_capturable_amount + .map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64()), + ) + }) + .unwrap_or((None, None)); - if let Some(true) = amount_to_capture.map(|req_amount_to_capture|(amount < req_amount_to_capture)) { + if let Some(true) = + amount_to_capture.map(|req_amount_to_capture| (amount < req_amount_to_capture)) + { utils::when( !(is_overcapture_applied == Some(true) - && maximum_capturable_amount >= amount_to_capture), + && maximum_capturable_amount >= amount_to_capture), || { Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "amount_to_capture is greater than amount".to_string() diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index e43686539108..940a4c9fad8d 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -403,22 +403,22 @@ impl GetTracker, api::PaymentsRequest> payment_attempt.capture_method = request.capture_method.or(payment_attempt.capture_method); - match (payment_attempt.overcapture_details.clone(), request.request_overcapture) { + match ( + payment_attempt.overcapture_details.clone(), + request.request_overcapture, + ) { (Some(mut overcapture_data), Some(request_overcapture)) => { - overcapture_data.request_overcapture = Some(request_overcapture); - - }, + overcapture_data.request_overcapture = Some(request_overcapture); + } (None, Some(request_overcapture)) => { - payment_attempt.overcapture_details = Some( - common_utils::types::OvercaptureData { - request_overcapture: Some(request_overcapture), - overcapture_applied: None, - maximum_capturable_amount: None, - overcaptured_amount: None, - } - ); - }, - _ => () + payment_attempt.overcapture_details = Some(common_utils::types::OvercaptureData { + request_overcapture: Some(request_overcapture), + overcapture_applied: None, + maximum_capturable_amount: None, + overcaptured_amount: None, + }); + } + _ => (), }; payment_attempt.customer_acceptance = request diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 7833a2802314..d87d1e7de3cb 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1143,8 +1143,8 @@ impl PaymentCreate { let overcapture_details = Some(common_utils::types::OvercaptureData { request_overcapture: request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)), + .request_overcapture + .or(Some(business_profile.always_request_overcapture)), overcapture_applied: None, maximum_capturable_amount: None, overcaptured_amount: None, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 746ad731876c..1ee3c7f86b4d 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -869,9 +869,22 @@ impl PostUpdateTracker, types::PaymentsCaptureData> F: 'b + Send, { let net_amount = payment_data.payment_attempt.net_amount.get_total_amount(); - let overcapture_applied = payment_data.payment_attempt.overcapture_details.as_ref().and_then(|overcapture_data|overcapture_data.overcapture_applied.clone()); - core_utils::get_overcaptured_amount(overcapture_applied, router_data.amount_captured.map(MinorUnit::new), net_amount) - .map(|overcaptured_amount| payment_data.payment_attempt.net_amount.set_overcaptured_amount(overcaptured_amount)); + let overcapture_applied = payment_data + .payment_attempt + .overcapture_details + .as_ref() + .and_then(|overcapture_data| overcapture_data.overcapture_applied.clone()); + core_utils::get_overcaptured_amount( + overcapture_applied, + router_data.amount_captured.map(MinorUnit::new), + net_amount, + ) + .map(|overcaptured_amount| { + payment_data + .payment_attempt + .net_amount + .set_overcaptured_amount(overcaptured_amount) + }); payment_data = Box::pin(payment_response_update_tracker( db, @@ -1574,15 +1587,21 @@ async fn payment_response_update_tracker( None }; - let overcapture_details = match payment_data.payment_attempt.overcapture_details.clone() { - Some(mut overcapture_details) => { - overcapture_details.overcapture_applied = overcapture_applied; - overcapture_details.maximum_capturable_amount = maximum_capturable_amount; - overcapture_details.overcaptured_amount = payment_data.payment_attempt.net_amount.get_overcaptured_amount(); - Some(overcapture_details) - } - None => None, - }; + let overcapture_details = + match payment_data.payment_attempt.overcapture_details.clone() { + Some(mut overcapture_details) => { + overcapture_details.overcapture_applied = + overcapture_applied; + overcapture_details.maximum_capturable_amount = + maximum_capturable_amount; + overcapture_details.overcaptured_amount = payment_data + .payment_attempt + .net_amount + .get_overcaptured_amount(); + Some(overcapture_details) + } + None => None, + }; // incase of success, update error code and error message let error_status = @@ -1758,7 +1777,6 @@ async fn payment_response_update_tracker( ), }; - (capture_updates, payment_attempt_update) } types::PaymentsResponseData::TransactionUnresolvedResponse { @@ -2582,4 +2600,3 @@ fn get_total_amount_captured( } } } - diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 43846bd6db3e..341982fa1ed8 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -443,24 +443,23 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - match (payment_attempt.overcapture_details.clone(), request.request_overcapture) { - (Some(mut overcapture_data), Some(request_overcapture)) => { - overcapture_data.request_overcapture = Some(request_overcapture); - - }, - (None, Some(request_overcapture)) => { - payment_attempt.overcapture_details = Some( - common_utils::types::OvercaptureData { - request_overcapture: Some(request_overcapture), - overcapture_applied: None, - maximum_capturable_amount: None, - overcaptured_amount: None, - } - ); - }, - _ => () - }; - + match ( + payment_attempt.overcapture_details.clone(), + request.request_overcapture, + ) { + (Some(mut overcapture_data), Some(request_overcapture)) => { + overcapture_data.request_overcapture = Some(request_overcapture); + } + (None, Some(request_overcapture)) => { + payment_attempt.overcapture_details = Some(common_utils::types::OvercaptureData { + request_overcapture: Some(request_overcapture), + overcapture_applied: None, + maximum_capturable_amount: None, + overcaptured_amount: None, + }); + } + _ => (), + }; let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) @@ -843,7 +842,7 @@ impl UpdateTracker, api::PaymentsRequest> for tax_amount, None, ), - overcapture_details, + overcapture_details, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 9fe6159e8547..98780e523b9c 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -394,7 +394,6 @@ where FData: Send, D: payments::OperationSessionGetters + payments::OperationSessionSetters + Send + Sync, { - let new_attempt_count = payment_data.get_payment_intent().attempt_count + 1; let new_payment_attempt = make_new_payment_attempt( connector, @@ -436,11 +435,22 @@ where .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not parse the connector response")?; - let overcapture_details = match payment_data.get_payment_attempt().overcapture_details.clone() { + let overcapture_details = match payment_data + .get_payment_attempt() + .overcapture_details + .clone() + { Some(mut overcapture_details) => { overcapture_details.overcapture_applied = overcapture_applied; overcapture_details.maximum_capturable_amount = maximum_capturable_amount; - overcapture_details.overcaptured_amount = get_overcaptured_amount(overcapture_applied, router_data.amount_captured.map(MinorUnit::new), payment_data.get_payment_attempt().net_amount.get_total_amount()); + overcapture_details.overcaptured_amount = get_overcaptured_amount( + overcapture_applied, + router_data.amount_captured.map(MinorUnit::new), + payment_data + .get_payment_attempt() + .net_amount + .get_total_amount(), + ); Some(overcapture_details) } None => None, diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 71b10cbc77a3..0e198b6fe311 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -975,8 +975,11 @@ where crate::logger::debug!("unified address details {:?}", unified_address); - let request_overcapture = payment_data.payment_attempt.overcapture_details.as_ref() - .and_then(|ovecapture_data|ovecapture_data.request_overcapture); + let request_overcapture = payment_data + .payment_attempt + .overcapture_details + .as_ref() + .and_then(|ovecapture_data| ovecapture_data.request_overcapture); router_data = types::RouterData { flow: PhantomData, @@ -2217,10 +2220,16 @@ where }) }); - let (overcapture_applied, maximum_capturable_amount) = payment_attempt.overcapture_details - .as_ref() - .map(|overcapture_data| (overcapture_data.overcapture_applied.clone(), overcapture_data.maximum_capturable_amount.clone())) - .unwrap_or((None, None)); + let (overcapture_applied, maximum_capturable_amount) = payment_attempt + .overcapture_details + .as_ref() + .map(|overcapture_data| { + ( + overcapture_data.overcapture_applied.clone(), + overcapture_data.maximum_capturable_amount.clone(), + ) + }) + .unwrap_or((None, None)); let connector_transaction_id = payment_attempt .get_connector_payment_id() @@ -2592,12 +2601,8 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay order_tax_amount: None, connector_mandate_id:None, shipping_cost: None, - overcapture_applied: pa.overcapture_details.as_ref().and_then(|overcapture_data| - overcapture_data.overcapture_applied.clone() - ), - maximum_capturable_amount: pa.overcapture_details.as_ref().and_then(|overcapture_data| - overcapture_data.maximum_capturable_amount.clone() - ), + overcapture_applied: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.overcapture_applied.clone()), + maximum_capturable_amount: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.maximum_capturable_amount.clone()), } } } diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index def38b70275f..d2bd00091931 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -457,15 +457,15 @@ pub fn get_overcaptured_amount( net_amount: MinorUnit, ) -> Option { match overcapture_applied.zip(amount_captured) { - Some((true, orginal_amount_captured)) => { - if net_amount < orginal_amount_captured{ - Some(orginal_amount_captured - net_amount) - } else { - None + Some((true, orginal_amount_captured)) => { + if net_amount < orginal_amount_captured { + Some(orginal_amount_captured - net_amount) + } else { + None + } } - }, - _ => None -} + _ => None, + } } #[cfg(test)] diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index f36f99befe09..baa852634193 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -1520,8 +1520,10 @@ impl DataModelExt for PaymentAttempt { let connector_transaction_id = storage_model .get_optional_connector_transaction_id() .cloned(); - let overcaptured_amount = storage_model.overcapture_details.as_ref() - .and_then(|overcapture_data|overcapture_data.overcaptured_amount.clone()); + let overcaptured_amount = storage_model + .overcapture_details + .as_ref() + .and_then(|overcapture_data| overcapture_data.overcaptured_amount.clone()); Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( storage_model.amount, @@ -1681,9 +1683,10 @@ impl DataModelExt for PaymentAttemptNew { } fn from_storage_model(storage_model: Self::StorageModel) -> Self { - let overcapture_amount = storage_model.overcapture_details.as_ref().and_then( - |overcapture_data| overcapture_data.overcaptured_amount.clone() - ); + let overcapture_amount = storage_model + .overcapture_details + .as_ref() + .and_then(|overcapture_data| overcapture_data.overcaptured_amount.clone()); Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( From 6436466a1078de34e14a1c5a7b91d4053ef7b6bb Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 23 Dec 2024 16:18:00 +0530 Subject: [PATCH 18/64] chroe: fix spell check error --- crates/router/src/core/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index d2bd00091931..29d5e09a3fb0 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -457,9 +457,9 @@ pub fn get_overcaptured_amount( net_amount: MinorUnit, ) -> Option { match overcapture_applied.zip(amount_captured) { - Some((true, orginal_amount_captured)) => { - if net_amount < orginal_amount_captured { - Some(orginal_amount_captured - net_amount) + Some((true, amount_captured_minor_unit)) => { + if net_amount < amount_captured_minor_unit { + Some(amount_captured_minor_unit - net_amount) } else { None } From 7c37b4df656e6f392f259d2c01849f99d8b1004b Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 24 Dec 2024 12:36:48 +0530 Subject: [PATCH 19/64] chore: remove get_should_always_enable_overcapture() --- crates/common_utils/src/id_type/merchant.rs | 8 -------- crates/diesel_models/src/payment_attempt.rs | 4 ---- 2 files changed, 12 deletions(-) diff --git a/crates/common_utils/src/id_type/merchant.rs b/crates/common_utils/src/id_type/merchant.rs index cac3dd5ff33a..e12f71e917f9 100644 --- a/crates/common_utils/src/id_type/merchant.rs +++ b/crates/common_utils/src/id_type/merchant.rs @@ -107,14 +107,6 @@ impl MerchantId { format!("max_auto_retries_enabled_{}", self.get_string_repr()) } - /// get_should_always_enable_overcapture key - pub fn get_should_always_enable_overcapture(&self) -> String { - format!( - "should_always_enable_overcapture_{}", - self.get_string_repr() - ) - } - /// get_requires_cvv_key pub fn get_requires_cvv_key(&self) -> String { format!("{}_requires_cvv", self.get_string_repr()) diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index c28349452914..567c6d30157d 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -798,9 +798,6 @@ pub struct PaymentAttemptUpdateInternal { // client_version: Option, // customer_acceptance: Option, // card_network: Option, - // pub request_overcapture: Option, - // pub overcapture_applied: Option, - // pub maximum_capturable_amount: Option, } #[cfg(feature = "v1")] @@ -863,7 +860,6 @@ pub struct PaymentAttemptUpdateInternal { #[cfg(feature = "v1")] impl PaymentAttemptUpdateInternal { - // to think about todooo pub fn populate_derived_fields(self, source: &PaymentAttempt) -> Self { let mut update_internal = self; update_internal.net_amount = Some( From fa626b106217607efe7ee7b14fed525808d3a8df Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 24 Dec 2024 14:33:57 +0530 Subject: [PATCH 20/64] chore: remove logger --- crates/router/src/connector/adyen/transformers.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index 20bdaa44f38d..e9d0cc7c45e6 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -1576,10 +1576,6 @@ impl TryFrom<&AdyenRouterData<&types::PaymentsAuthorizeRouterData>> for AdyenPay fn try_from( item: &AdyenRouterData<&types::PaymentsAuthorizeRouterData>, ) -> Result { - println!( - "$$$$$4request_overcapture: {:?}", - item.router_data.request_overcapture - ); match item .router_data .request From e5250e7df32e3ebca4d9f26ea8d7fc3b23995173 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 24 Dec 2024 14:56:07 +0530 Subject: [PATCH 21/64] chore: fix cypress test --- crates/diesel_models/src/schema.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index d8e78faf0d3b..9b599460c88b 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -215,8 +215,8 @@ diesel::table! { is_auto_retries_enabled -> Nullable, max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, - authentication_product_ids -> Nullable, always_request_overcapture -> Bool, + authentication_product_ids -> Nullable, } } @@ -973,9 +973,9 @@ diesel::table! { skip_external_tax_calculation -> Nullable, psd2_sca_exemption_type -> Nullable, split_payments -> Nullable, + request_overcapture -> Nullable, #[max_length = 64] platform_merchant_id -> Nullable, - request_overcapture -> Nullable, } } From d0fb6c764a91757effe9506bc0d6cfc64fa48f82 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 24 Dec 2024 15:54:11 +0530 Subject: [PATCH 22/64] chore: fix diesel migration error --- crates/common_enums/Cargo.toml | 2 +- crates/diesel_models/src/business_profile.rs | 1 - crates/diesel_models/src/schema.rs | 4 ++-- crates/diesel_models/src/schema_v2.rs | 3 --- .../down.sql | 0 .../up.sql | 0 .../down.sql | 0 .../up.sql | 0 .../down.sql | 0 .../up.sql | 0 10 files changed, 3 insertions(+), 7 deletions(-) rename migrations/{2024-12-09-072648_add_always_request_overcapture => 2024-12-24-072648_add_always_request_overcapture}/down.sql (100%) rename migrations/{2024-12-09-072648_add_always_request_overcapture => 2024-12-24-072648_add_always_request_overcapture}/up.sql (100%) rename migrations/{2024-12-12-123457_add_overcapture_fields_to_payment_attempt => 2024-12-24-123457_add_overcapture_fields_to_payment_attempt}/down.sql (100%) rename migrations/{2024-12-12-123457_add_overcapture_fields_to_payment_attempt => 2024-12-24-123457_add_overcapture_fields_to_payment_attempt}/up.sql (100%) rename migrations/{2024-12-11-83746_add_request_overcapture_to_payment_intent => 2024-12-24-83746_add_request_overcapture_to_payment_intent}/down.sql (100%) rename migrations/{2024-12-11-83746_add_request_overcapture_to_payment_intent => 2024-12-24-83746_add_request_overcapture_to_payment_intent}/up.sql (100%) diff --git a/crates/common_enums/Cargo.toml b/crates/common_enums/Cargo.toml index 92fc2f02066b..f8f25593c8bd 100644 --- a/crates/common_enums/Cargo.toml +++ b/crates/common_enums/Cargo.toml @@ -13,7 +13,7 @@ openapi = [] payouts = [] [dependencies] -diesel = { version = "2.2.3", features = ["postgres"] } +diesel = { version = "2.2.3", features = ["postgres", "128-column-tables"]} serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" strum = { version = "0.26", features = ["derive"] } diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index 71bde6c42d2c..2123e6fcff13 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -59,7 +59,6 @@ pub struct Profile { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, } #[cfg(feature = "v1")] diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 9b599460c88b..d8e78faf0d3b 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -215,8 +215,8 @@ diesel::table! { is_auto_retries_enabled -> Nullable, max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, - always_request_overcapture -> Bool, authentication_product_ids -> Nullable, + always_request_overcapture -> Bool, } } @@ -973,9 +973,9 @@ diesel::table! { skip_external_tax_calculation -> Nullable, psd2_sca_exemption_type -> Nullable, split_payments -> Nullable, - request_overcapture -> Nullable, #[max_length = 64] platform_merchant_id -> Nullable, + request_overcapture -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 3a2cbf9460c1..8bbb4baf9d74 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -224,7 +224,6 @@ diesel::table! { max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, authentication_product_ids -> Nullable, - always_request_overcapture -> Bool, } } @@ -860,7 +859,6 @@ diesel::table! { shipping_cost -> Nullable, order_tax_amount -> Nullable, connector_mandate_detail -> Nullable, - overcapture_details -> Nullable, } } @@ -938,7 +936,6 @@ diesel::table! { split_payments -> Nullable, #[max_length = 64] platform_merchant_id -> Nullable, - request_overcapture -> Nullable, } } diff --git a/migrations/2024-12-09-072648_add_always_request_overcapture/down.sql b/migrations/2024-12-24-072648_add_always_request_overcapture/down.sql similarity index 100% rename from migrations/2024-12-09-072648_add_always_request_overcapture/down.sql rename to migrations/2024-12-24-072648_add_always_request_overcapture/down.sql diff --git a/migrations/2024-12-09-072648_add_always_request_overcapture/up.sql b/migrations/2024-12-24-072648_add_always_request_overcapture/up.sql similarity index 100% rename from migrations/2024-12-09-072648_add_always_request_overcapture/up.sql rename to migrations/2024-12-24-072648_add_always_request_overcapture/up.sql diff --git a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql similarity index 100% rename from migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/down.sql rename to migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql diff --git a/migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql similarity index 100% rename from migrations/2024-12-12-123457_add_overcapture_fields_to_payment_attempt/up.sql rename to migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql diff --git a/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/down.sql b/migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/down.sql similarity index 100% rename from migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/down.sql rename to migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/down.sql diff --git a/migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/up.sql b/migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/up.sql similarity index 100% rename from migrations/2024-12-11-83746_add_request_overcapture_to_payment_intent/up.sql rename to migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/up.sql From 2e06db856763355392752c3b11a84768b6a6f6ab Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 26 Dec 2024 16:27:08 +0530 Subject: [PATCH 23/64] fix(router): add fields to schema_v2.rs --- crates/diesel_models/src/business_profile.rs | 1 + crates/diesel_models/src/schema_v2.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index 2123e6fcff13..71bde6c42d2c 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -59,6 +59,7 @@ pub struct Profile { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, + pub always_request_overcapture: bool, } #[cfg(feature = "v1")] diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 8bbb4baf9d74..3a2cbf9460c1 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -224,6 +224,7 @@ diesel::table! { max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, authentication_product_ids -> Nullable, + always_request_overcapture -> Bool, } } @@ -859,6 +860,7 @@ diesel::table! { shipping_cost -> Nullable, order_tax_amount -> Nullable, connector_mandate_detail -> Nullable, + overcapture_details -> Nullable, } } @@ -936,6 +938,7 @@ diesel::table! { split_payments -> Nullable, #[max_length = 64] platform_merchant_id -> Nullable, + request_overcapture -> Nullable, } } From 00e953a7d28e615d590df2e48fd280cf0508609d Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 26 Dec 2024 18:05:59 +0530 Subject: [PATCH 24/64] fix(router): remove overcapture_details from v2 PaymentAttempt Update --- crates/common_utils/src/types.rs | 1 + crates/diesel_models/src/payment_attempt.rs | 2 +- crates/diesel_models/src/payment_intent.rs | 2 -- .../src/payments/payment_attempt.rs | 13 ++++++++----- .../src/payments/payment_intent.rs | 6 ------ crates/hyperswitch_domain_models/src/router_data.rs | 2 ++ .../src/router_response_types.rs | 4 ++-- .../core/payments/operations/payment_response.rs | 2 +- .../payments/operations/payment_update_intent.rs | 1 - crates/router/src/core/payments/transformers.rs | 12 ++++++++---- crates/router/src/types/storage/payment_attempt.rs | 10 +++------- crates/router/tests/connectors/aci.rs | 2 ++ crates/router/tests/payments.rs | 4 ++++ crates/router/tests/payments2.rs | 4 ++++ crates/storage_impl/src/payments/payment_attempt.rs | 4 ++-- 15 files changed, 38 insertions(+), 31 deletions(-) diff --git a/crates/common_utils/src/types.rs b/crates/common_utils/src/types.rs index 7531a7732faa..3d55a8b265b6 100644 --- a/crates/common_utils/src/types.rs +++ b/crates/common_utils/src/types.rs @@ -1417,6 +1417,7 @@ crate::impl_to_sql_from_sql_json!(BrowserInformation); #[derive( ToSchema, Debug, + Default, Clone, serde::Deserialize, serde::Serialize, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 567c6d30157d..df39e8c5e5f0 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -94,7 +94,7 @@ pub struct PaymentAttempt { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub overcapture_details: Option, } #[cfg(feature = "v1")] diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs index 4e684e4ce606..94ec28b5db22 100644 --- a/crates/diesel_models/src/payment_intent.rs +++ b/crates/diesel_models/src/payment_intent.rs @@ -499,7 +499,6 @@ pub struct PaymentIntentUpdateFields { pub customer_details: Option, pub merchant_order_reference_id: Option, pub is_payment_processor_token_flow: Option, - pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -574,7 +573,6 @@ pub struct PaymentIntentUpdateInternal { pub frm_metadata: Option, pub request_external_three_ds_authentication: Option, pub updated_by: String, - pub request_overcapture: Option, } #[cfg(feature = "v1")] diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 99f9b74f963e..5faf03649d65 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -402,10 +402,8 @@ pub struct PaymentAttempt { pub id: id_type::GlobalAttemptId, /// The connector mandate details which are stored temporarily pub connector_mandate_detail: Option, - /// This is based on Payment Request and the configuration of the merchant in the business profile - pub request_overcapture: Option, - pub overcapture_applied: Option, - pub maximum_capturable_amount: Option, + /// Details related to payment overcapture + pub overcapture_details: Option, } impl PaymentAttempt { @@ -524,6 +522,7 @@ impl PaymentAttempt { error: None, connector_mandate_detail: None, id, + overcapture_details: None, }) } } @@ -1604,7 +1603,7 @@ impl behaviour::Conversion for PaymentAttempt { let overcaptured_amount = storage_model .overcapture_details .as_ref() - .and_then(|overcapture_data| overcapture_data.overcaptured_amount.clone()); + .and_then(|overcapture_data| overcapture_data.overcaptured_amount); Ok::>(Self { payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, @@ -1822,6 +1821,7 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_billing_address, connector, connector_mandate_detail, + overcapture_details, } = self; let AttemptAmountDetails { @@ -1899,6 +1899,7 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_billing_address: payment_method_billing_address.map(Encryption::from), connector_payment_data, connector_mandate_detail, + overcapture_details, }) } @@ -2010,6 +2011,7 @@ impl behaviour::Conversion for PaymentAttempt { connector: storage_model.connector, payment_method_billing_address, connector_mandate_detail: storage_model.connector_mandate_detail, + overcapture_details: storage_model.overcapture_details, }) } .await @@ -2094,6 +2096,7 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_type_v2: self.payment_method_type, id: self.id, connector_mandate_detail: self.connector_mandate_detail, + overcapture_details: self.overcapture_details, }) } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index 5a5b238129d1..4cc4a0e2f3e3 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -164,7 +164,6 @@ pub struct PaymentIntentUpdateFields { // updated_by is set internally, field not present in request pub updated_by: String, - pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -401,7 +400,6 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata: None, request_external_three_ds_authentication: None, updated_by, - request_overcapture: None, }, PaymentIntentUpdate::ConfirmIntentPostUpdate { @@ -443,7 +441,6 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata: None, request_external_three_ds_authentication: None, updated_by, - request_overcapture: None, }, PaymentIntentUpdate::SyncUpdate { status, @@ -524,7 +521,6 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata: None, request_external_three_ds_authentication: None, updated_by, - request_overcapture: None, }, PaymentIntentUpdate::UpdateIntent(boxed_intent) => { let PaymentIntentUpdateFields { @@ -558,7 +554,6 @@ impl From for diesel_models::PaymentIntentUpdateInternal { frm_metadata, request_external_three_ds_authentication, updated_by, - request_overcapture, } = *boxed_intent; Self { status: None, @@ -602,7 +597,6 @@ impl From for diesel_models::PaymentIntentUpdateInternal { request_external_three_ds_authentication.map(|val| val.as_bool()), updated_by, - request_overcapture: request_overcapture.map(|val| val.as_bool()), } } } diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index d89f9c94d216..cb542259d018 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -914,6 +914,8 @@ impl connector_response_reference_id, incremental_authorization_allowed, charge_id, + overcapture_applied, + maximum_capturable_amount, } => { let attempt_status = self.get_attempt_status_for_db_update(payment_data); diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs index 677c81c7bbeb..a4142a742c01 100644 --- a/crates/hyperswitch_domain_models/src/router_response_types.rs +++ b/crates/hyperswitch_domain_models/src/router_response_types.rs @@ -205,8 +205,8 @@ impl PaymentsResponseData { incremental_authorization_allowed: (*capture_incremental_auth_allowed) .or(*auth_incremental_auth_allowed), charge_id: capture_charge_id.clone().or(auth_charge_id.clone()), - overcapture_applied: auth_overcapture_applied.clone(), - maximum_capturable_amount: auth_maximum_capturable_amount.clone(), + overcapture_applied: *auth_overcapture_applied, + maximum_capturable_amount: *auth_maximum_capturable_amount, }), _ => Err(ApiErrorResponse::NotSupported { message: "Invalid Flow ".to_owned(), diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 1ee3c7f86b4d..4502ce6af416 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -873,7 +873,7 @@ impl PostUpdateTracker, types::PaymentsCaptureData> .payment_attempt .overcapture_details .as_ref() - .and_then(|overcapture_data| overcapture_data.overcapture_applied.clone()); + .and_then(|overcapture_data| overcapture_data.overcapture_applied); core_utils::get_overcaptured_amount( overcapture_applied, router_data.amount_captured.map(MinorUnit::new), diff --git a/crates/router/src/core/payments/operations/payment_update_intent.rs b/crates/router/src/core/payments/operations/payment_update_intent.rs index 1c0ad98d99d6..298006e5bed5 100644 --- a/crates/router/src/core/payments/operations/payment_update_intent.rs +++ b/crates/router/src/core/payments/operations/payment_update_intent.rs @@ -347,7 +347,6 @@ impl UpdateTracker, PaymentsUpdateIn request_external_three_ds_authentication: Some( intent.request_external_three_ds_authentication, ), - request_overcapture: Some(intent.request_overcapture), updated_by: intent.updated_by, tax_details: intent.amount_details.tax_details, })); diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 0e198b6fe311..0684e77ee19c 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -376,6 +376,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>( connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) @@ -544,6 +545,7 @@ pub async fn construct_payment_router_data_for_capture<'a>( connector_mandate_request_reference_id, psd2_sca_exemption_type: None, authentication_id: None, + request_overcapture: None, }; Ok(router_data) @@ -678,6 +680,7 @@ pub async fn construct_router_data_for_psync<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, }; Ok(router_data) @@ -843,6 +846,7 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>( connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, authentication_id: None, + request_overcapture: None, }; Ok(router_data) @@ -2225,8 +2229,8 @@ where .as_ref() .map(|overcapture_data| { ( - overcapture_data.overcapture_applied.clone(), - overcapture_data.maximum_capturable_amount.clone(), + overcapture_data.overcapture_applied, + overcapture_data.maximum_capturable_amount, ) }) .unwrap_or((None, None)); @@ -2601,8 +2605,8 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay order_tax_amount: None, connector_mandate_id:None, shipping_cost: None, - overcapture_applied: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.overcapture_applied.clone()), - maximum_capturable_amount: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.maximum_capturable_amount.clone()), + overcapture_applied: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.overcapture_applied), + maximum_capturable_amount: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.maximum_capturable_amount), } } } diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index 3c30df9ad2ae..dd7d3de3aff9 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -217,9 +217,7 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - request_overcapture: Default::default(), - overcapture_applied: Default::default(), - maximum_capturable_amount: Default::default(), + overcapture_details: Default::default(), }; let store = state @@ -304,8 +302,7 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - overcapture_applied: Default::default(), - maximum_capturable_amount: Default::default(), + overcapture_details: Default::default(), }; let store = state .stores @@ -403,8 +400,7 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - overcapture_applied: Default::default(), - maximum_capturable_amount: Default::default(), + overcapture_details: Default::default(), }; let store = state .stores diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index e3fd2bc1ee9c..b344664b505c 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -132,6 +132,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, + request_overcapture: None } } @@ -204,6 +205,7 @@ fn construct_refund_router_data() -> types::RefundsRouterData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, + request_overcapture: None, } } diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs index beaacb79fc01..b383ee359533 100644 --- a/crates/router/tests/payments.rs +++ b/crates/router/tests/payments.rs @@ -450,6 +450,8 @@ async fn payments_create_core() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, + maximum_capturable_amount: None, + overcapture_applied: None, }; let expected_response = services::ApplicationResponse::JsonWithHeaders((expected_response, vec![])); @@ -713,6 +715,8 @@ async fn payments_create_core_adyen_no_redirect() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, + maximum_capturable_amount: None, + overcapture_applied: None, }, vec![], )); diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs index 1d573d007ba6..16233dc82606 100644 --- a/crates/router/tests/payments2.rs +++ b/crates/router/tests/payments2.rs @@ -211,6 +211,8 @@ async fn payments_create_core() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, + maximum_capturable_amount: None, + overcapture_applied: None, }; let expected_response = @@ -483,6 +485,8 @@ async fn payments_create_core_adyen_no_redirect() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, + maximum_capturable_amount: None, + overcapture_applied: None, }, vec![], )); diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index baa852634193..7cbb68ba8e61 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -1523,7 +1523,7 @@ impl DataModelExt for PaymentAttempt { let overcaptured_amount = storage_model .overcapture_details .as_ref() - .and_then(|overcapture_data| overcapture_data.overcaptured_amount.clone()); + .and_then(|overcapture_data| overcapture_data.overcaptured_amount); Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( storage_model.amount, @@ -1686,7 +1686,7 @@ impl DataModelExt for PaymentAttemptNew { let overcapture_amount = storage_model .overcapture_details .as_ref() - .and_then(|overcapture_data| overcapture_data.overcaptured_amount.clone()); + .and_then(|overcapture_data| overcapture_data.overcaptured_amount); Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( From c72690fdbffc1fd612eb464a59bd4974ad74c30b Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:37:38 +0000 Subject: [PATCH 25/64] chore: run formatter --- crates/router/tests/connectors/aci.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index b344664b505c..5b3eb11b67f2 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -132,7 +132,7 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None + request_overcapture: None, } } From a10e7aaa1722261068689e2e23dd41d415d8606e Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Fri, 27 Dec 2024 14:46:06 +0530 Subject: [PATCH 26/64] fix(core): Add overcapture_details to payment attempt for manual capture --- crates/router/src/core/payments/helpers.rs | 24 +++++++++++++++++++ .../payments/operations/payment_confirm.rs | 19 +++------------ .../payments/operations/payment_create.rs | 19 ++++++++------- .../payments/operations/payment_update.rs | 21 ++++------------ 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index b96d095efbe5..cb5d72566944 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6293,3 +6293,27 @@ pub fn validate_platform_fees_for_marketplace( } Ok(()) } + +pub fn update_or_add_overcapture_details_if_required( + request_overcapture: Option, + payment_attempt: &mut PaymentAttempt, +) -> Result<(), errors::ApiErrorResponse> { + if let Some((request_overcapture, true)) = request_overcapture.zip(Some(payment_attempt.capture_method.eq(&Some(enums::CaptureMethod::Manual)))) { + match payment_attempt.overcapture_details { + Some(ref mut overcapture_data) => { + overcapture_data.request_overcapture = Some(request_overcapture); + } + None => { + payment_attempt.overcapture_details = Some(common_utils::types::OvercaptureData { + request_overcapture: Some(request_overcapture), + overcapture_applied: None, + maximum_capturable_amount: None, + overcaptured_amount: None, + }); + } + } + Ok(()) + } else { + Ok(()) + } +} \ No newline at end of file diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 44d0e646d8e0..c98ba0be338d 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -404,23 +404,10 @@ impl GetTracker, api::PaymentsRequest> payment_attempt.capture_method = request.capture_method.or(payment_attempt.capture_method); - match ( - payment_attempt.overcapture_details.clone(), + helpers::update_or_add_overcapture_details_if_required( request.request_overcapture, - ) { - (Some(mut overcapture_data), Some(request_overcapture)) => { - overcapture_data.request_overcapture = Some(request_overcapture); - } - (None, Some(request_overcapture)) => { - payment_attempt.overcapture_details = Some(common_utils::types::OvercaptureData { - request_overcapture: Some(request_overcapture), - overcapture_applied: None, - maximum_capturable_amount: None, - overcaptured_amount: None, - }); - } - _ => (), - }; + &mut payment_attempt, + )?; payment_attempt.customer_acceptance = request .customer_acceptance diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 6a69b7728d8e..fd339d79a3e0 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1143,14 +1143,17 @@ impl PaymentCreate { .transpose()? .flatten(); - let overcapture_details = Some(common_utils::types::OvercaptureData { - request_overcapture: request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)), - overcapture_applied: None, - maximum_capturable_amount: None, - overcaptured_amount: None, - }); + let overcapture_details = match request.capture_method.map(|capture_method| capture_method.eq(&common_enums::CaptureMethod::Manual)){ + Some(true) => Some(common_utils::types::OvercaptureData { + request_overcapture: request + .request_overcapture + .or(Some(business_profile.always_request_overcapture)), + overcapture_applied: None, + maximum_capturable_amount: None, + overcaptured_amount: None, + }), + Some(false) | None => None + }; if additional_pm_data.is_none() { // If recurring payment is made using payment_method_id, then fetch payment_method_data from retrieved payment_method object diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 09b25ae102e0..c6c4fbe47b4a 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -444,23 +444,10 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - match ( - payment_attempt.overcapture_details.clone(), - request.request_overcapture, - ) { - (Some(mut overcapture_data), Some(request_overcapture)) => { - overcapture_data.request_overcapture = Some(request_overcapture); - } - (None, Some(request_overcapture)) => { - payment_attempt.overcapture_details = Some(common_utils::types::OvercaptureData { - request_overcapture: Some(request_overcapture), - overcapture_applied: None, - maximum_capturable_amount: None, - overcaptured_amount: None, - }); - } - _ => (), - }; + helpers::update_or_add_overcapture_details_if_required( + request.request_overcapture, + &mut payment_attempt, + )?; let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) From f6503f07d6f7cdaa10cebe456e1247c2d895546d Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 09:17:08 +0000 Subject: [PATCH 27/64] chore: run formatter --- crates/router/src/core/payments/helpers.rs | 8 ++++++-- .../router/src/core/payments/operations/payment_create.rs | 7 +++++-- .../router/src/core/payments/operations/payment_update.rs | 8 ++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index cb5d72566944..58b7358eabd4 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6298,7 +6298,11 @@ pub fn update_or_add_overcapture_details_if_required( request_overcapture: Option, payment_attempt: &mut PaymentAttempt, ) -> Result<(), errors::ApiErrorResponse> { - if let Some((request_overcapture, true)) = request_overcapture.zip(Some(payment_attempt.capture_method.eq(&Some(enums::CaptureMethod::Manual)))) { + if let Some((request_overcapture, true)) = request_overcapture.zip(Some( + payment_attempt + .capture_method + .eq(&Some(enums::CaptureMethod::Manual)), + )) { match payment_attempt.overcapture_details { Some(ref mut overcapture_data) => { overcapture_data.request_overcapture = Some(request_overcapture); @@ -6316,4 +6320,4 @@ pub fn update_or_add_overcapture_details_if_required( } else { Ok(()) } -} \ No newline at end of file +} diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index fd339d79a3e0..5d9a16ceea2c 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1143,7 +1143,10 @@ impl PaymentCreate { .transpose()? .flatten(); - let overcapture_details = match request.capture_method.map(|capture_method| capture_method.eq(&common_enums::CaptureMethod::Manual)){ + let overcapture_details = match request + .capture_method + .map(|capture_method| capture_method.eq(&common_enums::CaptureMethod::Manual)) + { Some(true) => Some(common_utils::types::OvercaptureData { request_overcapture: request .request_overcapture @@ -1152,7 +1155,7 @@ impl PaymentCreate { maximum_capturable_amount: None, overcaptured_amount: None, }), - Some(false) | None => None + Some(false) | None => None, }; if additional_pm_data.is_none() { diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index c6c4fbe47b4a..26eda7c6beb5 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -444,10 +444,10 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - helpers::update_or_add_overcapture_details_if_required( - request.request_overcapture, - &mut payment_attempt, - )?; + helpers::update_or_add_overcapture_details_if_required( + request.request_overcapture, + &mut payment_attempt, + )?; let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) From f6fad46fca241d14e04c8d2bf3b47035d82e7465 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Fri, 27 Dec 2024 14:59:25 +0530 Subject: [PATCH 28/64] fix(clippy): add v1 flag to update_or_add_overcapture_details_if_required() --- crates/router/src/core/payments/helpers.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 58b7358eabd4..5e5c0d36fcba 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6294,6 +6294,7 @@ pub fn validate_platform_fees_for_marketplace( Ok(()) } +#[cfg(feature = "v1")] pub fn update_or_add_overcapture_details_if_required( request_overcapture: Option, payment_attempt: &mut PaymentAttempt, From 0ad35473e9576f3d5b2268dab78733edad883fe9 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Fri, 3 Jan 2025 18:13:46 +0530 Subject: [PATCH 29/64] refactor(core): remove request_overcapture from router data connector_response --- connector-template/transformers.rs | 2 +- .../hyperswitch_domain_models/src/router_data.rs | 2 -- .../router/src/connector/stripe/transformers.rs | 4 ++-- .../src/core/authentication/transformers.rs | 1 - .../src/core/fraud_check/flows/checkout_flow.rs | 1 - .../core/fraud_check/flows/fulfillment_flow.rs | 1 - .../src/core/fraud_check/flows/record_return.rs | 1 - .../src/core/fraud_check/flows/sale_flow.rs | 1 - .../core/fraud_check/flows/transaction_flow.rs | 1 - crates/router/src/core/mandate/utils.rs | 1 - crates/router/src/core/payments/helpers.rs | 1 - crates/router/src/core/payments/transformers.rs | 8 -------- crates/router/src/core/relay/utils.rs | 1 - .../core/unified_authentication_service/utils.rs | 1 - crates/router/src/core/utils.rs | 8 -------- crates/router/src/core/webhooks/utils.rs | 1 - crates/router/src/services/api.rs | 16 +++++++++++++++- crates/router/src/services/conversion_impls.rs | 1 - crates/router/src/types.rs | 2 -- crates/router/src/types/api/verify_connector.rs | 1 - 20 files changed, 18 insertions(+), 37 deletions(-) diff --git a/connector-template/transformers.rs b/connector-template/transformers.rs index 8d26b881e529..c76496bf3fd8 100644 --- a/connector-template/transformers.rs +++ b/connector-template/transformers.rs @@ -140,7 +140,7 @@ impl TryFrom { pub authentication_id: Option, /// Contains the type of sca exemption required for the transaction pub psd2_sca_exemption_type: Option, - - pub request_overcapture: Option, } // Different patterns of authentication. diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 5682d2c2f4ed..2cfc708d975a 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -1824,7 +1824,7 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntent &item.request, )), billing_address, - item.request_overcapture, + None, )?; validate_shipping_address_against_payment_method( @@ -2095,7 +2095,7 @@ impl TryFrom<&types::TokenizationRouterData> for TokenRequest { item.payment_method_token.clone(), None, StripeBillingAddress::default(), - item.request_overcapture, + None, //todooo )?; Ok(Self { token_data: payment_data.0, diff --git a/crates/router/src/core/authentication/transformers.rs b/crates/router/src/core/authentication/transformers.rs index c4f6afbff073..da6252d54292 100644 --- a/crates/router/src/core/authentication/transformers.rs +++ b/crates/router/src/core/authentication/transformers.rs @@ -192,7 +192,6 @@ pub fn construct_router_data( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type, - request_overcapture: None, }) } diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs index 3dff3d7e3557..b07268ae6668 100644 --- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs +++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs @@ -163,7 +163,6 @@ impl ConstructFlowSpecificData( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs index 28c1ed57db3f..d05f7280024a 100644 --- a/crates/router/src/core/fraud_check/flows/record_return.rs +++ b/crates/router/src/core/fraud_check/flows/record_return.rs @@ -131,7 +131,6 @@ impl ConstructFlowSpecificData( connector_mandate_request_reference_id: router_data.connector_mandate_request_reference_id, authentication_id: router_data.authentication_id, psd2_sca_exemption_type: router_data.psd2_sca_exemption_type, - request_overcapture: router_data.request_overcapture, } } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 0684e77ee19c..48be954b8a03 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -172,7 +172,6 @@ where connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } @@ -979,12 +978,6 @@ where crate::logger::debug!("unified address details {:?}", unified_address); - let request_overcapture = payment_data - .payment_attempt - .overcapture_details - .as_ref() - .and_then(|ovecapture_data| ovecapture_data.request_overcapture); - router_data = types::RouterData { flow: PhantomData, merchant_id: merchant_account.get_id().clone(), @@ -1054,7 +1047,6 @@ where connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: payment_data.payment_intent.psd2_sca_exemption_type, - request_overcapture, }; Ok(router_data) diff --git a/crates/router/src/core/relay/utils.rs b/crates/router/src/core/relay/utils.rs index a648d66e434b..0753be1ec435 100644 --- a/crates/router/src/core/relay/utils.rs +++ b/crates/router/src/core/relay/utils.rs @@ -133,7 +133,6 @@ pub async fn construct_relay_refund_router_data<'a, F>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs index aeef696d5b2a..e0d10251049a 100644 --- a/crates/router/src/core/unified_authentication_service/utils.rs +++ b/crates/router/src/core/unified_authentication_service/utils.rs @@ -168,6 +168,5 @@ pub fn construct_uas_router_data( connector_mandate_request_reference_id: None, authentication_id, psd2_sca_exemption_type: None, - request_overcapture: None, }) } diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 29d5e09a3fb0..0edb2ae2687f 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -217,7 +217,6 @@ pub async fn construct_payout_router_data<'a, F>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) @@ -399,7 +398,6 @@ pub async fn construct_refund_router_data<'a, F>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) @@ -726,7 +724,6 @@ pub async fn construct_accept_dispute_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } @@ -825,7 +822,6 @@ pub async fn construct_submit_evidence_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } @@ -930,7 +926,6 @@ pub async fn construct_upload_file_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } @@ -1055,7 +1050,6 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data<'a, F: Clone connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } @@ -1157,7 +1151,6 @@ pub async fn construct_defend_dispute_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } @@ -1253,7 +1246,6 @@ pub async fn construct_retrieve_file_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs index f824c7c9ed30..f86ed910e46a 100644 --- a/crates/router/src/core/webhooks/utils.rs +++ b/crates/router/src/core/webhooks/utils.rs @@ -125,7 +125,6 @@ pub async fn construct_webhook_router_data<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) } diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index cac856b2c48b..5b7d0ea2cba0 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -495,7 +495,21 @@ pub async fn send_request( None => client, } } - Method::Delete => client.delete(url), + Method::Delete => { + let client = client.delete(url); + match request.body { + Some(RequestContent::Json(payload)) => client.json(&payload), + Some(RequestContent::FormData(form)) => client.multipart(form), + Some(RequestContent::FormUrlEncoded(payload)) => client.form(&payload), + Some(RequestContent::Xml(payload)) => { + let body = quick_xml::se::to_string(&payload) + .change_context(errors::ApiClientError::BodySerializationFailed)?; + client.body(body).header("Content-Type", "application/xml") + } + Some(RequestContent::RawBytes(payload)) => client.body(payload), + None => client, + } + } } .add_headers(headers) .timeout(Duration::from_secs( diff --git a/crates/router/src/services/conversion_impls.rs b/crates/router/src/services/conversion_impls.rs index c5892c4ec630..3902ef624da2 100644 --- a/crates/router/src/services/conversion_impls.rs +++ b/crates/router/src/services/conversion_impls.rs @@ -81,7 +81,6 @@ fn get_default_router_data( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, } } diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 6e54e16698ed..19567d2e830a 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -966,7 +966,6 @@ impl ForeignFrom<(&RouterData, T2) .clone(), authentication_id: data.authentication_id.clone(), psd2_sca_exemption_type: data.psd2_sca_exemption_type, - request_overcapture: data.request_overcapture, } } } @@ -1034,7 +1033,6 @@ impl psd2_sca_exemption_type: None, additional_merchant_data: data.additional_merchant_data.clone(), connector_mandate_request_reference_id: None, - request_overcapture: None, } } } diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs index 88060df087bd..bd55bd96b96e 100644 --- a/crates/router/src/types/api/verify_connector.rs +++ b/crates/router/src/types/api/verify_connector.rs @@ -121,7 +121,6 @@ impl VerifyConnectorData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, } } } From 8b0523ead2032d3fb6d52c57bc00622ad56abbdf Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Fri, 3 Jan 2025 18:45:19 +0530 Subject: [PATCH 30/64] refactor(core): add request_overcapture to PaymentsAuthorizeData --- .../hyperswitch_domain_models/src/router_request_types.rs | 1 + crates/router/src/core/payments/transformers.rs | 7 +++++++ crates/router/src/types.rs | 1 + crates/router/src/types/api/verify_connector.rs | 1 + 4 files changed, 10 insertions(+) diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs index aa9fb2b5f1f0..478d474ea9f0 100644 --- a/crates/hyperswitch_domain_models/src/router_request_types.rs +++ b/crates/hyperswitch_domain_models/src/router_request_types.rs @@ -71,6 +71,7 @@ pub struct PaymentsAuthorizeData { pub integrity_object: Option, pub shipping_cost: Option, pub additional_payment_method_data: Option, + pub request_overcapture: Option, } #[derive(Debug, Clone)] diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 48be954b8a03..6a72225044ee 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -2858,6 +2858,12 @@ impl TryFrom> for types::PaymentsAuthoriz .clone(); let shipping_cost = payment_data.payment_intent.shipping_cost; + let request_overcapture = payment_data + .payment_attempt + .overcapture_details + .as_ref() + .and_then(|overcapture_details| overcapture_details.request_overcapture); + Ok(Self { payment_method_data: (payment_method_data.get_required_value("payment_method_data")?), setup_future_usage: payment_data.payment_intent.setup_future_usage, @@ -2909,6 +2915,7 @@ impl TryFrom> for types::PaymentsAuthoriz integrity_object: None, additional_payment_method_data, shipping_cost, + request_overcapture, }) } } diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 19567d2e830a..db73f9e421db 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -905,6 +905,7 @@ impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData { integrity_object: None, additional_payment_method_data: None, shipping_cost: data.request.shipping_cost, + request_overcapture: None, } } } diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs index bd55bd96b96e..cb337ff92021 100644 --- a/crates/router/src/types/api/verify_connector.rs +++ b/crates/router/src/types/api/verify_connector.rs @@ -60,6 +60,7 @@ impl VerifyConnectorData { integrity_object: None, additional_payment_method_data: None, shipping_cost: None, + request_overcapture: None, } } From 2386449c22fd130d658c8ff5bb01a9edb1a00dbf Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 6 Jan 2025 10:37:52 +0530 Subject: [PATCH 31/64] refactor(router): remove overcapture_applied and maximum_amount_capturable from connector_response --- .../src/connectors/airwallex/transformers.rs | 4 -- .../src/connectors/amazonpay/transformers.rs | 2 - .../src/connectors/bambora/transformers.rs | 12 ----- .../connectors/bamboraapac/transformers.rs | 8 ---- .../src/connectors/billwerk/transformers.rs | 2 - .../src/connectors/bitpay/transformers.rs | 2 - .../src/connectors/bluesnap.rs | 2 - .../src/connectors/bluesnap/transformers.rs | 2 - .../src/connectors/boku/transformers.rs | 2 - .../src/connectors/cashtocode/transformers.rs | 4 -- .../src/connectors/coinbase/transformers.rs | 2 - .../src/connectors/cryptopay/transformers.rs | 2 - .../src/connectors/datatrans/transformers.rs | 4 -- .../connectors/deutschebank/transformers.rs | 8 ---- .../connectors/digitalvirgo/transformers.rs | 4 -- .../src/connectors/dlocal/transformers.rs | 8 ---- .../src/connectors/elavon/transformers.rs | 6 --- .../src/connectors/fiserv/transformers.rs | 4 -- .../src/connectors/fiservemea/transformers.rs | 2 - .../src/connectors/fiuu/transformers.rs | 18 -------- .../src/connectors/forte/transformers.rs | 8 ---- .../src/connectors/globepay/transformers.rs | 4 -- .../src/connectors/gocardless/transformers.rs | 6 --- .../src/connectors/helcim/transformers.rs | 10 ----- .../src/connectors/inespay/transformers.rs | 2 - .../src/connectors/jpmorgan/transformers.rs | 8 ---- .../src/connectors/mollie/transformers.rs | 2 - .../connectors/multisafepay/transformers.rs | 2 - .../src/connectors/nexinets/transformers.rs | 4 -- .../src/connectors/nexixpay/transformers.rs | 14 ------ .../src/connectors/nomupay/transformers.rs | 2 - .../src/connectors/novalnet/transformers.rs | 8 ---- .../src/connectors/paybox/transformers.rs | 10 ----- .../src/connectors/payeezy/transformers.rs | 2 - .../src/connectors/payu/transformers.rs | 8 ---- .../src/connectors/placetopay/transformers.rs | 2 - .../src/connectors/powertranz/transformers.rs | 2 - .../src/connectors/prophetpay/transformers.rs | 8 ---- .../src/connectors/rapyd/transformers.rs | 2 - .../src/connectors/razorpay/transformers.rs | 4 -- .../src/connectors/redsys/transformers.rs | 2 - .../src/connectors/shift4/transformers.rs | 4 -- .../src/connectors/square/transformers.rs | 3 +- .../src/connectors/stax/transformers.rs | 2 - .../src/connectors/thunes/transformers.rs | 2 - .../src/connectors/tsys/transformers.rs | 4 -- .../src/connectors/volt/transformers.rs | 8 +--- .../src/connectors/worldline/transformers.rs | 4 -- .../src/connectors/worldpay.rs | 6 --- .../src/connectors/worldpay/transformers.rs | 2 - .../src/connectors/xendit/transformers.rs | 2 - .../src/connectors/zen/transformers.rs | 4 -- .../src/connectors/zsl/transformers.rs | 4 -- .../src/router_data.rs | 6 --- .../src/router_response_types.rs | 8 ---- .../router/src/connector/aci/transformers.rs | 2 - .../src/connector/adyen/transformers.rs | 18 -------- .../connector/authorizedotnet/transformers.rs | 8 ---- .../connector/bankofamerica/transformers.rs | 8 ---- .../src/connector/braintree/transformers.rs | 18 -------- .../src/connector/checkout/transformers.rs | 8 ---- .../src/connector/cybersource/transformers.rs | 12 ----- .../connector/dummyconnector/transformers.rs | 2 - .../src/connector/globalpay/transformers.rs | 2 - .../src/connector/iatapay/transformers.rs | 4 -- .../src/connector/itaubank/transformers.rs | 4 -- .../src/connector/klarna/transformers.rs | 10 ----- .../src/connector/mifinity/transformers.rs | 10 ----- .../router/src/connector/nmi/transformers.rs | 14 ------ .../router/src/connector/noon/transformers.rs | 2 - .../src/connector/nuvei/transformers.rs | 2 - .../src/connector/opayo/transformers.rs | 2 - .../src/connector/opennode/transformers.rs | 2 - .../src/connector/payme/transformers.rs | 9 +--- crates/router/src/connector/paypal.rs | 4 -- .../src/connector/paypal/transformers.rs | 20 --------- .../src/connector/plaid/transformers.rs | 4 -- .../src/connector/stripe/transformers.rs | 8 ---- .../src/connector/trustpay/transformers.rs | 10 ----- .../src/connector/wellsfargo/transformers.rs | 8 ---- .../wellsfargopayout/transformers.rs | 2 - .../payments/operations/payment_response.rs | 34 +++++++------- crates/router/src/core/payments/retry.rs | 44 +++++++++---------- .../router/src/core/payments/transformers.rs | 2 - crates/router/tests/connectors/utils.rs | 2 - .../down.sql | 3 -- .../up.sql | 5 ++- 87 files changed, 45 insertions(+), 505 deletions(-) diff --git a/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs b/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs index 9e70253ac9a9..075a7b070d6d 100644 --- a/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs @@ -671,8 +671,6 @@ impl TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -600,8 +594,6 @@ impl connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -637,8 +629,6 @@ impl connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -674,8 +664,6 @@ impl connector_response_reference_id: Some(item.response.order_number.to_string()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs b/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs index cf426d5fbf6c..f4399d105c5d 100644 --- a/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/bamboraapac/transformers.rs @@ -314,8 +314,6 @@ impl connector_response_reference_id: Some(connector_transaction_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -488,8 +486,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -636,8 +632,6 @@ impl connector_response_reference_id: Some(connector_transaction_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -917,8 +911,6 @@ impl connector_response_reference_id: Some(connector_transaction_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs b/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs index 088b41c7dd6c..05b9abae0515 100644 --- a/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/billwerk/transformers.rs @@ -292,8 +292,6 @@ impl TryFrom TryFrom TryFrom TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs b/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs index 0e1525748f94..7a70d97a102c 100644 --- a/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/cashtocode/transformers.rs @@ -275,8 +275,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ) } @@ -310,8 +308,6 @@ impl TryFrom TryFrom .or(Some(item.response.data.id)), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; match amount_captured_in_minor_units { diff --git a/crates/hyperswitch_connectors/src/connectors/datatrans/transformers.rs b/crates/hyperswitch_connectors/src/connectors/datatrans/transformers.rs index b5d7afc9ca78..2ec76cb2937e 100644 --- a/crates/hyperswitch_connectors/src/connectors/datatrans/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/datatrans/transformers.rs @@ -290,8 +290,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } }; @@ -410,8 +408,6 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs index aa3d0d1cae9b..85c5fc8dc816 100644 --- a/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/deutschebank/transformers.rs @@ -352,8 +352,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -405,8 +403,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -619,8 +615,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -694,8 +688,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs b/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs index 74ea4e7dbfb8..a9408e4e1c52 100644 --- a/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/digitalvirgo/transformers.rs @@ -168,8 +168,6 @@ impl TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: Some(response.ssl_txn_id.clone()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } } @@ -394,8 +392,6 @@ impl TryFrom> for PaymentsSyn connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -455,8 +451,6 @@ impl TryFrom> connector_response_reference_id: Some(response.ssl_txn_id.clone()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } } diff --git a/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs b/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs index b26f04905f8b..f4084525410e 100644 --- a/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/fiserv/transformers.rs @@ -386,8 +386,6 @@ impl TryFrom TryFrom TryFrom connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -796,8 +794,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -854,8 +850,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { @@ -902,8 +896,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Self { @@ -923,8 +915,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }); Self { response, @@ -1196,8 +1186,6 @@ impl TryFrom> for PaymentsSy connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok(Self { status, @@ -1259,8 +1247,6 @@ impl TryFrom> for PaymentsSy connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok(Self { status, @@ -1430,8 +1416,6 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok(Self { status, @@ -1543,8 +1527,6 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok(Self { status, diff --git a/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs b/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs index 540a3ef286c8..2583f47058bf 100644 --- a/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/forte/transformers.rs @@ -309,8 +309,6 @@ impl TryFrom TryFrom> connector_response_reference_id: Some(item.response.transaction_id.to_string()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), amount_captured: None, ..item.data @@ -495,8 +489,6 @@ impl TryFrom TryFrom TryFrom mandate_reference: Box::new(mandate_reference), network_txn_id: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: enums::AttemptStatus::Charged, ..item.data @@ -688,8 +686,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -721,8 +717,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs b/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs index d3b5ae47b38e..4a8ddf68df9a 100644 --- a/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/helcim/transformers.rs @@ -388,8 +388,6 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -441,8 +439,6 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -492,8 +488,6 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -574,8 +568,6 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data @@ -633,8 +625,6 @@ impl connector_response_reference_id: item.response.invoice_number.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: enums::AttemptStatus::from(item.response), ..item.data diff --git a/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs index e1f8134eba01..296d76546c84 100644 --- a/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/inespay/transformers.rs @@ -136,8 +136,6 @@ impl TryFrom TryFrom TryFrom connector_response_reference_id: Some(item.response.transaction_id.clone()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -718,8 +712,6 @@ impl connector_response_reference_id: Some(item.response.transaction_id.clone()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs b/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs index e81ef12e81ed..5257df672f40 100644 --- a/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/mollie/transformers.rs @@ -514,8 +514,6 @@ impl TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: Some(item.response.operation.order_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -832,8 +830,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -853,8 +849,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -978,8 +972,6 @@ impl connector_response_reference_id: Some(item.response.operation.order_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -1152,8 +1144,6 @@ impl connector_response_reference_id: Some(item.response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -1212,8 +1202,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -1277,8 +1265,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs index de641ff1a735..bea8b607daea 100644 --- a/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/nomupay/transformers.rs @@ -136,8 +136,6 @@ impl TryFrom TryFrom connector_response_reference_id: transaction_id.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -1092,8 +1088,6 @@ impl connector_response_reference_id: transaction_id.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -1263,8 +1257,6 @@ impl connector_response_reference_id: transaction_id.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs index bdb5b0940028..effe6df28db2 100644 --- a/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/paybox/transformers.rs @@ -700,8 +700,6 @@ impl TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs b/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs index 2c6598ea086a..49188803c4f6 100644 --- a/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/payeezy/transformers.rs @@ -448,8 +448,6 @@ impl TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -414,8 +412,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -464,8 +460,6 @@ impl TryFrom TryFrom TryFrom TryFrom TryFrom TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -809,8 +807,6 @@ impl TryFrom TryFrom TryFrom TryFrom PaymentsResponseDa connector_response_reference_id: Some(connector_response.transaction_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, } } @@ -278,8 +276,6 @@ fn get_payments_sync_response( ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, } } diff --git a/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs b/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs index e52b582ba653..517930749df2 100644 --- a/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/volt/transformers.rs @@ -290,8 +290,7 @@ impl TryFrom TryFrom TryFrom TryFrom> connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -637,8 +635,6 @@ impl TryFrom for Wo connector_response_reference_id: optional_correlation_id, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..data.clone() }) @@ -534,8 +532,6 @@ impl ConnectorIntegration for Wor connector_response_reference_id: optional_correlation_id, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..data.clone() }) @@ -637,8 +633,6 @@ impl ConnectorIntegration fo connector_response_reference_id: optional_correlation_id, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..data.clone() }) diff --git a/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs b/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs index 2c5f295f187d..ec23b520a200 100644 --- a/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/worldpay/transformers.rs @@ -729,8 +729,6 @@ impl connector_response_reference_id: optional_correlation_id.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), (Some(reason), _) => Err(ErrorResponse { code: worldpay_status.to_string(), diff --git a/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs b/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs index 5daad7f15b8a..c9d4cd2583c2 100644 --- a/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/xendit/transformers.rs @@ -136,8 +136,6 @@ impl TryFrom TryFrom TryFrom TryFrom { let attempt_status = self.get_attempt_status_for_db_update(payment_data); @@ -695,8 +693,6 @@ impl connector_response_reference_id, incremental_authorization_allowed, charge_id, - overcapture_applied, - maximum_capturable_amount, } => { let attempt_status = self.status; @@ -912,8 +908,6 @@ impl connector_response_reference_id, incremental_authorization_allowed, charge_id, - overcapture_applied, - maximum_capturable_amount, } => { let attempt_status = self.get_attempt_status_for_db_update(payment_data); diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs index a4142a742c01..61453f36b84e 100644 --- a/crates/hyperswitch_domain_models/src/router_response_types.rs +++ b/crates/hyperswitch_domain_models/src/router_response_types.rs @@ -27,8 +27,6 @@ pub enum PaymentsResponseData { connector_response_reference_id: Option, incremental_authorization_allowed: Option, charge_id: Option, - overcapture_applied: Option, - maximum_capturable_amount: Option, }, MultipleCaptureResponse { // pending_capture_id_list: Vec, @@ -166,8 +164,6 @@ impl PaymentsResponseData { connector_response_reference_id: auth_connector_response_reference_id, incremental_authorization_allowed: auth_incremental_auth_allowed, charge_id: auth_charge_id, - overcapture_applied: auth_overcapture_applied, - maximum_capturable_amount: auth_maximum_capturable_amount, }, Self::TransactionResponse { resource_id: capture_resource_id, @@ -178,8 +174,6 @@ impl PaymentsResponseData { connector_response_reference_id: capture_connector_response_reference_id, incremental_authorization_allowed: capture_incremental_auth_allowed, charge_id: capture_charge_id, - overcapture_applied: _, - maximum_capturable_amount: _, }, ) => Ok(Self::TransactionResponse { resource_id: capture_resource_id.clone(), @@ -205,8 +199,6 @@ impl PaymentsResponseData { incremental_authorization_allowed: (*capture_incremental_auth_allowed) .or(*auth_incremental_auth_allowed), charge_id: capture_charge_id.clone().or(auth_charge_id.clone()), - overcapture_applied: *auth_overcapture_applied, - maximum_capturable_amount: *auth_maximum_capturable_amount, }), _ => Err(ApiErrorResponse::NotSupported { message: "Invalid Flow ".to_owned(), diff --git a/crates/router/src/connector/aci/transformers.rs b/crates/router/src/connector/aci/transformers.rs index f4693e73ff16..3e25799c02e6 100644 --- a/crates/router/src/connector/aci/transformers.rs +++ b/crates/router/src/connector/aci/transformers.rs @@ -772,8 +772,6 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index e9d0cc7c45e6..aece1df65463 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -3417,8 +3417,6 @@ impl TryFrom> connector_response_reference_id: Some(item.response.reference), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -3454,8 +3452,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), payment_method_balance: Some(types::PaymentMethodBalance { currency: item.response.balance.currency, @@ -3526,8 +3522,6 @@ pub fn get_adyen_response( connector_response_reference_id: Some(response.merchant_reference), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3595,8 +3589,6 @@ pub fn get_webhook_response( connector_response_reference_id: Some(response.merchant_reference_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3673,8 +3665,6 @@ pub fn get_redirection_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3736,8 +3726,6 @@ pub fn get_present_to_shopper_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3798,8 +3786,6 @@ pub fn get_qr_code_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) } @@ -3843,8 +3829,6 @@ pub fn get_redirection_error_response( .or(response.psp_reference), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok((status, error, payments_response_data)) @@ -4212,8 +4196,6 @@ impl TryFrom> connector_response_reference_id: Some(item.response.reference), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), amount_captured: Some(0), ..item.data diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs index 9c5d90902c7a..9698b4ac5d83 100644 --- a/crates/router/src/connector/authorizedotnet/transformers.rs +++ b/crates/router/src/connector/authorizedotnet/transformers.rs @@ -408,8 +408,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -1145,8 +1143,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), }, ..item.data @@ -1220,8 +1216,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), }, ..item.data @@ -1547,8 +1541,6 @@ impl connector_response_reference_id: Some(transaction.transaction_id.clone()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: payment_status, ..item.data diff --git a/crates/router/src/connector/bankofamerica/transformers.rs b/crates/router/src/connector/bankofamerica/transformers.rs index 3894fbc348ed..71cc006700e4 100644 --- a/crates/router/src/connector/bankofamerica/transformers.rs +++ b/crates/router/src/connector/bankofamerica/transformers.rs @@ -427,8 +427,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), }, connector_response, @@ -1535,8 +1533,6 @@ fn get_payment_response( ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } } @@ -1850,8 +1846,6 @@ impl .unwrap_or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), connector_response, ..item.data @@ -1871,8 +1865,6 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/braintree/transformers.rs b/crates/router/src/connector/braintree/transformers.rs index e24330f3938d..00624ce0f9b1 100644 --- a/crates/router/src/connector/braintree/transformers.rs +++ b/crates/router/src/connector/braintree/transformers.rs @@ -451,8 +451,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { @@ -476,8 +474,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -631,8 +627,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { @@ -656,8 +650,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -718,8 +710,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { @@ -785,8 +775,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { @@ -1295,8 +1283,6 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { @@ -1407,8 +1393,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { @@ -1514,8 +1498,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; Ok(Self { diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs index 6e7750c8d448..cd758fffb690 100644 --- a/crates/router/src/connector/checkout/transformers.rs +++ b/crates/router/src/connector/checkout/transformers.rs @@ -701,8 +701,6 @@ impl TryFrom> ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok(Self { status, @@ -756,8 +754,6 @@ impl TryFrom> ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }; Ok(Self { status, @@ -834,8 +830,6 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status: response.into(), ..item.data @@ -937,8 +931,6 @@ impl TryFrom> connector_response_reference_id: item.response.reference, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status, amount_captured, diff --git a/crates/router/src/connector/cybersource/transformers.rs b/crates/router/src/connector/cybersource/transformers.rs index 693f94210b1a..7ce98d3d5a34 100644 --- a/crates/router/src/connector/cybersource/transformers.rs +++ b/crates/router/src/connector/cybersource/transformers.rs @@ -2576,8 +2576,6 @@ fn get_payment_response( ), incremental_authorization_allowed, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } } @@ -2675,8 +2673,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -3085,8 +3081,6 @@ impl connector_response_reference_id, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -3344,8 +3338,6 @@ impl mandate_status == enums::AttemptStatus::Authorized, ), charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), }, connector_response, @@ -3475,8 +3467,6 @@ impl .unwrap_or(Some(item.response.id)), incremental_authorization_allowed, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -3495,8 +3485,6 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/dummyconnector/transformers.rs b/crates/router/src/connector/dummyconnector/transformers.rs index 0f3f779f8806..79caa3d0a767 100644 --- a/crates/router/src/connector/dummyconnector/transformers.rs +++ b/crates/router/src/connector/dummyconnector/transformers.rs @@ -260,8 +260,6 @@ impl TryFrom types::PaymentsResponseData::TransactionResponse { @@ -403,8 +401,6 @@ fn get_iatpay_response( connector_response_reference_id: connector_response_reference_id.clone(), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }, }; diff --git a/crates/router/src/connector/itaubank/transformers.rs b/crates/router/src/connector/itaubank/transformers.rs index 2e8b678323e8..127f8526afe4 100644 --- a/crates/router/src/connector/itaubank/transformers.rs +++ b/crates/router/src/connector/itaubank/transformers.rs @@ -288,8 +288,6 @@ impl connector_response_reference_id: Some(item.response.txid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -378,8 +376,6 @@ impl connector_response_reference_id: Some(item.response.txid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rs index 0f6007cd3513..0826b0f2665b 100644 --- a/crates/router/src/connector/klarna/transformers.rs +++ b/crates/router/src/connector/klarna/transformers.rs @@ -390,8 +390,6 @@ impl TryFrom> connector_response_reference_id: Some(response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, - maximum_capturable_amount: None, - overcapture_applied: None, }), status: enums::AttemptStatus::foreign_from(( response.fraud_status.clone(), @@ -415,8 +413,6 @@ impl TryFrom> connector_response_reference_id: Some(response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, - maximum_capturable_amount: None, - overcapture_applied: None, }), status: enums::AttemptStatus::foreign_from(( response.status.clone(), @@ -580,8 +576,6 @@ impl .or(Some(response.order_id.clone())), incremental_authorization_allowed: None, charge_id: None, - maximum_capturable_amount: None, - overcapture_applied: None, }), ..item.data }), @@ -601,8 +595,6 @@ impl connector_response_reference_id: Some(response.order_id.clone()), incremental_authorization_allowed: None, charge_id: None, - maximum_capturable_amount: None, - overcapture_applied: None, }), ..item.data }), @@ -681,8 +673,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), status, ..item.data diff --git a/crates/router/src/connector/mifinity/transformers.rs b/crates/router/src/connector/mifinity/transformers.rs index 9bd7f405864f..1e2c420c767b 100644 --- a/crates/router/src/connector/mifinity/transformers.rs +++ b/crates/router/src/connector/mifinity/transformers.rs @@ -269,8 +269,6 @@ impl connector_response_reference_id: Some(trace_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -286,8 +284,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -357,8 +353,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -374,8 +368,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -392,8 +384,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 42ffa4da3201..4c33f0200172 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -213,8 +213,6 @@ impl connector_response_reference_id: Some(item.response.transactionid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), enums::AttemptStatus::AuthenticationPending, ), @@ -369,8 +367,6 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method @@ -755,8 +751,6 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), enums::AttemptStatus::CaptureInitiated, ), @@ -852,8 +846,6 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), enums::AttemptStatus::Charged, ), @@ -911,8 +903,6 @@ impl TryFrom> connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method @@ -964,8 +954,6 @@ impl connector_response_reference_id: Some(item.response.orderid), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), enums::AttemptStatus::VoidInitiated, ), @@ -1017,8 +1005,6 @@ impl TryFrom connector_response_reference_id, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } }, diff --git a/crates/router/src/connector/nuvei/transformers.rs b/crates/router/src/connector/nuvei/transformers.rs index cc400818c0d1..a4195655ed38 100644 --- a/crates/router/src/connector/nuvei/transformers.rs +++ b/crates/router/src/connector/nuvei/transformers.rs @@ -1628,8 +1628,6 @@ where connector_response_reference_id: response.order_id, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }, ..item.data diff --git a/crates/router/src/connector/opayo/transformers.rs b/crates/router/src/connector/opayo/transformers.rs index 8e2e8b0bb8e1..f55aa4325b06 100644 --- a/crates/router/src/connector/opayo/transformers.rs +++ b/crates/router/src/connector/opayo/transformers.rs @@ -152,8 +152,6 @@ impl connector_response_reference_id: Some(item.response.transaction_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/opennode/transformers.rs b/crates/router/src/connector/opennode/transformers.rs index 30a07865f719..1e8239d377bb 100644 --- a/crates/router/src/connector/opennode/transformers.rs +++ b/crates/router/src/connector/opennode/transformers.rs @@ -145,8 +145,6 @@ impl connector_response_reference_id: item.response.data.order_id, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } else { Ok(types::PaymentsResponseData::TransactionUnresolvedResponse { diff --git a/crates/router/src/connector/payme/transformers.rs b/crates/router/src/connector/payme/transformers.rs index 160d0650edf0..2f3b471342a8 100644 --- a/crates/router/src/connector/payme/transformers.rs +++ b/crates/router/src/connector/payme/transformers.rs @@ -260,8 +260,6 @@ impl TryFrom<&PaymePaySaleResponse> for types::PaymentsResponseData { connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) } } @@ -329,8 +327,6 @@ impl From<&SaleQuery> for types::PaymentsResponseData { connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, } } } @@ -551,8 +547,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), @@ -1131,8 +1125,7 @@ impl TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, + }) }; Ok(Self { diff --git a/crates/router/src/connector/paypal.rs b/crates/router/src/connector/paypal.rs index e377dc36e1a1..fb635708c23e 100644 --- a/crates/router/src/connector/paypal.rs +++ b/crates/router/src/connector/paypal.rs @@ -1228,8 +1228,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..data.clone() }) @@ -1281,8 +1279,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..data.clone() }) diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs index 103755daf3b6..67204d9673c8 100644 --- a/crates/router/src/connector/paypal/transformers.rs +++ b/crates/router/src/connector/paypal/transformers.rs @@ -624,8 +624,6 @@ impl connector_response_reference_id: Some(info_response.id.clone()), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -1862,8 +1860,6 @@ impl .or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -1989,8 +1985,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -2046,8 +2040,6 @@ impl ), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -2101,8 +2093,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -2141,8 +2131,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -2196,8 +2184,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -2267,8 +2253,6 @@ impl .or(Some(item.response.supplementary_data.related_ids.order_id)), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -2610,8 +2594,6 @@ impl TryFrom> .or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), amount_captured: Some(amount_captured), ..item.data @@ -2664,8 +2646,6 @@ impl .or(Some(item.response.id)), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) diff --git a/crates/router/src/connector/plaid/transformers.rs b/crates/router/src/connector/plaid/transformers.rs index cfa3bf22076d..29d4db1297f8 100644 --- a/crates/router/src/connector/plaid/transformers.rs +++ b/crates/router/src/connector/plaid/transformers.rs @@ -315,8 +315,6 @@ impl connector_response_reference_id: Some(item.response.payment_id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }, ..item.data @@ -403,8 +401,6 @@ impl TryFrom connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id, - overcapture_applied, - maximum_capturable_amount, }) }; @@ -2776,8 +2774,6 @@ impl connector_response_reference_id: Some(item.response.id.clone()), incremental_authorization_allowed: None, charge_id, - overcapture_applied, - maximum_capturable_amount, }) }; @@ -2858,8 +2854,6 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }) }; @@ -3571,8 +3565,6 @@ impl TryFrom .unwrap_or(Some(item.response.id)), incremental_authorization_allowed, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }) @@ -2184,8 +2178,6 @@ impl connector_response_reference_id: Some(item.response.id), incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..item.data }), diff --git a/crates/router/src/connector/wellsfargopayout/transformers.rs b/crates/router/src/connector/wellsfargopayout/transformers.rs index 95adab56f753..135cb5f53cbf 100644 --- a/crates/router/src/connector/wellsfargopayout/transformers.rs +++ b/crates/router/src/connector/wellsfargopayout/transformers.rs @@ -141,8 +141,6 @@ impl connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }), ..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 4502ce6af416..158cc6a37131 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1551,8 +1551,6 @@ async fn payment_response_update_tracker( connector_response_reference_id, incremental_authorization_allowed, charge_id, - overcapture_applied, - maximum_capturable_amount, .. } => { payment_data @@ -1587,21 +1585,21 @@ async fn payment_response_update_tracker( None }; - let overcapture_details = - match payment_data.payment_attempt.overcapture_details.clone() { - Some(mut overcapture_details) => { - overcapture_details.overcapture_applied = - overcapture_applied; - overcapture_details.maximum_capturable_amount = - maximum_capturable_amount; - overcapture_details.overcaptured_amount = payment_data - .payment_attempt - .net_amount - .get_overcaptured_amount(); - Some(overcapture_details) - } - None => None, - }; + let overcapture_details = None; //todoo + // match payment_data.payment_attempt.overcapture_details.clone() { + // Some(mut overcapture_details) => { + // overcapture_details.overcapture_applied = + // overcapture_applied; + // overcapture_details.maximum_capturable_amount = + // maximum_capturable_amount; + // overcapture_details.overcaptured_amount = payment_data + // .payment_attempt + // .net_amount + // .get_overcaptured_amount(); + // Some(overcapture_details) + // } + // None => None, + // }; // incase of success, update error code and error message let error_status = @@ -1750,7 +1748,7 @@ async fn payment_response_update_tracker( .get_amount_capturable( &payment_data, updated_attempt_status, - maximum_capturable_amount, + None, ) .map(MinorUnit::new), payment_method_id, diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 98780e523b9c..5bf30a3a5882 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -422,8 +422,6 @@ where connector_metadata, redirection_data, charge_id, - overcapture_applied, - maximum_capturable_amount, .. }) => { let encoded_data = payment_data.get_payment_attempt().encoded_data.clone(); @@ -435,26 +433,26 @@ where .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not parse the connector response")?; - let overcapture_details = match payment_data - .get_payment_attempt() - .overcapture_details - .clone() - { - Some(mut overcapture_details) => { - overcapture_details.overcapture_applied = overcapture_applied; - overcapture_details.maximum_capturable_amount = maximum_capturable_amount; - overcapture_details.overcaptured_amount = get_overcaptured_amount( - overcapture_applied, - router_data.amount_captured.map(MinorUnit::new), - payment_data - .get_payment_attempt() - .net_amount - .get_total_amount(), - ); - Some(overcapture_details) - } - None => None, - }; + // let overcapture_details = match payment_data + // .get_payment_attempt() //todoooo + // .overcapture_details + // .clone() + // { + // Some(mut overcapture_details) => { + // overcapture_details.overcapture_applied = overcapture_applied; + // overcapture_details.maximum_capturable_amount = maximum_capturable_amount; + // overcapture_details.overcaptured_amount = get_overcaptured_amount( + // overcapture_applied, + // router_data.amount_captured.map(MinorUnit::new), + // payment_data + // .get_payment_attempt() + // .net_amount + // .get_total_amount(), + // ); + // Some(overcapture_details) + // } + // None => None, + // }; let payment_attempt_update = storage::PaymentAttemptUpdate::ResponseUpdate { status: router_data.status, @@ -491,7 +489,7 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, - overcapture_details, + overcapture_details: None, }; #[cfg(feature = "v1")] diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 6a72225044ee..65bb32971c2e 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -911,8 +911,6 @@ where connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - overcapture_applied: None, - maximum_capturable_amount: None, }); let additional_data = PaymentAdditionalData { diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index bc982ee6a172..1fd5ed10345b 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -1128,8 +1128,6 @@ pub fn get_connector_metadata( connector_response_reference_id: _, incremental_authorization_allowed: _, charge_id: _, - overcapture_applied: _, - maximum_capturable_amount: _, }) => connector_metadata, _ => None, } diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql index f0cc9d1b51f5..4575b40ea58c 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql @@ -3,6 +3,3 @@ DROP COLUMN IF EXISTS request_overcapture; ALTER TABLE payment_attempt DROP COLUMN IF EXISTS overcapture_applied; - -ALTER TABLE payment_attempt -DROP COLUMN IF EXISTS maximum_capturable_amount; \ No newline at end of file diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql index 76adac0ffe96..090f817b0fc6 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql @@ -1,2 +1,5 @@ ALTER TABLE payment_attempt -ADD COLUMN IF NOT EXISTS overcapture_details JSONB DEFAULT NULL; \ No newline at end of file +ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN NOT NULL DEFAULT FALSE; + +ALTER TABLE payment_attempt +ADD COLUMN IF NOT EXISTS overcapture_applied BOOLEAN DEFAULT NULL; \ No newline at end of file From a7ad547ebc848227049a61f6a6ca20eaa9144908 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 05:08:53 +0000 Subject: [PATCH 32/64] chore: run formatter --- .../src/connectors/square/transformers.rs | 1 - .../src/connectors/volt/transformers.rs | 2 -- .../src/connector/payme/transformers.rs | 1 - .../payments/operations/payment_response.rs | 28 +++++++++---------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/crates/hyperswitch_connectors/src/connectors/square/transformers.rs b/crates/hyperswitch_connectors/src/connectors/square/transformers.rs index 6873896a149b..5abc93b3f882 100644 --- a/crates/hyperswitch_connectors/src/connectors/square/transformers.rs +++ b/crates/hyperswitch_connectors/src/connectors/square/transformers.rs @@ -395,7 +395,6 @@ impl TryFrom TryFrom TryFrom> connector_response_reference_id: None, incremental_authorization_allowed: None, charge_id: None, - }) }; Ok(Self { diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 158cc6a37131..0d95127c2bfa 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1586,20 +1586,20 @@ async fn payment_response_update_tracker( }; let overcapture_details = None; //todoo - // match payment_data.payment_attempt.overcapture_details.clone() { - // Some(mut overcapture_details) => { - // overcapture_details.overcapture_applied = - // overcapture_applied; - // overcapture_details.maximum_capturable_amount = - // maximum_capturable_amount; - // overcapture_details.overcaptured_amount = payment_data - // .payment_attempt - // .net_amount - // .get_overcaptured_amount(); - // Some(overcapture_details) - // } - // None => None, - // }; + // match payment_data.payment_attempt.overcapture_details.clone() { + // Some(mut overcapture_details) => { + // overcapture_details.overcapture_applied = + // overcapture_applied; + // overcapture_details.maximum_capturable_amount = + // maximum_capturable_amount; + // overcapture_details.overcaptured_amount = payment_data + // .payment_attempt + // .net_amount + // .get_overcaptured_amount(); + // Some(overcapture_details) + // } + // None => None, + // }; // incase of success, update error code and error message let error_status = From a5d2d22980c2e29f7cd5a300feb8d4d4ef519442 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 6 Jan 2025 10:41:58 +0530 Subject: [PATCH 33/64] chore: undo DB changes --- .../down.sql | 3 +++ .../up.sql | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql index 4575b40ea58c..f0cc9d1b51f5 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql @@ -3,3 +3,6 @@ DROP COLUMN IF EXISTS request_overcapture; ALTER TABLE payment_attempt DROP COLUMN IF EXISTS overcapture_applied; + +ALTER TABLE payment_attempt +DROP COLUMN IF EXISTS maximum_capturable_amount; \ No newline at end of file diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql index 090f817b0fc6..76adac0ffe96 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql @@ -1,5 +1,2 @@ ALTER TABLE payment_attempt -ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN NOT NULL DEFAULT FALSE; - -ALTER TABLE payment_attempt -ADD COLUMN IF NOT EXISTS overcapture_applied BOOLEAN DEFAULT NULL; \ No newline at end of file +ADD COLUMN IF NOT EXISTS overcapture_details JSONB DEFAULT NULL; \ No newline at end of file From 7cf1a5ffe4d63a2a43b931c924faf1732915ac09 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 6 Jan 2025 10:50:40 +0530 Subject: [PATCH 34/64] refactor(router): add overcapture_applied to ConnectorResponseData --- crates/hyperswitch_domain_models/src/router_data.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index f69c1db0e10b..f343cc516004 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -328,6 +328,7 @@ pub struct PaymentMethodBalance { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ConnectorResponseData { pub additional_payment_method_data: Option, + pub overcapture_applied : Option } impl ConnectorResponseData { @@ -336,10 +337,12 @@ impl ConnectorResponseData { ) -> Self { Self { additional_payment_method_data: Some(additional_payment_method_data), + overcapture_applied: None, } } } + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum AdditionalPaymentMethodConnectorResponse { Card { From 0da2fba553d88455d6a4984223eea92329ce5d4f Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 6 Jan 2025 13:39:29 +0530 Subject: [PATCH 35/64] refactor(core): replace overcapture_data with overcapture_applied and request_overcapture in payment_attempt --- crates/common_utils/src/types.rs | 29 ----- crates/diesel_models/src/payment_attempt.rs | 102 ++++++++++-------- crates/diesel_models/src/schema.rs | 3 +- crates/diesel_models/src/schema_v2.rs | 1 - crates/diesel_models/src/user/sample_data.rs | 4 +- .../src/payments/payment_attempt.rs | 63 ++++------- .../src/connector/stripe/transformers.rs | 8 +- crates/router/src/core/payments/helpers.rs | 49 +-------- .../payments/operations/payment_capture.rs | 4 +- .../payments/operations/payment_confirm.rs | 15 +-- .../payments/operations/payment_create.rs | 23 ++-- .../payments/operations/payment_response.rs | 24 +---- .../payments/operations/payment_update.rs | 15 +-- crates/router/src/core/payments/retry.rs | 5 +- .../router/src/core/payments/transformers.rs | 33 +++--- crates/router/src/core/utils.rs | 16 --- .../src/types/storage/payment_attempt.rs | 6 +- crates/router/src/utils/user/sample_data.rs | 2 +- .../src/mock_db/payment_attempt.rs | 3 +- .../src/payments/payment_attempt.rs | 25 ++--- .../down.sql | 3 - .../up.sql | 5 +- 22 files changed, 156 insertions(+), 282 deletions(-) diff --git a/crates/common_utils/src/types.rs b/crates/common_utils/src/types.rs index 3d55a8b265b6..5075b0e79784 100644 --- a/crates/common_utils/src/types.rs +++ b/crates/common_utils/src/types.rs @@ -1413,35 +1413,6 @@ pub struct BrowserInformation { #[cfg(feature = "v2")] crate::impl_to_sql_from_sql_json!(BrowserInformation); -/// Overcapture Data -#[derive( - ToSchema, - Debug, - Default, - Clone, - serde::Deserialize, - serde::Serialize, - Eq, - PartialEq, - diesel::AsExpression, -)] -#[diesel(sql_type = Jsonb)] -pub struct OvercaptureData { - /// Whether overcapture is requested - pub request_overcapture: Option, - - /// Whether overcapture is applied - pub overcapture_applied: Option, - - /// Maximum capturable amount - pub maximum_capturable_amount: Option, - - /// Overcaptured amount - pub overcaptured_amount: Option, -} - -crate::impl_to_sql_from_sql_json!(OvercaptureData); - /// Domain type for connector_transaction_id /// Maximum length for connector's transaction_id can be 128 characters in HS DB. /// In case connector's use an identifier whose length exceeds 128 characters, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index df39e8c5e5f0..3359c8629360 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -94,7 +94,6 @@ pub struct PaymentAttempt { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, - pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -173,7 +172,8 @@ pub struct PaymentAttempt { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, } #[cfg(feature = "v1")] @@ -280,7 +280,6 @@ pub struct PaymentAttemptNew { pub payment_method_subtype: storage_enums::PaymentMethodType, pub id: id_type::GlobalAttemptId, pub connector_mandate_detail: Option, - pub overcapture_details: Option, } #[cfg(feature = "v1")] @@ -354,7 +353,7 @@ pub struct PaymentAttemptNew { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -378,7 +377,7 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - overcapture_details: Option, + request_overcapture: Option, }, UpdateTrackers { payment_token: Option, @@ -428,7 +427,7 @@ pub enum PaymentAttemptUpdate { shipping_cost: Option, order_tax_amount: Option, connector_mandate_detail: Option, - overcapture_details: Option, + request_overcapture: Option, }, VoidUpdate { status: storage_enums::AttemptStatus, @@ -477,7 +476,7 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, - overcapture_details: Option, + overcapture_applied: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -538,6 +537,7 @@ pub enum PaymentAttemptUpdate { IncrementalAuthorizationAmountUpdate { amount: MinorUnit, amount_capturable: MinorUnit, + overcapture_applied: Option, }, AuthenticationUpdate { status: storage_enums::AttemptStatus, @@ -855,7 +855,8 @@ pub struct PaymentAttemptUpdateInternal { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, } #[cfg(feature = "v1")] @@ -879,15 +880,6 @@ impl PaymentAttemptUpdateInternal { + update_internal .order_tax_amount .or(source.order_tax_amount) - .unwrap_or(MinorUnit::new(0)) - + update_internal - .overcapture_details - .as_ref() - .and_then(|data| data.overcaptured_amount) - .or(source - .overcapture_details - .as_ref() - .and_then(|data| data.overcaptured_amount)) .unwrap_or(MinorUnit::new(0)), ); update_internal.card_network = update_internal @@ -1048,7 +1040,8 @@ impl PaymentAttemptUpdate { order_tax_amount, connector_transaction_data, connector_mandate_detail, - overcapture_details, + request_overcapture, + overcapture_applied, } = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source); PaymentAttempt { amount: amount.unwrap_or(source.amount), @@ -1107,7 +1100,8 @@ impl PaymentAttemptUpdate { connector_transaction_data: connector_transaction_data .or(source.connector_transaction_data), connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail), - overcapture_details: overcapture_details.or(source.overcapture_details), + request_overcapture: request_overcapture.or(source.request_overcapture), + overcapture_applied: overcapture_applied.or(source.overcapture_applied), ..source } } @@ -2107,7 +2101,7 @@ impl From for PaymentAttemptUpdateInternal { fingerprint_id, updated_by, payment_method_billing_address_id, - overcapture_details, + request_overcapture, } => Self { amount: Some(amount), currency: Some(currency), @@ -2161,7 +2155,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details, + request_overcapture, + overcapture_applied: None, }, PaymentAttemptUpdate::AuthenticationTypeUpdate { authentication_type, @@ -2218,7 +2213,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::ConfirmUpdate { amount, @@ -2254,7 +2250,7 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost, order_tax_amount, connector_mandate_detail, - overcapture_details, + request_overcapture, } => Self { amount: Some(amount), currency: Some(currency), @@ -2307,7 +2303,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount, connector_transaction_data: None, connector_mandate_detail, - overcapture_details, + request_overcapture, + overcapture_applied: None, }, PaymentAttemptUpdate::VoidUpdate { status, @@ -2365,7 +2362,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::RejectUpdate { status, @@ -2424,7 +2422,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::BlocklistUpdate { status, @@ -2483,7 +2482,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::ConnectorMandateDetailUpdate { connector_mandate_detail, @@ -2540,7 +2540,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::PaymentMethodDetailsUpdate { payment_method_id, @@ -2597,7 +2598,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::ResponseUpdate { status, @@ -2621,7 +2623,7 @@ impl From for PaymentAttemptUpdateInternal { payment_method_data, charge_id, connector_mandate_detail, - overcapture_details, + overcapture_applied, } => { let (connector_transaction_id, connector_transaction_data) = connector_transaction_id @@ -2680,7 +2682,8 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail, - overcapture_details, + request_overcapture: None, + overcapture_applied, } } PaymentAttemptUpdate::ErrorUpdate { @@ -2754,7 +2757,8 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, } } PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self { @@ -2809,7 +2813,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::UpdateTrackers { payment_token, @@ -2872,7 +2877,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::UnresolvedResponseUpdate { status, @@ -2942,7 +2948,8 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, } } PaymentAttemptUpdate::PreprocessingUpdate { @@ -3011,7 +3018,8 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, } } PaymentAttemptUpdate::CaptureUpdate { @@ -3070,7 +3078,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::AmountToCaptureUpdate { status, @@ -3128,7 +3137,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::ConnectorResponse { authentication_data, @@ -3195,12 +3205,14 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, } } PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { amount, amount_capturable, + overcapture_applied, } => Self { amount: Some(amount), modified_at: common_utils::date_time::now(), @@ -3253,7 +3265,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied, }, PaymentAttemptUpdate::AuthenticationUpdate { status, @@ -3313,7 +3326,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, PaymentAttemptUpdate::ManualUpdate { status, @@ -3382,7 +3396,8 @@ impl From for PaymentAttemptUpdateInternal { shipping_cost: None, order_tax_amount: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, } } PaymentAttemptUpdate::PostSessionTokensUpdate { @@ -3440,7 +3455,8 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, + overcapture_applied: None, }, } } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index d8e78faf0d3b..b350e7224262 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -890,7 +890,8 @@ diesel::table! { #[max_length = 512] connector_transaction_data -> Nullable, connector_mandate_detail -> Nullable, - overcapture_details -> Nullable, + request_overcapture -> Nullable, + overcapture_applied -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 3a2cbf9460c1..d1dab45a58af 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -860,7 +860,6 @@ diesel::table! { shipping_cost -> Nullable, order_tax_amount -> Nullable, connector_mandate_detail -> Nullable, - overcapture_details -> Nullable, } } diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs index dd83fc4de5da..1e2f712a625b 100644 --- a/crates/diesel_models/src/user/sample_data.rs +++ b/crates/diesel_models/src/user/sample_data.rs @@ -203,7 +203,7 @@ pub struct PaymentAttemptBatchNew { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -283,7 +283,7 @@ impl PaymentAttemptBatchNew { shipping_cost: self.shipping_cost, order_tax_amount: self.order_tax_amount, connector_mandate_detail: self.connector_mandate_detail, - overcapture_details: self.overcapture_details, + request_overcapture: self.request_overcapture, } } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 5faf03649d65..71efd7f3ad1e 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -402,8 +402,6 @@ pub struct PaymentAttempt { pub id: id_type::GlobalAttemptId, /// The connector mandate details which are stored temporarily pub connector_mandate_detail: Option, - /// Details related to payment overcapture - pub overcapture_details: Option, } impl PaymentAttempt { @@ -522,7 +520,6 @@ impl PaymentAttempt { error: None, connector_mandate_detail: None, id, - overcapture_details: None, }) } } @@ -593,7 +590,8 @@ pub struct PaymentAttempt { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, } #[cfg(feature = "v1")] @@ -609,8 +607,6 @@ pub struct NetAmount { surcharge_amount: Option, /// tax on surcharge amount tax_on_surcharge: Option, - /// overcaptured amount - overcaptured_amount: Option, } #[cfg(feature = "v1")] @@ -621,7 +617,6 @@ impl NetAmount { order_tax_amount: Option, surcharge_amount: Option, tax_on_surcharge: Option, - overcaptured_amount: Option, ) -> Self { Self { order_amount, @@ -629,7 +624,6 @@ impl NetAmount { order_tax_amount, surcharge_amount, tax_on_surcharge, - overcaptured_amount, } } @@ -658,9 +652,6 @@ impl NetAmount { .map(|surcharge_amount| surcharge_amount + self.tax_on_surcharge.unwrap_or_default()) } - pub fn get_overcaptured_amount(&self) -> Option { - self.overcaptured_amount - } pub fn get_total_amount(&self) -> MinorUnit { self.order_amount @@ -668,7 +659,6 @@ impl NetAmount { + self.order_tax_amount.unwrap_or_default() + self.surcharge_amount.unwrap_or_default() + self.tax_on_surcharge.unwrap_or_default() - + self.overcaptured_amount.unwrap_or_default() } pub fn set_order_amount(&mut self, order_amount: MinorUnit) { @@ -689,10 +679,6 @@ impl NetAmount { self.tax_on_surcharge = surcharge_details.map(|details| details.tax_on_surcharge_amount); } - pub fn set_overcaptured_amount(&mut self, overcaptured_amount: MinorUnit) { - self.overcaptured_amount = Some(overcaptured_amount); - } - pub fn from_payments_request( payments_request: &api_models::payments::PaymentsRequest, order_amount: MinorUnit, @@ -709,7 +695,6 @@ impl NetAmount { order_tax_amount: None, surcharge_amount, tax_on_surcharge, - overcaptured_amount: None, } } @@ -744,16 +729,12 @@ impl NetAmount { payment_attempt.net_amount.get_tax_on_surcharge() }) }); - let overcaptured_amount = payment_attempt - .and_then(|payment_attempt| payment_attempt.net_amount.get_overcaptured_amount()); - Self { order_amount, shipping_cost, order_tax_amount, surcharge_amount, tax_on_surcharge, - overcaptured_amount, } }) } @@ -858,7 +839,7 @@ pub struct PaymentAttemptNew { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub overcapture_details: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -880,7 +861,7 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - overcapture_details: Option, + request_overcapture: Option, }, UpdateTrackers { payment_token: Option, @@ -926,7 +907,7 @@ pub enum PaymentAttemptUpdate { client_version: Option, customer_acceptance: Option, connector_mandate_detail: Option, - overcapture_details: Option, + request_overcapture: Option, }, RejectUpdate { status: storage_enums::AttemptStatus, @@ -975,7 +956,7 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, - overcapture_details: Option, + overcapture_applied: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -1036,6 +1017,7 @@ pub enum PaymentAttemptUpdate { IncrementalAuthorizationAmountUpdate { net_amount: NetAmount, amount_capturable: MinorUnit, + overcapture_applied: Option, }, AuthenticationUpdate { status: storage_enums::AttemptStatus, @@ -1080,7 +1062,7 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, - overcapture_details, + request_overcapture, } => DieselPaymentAttemptUpdate::Update { amount: net_amount.get_order_amount(), currency, @@ -1099,7 +1081,7 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, - overcapture_details, + request_overcapture, }, Self::UpdateTrackers { payment_token, @@ -1182,7 +1164,7 @@ impl PaymentAttemptUpdate { client_version, customer_acceptance, connector_mandate_detail, - overcapture_details, + request_overcapture, } => DieselPaymentAttemptUpdate::ConfirmUpdate { amount: net_amount.get_order_amount(), currency, @@ -1217,7 +1199,7 @@ impl PaymentAttemptUpdate { shipping_cost: net_amount.get_shipping_cost(), order_tax_amount: net_amount.get_order_tax_amount(), connector_mandate_detail, - overcapture_details, + request_overcapture, }, Self::VoidUpdate { status, @@ -1250,7 +1232,7 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, - overcapture_details, + overcapture_applied, } => DieselPaymentAttemptUpdate::ResponseUpdate { status, connector, @@ -1273,7 +1255,7 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, - overcapture_details, + overcapture_applied, }, Self::UnresolvedResponseUpdate { status, @@ -1390,9 +1372,11 @@ impl PaymentAttemptUpdate { Self::IncrementalAuthorizationAmountUpdate { net_amount, amount_capturable, + overcapture_applied, } => DieselPaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { amount: net_amount.get_order_amount(), amount_capturable, + overcapture_applied, }, Self::AuthenticationUpdate { status, @@ -1583,7 +1567,8 @@ impl behaviour::Conversion for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, - overcapture_details: self.overcapture_details, + request_overcapture: self.request_overcapture, + overcapture_applied: self.overcapture_applied, }) } @@ -1600,10 +1585,6 @@ impl behaviour::Conversion for PaymentAttempt { let connector_transaction_id = storage_model .get_optional_connector_transaction_id() .cloned(); - let overcaptured_amount = storage_model - .overcapture_details - .as_ref() - .and_then(|overcapture_data| overcapture_data.overcaptured_amount); Ok::>(Self { payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, @@ -1615,7 +1596,6 @@ impl behaviour::Conversion for PaymentAttempt { storage_model.order_tax_amount, storage_model.surcharge_amount, storage_model.tax_amount, - overcaptured_amount, ), currency: storage_model.currency, save_to_locker: storage_model.save_to_locker, @@ -1670,7 +1650,8 @@ impl behaviour::Conversion for PaymentAttempt { profile_id: storage_model.profile_id, organization_id: storage_model.organization_id, connector_mandate_detail: storage_model.connector_mandate_detail, - overcapture_details: storage_model.overcapture_details, + request_overcapture: storage_model.request_overcapture, + overcapture_applied: storage_model.overcapture_applied, }) } .await @@ -1753,7 +1734,7 @@ impl behaviour::Conversion for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, - overcapture_details: self.overcapture_details, + request_overcapture: self.request_overcapture, }) } } @@ -1821,7 +1802,6 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_billing_address, connector, connector_mandate_detail, - overcapture_details, } = self; let AttemptAmountDetails { @@ -1899,7 +1879,6 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_billing_address: payment_method_billing_address.map(Encryption::from), connector_payment_data, connector_mandate_detail, - overcapture_details, }) } @@ -2011,7 +1990,6 @@ impl behaviour::Conversion for PaymentAttempt { connector: storage_model.connector, payment_method_billing_address, connector_mandate_detail: storage_model.connector_mandate_detail, - overcapture_details: storage_model.overcapture_details, }) } .await @@ -2096,7 +2074,6 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_type_v2: self.payment_method_type, id: self.id, connector_mandate_detail: self.connector_mandate_detail, - overcapture_details: self.overcapture_details, }) } } diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 81b6d92d398e..4042d4bd2665 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -1153,7 +1153,7 @@ fn create_stripe_payment_method( payment_method_token: Option, is_customer_initiated_mandate_payment: Option, billing_address: StripeBillingAddress, - is_overcapture_requested: Option, + is_request_overcapture: Option, ) -> Result< ( StripePaymentMethodData, @@ -1172,7 +1172,7 @@ fn create_stripe_payment_method( StripePaymentMethodData::try_from(( card_details, payment_method_auth_type, - is_overcapture_requested, + is_request_overcapture, ))?, Some(StripePaymentMethodType::Card), billing_address, @@ -1394,7 +1394,7 @@ fn get_stripe_card_network(card_network: common_enums::CardNetwork) -> Option)> for StripePaymentMethodData { type Error = errors::ConnectorError; fn try_from( - (card, payment_method_auth_type, is_overcapture_requested): ( + (card, payment_method_auth_type, is_request_overcapture): ( &domain::Card, Auth3ds, Option, @@ -1411,7 +1411,7 @@ impl TryFrom<(&domain::Card, Auth3ds, Option)> for StripePaymentMethodData .card_network .clone() .and_then(get_stripe_card_network), - payment_method_data_card_request_overcapture: match is_overcapture_requested { + payment_method_data_card_request_overcapture: match is_request_overcapture { Some(true) => Some(StripeOvercaptureRequest::IfAvailable), _ => None, }, diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 6064b0cc9c51..3fab7b4e6eec 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2609,25 +2609,13 @@ pub(crate) fn validate_status_with_capture_method( pub(crate) fn validate_amount_to_capture( amount: i64, amount_to_capture: Option, - overcapture_details: Option<&common_utils::types::OvercaptureData>, + is_overcapture_applied: Option, ) -> RouterResult<()> { - let (is_overcapture_applied, maximum_capturable_amount) = overcapture_details - .map(|overcapture_data| { - ( - overcapture_data.overcapture_applied, - overcapture_data - .maximum_capturable_amount - .map(|maximum_capturable_amount| maximum_capturable_amount.get_amount_as_i64()), - ) - }) - .unwrap_or((None, None)); - if let Some(true) = amount_to_capture.map(|req_amount_to_capture| (amount < req_amount_to_capture)) { utils::when( - !(is_overcapture_applied == Some(true) - && maximum_capturable_amount >= amount_to_capture), + is_overcapture_applied != Some(true), || { Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "amount_to_capture is greater than amount".to_string() @@ -4309,7 +4297,7 @@ impl AttemptType { organization_id: old_payment_attempt.organization_id, profile_id: old_payment_attempt.profile_id, connector_mandate_detail: None, - overcapture_details: old_payment_attempt.overcapture_details, + request_overcapture: old_payment_attempt.request_overcapture, } } @@ -6291,33 +6279,4 @@ pub fn validate_platform_fees_for_marketplace( } } Ok(()) -} - -#[cfg(feature = "v1")] -pub fn update_or_add_overcapture_details_if_required( - request_overcapture: Option, - payment_attempt: &mut PaymentAttempt, -) -> Result<(), errors::ApiErrorResponse> { - if let Some((request_overcapture, true)) = request_overcapture.zip(Some( - payment_attempt - .capture_method - .eq(&Some(enums::CaptureMethod::Manual)), - )) { - match payment_attempt.overcapture_details { - Some(ref mut overcapture_data) => { - overcapture_data.request_overcapture = Some(request_overcapture); - } - None => { - payment_attempt.overcapture_details = Some(common_utils::types::OvercaptureData { - request_overcapture: Some(request_overcapture), - overcapture_applied: None, - maximum_capturable_amount: None, - overcaptured_amount: None, - }); - } - } - Ok(()) - } else { - Ok(()) - } -} +} \ No newline at end of file diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 536ca1eb2435..2709d0b0802d 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -101,7 +101,7 @@ impl GetTracker, api::Paymen request .amount_to_capture .map(|capture_amount| capture_amount.get_amount_as_i64()), - payment_attempt.overcapture_details.as_ref(), + payment_attempt.overcapture_applied, )?; helpers::validate_capture_method(capture_method)?; @@ -114,7 +114,7 @@ impl GetTracker, api::Paymen helpers::validate_amount_to_capture( payment_attempt.amount_capturable.get_amount_as_i64(), Some(amount_to_capture.get_amount_as_i64()), - payment_attempt.overcapture_details.as_ref(), + payment_attempt.overcapture_applied, )?; let previous_captures = db diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index c98ba0be338d..a53255d6a2d5 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -404,10 +404,12 @@ impl GetTracker, api::PaymentsRequest> payment_attempt.capture_method = request.capture_method.or(payment_attempt.capture_method); - helpers::update_or_add_overcapture_details_if_required( - request.request_overcapture, - &mut payment_attempt, - )?; + match payment_attempt.capture_method { + Some(storage_enums::CaptureMethod::Manual) => { + payment_attempt.request_overcapture = request.request_overcapture.or(payment_attempt.request_overcapture); + } + _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? + }; payment_attempt.customer_acceptance = request .customer_acceptance @@ -1298,7 +1300,7 @@ impl UpdateTracker, api::PaymentsRequest> for let browser_info = payment_data.payment_attempt.browser_info.clone(); let frm_message = payment_data.frm_message.clone(); let capture_method = payment_data.payment_attempt.capture_method; - let overcapture_details = payment_data.payment_attempt.overcapture_details.clone(); + let request_overcapture = payment_data.payment_attempt.request_overcapture.clone(); let default_status_result = ( storage_enums::IntentStatus::Processing, @@ -1520,13 +1522,12 @@ impl UpdateTracker, api::PaymentsRequest> for .get_order_tax_amount(), surcharge_amount, tax_amount, - None, ), connector_mandate_detail: payment_data .payment_attempt .connector_mandate_detail, - overcapture_details, + request_overcapture, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 5d9a16ceea2c..099279a6e4ed 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1143,19 +1143,12 @@ impl PaymentCreate { .transpose()? .flatten(); - let overcapture_details = match request - .capture_method - .map(|capture_method| capture_method.eq(&common_enums::CaptureMethod::Manual)) - { - Some(true) => Some(common_utils::types::OvercaptureData { - request_overcapture: request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)), - overcapture_applied: None, - maximum_capturable_amount: None, - overcaptured_amount: None, - }), - Some(false) | None => None, + let request_overcapture = match (request.capture_method, request.confirm) { + (Some(api_models::enums::CaptureMethod::Manual), _) | + (None, Some(true)) => { + request.request_overcapture.or(Some(business_profile.always_request_overcapture)) + } + _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? }; if additional_pm_data.is_none() { @@ -1175,7 +1168,7 @@ impl PaymentCreate { }) .ok() }) - .and_then(|pmd| match pmd { + .and_then(|pmd: PaymentMethodsData| match pmd { PaymentMethodsData::Card(card) => { Some(api_models::payments::AdditionalPaymentData::Card(Box::new( api::CardDetailFromLocker::from(card).into(), @@ -1306,7 +1299,7 @@ impl PaymentCreate { organization_id: organization_id.clone(), profile_id, connector_mandate_detail: None, - overcapture_details, + request_overcapture, }, additional_pm_data, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 0d95127c2bfa..f270969e0089 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -417,9 +417,9 @@ impl PostUpdateTracker, types::PaymentsIncrementalAu None, None, None, - None, ), amount_capturable: incremental_authorization_details.total_amount, + overcapture_applied: None, //todooooo }, ), Some( @@ -868,24 +868,6 @@ impl PostUpdateTracker, types::PaymentsCaptureData> where F: 'b + Send, { - let net_amount = payment_data.payment_attempt.net_amount.get_total_amount(); - let overcapture_applied = payment_data - .payment_attempt - .overcapture_details - .as_ref() - .and_then(|overcapture_data| overcapture_data.overcapture_applied); - core_utils::get_overcaptured_amount( - overcapture_applied, - router_data.amount_captured.map(MinorUnit::new), - net_amount, - ) - .map(|overcaptured_amount| { - payment_data - .payment_attempt - .net_amount - .set_overcaptured_amount(overcaptured_amount) - }); - payment_data = Box::pin(payment_response_update_tracker( db, payment_data, @@ -1585,7 +1567,7 @@ async fn payment_response_update_tracker( None }; - let overcapture_details = None; //todoo + // let overcapture_details = None; todoo // match payment_data.payment_attempt.overcapture_details.clone() { // Some(mut overcapture_details) => { // overcapture_details.overcapture_applied = @@ -1770,7 +1752,7 @@ async fn payment_response_update_tracker( .payment_attempt .connector_mandate_detail .clone(), - overcapture_details, + overcapture_applied: None, // todo }), ), }; diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 26eda7c6beb5..86f0c3676910 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -444,10 +444,12 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - helpers::update_or_add_overcapture_details_if_required( - request.request_overcapture, - &mut payment_attempt, - )?; + match payment_attempt.capture_method { + Some(storage_enums::CaptureMethod::Manual) | None => { + payment_attempt.request_overcapture = request.request_overcapture.or(payment_attempt.request_overcapture); + } + _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? + }; let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) @@ -788,7 +790,7 @@ impl UpdateTracker, api::PaymentsRequest> for let payment_experience = payment_data.payment_attempt.payment_experience; let amount_to_capture = payment_data.payment_attempt.amount_to_capture; let capture_method = payment_data.payment_attempt.capture_method; - let overcapture_details = payment_data.payment_attempt.overcapture_details.clone(); + let request_overcapture = payment_data.payment_attempt.request_overcapture.clone(); let payment_method_billing_address_id = payment_data .payment_attempt .payment_method_billing_address_id @@ -828,9 +830,8 @@ impl UpdateTracker, api::PaymentsRequest> for None, surcharge_amount, tax_amount, - None, ), - overcapture_details, + request_overcapture, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 5bf30a3a5882..54683f7995ed 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -16,7 +16,6 @@ use crate::{ flows::{ConstructFlowSpecificData, Feature}, operations, }, - utils::get_overcaptured_amount, }, db::StorageInterface, routes::{ @@ -489,7 +488,7 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, - overcapture_details: None, + overcapture_applied: None, }; #[cfg(feature = "v1")] @@ -677,7 +676,7 @@ pub fn make_new_payment_attempt( charge_id: Default::default(), customer_acceptance: Default::default(), connector_mandate_detail: Default::default(), - overcapture_details: old_payment_attempt.overcapture_details, + request_overcapture: old_payment_attempt.request_overcapture, } } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 65bb32971c2e..ffdef748580d 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -2214,16 +2214,17 @@ where }) }); - let (overcapture_applied, maximum_capturable_amount) = payment_attempt - .overcapture_details - .as_ref() - .map(|overcapture_data| { - ( - overcapture_data.overcapture_applied, - overcapture_data.maximum_capturable_amount, - ) - }) - .unwrap_or((None, None)); + // let (overcapture_applied, maximum_capturable_amount) = payment_attempt + // .overcapture_details + // .as_ref() + // .map(|overcapture_data| { + // ( + // overcapture_data.overcapture_applied, + // overcapture_data.maximum_capturable_amount, + // ) + // }) + // .unwrap_or((None, None)); + //todooooo let connector_transaction_id = payment_attempt .get_connector_payment_id() @@ -2337,8 +2338,8 @@ where order_tax_amount, connector_mandate_id, shipping_cost: payment_intent.shipping_cost, - overcapture_applied, - maximum_capturable_amount, + overcapture_applied: None, + maximum_capturable_amount: None, //todoooo }; services::ApplicationResponse::JsonWithHeaders((payments_response, headers)) @@ -2595,8 +2596,8 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay order_tax_amount: None, connector_mandate_id:None, shipping_cost: None, - overcapture_applied: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.overcapture_applied), - maximum_capturable_amount: pa.overcapture_details.as_ref().and_then(|overcapture_data| overcapture_data.maximum_capturable_amount), + overcapture_applied: pa.overcapture_applied, + maximum_capturable_amount: None //todoo } } } @@ -2858,9 +2859,7 @@ impl TryFrom> for types::PaymentsAuthoriz let request_overcapture = payment_data .payment_attempt - .overcapture_details - .as_ref() - .and_then(|overcapture_details| overcapture_details.request_overcapture); + .request_overcapture; Ok(Self { payment_method_data: (payment_method_data.get_required_value("payment_method_data")?), diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 0edb2ae2687f..5c749eeced8f 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -449,22 +449,6 @@ pub fn validate_uuid(uuid: String, key: &str) -> Result, - amount_captured: Option, - net_amount: MinorUnit, -) -> Option { - match overcapture_applied.zip(amount_captured) { - Some((true, amount_captured_minor_unit)) => { - if net_amount < amount_captured_minor_unit { - Some(amount_captured_minor_unit - net_amount) - } else { - None - } - } - _ => None, - } -} #[cfg(test)] mod tests { diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index dd7d3de3aff9..074475fe014a 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -217,7 +217,7 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - overcapture_details: Default::default(), + request_overcapture: Default::default(), }; let store = state @@ -302,7 +302,7 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - overcapture_details: Default::default(), + request_overcapture: Default::default(), }; let store = state .stores @@ -400,7 +400,7 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - overcapture_details: Default::default(), + request_overcapture: Default::default(), }; let store = state .stores diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs index 1837c27e379d..f4499a0c72eb 100644 --- a/crates/router/src/utils/user/sample_data.rs +++ b/crates/router/src/utils/user/sample_data.rs @@ -362,7 +362,7 @@ pub async fn generate_sample_data( order_tax_amount: None, connector_transaction_data, connector_mandate_detail: None, - overcapture_details: None, + request_overcapture: None, }; let refund = if refunds_count < number_of_refunds && !is_failed_payment { diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs index a949f940ff54..426ba2d536d3 100644 --- a/crates/storage_impl/src/mock_db/payment_attempt.rs +++ b/crates/storage_impl/src/mock_db/payment_attempt.rs @@ -195,7 +195,8 @@ impl PaymentAttemptInterface for MockDb { organization_id: payment_attempt.organization_id, profile_id: payment_attempt.profile_id, connector_mandate_detail: payment_attempt.connector_mandate_detail, - overcapture_details: payment_attempt.overcapture_details, + request_overcapture: payment_attempt.request_overcapture, + overcapture_applied: None, }; payment_attempts.push(payment_attempt.clone()); Ok(payment_attempt) diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 7cbb68ba8e61..f80f50436da3 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -564,7 +564,8 @@ impl PaymentAttemptInterface for KVRouterStore { organization_id: payment_attempt.organization_id.clone(), profile_id: payment_attempt.profile_id.clone(), connector_mandate_detail: payment_attempt.connector_mandate_detail.clone(), - overcapture_details: payment_attempt.overcapture_details.clone(), + request_overcapture: payment_attempt.request_overcapture.clone(), + overcapture_applied: None, }; let field = format!("pa_{}", created_attempt.attempt_id); @@ -1512,7 +1513,8 @@ impl DataModelExt for PaymentAttempt { shipping_cost: self.net_amount.get_shipping_cost(), order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, - overcapture_details: self.overcapture_details, + request_overcapture: self.request_overcapture, + overcapture_applied: self.overcapture_applied, } } @@ -1520,10 +1522,6 @@ impl DataModelExt for PaymentAttempt { let connector_transaction_id = storage_model .get_optional_connector_transaction_id() .cloned(); - let overcaptured_amount = storage_model - .overcapture_details - .as_ref() - .and_then(|overcapture_data| overcapture_data.overcaptured_amount); Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( storage_model.amount, @@ -1531,7 +1529,6 @@ impl DataModelExt for PaymentAttempt { storage_model.order_tax_amount, storage_model.surcharge_amount, storage_model.tax_amount, - overcaptured_amount, ), payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, @@ -1594,8 +1591,8 @@ impl DataModelExt for PaymentAttempt { organization_id: storage_model.organization_id, profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, - overcapture_details: storage_model.overcapture_details, - } + request_overcapture: storage_model.request_overcapture, + overcapture_applied: storage_model.overcapture_applied, } } } @@ -1678,16 +1675,11 @@ impl DataModelExt for PaymentAttemptNew { shipping_cost: self.net_amount.get_shipping_cost(), order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, - overcapture_details: self.overcapture_details, + request_overcapture: self.request_overcapture, } } fn from_storage_model(storage_model: Self::StorageModel) -> Self { - let overcapture_amount = storage_model - .overcapture_details - .as_ref() - .and_then(|overcapture_data| overcapture_data.overcaptured_amount); - Self { net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new( storage_model.amount, @@ -1695,7 +1687,6 @@ impl DataModelExt for PaymentAttemptNew { storage_model.order_tax_amount, storage_model.surcharge_amount, storage_model.tax_amount, - overcapture_amount, ), payment_id: storage_model.payment_id, merchant_id: storage_model.merchant_id, @@ -1757,7 +1748,7 @@ impl DataModelExt for PaymentAttemptNew { organization_id: storage_model.organization_id, profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, - overcapture_details: storage_model.overcapture_details, + request_overcapture: storage_model.request_overcapture, } } } diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql index f0cc9d1b51f5..4575b40ea58c 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql @@ -3,6 +3,3 @@ DROP COLUMN IF EXISTS request_overcapture; ALTER TABLE payment_attempt DROP COLUMN IF EXISTS overcapture_applied; - -ALTER TABLE payment_attempt -DROP COLUMN IF EXISTS maximum_capturable_amount; \ No newline at end of file diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql index 76adac0ffe96..359d8ad9a7ea 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql @@ -1,2 +1,5 @@ ALTER TABLE payment_attempt -ADD COLUMN IF NOT EXISTS overcapture_details JSONB DEFAULT NULL; \ No newline at end of file +ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN DEFAULT NULL; + +ALTER TABLE payment_attempt +ADD COLUMN IF NOT EXISTS overcapture_applied BOOLEAN DEFAULT NULL; \ No newline at end of file From 132a124f51b5282048001fe15057451d33d1ce58 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 08:10:25 +0000 Subject: [PATCH 36/64] chore: run formatter --- crates/diesel_models/src/payment_attempt.rs | 4 +-- .../src/payments/payment_attempt.rs | 1 - .../src/router_data.rs | 3 +- crates/router/src/core/payments/helpers.rs | 15 ++++------ .../payments/operations/payment_confirm.rs | 8 ++++-- .../payments/operations/payment_create.rs | 13 +++++---- .../payments/operations/payment_response.rs | 28 +++++++++---------- .../payments/operations/payment_update.rs | 18 +++++++----- .../router/src/core/payments/transformers.rs | 4 +-- crates/router/src/core/utils.rs | 1 - .../src/payments/payment_attempt.rs | 3 +- 11 files changed, 50 insertions(+), 48 deletions(-) diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 3359c8629360..d998123e8d35 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -2949,7 +2949,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_applied: None, } } PaymentAttemptUpdate::PreprocessingUpdate { @@ -3019,7 +3019,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_applied: None, } } PaymentAttemptUpdate::CaptureUpdate { diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 71efd7f3ad1e..ed2287bf8167 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -652,7 +652,6 @@ impl NetAmount { .map(|surcharge_amount| surcharge_amount + self.tax_on_surcharge.unwrap_or_default()) } - pub fn get_total_amount(&self) -> MinorUnit { self.order_amount + self.shipping_cost.unwrap_or_default() diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index f343cc516004..f3902518b5dd 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -328,7 +328,7 @@ pub struct PaymentMethodBalance { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ConnectorResponseData { pub additional_payment_method_data: Option, - pub overcapture_applied : Option + pub overcapture_applied: Option, } impl ConnectorResponseData { @@ -342,7 +342,6 @@ impl ConnectorResponseData { } } - #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum AdditionalPaymentMethodConnectorResponse { Card { diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 3fab7b4e6eec..0983424184fc 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2614,14 +2614,11 @@ pub(crate) fn validate_amount_to_capture( if let Some(true) = amount_to_capture.map(|req_amount_to_capture| (amount < req_amount_to_capture)) { - utils::when( - is_overcapture_applied != Some(true), - || { - Err(report!(errors::ApiErrorResponse::InvalidRequestData { - message: "amount_to_capture is greater than amount".to_string() - })) - }, - ) + utils::when(is_overcapture_applied != Some(true), || { + Err(report!(errors::ApiErrorResponse::InvalidRequestData { + message: "amount_to_capture is greater than amount".to_string() + })) + }) } else { Ok(()) } @@ -6279,4 +6276,4 @@ pub fn validate_platform_fees_for_marketplace( } } Ok(()) -} \ No newline at end of file +} diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index a53255d6a2d5..3da6afed82b9 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -406,9 +406,13 @@ impl GetTracker, api::PaymentsRequest> match payment_attempt.capture_method { Some(storage_enums::CaptureMethod::Manual) => { - payment_attempt.request_overcapture = request.request_overcapture.or(payment_attempt.request_overcapture); + payment_attempt.request_overcapture = request + .request_overcapture + .or(payment_attempt.request_overcapture); } - _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? + _ => Err(errors::ApiErrorResponse::NotSupported { + message: "requesting overcapture is supported only via manual capture".to_owned(), + })?, }; payment_attempt.customer_acceptance = request diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 099279a6e4ed..0a353a0a40be 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1143,12 +1143,13 @@ impl PaymentCreate { .transpose()? .flatten(); - let request_overcapture = match (request.capture_method, request.confirm) { - (Some(api_models::enums::CaptureMethod::Manual), _) | - (None, Some(true)) => { - request.request_overcapture.or(Some(business_profile.always_request_overcapture)) - } - _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? + let request_overcapture = match (request.capture_method, request.confirm) { + (Some(api_models::enums::CaptureMethod::Manual), _) | (None, Some(true)) => request + .request_overcapture + .or(Some(business_profile.always_request_overcapture)), + _ => Err(errors::ApiErrorResponse::NotSupported { + message: "requesting overcapture is supported only via manual capture".to_owned(), + })?, }; if additional_pm_data.is_none() { diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index f270969e0089..153321c7a23f 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1568,20 +1568,20 @@ async fn payment_response_update_tracker( }; // let overcapture_details = None; todoo - // match payment_data.payment_attempt.overcapture_details.clone() { - // Some(mut overcapture_details) => { - // overcapture_details.overcapture_applied = - // overcapture_applied; - // overcapture_details.maximum_capturable_amount = - // maximum_capturable_amount; - // overcapture_details.overcaptured_amount = payment_data - // .payment_attempt - // .net_amount - // .get_overcaptured_amount(); - // Some(overcapture_details) - // } - // None => None, - // }; + // match payment_data.payment_attempt.overcapture_details.clone() { + // Some(mut overcapture_details) => { + // overcapture_details.overcapture_applied = + // overcapture_applied; + // overcapture_details.maximum_capturable_amount = + // maximum_capturable_amount; + // overcapture_details.overcaptured_amount = payment_data + // .payment_attempt + // .net_amount + // .get_overcaptured_amount(); + // Some(overcapture_details) + // } + // None => None, + // }; // incase of success, update error code and error message let error_status = diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 86f0c3676910..67410e05eae8 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -444,12 +444,16 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - match payment_attempt.capture_method { - Some(storage_enums::CaptureMethod::Manual) | None => { - payment_attempt.request_overcapture = request.request_overcapture.or(payment_attempt.request_overcapture); - } - _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? - }; + match payment_attempt.capture_method { + Some(storage_enums::CaptureMethod::Manual) | None => { + payment_attempt.request_overcapture = request + .request_overcapture + .or(payment_attempt.request_overcapture); + } + _ => Err(errors::ApiErrorResponse::NotSupported { + message: "requesting overcapture is supported only via manual capture".to_owned(), + })?, + }; let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) @@ -831,7 +835,7 @@ impl UpdateTracker, api::PaymentsRequest> for surcharge_amount, tax_amount, ), - request_overcapture, + request_overcapture, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index ffdef748580d..5697f9767020 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -2857,9 +2857,7 @@ impl TryFrom> for types::PaymentsAuthoriz .clone(); let shipping_cost = payment_data.payment_intent.shipping_cost; - let request_overcapture = payment_data - .payment_attempt - .request_overcapture; + let request_overcapture = payment_data.payment_attempt.request_overcapture; Ok(Self { payment_method_data: (payment_method_data.get_required_value("payment_method_data")?), diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index 5c749eeced8f..c30299eb21db 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -449,7 +449,6 @@ pub fn validate_uuid(uuid: String, key: &str) -> Result Date: Mon, 6 Jan 2025 18:04:44 +0530 Subject: [PATCH 37/64] refactor(router): remove maximum_capturable_amount from PaymentsResponse --- connector-template/transformers.rs | 2 -- crates/api_models/src/payments.rs | 3 --- crates/router/src/core/payments/retry.rs | 2 +- crates/router/src/core/payments/transformers.rs | 2 -- crates/router/tests/connectors/aci.rs | 1 - crates/router/tests/connectors/utils.rs | 1 - crates/router/tests/payments.rs | 2 -- crates/router/tests/payments2.rs | 2 -- 8 files changed, 1 insertion(+), 14 deletions(-) diff --git a/connector-template/transformers.rs b/connector-template/transformers.rs index c76496bf3fd8..b508596cbc08 100644 --- a/connector-template/transformers.rs +++ b/connector-template/transformers.rs @@ -139,8 +139,6 @@ impl TryFrom, - - /// Maximum capturable amount - pub maximum_capturable_amount: Option, } // Serialize is implemented because, this will be serialized in the api events. diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 54683f7995ed..28ac6bd886c2 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -488,7 +488,7 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, - overcapture_applied: None, + overcapture_applied: None, //todoo }; #[cfg(feature = "v1")] diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 5697f9767020..a52a2479e44f 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -2339,7 +2339,6 @@ where connector_mandate_id, shipping_cost: payment_intent.shipping_cost, overcapture_applied: None, - maximum_capturable_amount: None, //todoooo }; services::ApplicationResponse::JsonWithHeaders((payments_response, headers)) @@ -2597,7 +2596,6 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay connector_mandate_id:None, shipping_cost: None, overcapture_applied: pa.overcapture_applied, - maximum_capturable_amount: None //todoo } } } diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index 5b3eb11b67f2..d8f256d6c05e 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -132,7 +132,6 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, } } diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 1fd5ed10345b..361cda63a9f9 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -550,7 +550,6 @@ pub trait ConnectorActions: Connector { connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, authentication_id: None, - request_overcapture: None, } } diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs index b383ee359533..c245a852f902 100644 --- a/crates/router/tests/payments.rs +++ b/crates/router/tests/payments.rs @@ -450,7 +450,6 @@ async fn payments_create_core() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - maximum_capturable_amount: None, overcapture_applied: None, }; let expected_response = @@ -715,7 +714,6 @@ async fn payments_create_core_adyen_no_redirect() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - maximum_capturable_amount: None, overcapture_applied: None, }, vec![], diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs index 16233dc82606..051ffab3da50 100644 --- a/crates/router/tests/payments2.rs +++ b/crates/router/tests/payments2.rs @@ -211,7 +211,6 @@ async fn payments_create_core() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - maximum_capturable_amount: None, overcapture_applied: None, }; @@ -485,7 +484,6 @@ async fn payments_create_core_adyen_no_redirect() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - maximum_capturable_amount: None, overcapture_applied: None, }, vec![], From a5e03dadd814bc101ed0d2b737cb9f0663f4287e Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Mon, 6 Jan 2025 18:06:17 +0530 Subject: [PATCH 38/64] refactor(router): change the datatype of overcapture_data --- crates/hyperswitch_domain_models/src/router_data.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index f3902518b5dd..e9cf23977d50 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -328,7 +328,7 @@ pub struct PaymentMethodBalance { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ConnectorResponseData { pub additional_payment_method_data: Option, - pub overcapture_applied: Option, + pub overcapture_data: Option } impl ConnectorResponseData { @@ -337,11 +337,17 @@ impl ConnectorResponseData { ) -> Self { Self { additional_payment_method_data: Some(additional_payment_method_data), - overcapture_applied: None, + overcapture_data: None, } } } +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub struct OverCaptureData { + pub overcapture_applied: bool, + pub maximum_overcapture_amount: MinorUnit, +} + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum AdditionalPaymentMethodConnectorResponse { Card { From e6fb341479c5f1c19998485921f5e85a0d3f84d7 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 7 Jan 2025 10:21:23 +0530 Subject: [PATCH 39/64] refactor(router): undo debug statements and comments, impl in stripe --- crates/diesel_models/src/payment_attempt.rs | 4 +- .../src/payments/payment_attempt.rs | 3 - .../src/router_data.rs | 2 +- .../src/connector/stripe/transformers.rs | 58 ++++++++++++------- crates/router/src/connector/utils.rs | 20 ++++--- crates/router/src/core/payments.rs | 2 + .../payments/operations/payment_create.rs | 13 ++--- .../payments/operations/payment_response.rs | 24 ++------ crates/router/src/core/payments/retry.rs | 29 ++-------- .../router/src/core/payments/transformers.rs | 14 +---- crates/router/src/types.rs | 1 + 11 files changed, 71 insertions(+), 99 deletions(-) diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index d998123e8d35..3593ca2c88e3 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -537,7 +537,6 @@ pub enum PaymentAttemptUpdate { IncrementalAuthorizationAmountUpdate { amount: MinorUnit, amount_capturable: MinorUnit, - overcapture_applied: Option, }, AuthenticationUpdate { status: storage_enums::AttemptStatus, @@ -3212,7 +3211,6 @@ impl From for PaymentAttemptUpdateInternal { PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { amount, amount_capturable, - overcapture_applied, } => Self { amount: Some(amount), modified_at: common_utils::date_time::now(), @@ -3266,7 +3264,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied, + overcapture_applied: None, }, PaymentAttemptUpdate::AuthenticationUpdate { status, diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index ed2287bf8167..12052bd0bcf2 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -1016,7 +1016,6 @@ pub enum PaymentAttemptUpdate { IncrementalAuthorizationAmountUpdate { net_amount: NetAmount, amount_capturable: MinorUnit, - overcapture_applied: Option, }, AuthenticationUpdate { status: storage_enums::AttemptStatus, @@ -1371,11 +1370,9 @@ impl PaymentAttemptUpdate { Self::IncrementalAuthorizationAmountUpdate { net_amount, amount_capturable, - overcapture_applied, } => DieselPaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { amount: net_amount.get_order_amount(), amount_capturable, - overcapture_applied, }, Self::AuthenticationUpdate { status, diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index e9cf23977d50..17eb15c9e906 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -345,7 +345,7 @@ impl ConnectorResponseData { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct OverCaptureData { pub overcapture_applied: bool, - pub maximum_overcapture_amount: MinorUnit, + pub maximum_capturable_amount: MinorUnit, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 4042d4bd2665..6bd0578b0f8c 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -1824,7 +1824,7 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntent &item.request, )), billing_address, - None, + item.request.request_overcapture, )?; validate_shipping_address_against_payment_method( @@ -2095,7 +2095,7 @@ impl TryFrom<&types::TokenizationRouterData> for TokenRequest { item.payment_method_token.clone(), None, StripeBillingAddress::default(), - None, //todooo + None, )?; Ok(Self { token_data: payment_data.0, @@ -2458,7 +2458,7 @@ pub struct SetupIntentResponse { fn extract_payment_method_connector_response_from_latest_charge( stripe_charge_enum: &StripeChargeEnum, -) -> Option { +) -> Option { if let StripeChargeEnum::ChargeObject(charge_object) = stripe_charge_enum { charge_object .payment_method_details @@ -2468,12 +2468,11 @@ fn extract_payment_method_connector_response_from_latest_charge( None } .map(types::AdditionalPaymentMethodConnectorResponse::from) - .map(types::ConnectorResponseData::with_additional_payment_method_data) } fn extract_payment_method_connector_response_from_latest_attempt( stripe_latest_attempt: &LatestAttempt, -) -> Option { +) -> Option { if let LatestAttempt::PaymentIntentAttempt(intent_attempt) = stripe_latest_attempt { intent_attempt .payment_method_details @@ -2483,7 +2482,6 @@ fn extract_payment_method_connector_response_from_latest_attempt( None } .map(types::AdditionalPaymentMethodConnectorResponse::from) - .map(types::ConnectorResponseData::with_additional_payment_method_data) } impl @@ -2530,9 +2528,6 @@ impl _ => None, }; - let (overcapture_applied, maximum_capturable_amount) = - extract_overcapture_response(item.response.latest_charge.as_ref()); - let connector_metadata = get_connector_metadata(item.response.next_action.as_ref(), item.response.amount)?; @@ -2565,11 +2560,19 @@ impl }) }; - let connector_response_data = item + let additional_payment_method_data = item .response .latest_charge .as_ref() .and_then(extract_payment_method_connector_response_from_latest_charge); + let overcapture_data = item.response.latest_charge.as_ref().and_then(extract_overcapture_response_from_latest_charge); + let connector_response = if overcapture_data.is_some() || additional_payment_method_data.is_some() { + Some(types::ConnectorResponseData { + additional_payment_method_data, + overcapture_data, + })} else{ + None + }; Ok(Self { status, @@ -2583,7 +2586,7 @@ impl .amount_received .map(|amount| amount.get_amount_as_i64()), minor_amount_captured: item.response.amount_received, - connector_response: connector_response_data, + connector_response, ..item.data }) } @@ -2729,11 +2732,19 @@ impl let status = enums::AttemptStatus::from(item.response.status.to_owned()); - let connector_response_data = item + let additional_payment_method_data = item .response .latest_charge .as_ref() .and_then(extract_payment_method_connector_response_from_latest_charge); + let overcapture_data = item.response.latest_charge.as_ref().and_then(extract_overcapture_response_from_latest_charge); + let connector_response = if overcapture_data.is_some() || additional_payment_method_data.is_some() { + Some(types::ConnectorResponseData { + additional_payment_method_data, + overcapture_data, + })} else{ + None + }; let response = if connector_util::is_payment_failure(status) { types::PaymentsResponseData::foreign_try_from(( @@ -2754,8 +2765,6 @@ impl _ => None, }; - let (overcapture_applied, maximum_capturable_amount) = - extract_overcapture_response(item.response.latest_charge.as_ref()); let charge_id = item .response @@ -2785,7 +2794,7 @@ impl .amount_received .map(|amount| amount.get_amount_as_i64()), minor_amount_captured: item.response.amount_received, - connector_response: connector_response_data, + connector_response, ..item.data }) } @@ -2824,7 +2833,8 @@ impl .response .latest_attempt .as_ref() - .and_then(extract_payment_method_connector_response_from_latest_attempt); + .and_then(extract_payment_method_connector_response_from_latest_attempt) + .map(types::ConnectorResponseData::with_additional_payment_method_data); let response = if connector_util::is_payment_failure(status) { types::PaymentsResponseData::foreign_try_from(( @@ -4135,11 +4145,11 @@ fn get_transaction_metadata( meta_data } -fn extract_overcapture_response( - latest_charge: Option<&StripeChargeEnum>, -) -> (Option, Option) { - match latest_charge { - Some(StripeChargeEnum::ChargeObject(charge_object)) => charge_object +fn extract_overcapture_response_from_latest_charge( + latest_charge: &StripeChargeEnum, +) -> Option{ + let (overcapture_applied, maximum_overcapture_amount) = match latest_charge { + StripeChargeEnum::ChargeObject(charge_object) => charge_object .payment_method_details .as_ref() .and_then(|payment_method_details| match payment_method_details { @@ -4161,7 +4171,11 @@ fn extract_overcapture_response( }) .unwrap_or((None, None)), _ => (None, None), - } + }; + overcapture_applied.zip(maximum_overcapture_amount).map(|overcapture_data| types::OverCaptureData { + overcapture_applied: overcapture_data.0, + maximum_capturable_amount: overcapture_data.1, + }) } impl ForeignTryFrom<(&Option, u16, String)> for types::PaymentsResponseData { diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 171f19bc70ab..0c9ed3d28066 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -175,16 +175,18 @@ where } } enums::AttemptStatus::Charged => { - let captured_amount = - types::Capturable::get_captured_amount(&self.request, payment_data); let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); - if Some(total_capturable_amount) == captured_amount.map(MinorUnit::new) { - enums::AttemptStatus::Charged - } else if captured_amount.is_some() { - enums::AttemptStatus::PartialCharged - } else { - self.status - } + let is_overcapture_applied = payment_data.payment_attempt.overcapture_applied; + types::Capturable::get_captured_amount(&self.request, payment_data).map(MinorUnit::new).map(|captured_amount| + if total_capturable_amount == captured_amount || + (is_overcapture_applied == Some(true) && captured_amount > total_capturable_amount) { + enums::AttemptStatus::Charged + } else if captured_amount < total_capturable_amount{ + enums::AttemptStatus::PartialCharged + } else { + self.status + } + ).unwrap_or(self.status) } _ => self.status, } diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index cbf2cdea5384..5a29a7ef0ddf 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -482,6 +482,7 @@ where ) .await?; + let op_ref = &operation; let should_trigger_post_processing_flows = is_operation_confirm(&operation); @@ -584,6 +585,7 @@ where ) .await?; + #[cfg(all(feature = "retry", feature = "v1"))] let mut router_data = router_data; #[cfg(all(feature = "retry", feature = "v1"))] diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 0a353a0a40be..3e0fad8376bf 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1143,13 +1143,12 @@ impl PaymentCreate { .transpose()? .flatten(); - let request_overcapture = match (request.capture_method, request.confirm) { - (Some(api_models::enums::CaptureMethod::Manual), _) | (None, Some(true)) => request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)), - _ => Err(errors::ApiErrorResponse::NotSupported { - message: "requesting overcapture is supported only via manual capture".to_owned(), - })?, + let request_overcapture = match (request.capture_method, request.confirm) { + (Some(api_models::enums::CaptureMethod::Manual), _) | + (None, Some(false)) => { + request.request_overcapture.or(Some(business_profile.always_request_overcapture)) + } + _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? }; if additional_pm_data.is_none() { diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 153321c7a23f..a862cff0a251 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -419,7 +419,6 @@ impl PostUpdateTracker, types::PaymentsIncrementalAu None, ), amount_capturable: incremental_authorization_details.total_amount, - overcapture_applied: None, //todooooo }, ), Some( @@ -1490,6 +1489,7 @@ async fn payment_response_update_tracker( }, _ => router_data.get_attempt_status_for_db_update(&payment_data), }; + match payments_response { types::PaymentsResponseData::PreProcessingResponse { pre_processing_id, @@ -1567,21 +1567,9 @@ async fn payment_response_update_tracker( None }; - // let overcapture_details = None; todoo - // match payment_data.payment_attempt.overcapture_details.clone() { - // Some(mut overcapture_details) => { - // overcapture_details.overcapture_applied = - // overcapture_applied; - // overcapture_details.maximum_capturable_amount = - // maximum_capturable_amount; - // overcapture_details.overcaptured_amount = payment_data - // .payment_attempt - // .net_amount - // .get_overcaptured_amount(); - // Some(overcapture_details) - // } - // None => None, - // }; + let overcapture_data = router_data.connector_response.and_then(|resp| resp.overcapture_data); + let overcapture_applied = overcapture_data.as_ref().map(|data| data.overcapture_applied); + let maximum_capturable_amount = overcapture_data.as_ref().map(|data| data.maximum_capturable_amount); // incase of success, update error code and error message let error_status = @@ -1730,7 +1718,7 @@ async fn payment_response_update_tracker( .get_amount_capturable( &payment_data, updated_attempt_status, - None, + maximum_capturable_amount, ) .map(MinorUnit::new), payment_method_id, @@ -1752,7 +1740,7 @@ async fn payment_response_update_tracker( .payment_attempt .connector_mandate_detail .clone(), - overcapture_applied: None, // todo + overcapture_applied, }), ), }; diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index 28ac6bd886c2..a6f4964cde2b 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -414,6 +414,10 @@ where .clone() .and_then(|connector_response| connector_response.additional_payment_method_data), )?; + + let overcapture_data = router_data.connector_response.as_ref().and_then(|resp| resp.overcapture_data.clone()); + let overcapture_applied = overcapture_data.as_ref().map(|data| data.overcapture_applied); + let maximum_capturable_amount = overcapture_data.as_ref().map(|data| data.maximum_capturable_amount); match router_data.response { Ok(types::PaymentsResponseData::TransactionResponse { @@ -432,27 +436,6 @@ where .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Could not parse the connector response")?; - // let overcapture_details = match payment_data - // .get_payment_attempt() //todoooo - // .overcapture_details - // .clone() - // { - // Some(mut overcapture_details) => { - // overcapture_details.overcapture_applied = overcapture_applied; - // overcapture_details.maximum_capturable_amount = maximum_capturable_amount; - // overcapture_details.overcaptured_amount = get_overcaptured_amount( - // overcapture_applied, - // router_data.amount_captured.map(MinorUnit::new), - // payment_data - // .get_payment_attempt() - // .net_amount - // .get_total_amount(), - // ); - // Some(overcapture_details) - // } - // None => None, - // }; - let payment_attempt_update = storage::PaymentAttemptUpdate::ResponseUpdate { status: router_data.status, connector: None, @@ -478,7 +461,7 @@ where amount_capturable: if router_data.status.is_terminal_status() { Some(MinorUnit::new(0)) } else { - None + maximum_capturable_amount }, updated_by: storage_scheme.to_string(), authentication_data, @@ -488,7 +471,7 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, - overcapture_applied: None, //todoo + overcapture_applied, }; #[cfg(feature = "v1")] diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index a52a2479e44f..b9d9136f4c69 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -2214,18 +2214,6 @@ where }) }); - // let (overcapture_applied, maximum_capturable_amount) = payment_attempt - // .overcapture_details - // .as_ref() - // .map(|overcapture_data| { - // ( - // overcapture_data.overcapture_applied, - // overcapture_data.maximum_capturable_amount, - // ) - // }) - // .unwrap_or((None, None)); - //todooooo - let connector_transaction_id = payment_attempt .get_connector_payment_id() .map(ToString::to_string); @@ -2338,7 +2326,7 @@ where order_tax_amount, connector_mandate_id, shipping_cost: payment_intent.shipping_cost, - overcapture_applied: None, + overcapture_applied: payment_attempt.overcapture_applied, }; services::ApplicationResponse::JsonWithHeaders((payments_response, headers)) diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index db73f9e421db..b4a2a4497a49 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -45,6 +45,7 @@ pub use hyperswitch_domain_models::{ AccessToken, AdditionalPaymentMethodConnectorResponse, ApplePayCryptogramData, ApplePayPredecryptData, ConnectorAuthType, ConnectorResponseData, ErrorResponse, PaymentMethodBalance, PaymentMethodToken, RecurringMandatePaymentData, RouterData, + OverCaptureData, }, router_data_v2::{ AccessTokenFlowData, DisputesFlowData, ExternalAuthenticationFlowData, FilesFlowData, From 4d844f84d19376995ae1c512375727060a8a5537 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 04:52:22 +0000 Subject: [PATCH 40/64] chore: run formatter --- .../src/router_data.rs | 2 +- .../src/connector/stripe/transformers.rs | 57 ++++++++++++------- crates/router/src/connector/utils.rs | 25 ++++---- crates/router/src/core/payments.rs | 2 - .../payments/operations/payment_create.rs | 13 +++-- .../payments/operations/payment_response.rs | 12 +++- crates/router/src/core/payments/retry.rs | 15 +++-- crates/router/src/types.rs | 4 +- 8 files changed, 80 insertions(+), 50 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index 17eb15c9e906..a65974f1e7bd 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -328,7 +328,7 @@ pub struct PaymentMethodBalance { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ConnectorResponseData { pub additional_payment_method_data: Option, - pub overcapture_data: Option + pub overcapture_data: Option, } impl ConnectorResponseData { diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 6bd0578b0f8c..817ab65f8251 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -2565,14 +2565,20 @@ impl .latest_charge .as_ref() .and_then(extract_payment_method_connector_response_from_latest_charge); - let overcapture_data = item.response.latest_charge.as_ref().and_then(extract_overcapture_response_from_latest_charge); - let connector_response = if overcapture_data.is_some() || additional_payment_method_data.is_some() { - Some(types::ConnectorResponseData { - additional_payment_method_data, - overcapture_data, - })} else{ - None - }; + let overcapture_data = item + .response + .latest_charge + .as_ref() + .and_then(extract_overcapture_response_from_latest_charge); + let connector_response = + if overcapture_data.is_some() || additional_payment_method_data.is_some() { + Some(types::ConnectorResponseData { + additional_payment_method_data, + overcapture_data, + }) + } else { + None + }; Ok(Self { status, @@ -2737,14 +2743,20 @@ impl .latest_charge .as_ref() .and_then(extract_payment_method_connector_response_from_latest_charge); - let overcapture_data = item.response.latest_charge.as_ref().and_then(extract_overcapture_response_from_latest_charge); - let connector_response = if overcapture_data.is_some() || additional_payment_method_data.is_some() { - Some(types::ConnectorResponseData { - additional_payment_method_data, - overcapture_data, - })} else{ - None - }; + let overcapture_data = item + .response + .latest_charge + .as_ref() + .and_then(extract_overcapture_response_from_latest_charge); + let connector_response = + if overcapture_data.is_some() || additional_payment_method_data.is_some() { + Some(types::ConnectorResponseData { + additional_payment_method_data, + overcapture_data, + }) + } else { + None + }; let response = if connector_util::is_payment_failure(status) { types::PaymentsResponseData::foreign_try_from(( @@ -2765,7 +2777,6 @@ impl _ => None, }; - let charge_id = item .response .latest_charge @@ -4147,7 +4158,7 @@ fn get_transaction_metadata( fn extract_overcapture_response_from_latest_charge( latest_charge: &StripeChargeEnum, -) -> Option{ +) -> Option { let (overcapture_applied, maximum_overcapture_amount) = match latest_charge { StripeChargeEnum::ChargeObject(charge_object) => charge_object .payment_method_details @@ -4172,10 +4183,12 @@ fn extract_overcapture_response_from_latest_charge( .unwrap_or((None, None)), _ => (None, None), }; - overcapture_applied.zip(maximum_overcapture_amount).map(|overcapture_data| types::OverCaptureData { - overcapture_applied: overcapture_data.0, - maximum_capturable_amount: overcapture_data.1, - }) + overcapture_applied + .zip(maximum_overcapture_amount) + .map(|overcapture_data| types::OverCaptureData { + overcapture_applied: overcapture_data.0, + maximum_capturable_amount: overcapture_data.1, + }) } impl ForeignTryFrom<(&Option, u16, String)> for types::PaymentsResponseData { diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 0c9ed3d28066..189e897a9c40 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -177,16 +177,21 @@ where enums::AttemptStatus::Charged => { let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); let is_overcapture_applied = payment_data.payment_attempt.overcapture_applied; - types::Capturable::get_captured_amount(&self.request, payment_data).map(MinorUnit::new).map(|captured_amount| - if total_capturable_amount == captured_amount || - (is_overcapture_applied == Some(true) && captured_amount > total_capturable_amount) { - enums::AttemptStatus::Charged - } else if captured_amount < total_capturable_amount{ - enums::AttemptStatus::PartialCharged - } else { - self.status - } - ).unwrap_or(self.status) + types::Capturable::get_captured_amount(&self.request, payment_data) + .map(MinorUnit::new) + .map(|captured_amount| { + if total_capturable_amount == captured_amount + || (is_overcapture_applied == Some(true) + && captured_amount > total_capturable_amount) + { + enums::AttemptStatus::Charged + } else if captured_amount < total_capturable_amount { + enums::AttemptStatus::PartialCharged + } else { + self.status + } + }) + .unwrap_or(self.status) } _ => self.status, } diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 5a29a7ef0ddf..cbf2cdea5384 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -482,7 +482,6 @@ where ) .await?; - let op_ref = &operation; let should_trigger_post_processing_flows = is_operation_confirm(&operation); @@ -585,7 +584,6 @@ where ) .await?; - #[cfg(all(feature = "retry", feature = "v1"))] let mut router_data = router_data; #[cfg(all(feature = "retry", feature = "v1"))] diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 3e0fad8376bf..b9b1e1539d8a 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1143,12 +1143,13 @@ impl PaymentCreate { .transpose()? .flatten(); - let request_overcapture = match (request.capture_method, request.confirm) { - (Some(api_models::enums::CaptureMethod::Manual), _) | - (None, Some(false)) => { - request.request_overcapture.or(Some(business_profile.always_request_overcapture)) - } - _ => Err(errors::ApiErrorResponse::NotSupported{message: "requesting overcapture is supported only via manual capture".to_owned()})? + let request_overcapture = match (request.capture_method, request.confirm) { + (Some(api_models::enums::CaptureMethod::Manual), _) | (None, Some(false)) => request + .request_overcapture + .or(Some(business_profile.always_request_overcapture)), + _ => Err(errors::ApiErrorResponse::NotSupported { + message: "requesting overcapture is supported only via manual capture".to_owned(), + })?, }; if additional_pm_data.is_none() { diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index a862cff0a251..72a60531b0b8 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1567,9 +1567,15 @@ async fn payment_response_update_tracker( None }; - let overcapture_data = router_data.connector_response.and_then(|resp| resp.overcapture_data); - let overcapture_applied = overcapture_data.as_ref().map(|data| data.overcapture_applied); - let maximum_capturable_amount = overcapture_data.as_ref().map(|data| data.maximum_capturable_amount); + let overcapture_data = router_data + .connector_response + .and_then(|resp| resp.overcapture_data); + let overcapture_applied = overcapture_data + .as_ref() + .map(|data| data.overcapture_applied); + let maximum_capturable_amount = overcapture_data + .as_ref() + .map(|data| data.maximum_capturable_amount); // incase of success, update error code and error message let error_status = diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index a6f4964cde2b..b5e6e51952dc 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -414,10 +414,17 @@ where .clone() .and_then(|connector_response| connector_response.additional_payment_method_data), )?; - - let overcapture_data = router_data.connector_response.as_ref().and_then(|resp| resp.overcapture_data.clone()); - let overcapture_applied = overcapture_data.as_ref().map(|data| data.overcapture_applied); - let maximum_capturable_amount = overcapture_data.as_ref().map(|data| data.maximum_capturable_amount); + + let overcapture_data = router_data + .connector_response + .as_ref() + .and_then(|resp| resp.overcapture_data.clone()); + let overcapture_applied = overcapture_data + .as_ref() + .map(|data| data.overcapture_applied); + let maximum_capturable_amount = overcapture_data + .as_ref() + .map(|data| data.maximum_capturable_amount); match router_data.response { Ok(types::PaymentsResponseData::TransactionResponse { diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index b4a2a4497a49..86b8d7af48f0 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -44,8 +44,8 @@ pub use hyperswitch_domain_models::{ router_data::{ AccessToken, AdditionalPaymentMethodConnectorResponse, ApplePayCryptogramData, ApplePayPredecryptData, ConnectorAuthType, ConnectorResponseData, ErrorResponse, - PaymentMethodBalance, PaymentMethodToken, RecurringMandatePaymentData, RouterData, - OverCaptureData, + OverCaptureData, PaymentMethodBalance, PaymentMethodToken, RecurringMandatePaymentData, + RouterData, }, router_data_v2::{ AccessTokenFlowData, DisputesFlowData, ExternalAuthenticationFlowData, FilesFlowData, From b82bf8c7a2623b19a39ee516288ecf85aa0b49be Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 04:58:26 +0000 Subject: [PATCH 41/64] docs(openapi): re-generate OpenAPI specification --- api-reference-v2/openapi_spec.json | 16 ---------------- api-reference/openapi_spec.json | 16 ---------------- 2 files changed, 32 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index 179dd1a9ff48..ee4f74bd8225 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -15497,14 +15497,6 @@ "type": "boolean", "description": "Whether the payment is overcaptureable or not", "nullable": true - }, - "maximum_capturable_amount": { - "allOf": [ - { - "$ref": "#/components/schemas/MinorUnit" - } - ], - "nullable": true } } }, @@ -16414,14 +16406,6 @@ "type": "boolean", "description": "Whether the payment is overcaptureable or not", "nullable": true - }, - "maximum_capturable_amount": { - "allOf": [ - { - "$ref": "#/components/schemas/MinorUnit" - } - ], - "nullable": true } } }, diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 36108ede30cb..3908ef2658b4 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -18849,14 +18849,6 @@ "type": "boolean", "description": "Whether the payment is overcaptureable or not", "nullable": true - }, - "maximum_capturable_amount": { - "allOf": [ - { - "$ref": "#/components/schemas/MinorUnit" - } - ], - "nullable": true } } }, @@ -20110,14 +20102,6 @@ "type": "boolean", "description": "Whether the payment is overcaptureable or not", "nullable": true - }, - "maximum_capturable_amount": { - "allOf": [ - { - "$ref": "#/components/schemas/MinorUnit" - } - ], - "nullable": true } } }, From 1fdff4f304b954c45e89acddd6c7becb065289fd Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 7 Jan 2025 14:46:45 +0530 Subject: [PATCH 42/64] chore: fix clippy errors --- crates/common_enums/src/enums.rs | 12 ++++++++- crates/common_enums/src/transformers.rs | 10 +++++++ crates/common_utils/src/types.rs | 1 - crates/diesel_models/src/payment_attempt.rs | 2 ++ .../src/payments/payment_attempt.rs | 14 ++++++++++ crates/router/src/connector/utils.rs | 27 ++++++++----------- .../payments/operations/payment_confirm.rs | 2 +- .../payments/operations/payment_update.rs | 2 +- .../router/src/core/payments/transformers.rs | 5 +--- crates/router/tests/connectors/aci.rs | 1 - crates/router/tests/connectors/utils.rs | 1 + .../src/payments/payment_attempt.rs | 2 +- 12 files changed, 53 insertions(+), 26 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 083ed02d351b..20a90ea26220 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -3380,7 +3380,7 @@ pub enum External3dsAuthenticationRequest { } /// Whether overcapture is requested or not -#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] +#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] pub enum OverCaptureRequest { /// Request for overcapture Enable, @@ -3389,6 +3389,16 @@ pub enum OverCaptureRequest { Skip, } +/// Whether overcapture is allowed by the connector +#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] +pub enum OverCaptureApplied { + /// Request for overcapture + Applied, + /// Skip overcapture + #[default] + NotApplied, +} + /// Whether payment link is requested to be enabled or not for this transaction #[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] pub enum EnablePaymentLinkRequest { diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index 6ed16765602c..dcac632363fd 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -2040,6 +2040,16 @@ impl super::OverCaptureRequest { } } +/// Get the boolean value of the `OverCaptureApplied`. +impl super::OverCaptureApplied { + pub fn as_bool(&self) -> bool { + match self { + Self::Applied => true, + Self::NotApplied => false, + } + } +} + impl super::EnablePaymentLinkRequest { pub fn as_bool(&self) -> bool { match self { diff --git a/crates/common_utils/src/types.rs b/crates/common_utils/src/types.rs index 5075b0e79784..9e71ca76733f 100644 --- a/crates/common_utils/src/types.rs +++ b/crates/common_utils/src/types.rs @@ -1412,7 +1412,6 @@ pub struct BrowserInformation { #[cfg(feature = "v2")] crate::impl_to_sql_from_sql_json!(BrowserInformation); - /// Domain type for connector_transaction_id /// Maximum length for connector's transaction_id can be 128 characters in HS DB. /// In case connector's use an identifier whose length exceeds 128 characters, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 3593ca2c88e3..b6339938e601 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -94,6 +94,8 @@ pub struct PaymentAttempt { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, + pub request_overcapture: Option, + pub overcapture_applied: Option, } #[cfg(feature = "v1")] diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 12052bd0bcf2..8d90466711af 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -402,6 +402,10 @@ pub struct PaymentAttempt { pub id: id_type::GlobalAttemptId, /// The connector mandate details which are stored temporarily pub connector_mandate_detail: Option, + /// Whether to request for overcapture + pub request_overcapture: Option, + /// Whether overcapture was applied + pub overcapture_applied: Option, } impl PaymentAttempt { @@ -447,6 +451,16 @@ impl PaymentAttempt { self.connector_payment_id.as_deref() } + #[cfg(feature = "v1")] + pub fn is_overcapture_applied(&self) -> Option { + self.overcapture_applied + } + + #[cfg(feature = "v2")] + pub fn is_overcapture_applied(&self) -> Option { + self.overcapture_applied.as_bool() + } + /// Construct the domain model from the ConfirmIntentRequest and PaymentIntent #[cfg(feature = "v2")] pub async fn create_domain_model( diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 189e897a9c40..c84781431572 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -176,22 +176,17 @@ where } enums::AttemptStatus::Charged => { let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); - let is_overcapture_applied = payment_data.payment_attempt.overcapture_applied; - types::Capturable::get_captured_amount(&self.request, payment_data) - .map(MinorUnit::new) - .map(|captured_amount| { - if total_capturable_amount == captured_amount - || (is_overcapture_applied == Some(true) - && captured_amount > total_capturable_amount) - { - enums::AttemptStatus::Charged - } else if captured_amount < total_capturable_amount { - enums::AttemptStatus::PartialCharged - } else { - self.status - } - }) - .unwrap_or(self.status) + let is_overcapture_applied = payment_data.payment_attempt.is_overcapture_applied(); + types::Capturable::get_captured_amount(&self.request, payment_data).map(MinorUnit::new).map(|captured_amount| + if total_capturable_amount == captured_amount || + (is_overcapture_applied == Some(true) && captured_amount > total_capturable_amount) { + enums::AttemptStatus::Charged + } else if captured_amount < total_capturable_amount{ + enums::AttemptStatus::PartialCharged + } else { + self.status + } + ).unwrap_or(self.status) } _ => self.status, } diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 3da6afed82b9..bc9ce1abf228 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -1304,7 +1304,7 @@ impl UpdateTracker, api::PaymentsRequest> for let browser_info = payment_data.payment_attempt.browser_info.clone(); let frm_message = payment_data.frm_message.clone(); let capture_method = payment_data.payment_attempt.capture_method; - let request_overcapture = payment_data.payment_attempt.request_overcapture.clone(); + let request_overcapture = payment_data.payment_attempt.request_overcapture; let default_status_result = ( storage_enums::IntentStatus::Processing, diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 67410e05eae8..fd7c353e0bca 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -794,7 +794,7 @@ impl UpdateTracker, api::PaymentsRequest> for let payment_experience = payment_data.payment_attempt.payment_experience; let amount_to_capture = payment_data.payment_attempt.amount_to_capture; let capture_method = payment_data.payment_attempt.capture_method; - let request_overcapture = payment_data.payment_attempt.request_overcapture.clone(); + let request_overcapture = payment_data.payment_attempt.request_overcapture; let payment_method_billing_address_id = payment_data .payment_attempt .payment_method_billing_address_id diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index b9d9136f4c69..e0bf49a31439 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -291,6 +291,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>( integrity_object: None, shipping_cost: payment_data.payment_intent.amount_details.shipping_cost, additional_payment_method_data: None, + request_overcapture: None, }; let connector_mandate_request_reference_id = payment_data .payment_attempt @@ -375,7 +376,6 @@ pub async fn construct_payment_router_data_for_authorize<'a>( connector_mandate_request_reference_id, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) @@ -544,7 +544,6 @@ pub async fn construct_payment_router_data_for_capture<'a>( connector_mandate_request_reference_id, psd2_sca_exemption_type: None, authentication_id: None, - request_overcapture: None, }; Ok(router_data) @@ -679,7 +678,6 @@ pub async fn construct_router_data_for_psync<'a>( connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, }; Ok(router_data) @@ -845,7 +843,6 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>( connector_mandate_request_reference_id: None, psd2_sca_exemption_type: None, authentication_id: None, - request_overcapture: None, }; Ok(router_data) diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index d8f256d6c05e..e3fd2bc1ee9c 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -204,7 +204,6 @@ fn construct_refund_router_data() -> types::RefundsRouterData { connector_mandate_request_reference_id: None, authentication_id: None, psd2_sca_exemption_type: None, - request_overcapture: None, } } diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 361cda63a9f9..9498f3553af7 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -973,6 +973,7 @@ impl Default for PaymentAuthorizeType { merchant_order_reference_id: None, additional_payment_method_data: None, shipping_cost: None, + request_overcapture: None, }; Self(data) } diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 955e53a5414c..3477b51a2def 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -564,7 +564,7 @@ impl PaymentAttemptInterface for KVRouterStore { organization_id: payment_attempt.organization_id.clone(), profile_id: payment_attempt.profile_id.clone(), connector_mandate_detail: payment_attempt.connector_mandate_detail.clone(), - request_overcapture: payment_attempt.request_overcapture.clone(), + request_overcapture: payment_attempt.request_overcapture, overcapture_applied: None, }; From bac2badb16dc26efce99abe63d89cff49c0fe0d2 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 09:17:42 +0000 Subject: [PATCH 43/64] chore: run formatter --- .../src/payments/payment_attempt.rs | 2 +- crates/router/src/connector/utils.rs | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 8d90466711af..f22c187173b0 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -402,7 +402,7 @@ pub struct PaymentAttempt { pub id: id_type::GlobalAttemptId, /// The connector mandate details which are stored temporarily pub connector_mandate_detail: Option, - /// Whether to request for overcapture + /// Whether to request for overcapture pub request_overcapture: Option, /// Whether overcapture was applied pub overcapture_applied: Option, diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index c84781431572..e3e9248b648d 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -177,16 +177,21 @@ where enums::AttemptStatus::Charged => { let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); let is_overcapture_applied = payment_data.payment_attempt.is_overcapture_applied(); - types::Capturable::get_captured_amount(&self.request, payment_data).map(MinorUnit::new).map(|captured_amount| - if total_capturable_amount == captured_amount || - (is_overcapture_applied == Some(true) && captured_amount > total_capturable_amount) { - enums::AttemptStatus::Charged - } else if captured_amount < total_capturable_amount{ - enums::AttemptStatus::PartialCharged - } else { - self.status - } - ).unwrap_or(self.status) + types::Capturable::get_captured_amount(&self.request, payment_data) + .map(MinorUnit::new) + .map(|captured_amount| { + if total_capturable_amount == captured_amount + || (is_overcapture_applied == Some(true) + && captured_amount > total_capturable_amount) + { + enums::AttemptStatus::Charged + } else if captured_amount < total_capturable_amount { + enums::AttemptStatus::PartialCharged + } else { + self.status + } + }) + .unwrap_or(self.status) } _ => self.status, } From b081c080b6f5d2d44d38fd076d5c61216d904b0a Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 7 Jan 2025 19:24:25 +0530 Subject: [PATCH 44/64] refactor(core): change the datatype of request_overcapture and overcapture_status --- api-reference-v2/openapi_spec.json | 30 ++++++--- api-reference/openapi_spec.json | 62 +++++++++++++---- crates/api_models/src/payments.rs | 6 +- crates/common_enums/src/enums.rs | 50 +++++++++++--- crates/common_enums/src/transformers.rs | 23 +++++-- crates/diesel_models/src/payment_attempt.rs | 66 +++++++++---------- crates/diesel_models/src/payment_intent.rs | 12 ++-- crates/diesel_models/src/schema.rs | 9 ++- crates/diesel_models/src/user/sample_data.rs | 6 +- .../hyperswitch_domain_models/src/payments.rs | 2 +- .../src/payments/payment_attempt.rs | 32 ++++----- .../src/payments/payment_intent.rs | 4 +- .../src/router_data.rs | 2 +- .../src/router_request_types.rs | 2 +- crates/openapi/src/openapi.rs | 2 + crates/openapi/src/openapi_v2.rs | 1 + .../src/connector/stripe/transformers.rs | 24 ++++--- crates/router/src/connector/utils.rs | 4 +- .../payments/operations/payment_capture.rs | 8 ++- .../payments/operations/payment_create.rs | 11 +++- .../payments/operations/payment_response.rs | 6 +- crates/router/src/core/payments/retry.rs | 6 +- .../router/src/core/payments/transformers.rs | 4 +- crates/router/src/types.rs | 2 +- crates/router/tests/payments.rs | 4 +- crates/router/tests/payments2.rs | 4 +- .../src/mock_db/payment_attempt.rs | 2 +- .../src/payments/payment_attempt.rs | 6 +- .../down.sql | 6 +- .../up.sql | 6 +- .../up.sql | 2 +- 31 files changed, 251 insertions(+), 153 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index a8596da73915..cc06efd2502e 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -12401,8 +12401,16 @@ "type": "string", "description": "Whether overcapture is requested or not", "enum": [ - "Enable", - "Skip" + "enable", + "skip" + ] + }, + "OverCaptureStatus": { + "type": "string", + "description": "Whether overcapture is allowed by the connector", + "enum": [ + "applicable", + "not_applicable" ] }, "PayLaterData": { @@ -15493,9 +15501,12 @@ "description": "Connector Identifier for the payment method", "nullable": true }, - "overcapture_applied": { - "type": "boolean", - "description": "Whether the payment is overcaptureable or not", + "overcapture_status": { + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureStatus" + } + ], "nullable": true } } @@ -16402,9 +16413,12 @@ "description": "Connector Identifier for the payment method", "nullable": true }, - "overcapture_applied": { - "type": "boolean", - "description": "Whether the payment is overcaptureable or not", + "overcapture_status": { + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureStatus" + } + ], "nullable": true } } diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 739deff9d6c8..be098fa809cb 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -15517,6 +15517,22 @@ } } }, + "OverCaptureRequest": { + "type": "string", + "description": "Whether overcapture is requested or not", + "enum": [ + "enable", + "skip" + ] + }, + "OverCaptureStatus": { + "type": "string", + "description": "Whether overcapture is allowed by the connector", + "enum": [ + "applicable", + "not_applicable" + ] + }, "PayLaterData": { "oneOf": [ { @@ -17906,8 +17922,11 @@ "nullable": true }, "request_overcapture": { - "type": "boolean", - "description": "Whether to request overcapture on this payment", + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureRequest" + } + ], "nullable": true } } @@ -18304,8 +18323,11 @@ "nullable": true }, "request_overcapture": { - "type": "boolean", - "description": "Whether to request overcapture on this payment", + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureRequest" + } + ], "nullable": true } } @@ -18847,9 +18869,12 @@ "description": "Connector Identifier for the payment method", "nullable": true }, - "overcapture_applied": { - "type": "boolean", - "description": "Whether the payment is overcaptureable or not", + "overcapture_status": { + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureStatus" + } + ], "nullable": true } } @@ -19531,8 +19556,11 @@ "nullable": true }, "request_overcapture": { - "type": "boolean", - "description": "Whether to request overcapture on this payment", + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureRequest" + } + ], "nullable": true } }, @@ -20100,9 +20128,12 @@ "description": "Connector Identifier for the payment method", "nullable": true }, - "overcapture_applied": { - "type": "boolean", - "description": "Whether the payment is overcaptureable or not", + "overcapture_status": { + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureStatus" + } + ], "nullable": true } } @@ -20597,8 +20628,11 @@ "nullable": true }, "request_overcapture": { - "type": "boolean", - "description": "Whether to request overcapture on this payment", + "allOf": [ + { + "$ref": "#/components/schemas/OverCaptureRequest" + } + ], "nullable": true } } diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index dc1a59abae6e..7acbb9771778 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -1048,7 +1048,8 @@ pub struct PaymentsRequest { pub ctp_service_details: Option, /// Whether to request overcapture on this payment - pub request_overcapture: Option, + #[schema(value_type = Option)] + pub request_overcapture: Option, } #[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)] @@ -4763,7 +4764,8 @@ pub struct PaymentsResponse { pub connector_mandate_id: Option, /// Whether the payment is overcaptureable or not - pub overcapture_applied: Option, + #[schema(value_type = Option)] + pub overcapture_status: Option, } // Serialize is implemented because, this will be serialized in the api events. diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 20a90ea26220..83a40d086859 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -3380,9 +3380,26 @@ pub enum External3dsAuthenticationRequest { } /// Whether overcapture is requested or not -#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] +#[derive( + Clone, + Copy, + Debug, + Default, + Eq, + Hash, + PartialEq, + ToSchema, + serde::Deserialize, + serde::Serialize, + strum::Display, + strum::EnumIter, + strum::EnumString, +)] +#[router_derive::diesel_enum(storage_type = "text")] +#[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] pub enum OverCaptureRequest { - /// Request for overcapture + /// Request for applying overcapture Enable, /// Skip overcapture #[default] @@ -3390,13 +3407,30 @@ pub enum OverCaptureRequest { } /// Whether overcapture is allowed by the connector -#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Default, ToSchema)] -pub enum OverCaptureApplied { - /// Request for overcapture - Applied, - /// Skip overcapture +#[derive( + Clone, + Copy, + Debug, + Default, + Eq, + Hash, + PartialEq, + ToSchema, + serde::Deserialize, + serde::Serialize, + strum::Display, + strum::EnumIter, + strum::EnumString, +)] +#[router_derive::diesel_enum(storage_type = "text")] +#[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] +pub enum OverCaptureStatus { + /// Overcapture is allowed + Applicable, + /// Overcapture is not allowed #[default] - NotApplied, + NotApplicable, } /// Whether payment link is requested to be enabled or not for this transaction diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index dcac632363fd..5fab7bcacedd 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -2021,10 +2021,10 @@ impl super::External3dsAuthenticationRequest { } } -impl From> for super::OverCaptureRequest { - fn from(value: Option) -> Self { +impl From for super::OverCaptureRequest { + fn from(value: bool) -> Self { match value { - Some(true) => Self::Enable, + true => Self::Enable, _ => Self::Skip, } } @@ -2040,12 +2040,21 @@ impl super::OverCaptureRequest { } } -/// Get the boolean value of the `OverCaptureApplied`. -impl super::OverCaptureApplied { +impl From> for super::OverCaptureStatus { + fn from(value: Option) -> Self { + match value { + Some(true) => Self::Applicable, + _ => Self::NotApplicable, + } + } +} + +/// Get the boolean value of the `OverCaptureStatus`. +impl super::OverCaptureStatus { pub fn as_bool(&self) -> bool { match self { - Self::Applied => true, - Self::NotApplied => false, + Self::Applicable => true, + Self::NotApplicable => false, } } } diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index b6339938e601..06e1318d79e4 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -95,7 +95,7 @@ pub struct PaymentAttempt { pub order_tax_amount: Option, pub connector_mandate_detail: Option, pub request_overcapture: Option, - pub overcapture_applied: Option, + pub overcapture_status: Option, } #[cfg(feature = "v1")] @@ -174,8 +174,8 @@ pub struct PaymentAttempt { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, + pub request_overcapture: Option, + pub overcapture_status: Option, } #[cfg(feature = "v1")] @@ -355,7 +355,7 @@ pub struct PaymentAttemptNew { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -379,7 +379,7 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - request_overcapture: Option, + request_overcapture: Option, }, UpdateTrackers { payment_token: Option, @@ -429,7 +429,7 @@ pub enum PaymentAttemptUpdate { shipping_cost: Option, order_tax_amount: Option, connector_mandate_detail: Option, - request_overcapture: Option, + request_overcapture: Option, }, VoidUpdate { status: storage_enums::AttemptStatus, @@ -478,7 +478,7 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, - overcapture_applied: Option, + overcapture_status: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -856,8 +856,8 @@ pub struct PaymentAttemptUpdateInternal { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, + pub request_overcapture: Option, + pub overcapture_status: Option, } #[cfg(feature = "v1")] @@ -1042,7 +1042,7 @@ impl PaymentAttemptUpdate { connector_transaction_data, connector_mandate_detail, request_overcapture, - overcapture_applied, + overcapture_status, } = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source); PaymentAttempt { amount: amount.unwrap_or(source.amount), @@ -1102,7 +1102,7 @@ impl PaymentAttemptUpdate { .or(source.connector_transaction_data), connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail), request_overcapture: request_overcapture.or(source.request_overcapture), - overcapture_applied: overcapture_applied.or(source.overcapture_applied), + overcapture_status: overcapture_status.or(source.overcapture_status), ..source } } @@ -2157,7 +2157,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::AuthenticationTypeUpdate { authentication_type, @@ -2215,7 +2215,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::ConfirmUpdate { amount, @@ -2305,7 +2305,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail, request_overcapture, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::VoidUpdate { status, @@ -2364,7 +2364,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::RejectUpdate { status, @@ -2424,7 +2424,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::BlocklistUpdate { status, @@ -2484,7 +2484,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::ConnectorMandateDetailUpdate { connector_mandate_detail, @@ -2542,7 +2542,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::PaymentMethodDetailsUpdate { payment_method_id, @@ -2600,7 +2600,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::ResponseUpdate { status, @@ -2624,7 +2624,7 @@ impl From for PaymentAttemptUpdateInternal { payment_method_data, charge_id, connector_mandate_detail, - overcapture_applied, + overcapture_status, } => { let (connector_transaction_id, connector_transaction_data) = connector_transaction_id @@ -2684,7 +2684,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail, request_overcapture: None, - overcapture_applied, + overcapture_status, } } PaymentAttemptUpdate::ErrorUpdate { @@ -2759,7 +2759,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, } } PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self { @@ -2815,7 +2815,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::UpdateTrackers { payment_token, @@ -2879,7 +2879,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::UnresolvedResponseUpdate { status, @@ -2950,7 +2950,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, } } PaymentAttemptUpdate::PreprocessingUpdate { @@ -3020,7 +3020,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, } } PaymentAttemptUpdate::CaptureUpdate { @@ -3080,7 +3080,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::AmountToCaptureUpdate { status, @@ -3139,7 +3139,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::ConnectorResponse { authentication_data, @@ -3207,7 +3207,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, } } PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate { @@ -3266,7 +3266,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::AuthenticationUpdate { status, @@ -3327,7 +3327,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, PaymentAttemptUpdate::ManualUpdate { status, @@ -3397,7 +3397,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, } } PaymentAttemptUpdate::PostSessionTokensUpdate { @@ -3456,7 +3456,7 @@ impl From for PaymentAttemptUpdateInternal { connector_transaction_data: None, connector_mandate_detail: None, request_overcapture: None, - overcapture_applied: None, + overcapture_status: None, }, } } diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs index 8ab8afcce6b8..3bcff961dbba 100644 --- a/crates/diesel_models/src/payment_intent.rs +++ b/crates/diesel_models/src/payment_intent.rs @@ -75,7 +75,7 @@ pub struct PaymentIntent { pub psd2_sca_exemption_type: Option, pub split_payments: Option, pub platform_merchant_id: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -143,7 +143,7 @@ pub struct PaymentIntent { pub psd2_sca_exemption_type: Option, pub split_payments: Option, pub platform_merchant_id: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression, PartialEq)] @@ -305,7 +305,7 @@ pub struct PaymentIntentNew { pub apply_mit_exemption: Option, pub id: common_utils::id_type::GlobalPaymentId, pub platform_merchant_id: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -374,7 +374,7 @@ pub struct PaymentIntentNew { pub psd2_sca_exemption_type: Option, pub platform_merchant_id: Option, pub split_payments: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v2")] @@ -530,7 +530,7 @@ pub struct PaymentIntentUpdateFields { pub shipping_details: Option, pub is_payment_processor_token_flow: Option, pub tax_details: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } // TODO: uncomment fields as necessary @@ -615,7 +615,7 @@ pub struct PaymentIntentUpdateInternal { pub shipping_details: Option, pub is_payment_processor_token_flow: Option, pub tax_details: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index fd79ebbba913..8e5b2818c59d 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -890,8 +890,10 @@ diesel::table! { #[max_length = 512] connector_transaction_data -> Nullable, connector_mandate_detail -> Nullable, - request_overcapture -> Nullable, - overcapture_applied -> Nullable, + #[max_length = 32] + request_overcapture -> Nullable, + #[max_length = 32] + overcapture_status -> Nullable, } } @@ -976,7 +978,8 @@ diesel::table! { split_payments -> Nullable, #[max_length = 64] platform_merchant_id -> Nullable, - request_overcapture -> Nullable, + #[max_length = 32] + request_overcapture -> Nullable, } } diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs index 1e2f712a625b..36375535578e 100644 --- a/crates/diesel_models/src/user/sample_data.rs +++ b/crates/diesel_models/src/user/sample_data.rs @@ -1,6 +1,6 @@ use common_enums::{ - AttemptStatus, AuthenticationType, CaptureMethod, Currency, PaymentExperience, PaymentMethod, - PaymentMethodType, + AttemptStatus, AuthenticationType, CaptureMethod, Currency, OverCaptureRequest, + PaymentExperience, PaymentMethod, PaymentMethodType, }; use common_utils::types::{ConnectorTransactionId, MinorUnit}; use serde::{Deserialize, Serialize}; @@ -203,7 +203,7 @@ pub struct PaymentAttemptBatchNew { pub order_tax_amount: Option, pub connector_transaction_data: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs index 5f91eb5734f1..d9f7bf9060df 100644 --- a/crates/hyperswitch_domain_models/src/payments.rs +++ b/crates/hyperswitch_domain_models/src/payments.rs @@ -110,7 +110,7 @@ pub struct PaymentIntent { pub skip_external_tax_calculation: Option, pub psd2_sca_exemption_type: Option, pub platform_merchant_id: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } impl PaymentIntent { diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index f22c187173b0..9f0e869f1256 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -405,7 +405,7 @@ pub struct PaymentAttempt { /// Whether to request for overcapture pub request_overcapture: Option, /// Whether overcapture was applied - pub overcapture_applied: Option, + pub overcapture_status: Option, } impl PaymentAttempt { @@ -451,16 +451,6 @@ impl PaymentAttempt { self.connector_payment_id.as_deref() } - #[cfg(feature = "v1")] - pub fn is_overcapture_applied(&self) -> Option { - self.overcapture_applied - } - - #[cfg(feature = "v2")] - pub fn is_overcapture_applied(&self) -> Option { - self.overcapture_applied.as_bool() - } - /// Construct the domain model from the ConfirmIntentRequest and PaymentIntent #[cfg(feature = "v2")] pub async fn create_domain_model( @@ -604,8 +594,8 @@ pub struct PaymentAttempt { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub request_overcapture: Option, - pub overcapture_applied: Option, + pub request_overcapture: Option, + pub overcapture_status: Option, } #[cfg(feature = "v1")] @@ -852,7 +842,7 @@ pub struct PaymentAttemptNew { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -874,7 +864,7 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - request_overcapture: Option, + request_overcapture: Option, }, UpdateTrackers { payment_token: Option, @@ -920,7 +910,7 @@ pub enum PaymentAttemptUpdate { client_version: Option, customer_acceptance: Option, connector_mandate_detail: Option, - request_overcapture: Option, + request_overcapture: Option, }, RejectUpdate { status: storage_enums::AttemptStatus, @@ -969,7 +959,7 @@ pub enum PaymentAttemptUpdate { payment_method_data: Option, charge_id: Option, connector_mandate_detail: Option, - overcapture_applied: Option, + overcapture_status: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, @@ -1244,7 +1234,7 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, - overcapture_applied, + overcapture_status, } => DieselPaymentAttemptUpdate::ResponseUpdate { status, connector, @@ -1267,7 +1257,7 @@ impl PaymentAttemptUpdate { payment_method_data, charge_id, connector_mandate_detail, - overcapture_applied, + overcapture_status, }, Self::UnresolvedResponseUpdate { status, @@ -1578,7 +1568,7 @@ impl behaviour::Conversion for PaymentAttempt { shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, request_overcapture: self.request_overcapture, - overcapture_applied: self.overcapture_applied, + overcapture_status: self.overcapture_status, }) } @@ -1661,7 +1651,7 @@ impl behaviour::Conversion for PaymentAttempt { organization_id: storage_model.organization_id, connector_mandate_detail: storage_model.connector_mandate_detail, request_overcapture: storage_model.request_overcapture, - overcapture_applied: storage_model.overcapture_applied, + overcapture_status: storage_model.overcapture_status, }) } .await diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index 8be15e140380..fa856e8342e5 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -196,7 +196,7 @@ pub struct PaymentIntentUpdateFields { pub shipping_details: Option>>, pub is_payment_processor_token_flow: Option, pub tax_details: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -352,7 +352,7 @@ pub struct PaymentIntentUpdateInternal { pub shipping_details: Option>>, pub is_payment_processor_token_flow: Option, pub tax_details: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } // This conversion is used in the `update_payment_intent` function diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs index ae74d7d45295..fb648ca9c40a 100644 --- a/crates/hyperswitch_domain_models/src/router_data.rs +++ b/crates/hyperswitch_domain_models/src/router_data.rs @@ -343,7 +343,7 @@ impl ConnectorResponseData { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct OverCaptureData { - pub overcapture_applied: bool, + pub overcapture_status: common_enums::OverCaptureStatus, pub maximum_capturable_amount: MinorUnit, } diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs index 478d474ea9f0..a456907ddc42 100644 --- a/crates/hyperswitch_domain_models/src/router_request_types.rs +++ b/crates/hyperswitch_domain_models/src/router_request_types.rs @@ -71,7 +71,7 @@ pub struct PaymentsAuthorizeData { pub integrity_object: Option, pub shipping_cost: Option, pub additional_payment_method_data: Option, - pub request_overcapture: Option, + pub request_overcapture: Option, } #[derive(Debug, Clone)] diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs index 2f068b5609b8..2c93d520813d 100644 --- a/crates/openapi/src/openapi.rs +++ b/crates/openapi/src/openapi.rs @@ -586,6 +586,8 @@ Never share your secret api keys. Keep them guarded and secure. api_models::enums::EventType, api_models::enums::DecoupledAuthenticationType, api_models::enums::AuthenticationStatus, + api_models::enums::OverCaptureRequest, + api_models::enums::OverCaptureStatus, api_models::admin::MerchantAccountResponse, api_models::admin::MerchantConnectorId, api_models::admin::MerchantDetails, diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs index 89d3b78c97ca..0cd23966a3ad 100644 --- a/crates/openapi/src/openapi_v2.rs +++ b/crates/openapi/src/openapi_v2.rs @@ -535,6 +535,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::enums::RequestIncrementalAuthorization, api_models::enums::External3dsAuthenticationRequest, api_models::enums::OverCaptureRequest, + api_models::enums::OverCaptureStatus, api_models::enums::TaxCalculationOverride, api_models::enums::SurchargeCalculationOverride, api_models::payments::FrmMessage, diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 6d7ba98b5795..fb6aeb78ad94 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -1824,7 +1824,7 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntent &item.request, )), billing_address, - item.request.request_overcapture, + item.request.request_overcapture.map(|request_overcapture|request_overcapture.as_bool()), )?; validate_shipping_address_against_payment_method( @@ -2295,13 +2295,13 @@ pub struct StripeAdditionalCardDetails { #[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] pub struct StripeOvercaptureResponse { - status: Option, + status: Option, maximum_amount_capturable: Option, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq, Serialize)] #[serde(rename_all = "snake_case")] -pub enum StripeOvercaptureStatus { +pub enum StripeOverCaptureStatus { Available, Unavailable, } @@ -4159,16 +4159,20 @@ fn get_transaction_metadata( fn extract_overcapture_response_from_latest_charge( latest_charge: &StripeChargeEnum, ) -> Option { - let (overcapture_applied, maximum_overcapture_amount) = match latest_charge { + let (overcapture_status, maximum_overcapture_amount) = match latest_charge { StripeChargeEnum::ChargeObject(charge_object) => charge_object .payment_method_details .as_ref() .and_then(|payment_method_details| match payment_method_details { StripePaymentMethodDetailsResponse::Card { card } => { - let overcapture_applied = card.overcapture.as_ref().and_then(|overcapture| { + let overcapture_status = card.overcapture.as_ref().and_then(|overcapture| { match overcapture.status.clone() { - Some(StripeOvercaptureStatus::Available) => Some(true), - Some(StripeOvercaptureStatus::Unavailable) => Some(false), + Some(StripeOverCaptureStatus::Available) => { + Some(common_enums::OverCaptureStatus::Applicable) + } + Some(StripeOverCaptureStatus::Unavailable) => { + Some(common_enums::OverCaptureStatus::NotApplicable) + } None => None, } }); @@ -4176,17 +4180,17 @@ fn extract_overcapture_response_from_latest_charge( .overcapture .as_ref() .and_then(|overcapture| overcapture.maximum_amount_capturable); - Some((overcapture_applied, maximum_capturable_amount)) + Some((overcapture_status, maximum_capturable_amount)) } _ => None, }) .unwrap_or((None, None)), _ => (None, None), }; - overcapture_applied + overcapture_status .zip(maximum_overcapture_amount) .map(|overcapture_data| types::OverCaptureData { - overcapture_applied: overcapture_data.0, + overcapture_status: overcapture_data.0, maximum_capturable_amount: overcapture_data.1, }) } diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index e9de151924ca..67659f6d9f6f 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -175,12 +175,12 @@ where } enums::AttemptStatus::Charged => { let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); - let is_overcapture_applied = payment_data.payment_attempt.is_overcapture_applied(); + let overcapture_status = payment_data.payment_attempt.overcapture_status; types::Capturable::get_captured_amount(&self.request, payment_data) .map(MinorUnit::new) .map(|captured_amount| { if total_capturable_amount == captured_amount - || (is_overcapture_applied == Some(true) + || (overcapture_status == Some(enums::OverCaptureStatus::Available) && captured_amount > total_capturable_amount) { enums::AttemptStatus::Charged diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 2709d0b0802d..34f4ab7472b1 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -101,7 +101,9 @@ impl GetTracker, api::Paymen request .amount_to_capture .map(|capture_amount| capture_amount.get_amount_as_i64()), - payment_attempt.overcapture_applied, + payment_attempt + .request_overcapture + .map(|request_overcapture| request_overcapture.as_bool()), )?; helpers::validate_capture_method(capture_method)?; @@ -114,7 +116,9 @@ impl GetTracker, api::Paymen helpers::validate_amount_to_capture( payment_attempt.amount_capturable.get_amount_as_i64(), Some(amount_to_capture.get_amount_as_i64()), - payment_attempt.overcapture_applied, + payment_attempt + .overcapture_status + .map(|overcapture_status| overcapture_status.as_bool()), )?; let previous_captures = db diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index b9b1e1539d8a..5502529e179f 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1144,9 +1144,14 @@ impl PaymentCreate { .flatten(); let request_overcapture = match (request.capture_method, request.confirm) { - (Some(api_models::enums::CaptureMethod::Manual), _) | (None, Some(false)) => request - .request_overcapture - .or(Some(business_profile.always_request_overcapture)), + (Some(api_models::enums::CaptureMethod::Manual), _) => { + request + .request_overcapture + .or(Some(api_models::enums::OverCaptureRequest::from( + business_profile.always_request_overcapture, + ))) + } + (None, Some(false)) => None, _ => Err(errors::ApiErrorResponse::NotSupported { message: "requesting overcapture is supported only via manual capture".to_owned(), })?, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 20b3b141f866..019d86f3d1b7 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -1573,9 +1573,9 @@ async fn payment_response_update_tracker( let overcapture_data = router_data .connector_response .and_then(|resp| resp.overcapture_data); - let overcapture_applied = overcapture_data + let overcapture_status = overcapture_data .as_ref() - .map(|data| data.overcapture_applied); + .map(|data| data.overcapture_status); let maximum_capturable_amount = overcapture_data .as_ref() .map(|data| data.maximum_capturable_amount); @@ -1749,7 +1749,7 @@ async fn payment_response_update_tracker( .payment_attempt .connector_mandate_detail .clone(), - overcapture_applied, + overcapture_status, }), ), }; diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index b5e6e51952dc..bb6cbd2e1130 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -419,9 +419,9 @@ where .connector_response .as_ref() .and_then(|resp| resp.overcapture_data.clone()); - let overcapture_applied = overcapture_data + let overcapture_status = overcapture_data .as_ref() - .map(|data| data.overcapture_applied); + .map(|data| data.overcapture_status); let maximum_capturable_amount = overcapture_data .as_ref() .map(|data| data.maximum_capturable_amount); @@ -478,7 +478,7 @@ where payment_method_data: additional_payment_method_data, charge_id, connector_mandate_detail: None, - overcapture_applied, + overcapture_status, }; #[cfg(feature = "v1")] diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index fdad2e4bdd5c..035272bfbd4d 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -2290,7 +2290,7 @@ where order_tax_amount, connector_mandate_id, shipping_cost: payment_intent.shipping_cost, - overcapture_applied: payment_attempt.overcapture_applied, + overcapture_status: payment_attempt.overcapture_status, }; services::ApplicationResponse::JsonWithHeaders((payments_response, headers)) @@ -2547,7 +2547,7 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay order_tax_amount: None, connector_mandate_id:None, shipping_cost: None, - overcapture_applied: pa.overcapture_applied, + overcapture_status: pa.overcapture_status, } } } diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 65f5aff0a23d..2e9d8933e41b 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -390,7 +390,7 @@ impl Capturable for CompleteAuthorizeData { | common_enums::IntentStatus::PartiallyCapturedAndCapturable => None, } }, - common_enums::CaptureMethod::Manual =>maximum_capturable_amount.or(Some(payment_data.payment_attempt.get_total_amount())).map(|amount_capturable| amount_capturable.get_amount_as_i64()), + common_enums::CaptureMethod::Manual => maximum_capturable_amount.or(Some(payment_data.payment_attempt.get_total_amount())).map(|amount_capturable| amount_capturable.get_amount_as_i64()), // In case of manual multiple, amount capturable must be inferred from all captures. common_enums::CaptureMethod::ManualMultiple | // Scheduled capture is not supported as of now diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs index d96719a17508..b62938587ccf 100644 --- a/crates/router/tests/payments.rs +++ b/crates/router/tests/payments.rs @@ -451,7 +451,7 @@ async fn payments_create_core() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - overcapture_applied: None, + overcapture_status: None, }; let expected_response = services::ApplicationResponse::JsonWithHeaders((expected_response, vec![])); @@ -716,7 +716,7 @@ async fn payments_create_core_adyen_no_redirect() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - overcapture_applied: None, + overcapture_status: None, }, vec![], )); diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs index 0ea1975c09b8..517a90a60f91 100644 --- a/crates/router/tests/payments2.rs +++ b/crates/router/tests/payments2.rs @@ -212,7 +212,7 @@ async fn payments_create_core() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - overcapture_applied: None, + overcapture_status: None, }; let expected_response = @@ -486,7 +486,7 @@ async fn payments_create_core_adyen_no_redirect() { order_tax_amount: None, connector_mandate_id: None, shipping_cost: None, - overcapture_applied: None, + overcapture_status: None, }, vec![], )); diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs index 426ba2d536d3..deb2738b98a7 100644 --- a/crates/storage_impl/src/mock_db/payment_attempt.rs +++ b/crates/storage_impl/src/mock_db/payment_attempt.rs @@ -196,7 +196,7 @@ impl PaymentAttemptInterface for MockDb { profile_id: payment_attempt.profile_id, connector_mandate_detail: payment_attempt.connector_mandate_detail, request_overcapture: payment_attempt.request_overcapture, - overcapture_applied: None, + overcapture_status: None, }; payment_attempts.push(payment_attempt.clone()); Ok(payment_attempt) diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 3477b51a2def..2c994113a6a1 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -565,7 +565,7 @@ impl PaymentAttemptInterface for KVRouterStore { profile_id: payment_attempt.profile_id.clone(), connector_mandate_detail: payment_attempt.connector_mandate_detail.clone(), request_overcapture: payment_attempt.request_overcapture, - overcapture_applied: None, + overcapture_status: None, }; let field = format!("pa_{}", created_attempt.attempt_id); @@ -1514,7 +1514,7 @@ impl DataModelExt for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, request_overcapture: self.request_overcapture, - overcapture_applied: self.overcapture_applied, + overcapture_status: self.overcapture_status, } } @@ -1592,7 +1592,7 @@ impl DataModelExt for PaymentAttempt { profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, request_overcapture: storage_model.request_overcapture, - overcapture_applied: storage_model.overcapture_applied, + overcapture_status: storage_model.overcapture_status, } } } diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql index 4575b40ea58c..eebd7df7dafc 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/down.sql @@ -1,5 +1,3 @@ ALTER TABLE payment_attempt -DROP COLUMN IF EXISTS request_overcapture; - -ALTER TABLE payment_attempt -DROP COLUMN IF EXISTS overcapture_applied; +DROP COLUMN IF EXISTS request_overcapture, +DROP COLUMN IF EXISTS overcapture_status; diff --git a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql index 359d8ad9a7ea..322d4c816a48 100644 --- a/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql +++ b/migrations/2024-12-24-123457_add_overcapture_fields_to_payment_attempt/up.sql @@ -1,5 +1,3 @@ ALTER TABLE payment_attempt -ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN DEFAULT NULL; - -ALTER TABLE payment_attempt -ADD COLUMN IF NOT EXISTS overcapture_applied BOOLEAN DEFAULT NULL; \ No newline at end of file +ADD COLUMN IF NOT EXISTS request_overcapture VARCHAR(32) DEFAULT NULL, +ADD COLUMN IF NOT EXISTS overcapture_status VARCHAR(32) DEFAULT NULL; \ No newline at end of file diff --git a/migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/up.sql b/migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/up.sql index ed3b1d019d55..78ff94f88706 100644 --- a/migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/up.sql +++ b/migrations/2024-12-24-83746_add_request_overcapture_to_payment_intent/up.sql @@ -1 +1 @@ -ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS request_overcapture BOOLEAN; \ No newline at end of file +ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS request_overcapture VARCHAR(32) DEFAULT NULL; \ No newline at end of file From 794aea59a5f034528877e78759ac14bf4873fc07 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 7 Jan 2025 19:43:58 +0530 Subject: [PATCH 45/64] chore: fix v2 clippy error --- crates/diesel_models/src/schema_v2.rs | 7 ++++++- .../src/payments/payment_attempt.rs | 8 ++++++++ .../src/payments/payment_intent.rs | 6 +++--- crates/router/src/connector/utils.rs | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index eed1da63c5a0..5ebdc0527992 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -860,6 +860,10 @@ diesel::table! { shipping_cost -> Nullable, order_tax_amount -> Nullable, connector_mandate_detail -> Nullable, + #[max_length = 32] + request_overcapture -> Nullable, + #[max_length = 32] + overcapture_status -> Nullable, } } @@ -937,7 +941,8 @@ diesel::table! { split_payments -> Nullable, #[max_length = 64] platform_merchant_id -> Nullable, - request_overcapture -> Nullable, + #[max_length = 32] + request_overcapture -> Nullable, } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 9f0e869f1256..49d28ef01887 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -524,6 +524,8 @@ impl PaymentAttempt { error: None, connector_mandate_detail: None, id, + overcapture_status: None, + request_overcapture: None, }) } } @@ -1802,6 +1804,8 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_billing_address, connector, connector_mandate_detail, + request_overcapture, + overcapture_status, } = self; let AttemptAmountDetails { @@ -1879,6 +1883,8 @@ impl behaviour::Conversion for PaymentAttempt { payment_method_billing_address: payment_method_billing_address.map(Encryption::from), connector_payment_data, connector_mandate_detail, + overcapture_status, + request_overcapture, }) } @@ -1990,6 +1996,8 @@ impl behaviour::Conversion for PaymentAttempt { connector: storage_model.connector, payment_method_billing_address, connector_mandate_detail: storage_model.connector_mandate_detail, + request_overcapture: storage_model.request_overcapture, + overcapture_status: storage_model.overcapture_status, }) } .await diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index fa856e8342e5..2de0bab4557b 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -1401,7 +1401,7 @@ impl behaviour::Conversion for PaymentIntent { psd2_sca_exemption_type: None, platform_merchant_id, split_payments: None, - request_overcapture: Some(request_overcapture.as_bool()), + request_overcapture: Some(request_overcapture), }) } async fn convert_back( @@ -1528,7 +1528,7 @@ impl behaviour::Conversion for PaymentIntent { payment_link_config: storage_model.payment_link_config, routing_algorithm_id: storage_model.routing_algorithm_id, platform_merchant_id: storage_model.platform_merchant_id, - request_overcapture: storage_model.request_overcapture.into(), + request_overcapture: storage_model.request_overcapture.unwrap_or_default(), }) } .await @@ -1602,7 +1602,7 @@ impl behaviour::Conversion for PaymentIntent { enable_payment_link: Some(self.enable_payment_link.as_bool()), apply_mit_exemption: Some(self.apply_mit_exemption.as_bool()), platform_merchant_id: self.platform_merchant_id, - request_overcapture: Some(self.request_overcapture.as_bool()), + request_overcapture: Some(self.request_overcapture), }) } } diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 67659f6d9f6f..a4d0c118f6a4 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -180,7 +180,7 @@ where .map(MinorUnit::new) .map(|captured_amount| { if total_capturable_amount == captured_amount - || (overcapture_status == Some(enums::OverCaptureStatus::Available) + || (overcapture_status == Some(enums::OverCaptureStatus::Applicable) && captured_amount > total_capturable_amount) { enums::AttemptStatus::Charged From 09cbc2522bbdbc4b54299f7f6c1122a656062cb1 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 8 Jan 2025 12:52:09 +0530 Subject: [PATCH 46/64] chore: fix clippy error --- crates/router/src/connector/stripe/transformers.rs | 4 ++-- crates/router/src/core/payments/transformers.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index fb6aeb78ad94..e35d54791c61 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -1153,7 +1153,7 @@ fn create_stripe_payment_method( payment_method_token: Option, is_customer_initiated_mandate_payment: Option, billing_address: StripeBillingAddress, - is_request_overcapture: Option, + request_overcapture: Option, ) -> Result< ( StripePaymentMethodData, @@ -1172,7 +1172,7 @@ fn create_stripe_payment_method( StripePaymentMethodData::try_from(( card_details, payment_method_auth_type, - is_request_overcapture, + request_overcapture, ))?, Some(StripePaymentMethodType::Card), billing_address, diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 035272bfbd4d..3a1219447b8d 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -1348,7 +1348,7 @@ where request_external_three_ds_authentication: payment_intent .request_external_three_ds_authentication .clone(), - request_overcapture: payment_intent.request_overcapture.clone(), + request_overcapture: payment_intent.request_overcapture, }, vec![], ))) From c5a8f45c5dfe675bbfa3d4e0ead4f10c882bd368 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger <131388445+AkshayaFoiger@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:43:58 +0530 Subject: [PATCH 47/64] Update crates/router/src/connector/utils.rs Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com> --- crates/router/src/connector/utils.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index a4d0c118f6a4..12b3c95f02f2 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -176,9 +176,10 @@ where enums::AttemptStatus::Charged => { let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); let overcapture_status = payment_data.payment_attempt.overcapture_status; - types::Capturable::get_captured_amount(&self.request, payment_data) - .map(MinorUnit::new) - .map(|captured_amount| { + let captured_amount_option = types::Capturable::get_captured_amount(&self.request, payment_data) + .map(MinorUnit::new); + match captured_amount_option { + Some(captured_amount) => { if total_capturable_amount == captured_amount || (overcapture_status == Some(enums::OverCaptureStatus::Applicable) && captured_amount > total_capturable_amount) @@ -189,8 +190,9 @@ where } else { self.status } - }) - .unwrap_or(self.status) + }, + None => self.status + } } _ => self.status, } From 772edc6a5d4892f94a4974dbd67f879863428189 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:15:03 +0000 Subject: [PATCH 48/64] chore: run formatter --- crates/router/src/connector/utils.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 12b3c95f02f2..f8a9adfa53f2 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -176,8 +176,9 @@ where enums::AttemptStatus::Charged => { let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); let overcapture_status = payment_data.payment_attempt.overcapture_status; - let captured_amount_option = types::Capturable::get_captured_amount(&self.request, payment_data) - .map(MinorUnit::new); + let captured_amount_option = + types::Capturable::get_captured_amount(&self.request, payment_data) + .map(MinorUnit::new); match captured_amount_option { Some(captured_amount) => { if total_capturable_amount == captured_amount @@ -190,8 +191,8 @@ where } else { self.status } - }, - None => self.status + } + None => self.status, } } _ => self.status, From 5bfc4392db2975a58bc6080cae01924f878073c4 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 8 Jan 2025 22:11:23 +0530 Subject: [PATCH 49/64] refactor(router): fix comments --- crates/api_models/src/admin.rs | 14 +---- crates/diesel_models/src/business_profile.rs | 14 ++--- crates/diesel_models/src/schema.rs | 2 +- crates/diesel_models/src/schema_v2.rs | 2 +- .../src/business_profile.rs | 19 ++----- crates/router/src/core/admin.rs | 4 +- crates/router/src/core/payments/helpers.rs | 52 +++++++++++++++++++ .../payments/operations/payment_confirm.rs | 16 ++---- .../payments/operations/payment_create.rs | 25 ++++----- .../payments/operations/payment_update.rs | 20 ++----- crates/router/src/services/api.rs | 16 +----- crates/router/src/types/api/admin.rs | 1 - .../up.sql | 2 +- 13 files changed, 87 insertions(+), 100 deletions(-) diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index ec865b9eab8a..f8b9983be49f 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -1867,7 +1867,7 @@ pub struct ProfileCreate { /// Indicates if the overcapture is always requested or not. #[serde(default)] - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[nutype::nutype( @@ -1986,9 +1986,6 @@ pub struct ProfileCreate { #[schema(value_type = Option, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)] pub authentication_product_ids: Option>, - /// Indicates if the overcapture is always requested or not. - #[schema(default = false, example = false)] - pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -2128,7 +2125,7 @@ pub struct ProfileResponse { /// Indicates if the overcapture is always requested or not. #[schema(default = false, example = false)] - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[cfg(feature = "v2")] @@ -2253,9 +2250,6 @@ pub struct ProfileResponse { #[schema(value_type = Option, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)] pub authentication_product_ids: Option, - /// Indicates if the overcapture is always requested or not. - #[schema(default = false, example = false)] - pub always_request_overcapture: bool, } #[cfg(feature = "v1")] @@ -2501,10 +2495,6 @@ pub struct ProfileUpdate { /// Product authentication ids #[schema(value_type = Option, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)] pub authentication_product_ids: Option>, - - /// Indicates if the overcapture is always requested or not. - #[schema(default = false, example = false)] - pub always_request_overcapture: Option, } #[derive(Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)] diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs index 71bde6c42d2c..18cd00508ad4 100644 --- a/crates/diesel_models/src/business_profile.rs +++ b/crates/diesel_models/src/business_profile.rs @@ -59,7 +59,7 @@ pub struct Profile { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[cfg(feature = "v1")] @@ -105,7 +105,7 @@ pub struct ProfileNew { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[cfg(feature = "v1")] @@ -255,7 +255,7 @@ impl ProfileUpdateInternal { authentication_product_ids: authentication_product_ids .or(source.authentication_product_ids), always_request_overcapture: always_request_overcapture - .unwrap_or(source.always_request_overcapture), + .or(source.always_request_overcapture), } } } @@ -312,7 +312,7 @@ pub struct Profile { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } impl Profile { @@ -373,7 +373,6 @@ pub struct ProfileNew { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, } #[cfg(feature = "v2")] @@ -418,7 +417,6 @@ pub struct ProfileUpdateInternal { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: Option, pub authentication_product_ids: Option, - pub always_request_overcapture: Option, } #[cfg(feature = "v2")] @@ -462,7 +460,6 @@ impl ProfileUpdateInternal { max_auto_retries_enabled, is_click_to_pay_enabled, authentication_product_ids, - always_request_overcapture, } = self; Profile { id: source.id, @@ -531,8 +528,7 @@ impl ProfileUpdateInternal { .unwrap_or(source.is_click_to_pay_enabled), authentication_product_ids: authentication_product_ids .or(source.authentication_product_ids), - always_request_overcapture: always_request_overcapture - .unwrap_or(source.always_request_overcapture), + always_request_overcapture: source.always_request_overcapture, } } } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 8e5b2818c59d..210af95d505b 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -216,7 +216,7 @@ diesel::table! { max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, authentication_product_ids -> Nullable, - always_request_overcapture -> Bool, + always_request_overcapture -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 5ebdc0527992..e5d886c8f44e 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -224,7 +224,7 @@ diesel::table! { max_auto_retries_enabled -> Nullable, is_click_to_pay_enabled -> Bool, authentication_product_ids -> Nullable, - always_request_overcapture -> Bool, + always_request_overcapture -> Nullable, } } diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs index 823d5ed73c57..b1d1f9cd2d64 100644 --- a/crates/hyperswitch_domain_models/src/business_profile.rs +++ b/crates/hyperswitch_domain_models/src/business_profile.rs @@ -60,7 +60,7 @@ pub struct Profile { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[cfg(feature = "v1")] @@ -103,7 +103,7 @@ pub struct ProfileSetter { pub max_auto_retries_enabled: Option, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[cfg(feature = "v1")] @@ -744,7 +744,7 @@ pub struct Profile { pub is_network_tokenization_enabled: bool, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, + pub always_request_overcapture: Option, } #[cfg(feature = "v2")] @@ -787,7 +787,6 @@ pub struct ProfileSetter { pub is_network_tokenization_enabled: bool, pub is_click_to_pay_enabled: bool, pub authentication_product_ids: Option, - pub always_request_overcapture: bool, } #[cfg(feature = "v2")] @@ -837,7 +836,7 @@ impl From for Profile { is_network_tokenization_enabled: value.is_network_tokenization_enabled, is_click_to_pay_enabled: value.is_click_to_pay_enabled, authentication_product_ids: value.authentication_product_ids, - always_request_overcapture: value.always_request_overcapture, + always_request_overcapture: None, } } } @@ -890,7 +889,6 @@ pub struct ProfileGeneralUpdate { pub is_network_tokenization_enabled: Option, pub is_click_to_pay_enabled: Option, pub authentication_product_ids: Option, - pub always_request_overcapture: Option, } #[cfg(feature = "v2")] @@ -951,7 +949,6 @@ impl From for ProfileUpdateInternal { is_network_tokenization_enabled, is_click_to_pay_enabled, authentication_product_ids, - always_request_overcapture, } = *update; Self { profile_name, @@ -992,7 +989,6 @@ impl From for ProfileUpdateInternal { max_auto_retries_enabled: None, is_click_to_pay_enabled: None, authentication_product_ids, - always_request_overcapture, } } ProfileUpdate::RoutingAlgorithmUpdate { @@ -1036,7 +1032,6 @@ impl From for ProfileUpdateInternal { max_auto_retries_enabled: None, is_click_to_pay_enabled: None, authentication_product_ids: None, - always_request_overcapture: None, }, ProfileUpdate::ExtendedCardInfoUpdate { is_extended_card_info_enabled, @@ -1078,7 +1073,6 @@ impl From for ProfileUpdateInternal { max_auto_retries_enabled: None, is_click_to_pay_enabled: None, authentication_product_ids: None, - always_request_overcapture: None, }, ProfileUpdate::ConnectorAgnosticMitUpdate { is_connector_agnostic_mit_enabled, @@ -1120,7 +1114,6 @@ impl From for ProfileUpdateInternal { max_auto_retries_enabled: None, is_click_to_pay_enabled: None, authentication_product_ids: None, - always_request_overcapture: None, }, ProfileUpdate::DefaultRoutingFallbackUpdate { default_fallback_routing, @@ -1162,7 +1155,6 @@ impl From for ProfileUpdateInternal { max_auto_retries_enabled: None, is_click_to_pay_enabled: None, authentication_product_ids: None, - always_request_overcapture: None, }, ProfileUpdate::NetworkTokenizationUpdate { is_network_tokenization_enabled, @@ -1204,7 +1196,6 @@ impl From for ProfileUpdateInternal { max_auto_retries_enabled: None, is_click_to_pay_enabled: None, authentication_product_ids: None, - always_request_overcapture: None, }, ProfileUpdate::CollectCvvDuringPaymentUpdate { should_collect_cvv_during_payment, @@ -1246,7 +1237,6 @@ impl From for ProfileUpdateInternal { max_auto_retries_enabled: None, is_click_to_pay_enabled: None, authentication_product_ids: None, - always_request_overcapture: None, }, } } @@ -1437,7 +1427,6 @@ impl super::behaviour::Conversion for Profile { max_auto_retries_enabled: None, is_click_to_pay_enabled: self.is_click_to_pay_enabled, authentication_product_ids: self.authentication_product_ids, - always_request_overcapture: self.always_request_overcapture, }) } } diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 8c16e59bc646..9e4b72febf28 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -3821,8 +3821,7 @@ impl ProfileCreateBridge for api::ProfileCreate { is_tax_connector_enabled: self.is_tax_connector_enabled, is_network_tokenization_enabled: self.is_network_tokenization_enabled, is_click_to_pay_enabled: self.is_click_to_pay_enabled, - authentication_product_ids, - always_request_overcapture: self.always_request_overcapture, + authentication_product_ids, })) } } @@ -4187,7 +4186,6 @@ impl ProfileUpdateBridge for api::ProfileUpdate { is_network_tokenization_enabled: self.is_network_tokenization_enabled, is_click_to_pay_enabled: self.is_click_to_pay_enabled, authentication_product_ids, - always_request_overcapture: self.always_request_overcapture, }, ))) } diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 1419ad797d12..e7d0bfb21d8e 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6276,3 +6276,55 @@ pub fn validate_platform_fees_for_marketplace( } Ok(()) } + +pub fn validate_overcapture_request_for_payments_create( + capture_method: Option, + request_overcapture: Option, +) -> Result<(), errors::ApiErrorResponse> { + utils::when( + request_overcapture == Some(api_enums::OverCaptureRequest::Enable) && capture_method != Some(api_enums::CaptureMethod::Manual), + || { + Err(errors::ApiErrorResponse::InvalidRequestData { + message: "Overcapture is only supported for manual capture".to_string(), + }) + } +) +} + +pub fn get_overcapture_request_for_payments_update( + payment_attempt: &PaymentAttempt, + payment_intent: &PaymentIntent, + request: Option<&api_models::payments::PaymentsRequest>, + profile: &domain::Profile, +) -> Result, errors::ApiErrorResponse> { + let req_request_overcapture = request.and_then(|req| req.request_overcapture); + match payment_attempt.capture_method { + Some(api_enums::CaptureMethod::Manual) => { + Ok(req_request_overcapture + .or(payment_intent.request_overcapture) + .or(profile.always_request_overcapture.map(api_enums::OverCaptureRequest::from))) + }, + Some(_) => { + match payment_attempt.request_overcapture { + Some(api_enums::OverCaptureRequest::Enable) => { + // case where we set the request_overcapture from the business profile + if payment_intent.request_overcapture.is_none() { + Ok(Some(api_enums::OverCaptureRequest::Skip)) + } else { + Err(errors::ApiErrorResponse::InvalidRequestData { + message: "Capture method cannot be changed. Overcapture is only supported for manual capture".to_string(), + })? + }}, + request_overcapture => Ok(request_overcapture), + }} + None => { + if matches!(req_request_overcapture, Some(api_enums::OverCaptureRequest::Enable)) { + Err(errors::ApiErrorResponse::InvalidRequestData { + message: "Overcapture is only supported for manual capture".to_string(), + })? + } else { + Ok(None) + } + } + } +} \ No newline at end of file diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index bc9ce1abf228..c307fabfafcc 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -404,17 +404,6 @@ impl GetTracker, api::PaymentsRequest> payment_attempt.capture_method = request.capture_method.or(payment_attempt.capture_method); - match payment_attempt.capture_method { - Some(storage_enums::CaptureMethod::Manual) => { - payment_attempt.request_overcapture = request - .request_overcapture - .or(payment_attempt.request_overcapture); - } - _ => Err(errors::ApiErrorResponse::NotSupported { - message: "requesting overcapture is supported only via manual capture".to_owned(), - })?, - }; - payment_attempt.customer_acceptance = request .customer_acceptance .clone() @@ -792,6 +781,7 @@ impl GetTracker, api::PaymentsRequest> )), // connector_mandate_request_reference_id )), ); + payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update(&payment_attempt, &payment_intent, None, &business_profile)?; let payment_data = PaymentData { flow: PhantomData, @@ -1304,7 +1294,6 @@ impl UpdateTracker, api::PaymentsRequest> for let browser_info = payment_data.payment_attempt.browser_info.clone(); let frm_message = payment_data.frm_message.clone(); let capture_method = payment_data.payment_attempt.capture_method; - let request_overcapture = payment_data.payment_attempt.request_overcapture; let default_status_result = ( storage_enums::IntentStatus::Processing, @@ -1483,6 +1472,7 @@ impl UpdateTracker, api::PaymentsRequest> for ), None => (None, None, None), }; + let request_overcapture = payment_data.payment_attempt.request_overcapture; let payment_attempt_fut = tokio::spawn( async move { @@ -1531,7 +1521,7 @@ impl UpdateTracker, api::PaymentsRequest> for connector_mandate_detail: payment_data .payment_attempt .connector_mandate_detail, - request_overcapture, + request_overcapture }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 5502529e179f..c88d5740f6e5 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -993,7 +993,9 @@ impl ValidateRequest { - request - .request_overcapture - .or(Some(api_models::enums::OverCaptureRequest::from( - business_profile.always_request_overcapture, - ))) - } - (None, Some(false)) => None, - _ => Err(errors::ApiErrorResponse::NotSupported { - message: "requesting overcapture is supported only via manual capture".to_owned(), - })?, - }; + + let request_overcapture = request.request_overcapture.or_else(|| { + if matches!(request.capture_method, Some(api_models::enums::CaptureMethod::Manual)) { + business_profile.always_request_overcapture.map(api_models::enums::OverCaptureRequest::from) + } else { + None + } + }); if additional_pm_data.is_none() { // If recurring payment is made using payment_method_id, then fetch payment_method_data from retrieved payment_method object diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index fd7c353e0bca..b8af3cfed181 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -393,10 +393,6 @@ impl GetTracker, api::PaymentsRequest> .request_external_three_ds_authentication .or(payment_intent.request_external_three_ds_authentication); - payment_intent.request_overcapture = request - .request_overcapture - .or(payment_intent.request_overcapture); - payment_intent.merchant_order_reference_id = request .merchant_order_reference_id .clone() @@ -444,21 +440,15 @@ impl GetTracker, api::PaymentsRequest> id: profile_id.get_string_repr().to_owned(), })?; - match payment_attempt.capture_method { - Some(storage_enums::CaptureMethod::Manual) | None => { - payment_attempt.request_overcapture = request - .request_overcapture - .or(payment_attempt.request_overcapture); - } - _ => Err(errors::ApiErrorResponse::NotSupported { - message: "requesting overcapture is supported only via manual capture".to_owned(), - })?, - }; - let surcharge_details = request.surcharge_details.map(|request_surcharge_details| { payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) }); + payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update(&payment_attempt, &payment_intent, Some(&request), &business_profile)?; + payment_intent.request_overcapture = request + .request_overcapture + .or(payment_intent.request_overcapture); + let payment_data = PaymentData { flow: PhantomData, payment_intent, diff --git a/crates/router/src/services/api.rs b/crates/router/src/services/api.rs index dd8f1755bed4..f90528353cfb 100644 --- a/crates/router/src/services/api.rs +++ b/crates/router/src/services/api.rs @@ -496,21 +496,7 @@ pub async fn send_request( None => client, } } - Method::Delete => { - let client = client.delete(url); - match request.body { - Some(RequestContent::Json(payload)) => client.json(&payload), - Some(RequestContent::FormData(form)) => client.multipart(form), - Some(RequestContent::FormUrlEncoded(payload)) => client.form(&payload), - Some(RequestContent::Xml(payload)) => { - let body = quick_xml::se::to_string(&payload) - .change_context(errors::ApiClientError::BodySerializationFailed)?; - client.body(body).header("Content-Type", "application/xml") - } - Some(RequestContent::RawBytes(payload)) => client.body(payload), - None => client, - } - } + Method::Delete => client.delete(url), } .add_headers(headers) .timeout(Duration::from_secs( diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs index 001b03fe47eb..546d6b513390 100644 --- a/crates/router/src/types/api/admin.rs +++ b/crates/router/src/types/api/admin.rs @@ -250,7 +250,6 @@ impl ForeignTryFrom for ProfileResponse { is_network_tokenization_enabled: item.is_network_tokenization_enabled, is_click_to_pay_enabled: item.is_click_to_pay_enabled, authentication_product_ids: item.authentication_product_ids, - always_request_overcapture: item.always_request_overcapture, }) } } diff --git a/migrations/2024-12-24-072648_add_always_request_overcapture/up.sql b/migrations/2024-12-24-072648_add_always_request_overcapture/up.sql index 1a5555cc773a..e8c17d89b520 100644 --- a/migrations/2024-12-24-072648_add_always_request_overcapture/up.sql +++ b/migrations/2024-12-24-072648_add_always_request_overcapture/up.sql @@ -1 +1 @@ -ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS always_request_overcapture BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file +ALTER TABLE business_profile ADD COLUMN IF NOT EXISTS always_request_overcapture BOOLEAN DEFAULT NULL; \ No newline at end of file From 70b8d585de56dcf8fd516f63b721cfc789d8678b Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:42:29 +0000 Subject: [PATCH 50/64] chore: run formatter --- crates/api_models/src/admin.rs | 2 - crates/router/src/core/admin.rs | 2 +- crates/router/src/core/payments/helpers.rs | 46 +++++++++++-------- .../payments/operations/payment_confirm.rs | 9 +++- .../payments/operations/payment_create.rs | 29 +++++++----- .../payments/operations/payment_update.rs | 13 ++++-- 6 files changed, 61 insertions(+), 40 deletions(-) diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index f8b9983be49f..48088ff2239b 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -1985,7 +1985,6 @@ pub struct ProfileCreate { /// Product authentication ids #[schema(value_type = Option, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)] pub authentication_product_ids: Option>, - } #[cfg(feature = "v1")] @@ -2249,7 +2248,6 @@ pub struct ProfileResponse { /// Product authentication ids #[schema(value_type = Option, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)] pub authentication_product_ids: Option, - } #[cfg(feature = "v1")] diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs index 9e4b72febf28..8fcbdbee4f70 100644 --- a/crates/router/src/core/admin.rs +++ b/crates/router/src/core/admin.rs @@ -3821,7 +3821,7 @@ impl ProfileCreateBridge for api::ProfileCreate { is_tax_connector_enabled: self.is_tax_connector_enabled, is_network_tokenization_enabled: self.is_network_tokenization_enabled, is_click_to_pay_enabled: self.is_click_to_pay_enabled, - authentication_product_ids, + authentication_product_ids, })) } } diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index e7d0bfb21d8e..ace5a0c63005 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6282,13 +6282,14 @@ pub fn validate_overcapture_request_for_payments_create( request_overcapture: Option, ) -> Result<(), errors::ApiErrorResponse> { utils::when( - request_overcapture == Some(api_enums::OverCaptureRequest::Enable) && capture_method != Some(api_enums::CaptureMethod::Manual), - || { - Err(errors::ApiErrorResponse::InvalidRequestData { - message: "Overcapture is only supported for manual capture".to_string(), - }) - } -) + request_overcapture == Some(api_enums::OverCaptureRequest::Enable) + && capture_method != Some(api_enums::CaptureMethod::Manual), + || { + Err(errors::ApiErrorResponse::InvalidRequestData { + message: "Overcapture is only supported for manual capture".to_string(), + }) + }, + ) } pub fn get_overcapture_request_for_payments_update( @@ -6299,11 +6300,11 @@ pub fn get_overcapture_request_for_payments_update( ) -> Result, errors::ApiErrorResponse> { let req_request_overcapture = request.and_then(|req| req.request_overcapture); match payment_attempt.capture_method { - Some(api_enums::CaptureMethod::Manual) => { - Ok(req_request_overcapture - .or(payment_intent.request_overcapture) - .or(profile.always_request_overcapture.map(api_enums::OverCaptureRequest::from))) - }, + Some(api_enums::CaptureMethod::Manual) => Ok(req_request_overcapture + .or(payment_intent.request_overcapture) + .or(profile + .always_request_overcapture + .map(api_enums::OverCaptureRequest::from))), Some(_) => { match payment_attempt.request_overcapture { Some(api_enums::OverCaptureRequest::Enable) => { @@ -6311,20 +6312,25 @@ pub fn get_overcapture_request_for_payments_update( if payment_intent.request_overcapture.is_none() { Ok(Some(api_enums::OverCaptureRequest::Skip)) } else { - Err(errors::ApiErrorResponse::InvalidRequestData { + Err(errors::ApiErrorResponse::InvalidRequestData { message: "Capture method cannot be changed. Overcapture is only supported for manual capture".to_string(), })? - }}, - request_overcapture => Ok(request_overcapture), - }} + } + } + request_overcapture => Ok(request_overcapture), + } + } None => { - if matches!(req_request_overcapture, Some(api_enums::OverCaptureRequest::Enable)) { + if matches!( + req_request_overcapture, + Some(api_enums::OverCaptureRequest::Enable) + ) { Err(errors::ApiErrorResponse::InvalidRequestData { message: "Overcapture is only supported for manual capture".to_string(), })? } else { Ok(None) } - } - } -} \ No newline at end of file + } + } +} diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index c307fabfafcc..37c7f376c355 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -781,7 +781,12 @@ impl GetTracker, api::PaymentsRequest> )), // connector_mandate_request_reference_id )), ); - payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update(&payment_attempt, &payment_intent, None, &business_profile)?; + payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update( + &payment_attempt, + &payment_intent, + None, + &business_profile, + )?; let payment_data = PaymentData { flow: PhantomData, @@ -1521,7 +1526,7 @@ impl UpdateTracker, api::PaymentsRequest> for connector_mandate_detail: payment_data .payment_attempt .connector_mandate_detail, - request_overcapture + request_overcapture, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index c88d5740f6e5..42c1e1b06046 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -993,9 +993,12 @@ impl ValidateRequest GetTracker, api::PaymentsRequest> payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) }); - payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update(&payment_attempt, &payment_intent, Some(&request), &business_profile)?; + payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update( + &payment_attempt, + &payment_intent, + Some(&request), + &business_profile, + )?; payment_intent.request_overcapture = request - .request_overcapture - .or(payment_intent.request_overcapture); - + .request_overcapture + .or(payment_intent.request_overcapture); + let payment_data = PaymentData { flow: PhantomData, payment_intent, From 5b1ce51ecb12f56375fb485f2691edb380f2eb5b Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:48:36 +0000 Subject: [PATCH 51/64] docs(openapi): re-generate OpenAPI specification --- api-reference-v2/openapi_spec.json | 18 ++---------------- api-reference/openapi_spec.json | 9 +++++---- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index cc06efd2502e..15f8c03c68ec 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -18106,8 +18106,7 @@ "ProfileCreate": { "type": "object", "required": [ - "profile_name", - "always_request_overcapture" + "profile_name" ], "properties": { "profile_name": { @@ -18276,12 +18275,6 @@ "type": "object", "description": "Product authentication ids", "nullable": true - }, - "always_request_overcapture": { - "type": "boolean", - "description": "Indicates if the overcapture is always requested or not.", - "default": false, - "example": false } }, "additionalProperties": false @@ -18315,8 +18308,7 @@ "is_tax_connector_enabled", "is_network_tokenization_enabled", "should_collect_cvv_during_payment", - "is_click_to_pay_enabled", - "always_request_overcapture" + "is_click_to_pay_enabled" ], "properties": { "merchant_id": { @@ -18507,12 +18499,6 @@ "type": "object", "description": "Product authentication ids", "nullable": true - }, - "always_request_overcapture": { - "type": "boolean", - "description": "Indicates if the overcapture is always requested or not.", - "default": false, - "example": false } } }, diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index be098fa809cb..3a6213d6b6eb 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -22603,7 +22603,8 @@ }, "always_request_overcapture": { "type": "boolean", - "description": "Indicates if the overcapture is always requested or not." + "description": "Indicates if the overcapture is always requested or not.", + "nullable": true } }, "additionalProperties": false @@ -22637,8 +22638,7 @@ "is_tax_connector_enabled", "is_network_tokenization_enabled", "is_auto_retries_enabled", - "is_click_to_pay_enabled", - "always_request_overcapture" + "is_click_to_pay_enabled" ], "properties": { "merchant_id": { @@ -22851,7 +22851,8 @@ "type": "boolean", "description": "Indicates if the overcapture is always requested or not.", "default": false, - "example": false + "example": false, + "nullable": true } } }, From dc4875fbeec839cd68d1e0f6336823f2e6b86d35 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 8 Jan 2025 22:36:10 +0530 Subject: [PATCH 52/64] refactor(router): replace or with unwrap_or --- crates/router/src/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 2e9d8933e41b..b41105dd32c7 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -305,7 +305,7 @@ impl Capturable for PaymentsAuthorizeData { | common_enums::IntentStatus::PartiallyCapturedAndCapturable => None, } }, - common_enums::CaptureMethod::Manual => maximum_capturable_amount.or( Some(payment_data.payment_attempt.get_total_amount())).map(|amount_capturable|amount_capturable.get_amount_as_i64()), + common_enums::CaptureMethod::Manual => Some(maximum_capturable_amount.unwrap_or(payment_data.payment_attempt.get_total_amount()).get_amount_as_i64()), // In case of manual multiple, amount capturable must be inferred from all captures. common_enums::CaptureMethod::ManualMultiple | // Scheduled capture is not supported as of now @@ -390,7 +390,7 @@ impl Capturable for CompleteAuthorizeData { | common_enums::IntentStatus::PartiallyCapturedAndCapturable => None, } }, - common_enums::CaptureMethod::Manual => maximum_capturable_amount.or(Some(payment_data.payment_attempt.get_total_amount())).map(|amount_capturable| amount_capturable.get_amount_as_i64()), + common_enums::CaptureMethod::Manual => Some(maximum_capturable_amount.unwrap_or(payment_data.payment_attempt.get_total_amount()).get_amount_as_i64()), // In case of manual multiple, amount capturable must be inferred from all captures. common_enums::CaptureMethod::ManualMultiple | // Scheduled capture is not supported as of now From ea75734e6d55d10b54315f9521f26dad9a8fa7af Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 9 Jan 2025 10:24:10 +0530 Subject: [PATCH 53/64] chore: fix clippy errors --- crates/router/src/core/payments/helpers.rs | 1 + crates/router/src/core/payments/operations/payment_update.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index ace5a0c63005..e339a14893ff 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6292,6 +6292,7 @@ pub fn validate_overcapture_request_for_payments_create( ) } +#[cfg(feature = "v1")] pub fn get_overcapture_request_for_payments_update( payment_attempt: &PaymentAttempt, payment_intent: &PaymentIntent, diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 61fc8dc09a9b..069703ad9dba 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -447,7 +447,7 @@ impl GetTracker, api::PaymentsRequest> payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update( &payment_attempt, &payment_intent, - Some(&request), + Some(request), &business_profile, )?; payment_intent.request_overcapture = request From 97252aa58b2babd55827de7f64d3faf4ce2ec931 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 9 Jan 2025 13:33:10 +0530 Subject: [PATCH 54/64] refactor(router): remove request_overcapture from v2 PaymentsRequest --- crates/api_models/src/payments.rs | 11 ----------- crates/hyperswitch_domain_models/src/payments.rs | 4 ++-- .../src/payments/payment_intent.rs | 6 +++--- .../core/payments/operations/payment_update_intent.rs | 2 -- crates/router/src/core/payments/transformers.rs | 1 - 5 files changed, 5 insertions(+), 19 deletions(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 7acbb9771778..5d0cba48ea9a 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -234,10 +234,6 @@ pub struct PaymentsCreateIntentRequest { #[schema(value_type = Option)] pub request_external_three_ds_authentication: Option, - - /// Whether to perform overcapture (if applicable) - #[schema(value_type = Option)] - pub request_overcapture: Option, } #[cfg(feature = "v2")] @@ -399,10 +395,6 @@ pub struct PaymentsUpdateIntentRequest { #[schema(value_type = Option)] pub request_external_three_ds_authentication: Option, - - /// Whether to perform overcapture (if applicable) - #[schema(value_type = Option)] - pub request_overcapture: Option, } #[derive(Debug, serde::Serialize, Clone, ToSchema)] @@ -537,9 +529,6 @@ pub struct PaymentsIntentResponse { #[schema(value_type = External3dsAuthenticationRequest)] pub request_external_three_ds_authentication: common_enums::External3dsAuthenticationRequest, - /// Whether to perform overcapture (if applicable) - #[schema(value_type = OverCaptureRequest)] - pub request_overcapture: common_enums::OverCaptureRequest, } #[cfg(feature = "v2")] diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs index d9f7bf9060df..a37d2e0189e2 100644 --- a/crates/hyperswitch_domain_models/src/payments.rs +++ b/crates/hyperswitch_domain_models/src/payments.rs @@ -370,7 +370,7 @@ pub struct PaymentIntent { /// Identifier for the platform merchant. pub platform_merchant_id: Option, /// Denotes whether to request for overcapture - pub request_overcapture: common_enums::OverCaptureRequest, + pub request_overcapture: Option, } #[cfg(feature = "v2")] @@ -513,7 +513,7 @@ impl PaymentIntent { routing_algorithm_id: request.routing_algorithm_id, platform_merchant_id: platform_merchant_id .map(|merchant_account| merchant_account.get_id().to_owned()), - request_overcapture: request.request_overcapture.unwrap_or_default(), + request_overcapture: None, }) } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index 2de0bab4557b..b5808a904211 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -1401,7 +1401,7 @@ impl behaviour::Conversion for PaymentIntent { psd2_sca_exemption_type: None, platform_merchant_id, split_payments: None, - request_overcapture: Some(request_overcapture), + request_overcapture, }) } async fn convert_back( @@ -1528,7 +1528,7 @@ impl behaviour::Conversion for PaymentIntent { payment_link_config: storage_model.payment_link_config, routing_algorithm_id: storage_model.routing_algorithm_id, platform_merchant_id: storage_model.platform_merchant_id, - request_overcapture: storage_model.request_overcapture.unwrap_or_default(), + request_overcapture: storage_model.request_overcapture, }) } .await @@ -1602,7 +1602,7 @@ impl behaviour::Conversion for PaymentIntent { enable_payment_link: Some(self.enable_payment_link.as_bool()), apply_mit_exemption: Some(self.apply_mit_exemption.as_bool()), platform_merchant_id: self.platform_merchant_id, - request_overcapture: Some(self.request_overcapture), + request_overcapture: self.request_overcapture, }) } } diff --git a/crates/router/src/core/payments/operations/payment_update_intent.rs b/crates/router/src/core/payments/operations/payment_update_intent.rs index 298006e5bed5..4782d237e211 100644 --- a/crates/router/src/core/payments/operations/payment_update_intent.rs +++ b/crates/router/src/core/payments/operations/payment_update_intent.rs @@ -170,7 +170,6 @@ impl GetTracker, PaymentsUpda session_expiry, frm_metadata, request_external_three_ds_authentication, - request_overcapture, } = request.clone(); let batch_encrypted_data = domain_types::crypto_operation( @@ -269,7 +268,6 @@ impl GetTracker, PaymentsUpda routing_algorithm_id: routing_algorithm_id.or(payment_intent.routing_algorithm_id), allowed_payment_method_types: allowed_payment_method_types .or(payment_intent.allowed_payment_method_types), - request_overcapture: request_overcapture.unwrap_or(payment_intent.request_overcapture), ..payment_intent }; diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 3a1219447b8d..364f5872376f 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -1348,7 +1348,6 @@ where request_external_three_ds_authentication: payment_intent .request_external_three_ds_authentication .clone(), - request_overcapture: payment_intent.request_overcapture, }, vec![], ))) From 05625ceef89aa123b08ffe10ed464f1bc51dc8e6 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:04:10 +0000 Subject: [PATCH 55/64] chore: run formatter --- crates/api_models/src/payments.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 5d0cba48ea9a..8fb258198ddb 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -528,7 +528,6 @@ pub struct PaymentsIntentResponse { /// Whether to perform external authentication (if applicable) #[schema(value_type = External3dsAuthenticationRequest)] pub request_external_three_ds_authentication: common_enums::External3dsAuthenticationRequest, - } #[cfg(feature = "v2")] From 02a2c7f47e9c8c9beb5b7a2cecb4fc1736506ae4 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:10:15 +0000 Subject: [PATCH 56/64] docs(openapi): re-generate OpenAPI specification --- api-reference-v2/openapi_spec.json | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index 15f8c03c68ec..2fafd31f142f 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -14952,14 +14952,6 @@ } ], "nullable": true - }, - "request_overcapture": { - "allOf": [ - { - "$ref": "#/components/schemas/OverCaptureRequest" - } - ], - "nullable": true } }, "additionalProperties": false @@ -15682,8 +15674,7 @@ "payment_link_enabled", "request_incremental_authorization", "expires_on", - "request_external_three_ds_authentication", - "request_overcapture" + "request_external_three_ds_authentication" ], "properties": { "id": { @@ -15844,9 +15835,6 @@ }, "request_external_three_ds_authentication": { "$ref": "#/components/schemas/External3dsAuthenticationRequest" - }, - "request_overcapture": { - "$ref": "#/components/schemas/OverCaptureRequest" } }, "additionalProperties": false @@ -16750,14 +16738,6 @@ } ], "nullable": true - }, - "request_overcapture": { - "allOf": [ - { - "$ref": "#/components/schemas/OverCaptureRequest" - } - ], - "nullable": true } }, "additionalProperties": false From 376d0fa2d3ba7585ba8fd89974e81b663f0b4f2a Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Thu, 9 Jan 2025 17:42:39 +0530 Subject: [PATCH 57/64] refactor(core): change the error message --- crates/router/src/core/payments/helpers.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index e339a14893ff..b89e80399e7e 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6285,8 +6285,8 @@ pub fn validate_overcapture_request_for_payments_create( request_overcapture == Some(api_enums::OverCaptureRequest::Enable) && capture_method != Some(api_enums::CaptureMethod::Manual), || { - Err(errors::ApiErrorResponse::InvalidRequestData { - message: "Overcapture is only supported for manual capture".to_string(), + Err(errors::ApiErrorResponse::PreconditionFailed { + message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), }) }, ) @@ -6313,8 +6313,8 @@ pub fn get_overcapture_request_for_payments_update( if payment_intent.request_overcapture.is_none() { Ok(Some(api_enums::OverCaptureRequest::Skip)) } else { - Err(errors::ApiErrorResponse::InvalidRequestData { - message: "Capture method cannot be changed. Overcapture is only supported for manual capture".to_string(), + Err(errors::ApiErrorResponse::PreconditionFailed { + message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), })? } } @@ -6326,8 +6326,8 @@ pub fn get_overcapture_request_for_payments_update( req_request_overcapture, Some(api_enums::OverCaptureRequest::Enable) ) { - Err(errors::ApiErrorResponse::InvalidRequestData { - message: "Overcapture is only supported for manual capture".to_string(), + Err(errors::ApiErrorResponse::PreconditionFailed { + message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), })? } else { Ok(None) From 555c33c97257a7751fef49f1e332e2bf6d33c058 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Sun, 12 Jan 2025 11:59:09 +0530 Subject: [PATCH 58/64] refactor(router): update request_overcapture during confirm call --- crates/diesel_models/src/payment_attempt.rs | 5 +---- crates/diesel_models/src/user/sample_data.rs | 1 - .../src/payments/payment_attempt.rs | 5 ----- crates/router/src/core/payments/helpers.rs | 22 +++++-------------- .../payments/operations/payment_capture.rs | 6 ----- .../payments/operations/payment_create.rs | 18 +-------------- .../payments/operations/payment_update.rs | 20 ++++++++--------- crates/router/src/core/payments/retry.rs | 1 - .../src/types/storage/payment_attempt.rs | 3 --- .../src/mock_db/payment_attempt.rs | 2 +- .../src/payments/payment_attempt.rs | 4 +--- 11 files changed, 19 insertions(+), 68 deletions(-) diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 06e1318d79e4..7cb5435680bb 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -355,7 +355,6 @@ pub struct PaymentAttemptNew { pub shipping_cost: Option, pub order_tax_amount: Option, pub connector_mandate_detail: Option, - pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -379,7 +378,6 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - request_overcapture: Option, }, UpdateTrackers { payment_token: Option, @@ -2102,7 +2100,6 @@ impl From for PaymentAttemptUpdateInternal { fingerprint_id, updated_by, payment_method_billing_address_id, - request_overcapture, } => Self { amount: Some(amount), currency: Some(currency), @@ -2156,7 +2153,7 @@ impl From for PaymentAttemptUpdateInternal { order_tax_amount: None, connector_transaction_data: None, connector_mandate_detail: None, - request_overcapture, + request_overcapture: None, overcapture_status: None, }, PaymentAttemptUpdate::AuthenticationTypeUpdate { diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs index 36375535578e..71eadb46c942 100644 --- a/crates/diesel_models/src/user/sample_data.rs +++ b/crates/diesel_models/src/user/sample_data.rs @@ -283,7 +283,6 @@ impl PaymentAttemptBatchNew { shipping_cost: self.shipping_cost, order_tax_amount: self.order_tax_amount, connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, } } } diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs index 49d28ef01887..10fedf2a3a5a 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs @@ -844,7 +844,6 @@ pub struct PaymentAttemptNew { pub profile_id: id_type::ProfileId, pub organization_id: id_type::OrganizationId, pub connector_mandate_detail: Option, - pub request_overcapture: Option, } #[cfg(feature = "v1")] @@ -866,7 +865,6 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, payment_method_billing_address_id: Option, updated_by: String, - request_overcapture: Option, }, UpdateTrackers { payment_token: Option, @@ -1066,7 +1064,6 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, - request_overcapture, } => DieselPaymentAttemptUpdate::Update { amount: net_amount.get_order_amount(), currency, @@ -1085,7 +1082,6 @@ impl PaymentAttemptUpdate { fingerprint_id, payment_method_billing_address_id, updated_by, - request_overcapture, }, Self::UpdateTrackers { payment_token, @@ -1736,7 +1732,6 @@ impl behaviour::Conversion for PaymentAttempt { order_tax_amount: self.net_amount.get_order_tax_amount(), shipping_cost: self.net_amount.get_shipping_cost(), connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, }) } } diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index b89e80399e7e..1f1691910f68 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -2609,19 +2609,15 @@ pub(crate) fn validate_status_with_capture_method( pub(crate) fn validate_amount_to_capture( amount: i64, amount_to_capture: Option, - is_overcapture_applied: Option, ) -> RouterResult<()> { - if let Some(true) = - amount_to_capture.map(|req_amount_to_capture| (amount < req_amount_to_capture)) - { - utils::when(is_overcapture_applied != Some(true), || { + utils::when( + amount_to_capture.is_some() && (Some(amount) < amount_to_capture), + || { Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "amount_to_capture is greater than amount".to_string() })) - }) - } else { - Ok(()) - } + }, + ) } #[cfg(feature = "v1")] @@ -4293,7 +4289,6 @@ impl AttemptType { organization_id: old_payment_attempt.organization_id, profile_id: old_payment_attempt.profile_id, connector_mandate_detail: None, - request_overcapture: old_payment_attempt.request_overcapture, } } @@ -6277,7 +6272,7 @@ pub fn validate_platform_fees_for_marketplace( Ok(()) } -pub fn validate_overcapture_request_for_payments_create( +pub fn validate_overcapture_request( capture_method: Option, request_overcapture: Option, ) -> Result<(), errors::ApiErrorResponse> { @@ -6309,14 +6304,9 @@ pub fn get_overcapture_request_for_payments_update( Some(_) => { match payment_attempt.request_overcapture { Some(api_enums::OverCaptureRequest::Enable) => { - // case where we set the request_overcapture from the business profile - if payment_intent.request_overcapture.is_none() { - Ok(Some(api_enums::OverCaptureRequest::Skip)) - } else { Err(errors::ApiErrorResponse::PreconditionFailed { message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), })? - } } request_overcapture => Ok(request_overcapture), } diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index 34f4ab7472b1..ebe49f59f649 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -101,9 +101,6 @@ impl GetTracker, api::Paymen request .amount_to_capture .map(|capture_amount| capture_amount.get_amount_as_i64()), - payment_attempt - .request_overcapture - .map(|request_overcapture| request_overcapture.as_bool()), )?; helpers::validate_capture_method(capture_method)?; @@ -116,9 +113,6 @@ impl GetTracker, api::Paymen helpers::validate_amount_to_capture( payment_attempt.amount_capturable.get_amount_as_i64(), Some(amount_to_capture.get_amount_as_i64()), - payment_attempt - .overcapture_status - .map(|overcapture_status| overcapture_status.as_bool()), )?; let previous_captures = db diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 42c1e1b06046..802b95b9b583 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -325,7 +325,6 @@ impl GetTracker, api::PaymentsRequest> &payment_method_info, merchant_key_store, profile_id, - &business_profile, &customer_acceptance, ) .await?; @@ -994,7 +993,7 @@ impl ValidateRequest, _key_store: &domain::MerchantKeyStore, profile_id: common_utils::id_type::ProfileId, - business_profile: &domain::Profile, customer_acceptance: &Option, ) -> RouterResult<( storage::PaymentAttemptNew, @@ -1148,19 +1146,6 @@ impl PaymentCreate { .transpose()? .flatten(); - let request_overcapture = request.request_overcapture.or_else(|| { - if matches!( - request.capture_method, - Some(api_models::enums::CaptureMethod::Manual) - ) { - business_profile - .always_request_overcapture - .map(api_models::enums::OverCaptureRequest::from) - } else { - None - } - }); - if additional_pm_data.is_none() { // If recurring payment is made using payment_method_id, then fetch payment_method_data from retrieved payment_method object additional_pm_data = payment_method_info.as_ref().and_then(|pm_info| { @@ -1309,7 +1294,6 @@ impl PaymentCreate { organization_id: organization_id.clone(), profile_id, connector_mandate_detail: None, - request_overcapture, }, additional_pm_data, diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 069703ad9dba..6358ef4f9c0b 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -444,15 +444,16 @@ impl GetTracker, api::PaymentsRequest> payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) }); - payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update( - &payment_attempt, - &payment_intent, - Some(request), - &business_profile, + helpers::validate_overcapture_request( + payment_attempt.capture_method, + request + .request_overcapture + .or(payment_intent.request_overcapture), )?; + payment_intent.request_overcapture = request - .request_overcapture - .or(payment_intent.request_overcapture); + .request_overcapture + .or(payment_intent.request_overcapture); let payment_data = PaymentData { flow: PhantomData, @@ -788,9 +789,7 @@ impl UpdateTracker, api::PaymentsRequest> for let payment_method_type = payment_data.payment_attempt.payment_method_type; let payment_experience = payment_data.payment_attempt.payment_experience; let amount_to_capture = payment_data.payment_attempt.amount_to_capture; - let capture_method = payment_data.payment_attempt.capture_method; - let request_overcapture = payment_data.payment_attempt.request_overcapture; - let payment_method_billing_address_id = payment_data + let capture_method = payment_data.payment_attempt.capture_method; let payment_method_billing_address_id = payment_data .payment_attempt .payment_method_billing_address_id .clone(); @@ -830,7 +829,6 @@ impl UpdateTracker, api::PaymentsRequest> for surcharge_amount, tax_amount, ), - request_overcapture, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index bb6cbd2e1130..8432b8492c25 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -666,7 +666,6 @@ pub fn make_new_payment_attempt( charge_id: Default::default(), customer_acceptance: Default::default(), connector_mandate_detail: Default::default(), - request_overcapture: old_payment_attempt.request_overcapture, } } diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs index 074475fe014a..0291374d54f6 100644 --- a/crates/router/src/types/storage/payment_attempt.rs +++ b/crates/router/src/types/storage/payment_attempt.rs @@ -217,7 +217,6 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - request_overcapture: Default::default(), }; let store = state @@ -302,7 +301,6 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - request_overcapture: Default::default(), }; let store = state .stores @@ -400,7 +398,6 @@ mod tests { profile_id: common_utils::generate_profile_id_of_default_length(), organization_id: Default::default(), connector_mandate_detail: Default::default(), - request_overcapture: Default::default(), }; let store = state .stores diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs index deb2738b98a7..1dfadbd9eb19 100644 --- a/crates/storage_impl/src/mock_db/payment_attempt.rs +++ b/crates/storage_impl/src/mock_db/payment_attempt.rs @@ -195,7 +195,7 @@ impl PaymentAttemptInterface for MockDb { organization_id: payment_attempt.organization_id, profile_id: payment_attempt.profile_id, connector_mandate_detail: payment_attempt.connector_mandate_detail, - request_overcapture: payment_attempt.request_overcapture, + request_overcapture: None, overcapture_status: None, }; payment_attempts.push(payment_attempt.clone()); diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 2c994113a6a1..92212cabd433 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -564,7 +564,7 @@ impl PaymentAttemptInterface for KVRouterStore { organization_id: payment_attempt.organization_id.clone(), profile_id: payment_attempt.profile_id.clone(), connector_mandate_detail: payment_attempt.connector_mandate_detail.clone(), - request_overcapture: payment_attempt.request_overcapture, + request_overcapture: None, overcapture_status: None, }; @@ -1676,7 +1676,6 @@ impl DataModelExt for PaymentAttemptNew { shipping_cost: self.net_amount.get_shipping_cost(), order_tax_amount: self.net_amount.get_order_tax_amount(), connector_mandate_detail: self.connector_mandate_detail, - request_overcapture: self.request_overcapture, } } @@ -1749,7 +1748,6 @@ impl DataModelExt for PaymentAttemptNew { organization_id: storage_model.organization_id, profile_id: storage_model.profile_id, connector_mandate_detail: storage_model.connector_mandate_detail, - request_overcapture: storage_model.request_overcapture, } } } From b38ff2ed0d9b7d74958613f7464ba9d9f4255dd2 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Sun, 12 Jan 2025 06:30:12 +0000 Subject: [PATCH 59/64] chore: run formatter --- .../src/core/payments/operations/payment_create.rs | 5 +---- .../src/core/payments/operations/payment_update.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 802b95b9b583..3db5d13382eb 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -993,10 +993,7 @@ impl ValidateRequest GetTracker, api::PaymentsRequest> helpers::validate_overcapture_request( payment_attempt.capture_method, request - .request_overcapture - .or(payment_intent.request_overcapture), + .request_overcapture + .or(payment_intent.request_overcapture), )?; payment_intent.request_overcapture = request - .request_overcapture - .or(payment_intent.request_overcapture); + .request_overcapture + .or(payment_intent.request_overcapture); let payment_data = PaymentData { flow: PhantomData, @@ -789,7 +789,8 @@ impl UpdateTracker, api::PaymentsRequest> for let payment_method_type = payment_data.payment_attempt.payment_method_type; let payment_experience = payment_data.payment_attempt.payment_experience; let amount_to_capture = payment_data.payment_attempt.amount_to_capture; - let capture_method = payment_data.payment_attempt.capture_method; let payment_method_billing_address_id = payment_data + let capture_method = payment_data.payment_attempt.capture_method; + let payment_method_billing_address_id = payment_data .payment_attempt .payment_method_billing_address_id .clone(); From 754bd56e379082d65b08abf41c2f94dd1ee91309 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Tue, 21 Jan 2025 20:39:55 +0530 Subject: [PATCH 60/64] refactor(router): resolve comment --- crates/api_models/src/admin.rs | 2 +- crates/common_enums/src/transformers.rs | 19 ++++++-------- .../src/connector/stripe/transformers.rs | 6 +++-- crates/router/src/core/payments/helpers.rs | 26 +++++-------------- .../payments/operations/payment_confirm.rs | 2 +- .../payments/operations/payment_create.rs | 2 +- .../payments/operations/payment_update.rs | 12 ++++----- 7 files changed, 26 insertions(+), 43 deletions(-) diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs index 48088ff2239b..0ec75872df5d 100644 --- a/crates/api_models/src/admin.rs +++ b/crates/api_models/src/admin.rs @@ -2380,7 +2380,7 @@ pub struct ProfileUpdate { pub authentication_product_ids: Option>, /// Indicates if the overcapture is always requested or not. - #[schema(default = false, example = false)] + #[schema(example = false)] pub always_request_overcapture: Option, } diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index 5fab7bcacedd..0c23cf85264b 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -2032,7 +2032,7 @@ impl From for super::OverCaptureRequest { /// Get the boolean value of the `OverCaptureRequest`. impl super::OverCaptureRequest { - pub fn as_bool(&self) -> bool { + pub fn is_enabled(&self) -> bool { match self { Self::Enable => true, Self::Skip => false, @@ -2040,18 +2040,9 @@ impl super::OverCaptureRequest { } } -impl From> for super::OverCaptureStatus { - fn from(value: Option) -> Self { - match value { - Some(true) => Self::Applicable, - _ => Self::NotApplicable, - } - } -} - /// Get the boolean value of the `OverCaptureStatus`. impl super::OverCaptureStatus { - pub fn as_bool(&self) -> bool { + pub fn is_applicable(&self) -> bool { match self { Self::Applicable => true, Self::NotApplicable => false, @@ -2059,6 +2050,12 @@ impl super::OverCaptureStatus { } } +impl super::CaptureMethod { + pub fn is_manual(&self) -> bool { + matches!(self, Self::Manual) + } +} + impl super::EnablePaymentLinkRequest { pub fn as_bool(&self) -> bool { match self { diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index e35d54791c61..4b8cde425b5e 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -245,6 +245,7 @@ pub struct StripePayLaterData { #[serde(rename_all = "snake_case")] pub enum StripeOvercaptureRequest { IfAvailable, + Never, } #[derive(Debug, Eq, PartialEq, Serialize)] @@ -1413,7 +1414,8 @@ impl TryFrom<(&domain::Card, Auth3ds, Option)> for StripePaymentMethodData .and_then(get_stripe_card_network), payment_method_data_card_request_overcapture: match is_request_overcapture { Some(true) => Some(StripeOvercaptureRequest::IfAvailable), - _ => None, + Some(false) => Some(StripeOvercaptureRequest::Never), + None => None, }, })) } @@ -1824,7 +1826,7 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntent &item.request, )), billing_address, - item.request.request_overcapture.map(|request_overcapture|request_overcapture.as_bool()), + item.request.request_overcapture.map(|request_overcapture|request_overcapture.is_enabled()), )?; validate_shipping_address_against_payment_method( diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 1f1691910f68..8d57668535ea 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6277,8 +6277,8 @@ pub fn validate_overcapture_request( request_overcapture: Option, ) -> Result<(), errors::ApiErrorResponse> { utils::when( - request_overcapture == Some(api_enums::OverCaptureRequest::Enable) - && capture_method != Some(api_enums::CaptureMethod::Manual), + request_overcapture.unwrap_or(api_enums::OverCaptureRequest::Skip).is_enabled() + && capture_method.unwrap_or(api_enums::CaptureMethod::Automatic).is_manual(), || { Err(errors::ApiErrorResponse::PreconditionFailed { message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), @@ -6291,18 +6291,16 @@ pub fn validate_overcapture_request( pub fn get_overcapture_request_for_payments_update( payment_attempt: &PaymentAttempt, payment_intent: &PaymentIntent, - request: Option<&api_models::payments::PaymentsRequest>, profile: &domain::Profile, ) -> Result, errors::ApiErrorResponse> { - let req_request_overcapture = request.and_then(|req| req.request_overcapture); match payment_attempt.capture_method { - Some(api_enums::CaptureMethod::Manual) => Ok(req_request_overcapture - .or(payment_intent.request_overcapture) + Some(api_enums::CaptureMethod::Manual) => Ok( + payment_intent.request_overcapture .or(profile .always_request_overcapture .map(api_enums::OverCaptureRequest::from))), - Some(_) => { - match payment_attempt.request_overcapture { + Some(_) | None => { + match payment_intent.request_overcapture { Some(api_enums::OverCaptureRequest::Enable) => { Err(errors::ApiErrorResponse::PreconditionFailed { message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), @@ -6311,17 +6309,5 @@ pub fn get_overcapture_request_for_payments_update( request_overcapture => Ok(request_overcapture), } } - None => { - if matches!( - req_request_overcapture, - Some(api_enums::OverCaptureRequest::Enable) - ) { - Err(errors::ApiErrorResponse::PreconditionFailed { - message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), - })? - } else { - Ok(None) - } - } } } diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 37c7f376c355..a5f21ab11787 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -781,10 +781,10 @@ impl GetTracker, api::PaymentsRequest> )), // connector_mandate_request_reference_id )), ); + payment_attempt.request_overcapture = helpers::get_overcapture_request_for_payments_update( &payment_attempt, &payment_intent, - None, &business_profile, )?; diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 3db5d13382eb..f4ef0a29cf87 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -1160,7 +1160,7 @@ impl PaymentCreate { }) .ok() }) - .and_then(|pmd: PaymentMethodsData| match pmd { + .and_then(|pmd| match pmd { PaymentMethodsData::Card(card) => { Some(api_models::payments::AdditionalPaymentData::Card(Box::new( api::CardDetailFromLocker::from(card).into(), diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index c86ce27e4f9a..67eb50d1088e 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -444,17 +444,15 @@ impl GetTracker, api::PaymentsRequest> payments::types::SurchargeDetails::from((&request_surcharge_details, &payment_attempt)) }); + payment_intent.request_overcapture = request + .request_overcapture + .or(payment_intent.request_overcapture); + helpers::validate_overcapture_request( payment_attempt.capture_method, - request - .request_overcapture - .or(payment_intent.request_overcapture), + payment_intent.request_overcapture, )?; - payment_intent.request_overcapture = request - .request_overcapture - .or(payment_intent.request_overcapture); - let payment_data = PaymentData { flow: PhantomData, payment_intent, From 92ffe4c23f363abe163446e7b2bf03edfe61f8f5 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 05:28:41 +0000 Subject: [PATCH 61/64] chore: run formatter --- crates/router/src/core/payments/helpers.rs | 8 ++++++-- .../router/src/core/payments/operations/payment_update.rs | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 4088f863b820..c17f7c09e121 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -6398,8 +6398,12 @@ pub fn validate_overcapture_request( request_overcapture: Option, ) -> Result<(), errors::ApiErrorResponse> { utils::when( - request_overcapture.unwrap_or(api_enums::OverCaptureRequest::Skip).is_enabled() - && capture_method.unwrap_or(api_enums::CaptureMethod::Automatic).is_manual(), + request_overcapture + .unwrap_or(api_enums::OverCaptureRequest::Skip) + .is_enabled() + && capture_method + .unwrap_or(api_enums::CaptureMethod::Automatic) + .is_manual(), || { Err(errors::ApiErrorResponse::PreconditionFailed { message: "Requesting overcapture is only supported when the capture method is set to manual".to_string(), diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 67eb50d1088e..68450a81568c 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -445,8 +445,8 @@ impl GetTracker, api::PaymentsRequest> }); payment_intent.request_overcapture = request - .request_overcapture - .or(payment_intent.request_overcapture); + .request_overcapture + .or(payment_intent.request_overcapture); helpers::validate_overcapture_request( payment_attempt.capture_method, From b9ed824c5557d5e7fa5be0c6c2e2fa1883007a69 Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 22 Jan 2025 12:23:59 +0530 Subject: [PATCH 62/64] refaactor(router): remove is_enabled for overcapturerequest --- crates/common_enums/src/transformers.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index 0c23cf85264b..3502db9a485a 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -2030,16 +2030,6 @@ impl From for super::OverCaptureRequest { } } -/// Get the boolean value of the `OverCaptureRequest`. -impl super::OverCaptureRequest { - pub fn is_enabled(&self) -> bool { - match self { - Self::Enable => true, - Self::Skip => false, - } - } -} - /// Get the boolean value of the `OverCaptureStatus`. impl super::OverCaptureStatus { pub fn is_applicable(&self) -> bool { From 895c8cf1ea2d50cbca9a87cb916b70f4da60b56c Mon Sep 17 00:00:00 2001 From: AkshayaFoiger Date: Wed, 22 Jan 2025 12:53:30 +0530 Subject: [PATCH 63/64] remove the impl function --- crates/common_enums/src/enums.rs | 34 +++++++++++++++++++++++++ crates/common_enums/src/transformers.rs | 25 ------------------ 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 326d6172d83a..c7ce1e06e270 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -3704,3 +3704,37 @@ pub enum FeatureStatus { NotSupported, Supported, } + +impl From for OverCaptureRequest { + fn from(value: bool) -> Self { + match value { + true => Self::Enable, + _ => Self::Skip, + } + } +} + +impl OverCaptureRequest { + pub fn is_enabled(&self) -> bool { + match self { + Self::Enable => true, + Self::Skip => false, + } + } +} + +impl OverCaptureStatus { + pub fn is_applicable(&self) -> bool { + match self { + Self::Applicable => true, + Self::NotApplicable => false, + } + } +} + +impl CaptureMethod { + pub fn is_manual(&self) -> bool { + matches!(self, Self::Manual) + } +} + diff --git a/crates/common_enums/src/transformers.rs b/crates/common_enums/src/transformers.rs index 3502db9a485a..7611ae127ee7 100644 --- a/crates/common_enums/src/transformers.rs +++ b/crates/common_enums/src/transformers.rs @@ -2021,31 +2021,6 @@ impl super::External3dsAuthenticationRequest { } } -impl From for super::OverCaptureRequest { - fn from(value: bool) -> Self { - match value { - true => Self::Enable, - _ => Self::Skip, - } - } -} - -/// Get the boolean value of the `OverCaptureStatus`. -impl super::OverCaptureStatus { - pub fn is_applicable(&self) -> bool { - match self { - Self::Applicable => true, - Self::NotApplicable => false, - } - } -} - -impl super::CaptureMethod { - pub fn is_manual(&self) -> bool { - matches!(self, Self::Manual) - } -} - impl super::EnablePaymentLinkRequest { pub fn as_bool(&self) -> bool { match self { From b75a2a8733b75ecb7e03d91421fc003eb8f685ce Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 07:26:44 +0000 Subject: [PATCH 64/64] chore: run formatter --- crates/common_enums/src/enums.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index c7ce1e06e270..299f30a9a189 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -3737,4 +3737,3 @@ impl CaptureMethod { matches!(self, Self::Manual) } } -