diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index 8710c69aa5..dfb8e89997 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -352,6 +352,9 @@ impl SurchargeDetailsResponse { request_surcharge_details.surcharge_amount == self.surcharge_amount && request_surcharge_details.tax_amount.unwrap_or(0) == self.tax_on_surcharge_amount } + pub fn get_total_surcharge_amount(&self) -> i64 { + self.surcharge_amount + self.tax_on_surcharge_amount + } } #[derive(Clone, Debug)] diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index a997960edc..74559f8ed6 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -347,6 +347,9 @@ impl RequestSurchargeDetails { final_amount: original_amount + surcharge_amount + tax_on_surcharge_amount, } } + pub fn get_total_surcharge_amount(&self) -> i64 { + self.surcharge_amount + self.tax_amount.unwrap_or(0) + } } #[derive(Default, Debug, Clone, Copy)] diff --git a/crates/data_models/src/payments/payment_attempt.rs b/crates/data_models/src/payments/payment_attempt.rs index b866237745..a937c78590 100644 --- a/crates/data_models/src/payments/payment_attempt.rs +++ b/crates/data_models/src/payments/payment_attempt.rs @@ -264,6 +264,8 @@ pub enum PaymentAttemptUpdate { error_message: Option>, amount_capturable: Option, updated_by: String, + surcharge_amount: Option, + tax_amount: Option, merchant_connector_id: Option, }, RejectUpdate { @@ -291,8 +293,6 @@ pub enum PaymentAttemptUpdate { error_reason: Option>, connector_response_reference_id: Option, amount_capturable: Option, - surcharge_amount: Option, - tax_amount: Option, updated_by: String, authentication_data: Option, encoded_data: Option, @@ -321,8 +321,6 @@ pub enum PaymentAttemptUpdate { error_message: Option>, error_reason: Option>, amount_capturable: Option, - surcharge_amount: Option, - tax_amount: Option, updated_by: String, unified_code: Option>, unified_message: Option>, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 42af827f52..9cc6632c63 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -180,6 +180,8 @@ pub enum PaymentAttemptUpdate { error_code: Option>, error_message: Option>, amount_capturable: Option, + surcharge_amount: Option, + tax_amount: Option, updated_by: String, merchant_connector_id: Option, }, @@ -208,8 +210,6 @@ pub enum PaymentAttemptUpdate { error_reason: Option>, connector_response_reference_id: Option, amount_capturable: Option, - surcharge_amount: Option, - tax_amount: Option, updated_by: String, authentication_data: Option, encoded_data: Option, @@ -238,8 +238,6 @@ pub enum PaymentAttemptUpdate { error_message: Option>, error_reason: Option>, amount_capturable: Option, - surcharge_amount: Option, - tax_amount: Option, updated_by: String, unified_code: Option>, unified_message: Option>, @@ -443,6 +441,8 @@ impl From for PaymentAttemptUpdateInternal { amount_capturable, updated_by, merchant_connector_id, + surcharge_amount, + tax_amount, } => Self { amount: Some(amount), currency: Some(currency), @@ -463,6 +463,8 @@ impl From for PaymentAttemptUpdateInternal { amount_capturable, updated_by, merchant_connector_id, + surcharge_amount, + tax_amount, ..Default::default() }, PaymentAttemptUpdate::VoidUpdate { @@ -501,8 +503,6 @@ impl From for PaymentAttemptUpdateInternal { error_reason, connector_response_reference_id, amount_capturable, - surcharge_amount, - tax_amount, updated_by, authentication_data, encoded_data, @@ -524,8 +524,6 @@ impl From for PaymentAttemptUpdateInternal { connector_response_reference_id, amount_capturable, updated_by, - surcharge_amount, - tax_amount, authentication_data, encoded_data, unified_code, @@ -539,8 +537,6 @@ impl From for PaymentAttemptUpdateInternal { error_message, error_reason, amount_capturable, - surcharge_amount, - tax_amount, updated_by, unified_code, unified_message, @@ -554,8 +550,6 @@ impl From for PaymentAttemptUpdateInternal { error_reason, amount_capturable, updated_by, - surcharge_amount, - tax_amount, unified_code, unified_message, connector_transaction_id, diff --git a/crates/euclid/src/backend/vir_interpreter/types.rs b/crates/euclid/src/backend/vir_interpreter/types.rs index a144cdaafd..d0eca5fec2 100644 --- a/crates/euclid/src/backend/vir_interpreter/types.rs +++ b/crates/euclid/src/backend/vir_interpreter/types.rs @@ -74,6 +74,10 @@ impl Context { } } + if let Some(card_network) = payment_method.card_network { + enum_values.insert(EuclidValue::CardNetwork(card_network)); + } + if let Some(at) = payment.authentication_type { enum_values.insert(EuclidValue::AuthenticationType(at)); } diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index e096f1878a..803c511f3a 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -113,7 +113,8 @@ where enums::AttemptStatus::Charged => { let captured_amount = types::Capturable::get_capture_amount(&self.request, payment_data); - if Some(payment_data.payment_attempt.get_total_amount()) == captured_amount { + let total_capturable_amount = payment_data.payment_attempt.get_total_amount(); + if Some(total_capturable_amount) == captured_amount { enums::AttemptStatus::Charged } else if captured_amount.is_some() { enums::AttemptStatus::PartialCharged diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index d813c96ce9..4b0920a55f 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1693,7 +1693,8 @@ pub(crate) fn validate_status_with_capture_method( field_name: "payment.status".to_string(), current_flow: "captured".to_string(), current_value: status.to_string(), - states: "requires_capture, partially_captured, processing".to_string() + states: "requires_capture, partially_captured_and_capturable, processing" + .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 33270795b3..97b0641d2e 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -693,6 +693,15 @@ impl let m_error_message = error_message.clone(); let m_db = state.clone().store; + let surcharge_amount = payment_data + .surcharge_details + .as_ref() + .map(|surcharge_details| surcharge_details.surcharge_amount); + let tax_amount = payment_data + .surcharge_details + .as_ref() + .map(|surcharge_details| surcharge_details.tax_on_surcharge_amount); + let payment_attempt_fut = tokio::spawn( async move { m_db.update_payment_attempt_with_attempt_id( @@ -716,6 +725,8 @@ impl amount_capturable: Some(authorized_amount), updated_by: storage_scheme.to_string(), merchant_connector_id, + surcharge_amount, + tax_amount, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index beefa53c56..2de5df38db 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -372,8 +372,6 @@ async fn payment_response_update_tracker( } else { None }, - surcharge_amount: router_data.request.get_surcharge_amount(), - tax_amount: router_data.request.get_tax_on_surcharge_amount(), updated_by: storage_scheme.to_string(), unified_code: option_gsm.clone().map(|gsm| gsm.unified_code), unified_message: option_gsm.map(|gsm| gsm.unified_message), @@ -497,8 +495,6 @@ async fn payment_response_update_tracker( } else { None }, - surcharge_amount: router_data.request.get_surcharge_amount(), - tax_amount: router_data.request.get_tax_on_surcharge_amount(), updated_by: storage_scheme.to_string(), authentication_data, encoded_data, diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs index c5501ab4dc..0fd45c5af3 100644 --- a/crates/router/src/core/payments/retry.rs +++ b/crates/router/src/core/payments/retry.rs @@ -382,8 +382,6 @@ where } else { None }, - surcharge_amount: None, - tax_amount: None, updated_by: storage_scheme.to_string(), authentication_data, encoded_data, @@ -410,8 +408,6 @@ where status: storage_enums::AttemptStatus::Failure, error_reason: Some(error_response.reason.clone()), amount_capturable: Some(0), - surcharge_amount: None, - tax_amount: None, updated_by: storage_scheme.to_string(), unified_code: option_gsm.clone().map(|gsm| gsm.unified_code), unified_message: option_gsm.map(|gsm| gsm.unified_message), diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 79c3c11eda..8c9d030965 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -551,12 +551,6 @@ pub trait Capturable { { None } - fn get_surcharge_amount(&self) -> Option { - None - } - fn get_tax_on_surcharge_amount(&self) -> Option { - None - } } impl Capturable for PaymentsAuthorizeData { @@ -570,16 +564,6 @@ impl Capturable for PaymentsAuthorizeData { .map(|surcharge_details| surcharge_details.final_amount); final_amount.or(Some(self.amount)) } - fn get_surcharge_amount(&self) -> Option { - self.surcharge_details - .as_ref() - .map(|surcharge_details| surcharge_details.surcharge_amount) - } - fn get_tax_on_surcharge_amount(&self) -> Option { - self.surcharge_details - .as_ref() - .map(|surcharge_details| surcharge_details.tax_on_surcharge_amount) - } } impl Capturable for PaymentsCaptureData { @@ -620,7 +604,7 @@ impl Capturable for PaymentsSyncData { payment_data .payment_attempt .amount_to_capture - .or(Some(payment_data.payment_attempt.get_total_amount())) + .or_else(|| Some(payment_data.payment_attempt.get_total_amount())) } } diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rs index 04f91f30bc..f2760a0058 100644 --- a/crates/router/src/workflows/payment_sync.rs +++ b/crates/router/src/workflows/payment_sync.rs @@ -135,8 +135,6 @@ impl ProcessTrackerWorkflow for PaymentsSyncWorkflow { consts::REQUEST_TIMEOUT_ERROR_MESSAGE_FROM_PSYNC.to_string(), )), amount_capturable: Some(0), - surcharge_amount: None, - tax_amount: None, updated_by: merchant_account.storage_scheme.to_string(), unified_code: None, unified_message: None, diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 0526fcec9c..543cf10598 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -1215,6 +1215,8 @@ impl DataModelExt for PaymentAttemptUpdate { error_code, error_message, amount_capturable, + surcharge_amount, + tax_amount, updated_by, merchant_connector_id: connector_id, } => DieselPaymentAttemptUpdate::ConfirmUpdate { @@ -1234,6 +1236,8 @@ impl DataModelExt for PaymentAttemptUpdate { error_code, error_message, amount_capturable, + surcharge_amount, + tax_amount, updated_by, merchant_connector_id: connector_id, }, @@ -1261,8 +1265,6 @@ impl DataModelExt for PaymentAttemptUpdate { connector_response_reference_id, amount_capturable, updated_by, - surcharge_amount, - tax_amount, authentication_data, encoded_data, unified_code, @@ -1282,8 +1284,6 @@ impl DataModelExt for PaymentAttemptUpdate { connector_response_reference_id, amount_capturable, updated_by, - surcharge_amount, - tax_amount, authentication_data, encoded_data, unified_code, @@ -1320,8 +1320,6 @@ impl DataModelExt for PaymentAttemptUpdate { error_message, error_reason, amount_capturable, - tax_amount, - surcharge_amount, updated_by, unified_code, unified_message, @@ -1333,8 +1331,6 @@ impl DataModelExt for PaymentAttemptUpdate { error_message, error_reason, amount_capturable, - surcharge_amount, - tax_amount, updated_by, unified_code, unified_message, @@ -1480,6 +1476,8 @@ impl DataModelExt for PaymentAttemptUpdate { error_code, error_message, amount_capturable, + surcharge_amount, + tax_amount, updated_by, merchant_connector_id: connector_id, } => Self::ConfirmUpdate { @@ -1499,6 +1497,8 @@ impl DataModelExt for PaymentAttemptUpdate { error_code, error_message, amount_capturable, + surcharge_amount, + tax_amount, updated_by, merchant_connector_id: connector_id, }, @@ -1526,8 +1526,6 @@ impl DataModelExt for PaymentAttemptUpdate { connector_response_reference_id, amount_capturable, updated_by, - surcharge_amount, - tax_amount, authentication_data, encoded_data, unified_code, @@ -1547,8 +1545,6 @@ impl DataModelExt for PaymentAttemptUpdate { connector_response_reference_id, amount_capturable, updated_by, - surcharge_amount, - tax_amount, authentication_data, encoded_data, unified_code, @@ -1585,8 +1581,6 @@ impl DataModelExt for PaymentAttemptUpdate { error_message, error_reason, amount_capturable, - surcharge_amount, - tax_amount, updated_by, unified_code, unified_message, @@ -1599,8 +1593,6 @@ impl DataModelExt for PaymentAttemptUpdate { error_reason, amount_capturable, updated_by, - surcharge_amount, - tax_amount, unified_code, unified_message, connector_transaction_id, diff --git a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Confirm/request.json b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Confirm/request.json index 8559af25e8..91426564e8 100644 --- a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Confirm/request.json +++ b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Confirm/request.json @@ -39,10 +39,6 @@ }, "raw_json_formatted": { "client_secret": "{{client_secret}}", - "surcharge_details": { - "surcharge_amount": 5, - "tax_amount": 5 - }, "payment_method": "card", "payment_method_data": { "card": { diff --git a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Create/request.json b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Create/request.json index f7d813c34e..9e084a35c8 100644 --- a/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Create/request.json +++ b/postman/collection-dir/paypal/Flow Testcases/Happy Cases/Scenario8-Create payment with Manual capture with confirm false and surcharge_data/Payments - Create/request.json @@ -31,6 +31,10 @@ "description": "Its my first payment request", "authentication_type": "no_three_ds", "return_url": "https://duck.com", + "surcharge_details": { + "surcharge_amount": 5, + "tax_amount": 5 + }, "billing": { "address": { "line1": "1467",