Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(router): modify `net_amount` to be a struct in the domain model of payment_attempt and handle amount changes across all flows (#6252)

Sai Harsha Vardhan5930089682f8
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json
index 44ac1d3e08..9a852bb15c 100644
--- a/api-reference-v2/openapi_spec.json
+++ b/api-reference-v2/openapi_spec.json
@@ -19597,8 +19597,7 @@
"surcharge",
"display_surcharge_amount",
"display_tax_on_surcharge_amount",
- "display_total_surcharge_amount",
- "display_final_amount"
+ "display_total_surcharge_amount"
],
"properties": {
"surcharge": {
@@ -19626,11 +19625,6 @@
"type": "number",
"format": "double",
"description": "sum of display_surcharge_amount and display_tax_on_surcharge_amount"
- },
- "display_final_amount": {
- "type": "number",
- "format": "double",
- "description": "sum of original amount,"
}
}
},
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 90239bb8a0..c0b8a0d2f0 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -23426,8 +23426,7 @@
"surcharge",
"display_surcharge_amount",
"display_tax_on_surcharge_amount",
- "display_total_surcharge_amount",
- "display_final_amount"
+ "display_total_surcharge_amount"
],
"properties": {
"surcharge": {
@@ -23455,11 +23454,6 @@
"type": "number",
"format": "double",
"description": "sum of display_surcharge_amount and display_tax_on_surcharge_amount"
- },
- "display_final_amount": {
- "type": "number",
- "format": "double",
- "description": "sum of original amount,"
}
}
},
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index 1a82dc0e26..84106a87d9 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -1144,8 +1144,6 @@ pub struct SurchargeDetailsResponse {
pub display_tax_on_surcharge_amount: f64,
/// sum of display_surcharge_amount and display_tax_on_surcharge_amount
pub display_total_surcharge_amount: f64,
- /// sum of original amount,
- pub display_final_amount: f64,
}
#[derive(Clone, Debug, PartialEq, serde::Serialize, ToSchema)]
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index a758d45785..9df0eca96d 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -881,6 +881,14 @@ impl RequestSurchargeDetails {
pub fn get_total_surcharge_amount(&self) -> MinorUnit {
self.surcharge_amount + self.tax_amount.unwrap_or_default()
}
+
+ pub fn get_surcharge_amount(&self) -> MinorUnit {
+ self.surcharge_amount
+ }
+
+ pub fn get_tax_amount(&self) -> Option<MinorUnit> {
+ self.tax_amount
+ }
}
#[derive(Default, Debug, Clone)]
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 75a9aeda2b..061f00f829 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -150,19 +150,6 @@ pub struct PaymentAttempt {
pub order_tax_amount: Option<MinorUnit>,
}
-#[cfg(feature = "v1")]
-impl PaymentAttempt {
- pub fn get_or_calculate_net_amount(&self) -> MinorUnit {
- self.net_amount.unwrap_or(
- self.amount
- + self.surcharge_amount.unwrap_or(MinorUnit::new(0))
- + self.tax_amount.unwrap_or(MinorUnit::new(0))
- + self.shipping_cost.unwrap_or(MinorUnit::new(0))
- + self.order_tax_amount.unwrap_or(MinorUnit::new(0)),
- )
- }
-}
-
#[derive(Clone, Debug, Eq, PartialEq, Queryable, Serialize, Deserialize)]
pub struct PaymentListFilters {
pub connector: Vec<String>,
@@ -298,47 +285,6 @@ pub struct PaymentAttemptNew {
pub order_tax_amount: Option<MinorUnit>,
}
-#[cfg(feature = "v1")]
-impl PaymentAttemptNew {
- /// returns amount + surcharge_amount + tax_amount (surcharge) + shipping_cost + order_tax_amount
- pub fn calculate_net_amount(&self) -> MinorUnit {
- self.amount
- + self.surcharge_amount.unwrap_or(MinorUnit::new(0))
- + self.tax_amount.unwrap_or(MinorUnit::new(0))
- + self.shipping_cost.unwrap_or(MinorUnit::new(0))
- }
-
- pub fn get_or_calculate_net_amount(&self) -> MinorUnit {
- self.net_amount
- .unwrap_or_else(|| self.calculate_net_amount())
- }
-
- pub fn populate_derived_fields(self) -> Self {
- let mut payment_attempt_new = self;
- payment_attempt_new.net_amount = Some(payment_attempt_new.calculate_net_amount());
- payment_attempt_new
- }
-}
-
-#[cfg(feature = "v2")]
-impl PaymentAttemptNew {
- /// returns amount + surcharge_amount + tax_amount
- pub fn calculate_net_amount(&self) -> MinorUnit {
- todo!();
- }
-
- pub fn get_or_calculate_net_amount(&self) -> MinorUnit {
- self.net_amount
- .unwrap_or_else(|| self.calculate_net_amount())
- }
-
- pub fn populate_derived_fields(self) -> Self {
- let mut payment_attempt_new = self;
- payment_attempt_new.net_amount = Some(payment_attempt_new.calculate_net_amount());
- payment_attempt_new
- }
-}
-
#[cfg(feature = "v1")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PaymentAttemptUpdate {
diff --git a/crates/diesel_models/src/query/payment_attempt.rs b/crates/diesel_models/src/query/payment_attempt.rs
index ad056aef6d..67af7a3bef 100644
--- a/crates/diesel_models/src/query/payment_attempt.rs
+++ b/crates/diesel_models/src/query/payment_attempt.rs
@@ -24,7 +24,7 @@ use crate::{
impl PaymentAttemptNew {
pub async fn insert(self, conn: &PgPooledConn) -> StorageResult<PaymentAttempt> {
- generics::generic_insert(conn, self.populate_derived_fields()).await
+ generics::generic_insert(conn, self).await
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index c71e08c79e..31423c33d2 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -11,6 +11,7 @@ use common_utils::{
};
use diesel_models::{
PaymentAttempt as DieselPaymentAttempt, PaymentAttemptNew as DieselPaymentAttemptNew,
+ PaymentAttemptUpdate as DieselPaymentAttemptUpdate,
};
use error_stack::ResultExt;
use masking::Secret;
@@ -24,7 +25,7 @@ use crate::merchant_key_store::MerchantKeyStore;
use crate::{
behaviour, errors,
mandates::{MandateDataType, MandateDetails},
- ForeignIDRef,
+ router_request_types, ForeignIDRef,
};
#[async_trait::async_trait]
@@ -273,15 +274,12 @@ pub struct PaymentAttempt {
pub merchant_id: id_type::MerchantId,
pub attempt_id: String,
pub status: storage_enums::AttemptStatus,
- pub amount: MinorUnit,
- pub net_amount: MinorUnit,
+ pub net_amount: NetAmount,
pub currency: Option<storage_enums::Currency>,
pub save_to_locker: Option<bool>,
pub connector: Option<String>,
pub error_message: Option<String>,
pub offer_amount: Option<MinorUnit>,
- pub surcharge_amount: Option<MinorUnit>,
- pub tax_amount: Option<MinorUnit>,
pub payment_method_id: Option<String>,
pub payment_method: Option<storage_enums::PaymentMethod>,
pub connector_transaction_id: Option<String>,
@@ -334,8 +332,149 @@ pub struct PaymentAttempt {
pub customer_acceptance: Option<pii::SecretSerdeValue>,
pub profile_id: id_type::ProfileId,
pub organization_id: id_type::OrganizationId,
- pub shipping_cost: Option<MinorUnit>,
- pub order_tax_amount: Option<MinorUnit>,
+}
+
+#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default)]
+pub struct NetAmount {
+ /// The payment amount
+ order_amount: MinorUnit,
+ /// The shipping cost of the order
+ shipping_cost: Option<MinorUnit>,
+ /// Tax amount related to the order
+ order_tax_amount: Option<MinorUnit>,
+ /// The surcharge amount to be added to the order
+ surcharge_amount: Option<MinorUnit>,
+ /// tax on surcharge amount
+ tax_on_surcharge: Option<MinorUnit>,
+}
+
+impl NetAmount {
+ pub fn new(
+ order_amount: MinorUnit,
+ shipping_cost: Option<MinorUnit>,
+ order_tax_amount: Option<MinorUnit>,
+ surcharge_amount: Option<MinorUnit>,
+ tax_on_surcharge: Option<MinorUnit>,
+ ) -> Self {
+ Self {
+ order_amount,
+ shipping_cost,
+ order_tax_amount,
+ surcharge_amount,
+ tax_on_surcharge,
+ }
+ }
+
+ pub fn get_order_amount(&self) -> MinorUnit {
+ self.order_amount
+ }
+
+ pub fn get_shipping_cost(&self) -> Option<MinorUnit> {
+ self.shipping_cost
+ }
+
+ pub fn get_order_tax_amount(&self) -> Option<MinorUnit> {
+ self.order_tax_amount
+ }
+
+ pub fn get_surcharge_amount(&self) -> Option<MinorUnit> {
+ self.surcharge_amount
+ }
+
+ pub fn get_tax_on_surcharge(&self) -> Option<MinorUnit> {
+ self.tax_on_surcharge
+ }
+
+ pub fn get_total_surcharge_amount(&self) -> Option<MinorUnit> {
+ self.surcharge_amount
+ .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()
+ + self.order_tax_amount.unwrap_or_default()
+ + self.surcharge_amount.unwrap_or_default()
+ + self.tax_on_surcharge.unwrap_or_default()
+ }
+
+ pub fn set_order_amount(&mut self, order_amount: MinorUnit) {
+ self.order_amount = order_amount;
+ }
+
+ pub fn set_order_tax_amount(&mut self, order_tax_amount: Option<MinorUnit>) {
+ self.order_tax_amount = order_tax_amount;
+ }
+
+ pub fn set_surcharge_details(
+ &mut self,
+ surcharge_details: Option<router_request_types::SurchargeDetails>,
+ ) {
+ self.surcharge_amount = surcharge_details
+ .clone()
+ .map(|details| details.surcharge_amount);
+ self.tax_on_surcharge = surcharge_details.map(|details| details.tax_on_surcharge_amount);
+ }
+
+ pub fn from_payments_request(
+ payments_request: &api_models::payments::PaymentsRequest,
+ order_amount: MinorUnit,
+ ) -> Self {
+ let surcharge_amount = payments_request
+ .surcharge_details
+ .map(|surcharge_details| surcharge_details.surcharge_amount);
+ let tax_on_surcharge = payments_request
+ .surcharge_details
+ .and_then(|surcharge_details| surcharge_details.tax_amount);
+ Self {
+ order_amount,
+ shipping_cost: payments_request.shipping_cost,
+ order_tax_amount: None,
+ surcharge_amount,
+ tax_on_surcharge,
+ }
+ }
+
+ #[cfg(feature = "v1")]
+ pub fn from_payments_request_and_payment_attempt(
+ payments_request: &api_models::payments::PaymentsRequest,
+ payment_attempt: Option<&PaymentAttempt>,
+ ) -> Option<Self> {
+ let option_order_amount = payments_request
+ .amount
+ .map(MinorUnit::from)
+ .or(payment_attempt
+ .map(|payment_attempt| payment_attempt.net_amount.get_order_amount()));
+ option_order_amount.map(|order_amount| {
+ let shipping_cost = payments_request.shipping_cost.or(payment_attempt
+ .and_then(|payment_attempt| payment_attempt.net_amount.get_shipping_cost()));
+ let order_tax_amount = payment_attempt
+ .and_then(|payment_attempt| payment_attempt.net_amount.get_order_tax_amount());
+ let surcharge_amount = payments_request
+ .surcharge_details
+ .map(|surcharge_details| surcharge_details.get_surcharge_amount())
+ .or_else(|| {
+ payment_attempt.and_then(|payment_attempt| {
+ payment_attempt.net_amount.get_surcharge_amount()
+ })
+ });
+ let tax_on_surcharge = payments_request
+ .surcharge_details
+ .and_then(|surcharge_details| surcharge_details.get_tax_amount())
+ .or_else(|| {
+ payment_attempt.and_then(|payment_attempt| {
+ payment_attempt.net_amount.get_tax_on_surcharge()
+ })
+ });
+ Self {
+ order_amount,
+ shipping_cost,
+ order_tax_amount,
+ surcharge_amount,
+ tax_on_surcharge,
+ }
+ })
+ }
}
#[cfg(feature = "v2")]
@@ -352,14 +491,11 @@ impl PaymentAttempt {
#[cfg(feature = "v1")]
impl PaymentAttempt {
pub fn get_total_amount(&self) -> MinorUnit {
- self.amount
- + self.surcharge_amount.unwrap_or_default()
- + self.tax_amount.unwrap_or_default()
+ self.net_amount.get_total_amount()
}
pub fn get_total_surcharge_amount(&self) -> Option<MinorUnit> {
- self.surcharge_amount
- .map(|surcharge_amount| surcharge_amount + self.tax_amount.unwrap_or_default())
+ self.net_amount.get_total_surcharge_amount()
}
}
@@ -429,18 +565,15 @@ pub struct PaymentAttemptNew {
pub merchant_id: id_type::MerchantId,
pub attempt_id: String,
pub status: storage_enums::AttemptStatus,
- pub amount: MinorUnit,
/// amount + surcharge_amount + tax_amount
/// This field will always be derived before updating in the Database
- pub net_amount: MinorUnit,
+ pub net_amount: NetAmount,
pub currency: Option<storage_enums::Currency>,
// pub auto_capture: Option<bool>,
pub save_to_locker: Option<bool>,
pub connector: Option<String>,
pub error_message: Option<String>,
pub offer_amount: Option<MinorUnit>,
- pub surcharge_amount: Option<MinorUnit>,
- pub tax_amount: Option<MinorUnit>,
pub payment_method_id: Option<String>,
pub payment_method: Option<storage_enums::PaymentMethod>,
pub capture_method: Option<storage_enums::CaptureMethod>,
@@ -490,45 +623,13 @@ pub struct PaymentAttemptNew {
pub customer_acceptance: Option<pii::SecretSerdeValue>,
pub profile_id: id_type::ProfileId,
pub organization_id: id_type::OrganizationId,
- pub shipping_cost: Option<MinorUnit>,
- pub order_tax_amount: Option<MinorUnit>,
-}
-
-#[cfg(feature = "v2")]
-impl PaymentAttemptNew {
- /// returns amount + surcharge_amount + tax_amount
- pub fn calculate_net_amount(&self) -> MinorUnit {
- todo!();
- }
-
- pub fn populate_derived_fields(self) -> Self {
- todo!()
- }
-}
-
-#[cfg(feature = "v1")]
-impl PaymentAttemptNew {
- /// returns amount + surcharge_amount + tax_amount
- pub fn calculate_net_amount(&self) -> MinorUnit {
- self.amount
- + self.surcharge_amount.unwrap_or_default()
- + self.tax_amount.unwrap_or_default()
- + self.shipping_cost.unwrap_or_default()
- + self.order_tax_amount.unwrap_or_default()
- }
-
- pub fn populate_derived_fields(self) -> Self {
- let mut payment_attempt_new = self;
- payment_attempt_new.net_amount = payment_attempt_new.calculate_net_amount();
- payment_attempt_new
- }
}
#[cfg(feature = "v1")]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PaymentAttemptUpdate {
Update {
- amount: MinorUnit,
+ net_amount: NetAmount,
currency: storage_enums::Currency,
status: storage_enums::AttemptStatus,
authentication_type: Option<storage_enums::AuthenticationType>,
@@ -540,8 +641,6 @@ pub enum PaymentAttemptUpdate {
business_sub_label: Option<String>,
amount_to_capture: Option<MinorUnit>,
capture_method: Option<storage_enums::CaptureMethod>,
- surcharge_amount: Option<MinorUnit>,
- tax_amount: Option<MinorUnit>,
fingerprint_id: Option<String>,
payment_method_billing_address_id: Option<String>,
updated_by: String,
@@ -561,7 +660,7 @@ pub enum PaymentAttemptUpdate {
updated_by: String,
},
ConfirmUpdate {
- amount: MinorUnit,
+ net_amount: NetAmount,
currency: storage_enums::Currency,
status: storage_enums::AttemptStatus,
authentication_type: Option<storage_enums::AuthenticationType>,
@@ -579,8 +678,6 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
amount_capturable: Option<MinorUnit>,
updated_by: String,
- surcharge_amount: Option<MinorUnit>,
- tax_amount: Option<MinorUnit>,
merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,
external_three_ds_authentication_attempted: Option<bool>,
authentication_connector: Option<String>,
@@ -591,8 +688,6 @@ pub enum PaymentAttemptUpdate {
client_source: Option<String>,
client_version: Option<String>,
customer_acceptance: Option<pii::SecretSerdeValue>,
- shipping_cost: Option<MinorUnit>,
- order_tax_amount: Option<MinorUnit>,
},
RejectUpdate {
status: storage_enums::AttemptStatus,
@@ -694,7 +789,7 @@ pub enum PaymentAttemptUpdate {
updated_by: String,
},
IncrementalAuthorizationAmountUpdate {
- amount: MinorUnit,
+ net_amount: NetAmount,
amount_capturable: MinorUnit,
},
AuthenticationUpdate {
@@ -716,6 +811,359 @@ pub enum PaymentAttemptUpdate {
},
}
+#[cfg(feature = "v1")]
+impl PaymentAttemptUpdate {
+ pub fn to_storage_model(self) -> diesel_models::PaymentAttemptUpdate {
+ match self {
+ Self::Update {
+ net_amount,
+ currency,
+ status,
+ authentication_type,
+ payment_method,
+ payment_token,
+ payment_method_data,
+ payment_method_type,
+ payment_experience,
+ business_sub_label,
+ amount_to_capture,
+ capture_method,
+ fingerprint_id,
+ payment_method_billing_address_id,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::Update {
+ amount: net_amount.get_order_amount(),
+ currency,
+ status,
+ authentication_type,
+ payment_method,
+ payment_token,
+ payment_method_data,
+ payment_method_type,
+ payment_experience,
+ business_sub_label,
+ amount_to_capture,
+ capture_method,
+ surcharge_amount: net_amount.get_surcharge_amount(),
+ tax_amount: net_amount.get_tax_on_surcharge(),
+ fingerprint_id,
+ payment_method_billing_address_id,
+ updated_by,
+ },
+ Self::UpdateTrackers {
+ payment_token,
+ connector,
+ straight_through_algorithm,
+ amount_capturable,
+ updated_by,
+ surcharge_amount,
+ tax_amount,
+ merchant_connector_id,
+ } => DieselPaymentAttemptUpdate::UpdateTrackers {
+ payment_token,
+ connector,
+ straight_through_algorithm,
+ amount_capturable,
+ surcharge_amount,
+ tax_amount,
+ updated_by,
+ merchant_connector_id,
+ },
+ Self::AuthenticationTypeUpdate {
+ authentication_type,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::AuthenticationTypeUpdate {
+ authentication_type,
+ updated_by,
+ },
+ Self::BlocklistUpdate {
+ status,
+ error_code,
+ error_message,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::BlocklistUpdate {
+ status,
+ error_code,
+ error_message,
+ updated_by,
+ },
+ Self::PaymentMethodDetailsUpdate {
+ payment_method_id,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::PaymentMethodDetailsUpdate {
+ payment_method_id,
+ updated_by,
+ },
+ Self::ConfirmUpdate {
+ net_amount,
+ currency,
+ status,
+ authentication_type,
+ capture_method,
+ payment_method,
+ browser_info,
+ connector,
+ payment_token,
+ payment_method_data,
+ payment_method_type,
+ payment_experience,
+ business_sub_label,
+ straight_through_algorithm,
+ error_code,
+ error_message,
+ amount_capturable,
+ fingerprint_id,
+ updated_by,
+ merchant_connector_id: connector_id,
+ payment_method_id,
+ external_three_ds_authentication_attempted,
+ authentication_connector,
+ authentication_id,
+ payment_method_billing_address_id,
+ client_source,
+ client_version,
+ customer_acceptance,
+ } => DieselPaymentAttemptUpdate::ConfirmUpdate {
+ amount: net_amount.get_order_amount(),
+ currency,
+ status,
+ authentication_type,
+ capture_method,
+ payment_method,
+ browser_info,
+ connector,
+ payment_token,
+ payment_method_data,
+ payment_method_type,
+ payment_experience,
+ business_sub_label,
+ straight_through_algorithm,
+ error_code,
+ error_message,
+ amount_capturable,
+ surcharge_amount: net_amount.get_surcharge_amount(),
+ tax_amount: net_amount.get_tax_on_surcharge(),
+ fingerprint_id,
+ updated_by,
+ merchant_connector_id: connector_id,
+ payment_method_id,
+ external_three_ds_authentication_attempted,
+ authentication_connector,
+ authentication_id,
+ payment_method_billing_address_id,
+ client_source,
+ client_version,
+ customer_acceptance,
+ shipping_cost: net_amount.get_shipping_cost(),
+ order_tax_amount: net_amount.get_order_tax_amount(),
+ },
+ Self::VoidUpdate {
+ status,
+ cancellation_reason,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::VoidUpdate {
+ status,
+ cancellation_reason,
+ updated_by,
+ },
+ Self::ResponseUpdate {
+ status,
+ connector,
+ connector_transaction_id,
+ authentication_type,
+ payment_method_id,
+ mandate_id,
+ connector_metadata,
+ payment_token,
+ error_code,
+ error_message,
+ error_reason,
+ connector_response_reference_id,
+ amount_capturable,
+ updated_by,
+ authentication_data,
+ encoded_data,
+ unified_code,
+ unified_message,
+ payment_method_data,
+ charge_id,
+ } => DieselPaymentAttemptUpdate::ResponseUpdate {
+ status,
+ connector,
+ connector_transaction_id,
+ authentication_type,
+ payment_method_id,
+ mandate_id,
+ connector_metadata,
+ payment_token,
+ error_code,
+ error_message,
+ error_reason,
+ connector_response_reference_id,
+ amount_capturable,
+ updated_by,
+ authentication_data,
+ encoded_data,
+ unified_code,
+ unified_message,
+ payment_method_data,
+ charge_id,
+ },
+ Self::UnresolvedResponseUpdate {
+ status,
+ connector,
+ connector_transaction_id,
+ payment_method_id,
+ error_code,
+ error_message,
+ error_reason,
+ connector_response_reference_id,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::UnresolvedResponseUpdate {
+ status,
+ connector,
+ connector_transaction_id,
+ payment_method_id,
+ error_code,
+ error_message,
+ error_reason,
+ connector_response_reference_id,
+ updated_by,
+ },
+ Self::StatusUpdate { status, updated_by } => {
+ DieselPaymentAttemptUpdate::StatusUpdate { status, updated_by }
+ }
+ Self::ErrorUpdate {
+ connector,
+ status,
+ error_code,
+ error_message,
+ error_reason,
+ amount_capturable,
+ updated_by,
+ unified_code,
+ unified_message,
+ connector_transaction_id,
+ payment_method_data,
+ authentication_type,
+ } => DieselPaymentAttemptUpdate::ErrorUpdate {
+ connector,
+ status,
+ error_code,
+ error_message,
+ error_reason,
+ amount_capturable,
+ updated_by,
+ unified_code,
+ unified_message,
+ connector_transaction_id,
+ payment_method_data,
+ authentication_type,
+ },
+ Self::CaptureUpdate {
+ multiple_capture_count,
+ updated_by,
+ amount_to_capture,
+ } => DieselPaymentAttemptUpdate::CaptureUpdate {
+ multiple_capture_count,
+ updated_by,
+ amount_to_capture,
+ },
+ Self::PreprocessingUpdate {
+ status,
+ payment_method_id,
+ connector_metadata,
+ preprocessing_step_id,
+ connector_transaction_id,
+ connector_response_reference_id,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::PreprocessingUpdate {
+ status,
+ payment_method_id,
+ connector_metadata,
+ preprocessing_step_id,
+ connector_transaction_id,
+ connector_response_reference_id,
+ updated_by,
+ },
+ Self::RejectUpdate {
+ status,
+ error_code,
+ error_message,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::RejectUpdate {
+ status,
+ error_code,
+ error_message,
+ updated_by,
+ },
+ Self::AmountToCaptureUpdate {
+ status,
+ amount_capturable,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::AmountToCaptureUpdate {
+ status,
+ amount_capturable,
+ updated_by,
+ },
+ Self::ConnectorResponse {
+ authentication_data,
+ encoded_data,
+ connector_transaction_id,
+ connector,
+ charge_id,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::ConnectorResponse {
+ authentication_data,
+ encoded_data,
+ connector_transaction_id,
+ connector,
+ charge_id,
+ updated_by,
+ },
+ Self::IncrementalAuthorizationAmountUpdate {
+ net_amount,
+ amount_capturable,
+ } => DieselPaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
+ amount: net_amount.get_order_amount(),
+ amount_capturable,
+ },
+ Self::AuthenticationUpdate {
+ status,
+ external_three_ds_authentication_attempted,
+ authentication_connector,
+ authentication_id,
+ updated_by,
+ } => DieselPaymentAttemptUpdate::AuthenticationUpdate {
+ status,
+ external_three_ds_authentication_attempted,
+ authentication_connector,
+ authentication_id,
+ updated_by,
+ },
+ Self::ManualUpdate {
+ status,
+ error_code,
+ error_message,
+ error_reason,
+ updated_by,
+ unified_code,
+ unified_message,
+ connector_transaction_id,
+ } => DieselPaymentAttemptUpdate::ManualUpdate {
+ status,
+ error_code,
+ error_message,
+ error_reason,
+ updated_by,
+ unified_code,
+ unified_message,
+ connector_transaction_id,
+ },
+ }
+ }
+}
+
// TODO: Add fields as necessary
#[cfg(feature = "v2")]
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -756,14 +1204,14 @@ impl behaviour::Conversion for PaymentAttempt {
merchant_id: self.merchant_id,
attempt_id: self.attempt_id,
status: self.status,
- amount: self.amount,
+ amount: self.net_amount.get_order_amount(),
currency: self.currency,
save_to_locker: self.save_to_locker,
connector: self.connector,
error_message: self.error_message,
offer_amount: self.offer_amount,
- surcharge_amount: self.surcharge_amount,
- tax_amount: self.tax_amount,
+ surcharge_amount: self.net_amount.get_surcharge_amount(),
+ tax_amount: self.net_amount.get_tax_on_surcharge(),
payment_method_id: self.payment_method_id,
payment_method: self.payment_method,
connector_transaction_id: self.connector_transaction_id,
@@ -798,7 +1246,7 @@ impl behaviour::Conversion for PaymentAttempt {
encoded_data: self.encoded_data,
unified_code: self.unified_code,
unified_message: self.unified_message,
- net_amount: Some(self.net_amount),
+ net_amount: Some(self.net_amount.get_total_amount()),
external_three_ds_authentication_attempted: self
.external_three_ds_authentication_attempted,
authentication_connector: self.authentication_connector,
@@ -813,8 +1261,8 @@ impl behaviour::Conversion for PaymentAttempt {
profile_id: self.profile_id,
organization_id: self.organization_id,
card_network,
- order_tax_amount: self.order_tax_amount,
- shipping_cost: self.shipping_cost,
+ order_tax_amount: self.net_amount.get_order_tax_amount(),
+ shipping_cost: self.net_amount.get_shipping_cost(),
})
}
@@ -828,21 +1276,23 @@ impl behaviour::Conversion for PaymentAttempt {
Self: Sized,
{
async {
- let net_amount = storage_model.get_or_calculate_net_amount();
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
payment_id: storage_model.payment_id,
merchant_id: storage_model.merchant_id,
attempt_id: storage_model.attempt_id,
status: storage_model.status,
- amount: storage_model.amount,
- net_amount,
+ net_amount: NetAmount::new(
+ storage_model.amount,
+ storage_model.shipping_cost,
+ storage_model.order_tax_amount,
+ storage_model.surcharge_amount,
+ storage_model.tax_amount,
+ ),
currency: storage_model.currency,
save_to_locker: storage_model.save_to_locker,
connector: storage_model.connector,
error_message: storage_model.error_message,
offer_amount: storage_model.offer_amount,
- surcharge_amount: storage_model.surcharge_amount,
- tax_amount: storage_model.tax_amount,
payment_method_id: storage_model.payment_method_id,
payment_method: storage_model.payment_method,
connector_transaction_id: storage_model.connector_transaction_id,
@@ -890,8 +1340,6 @@ impl behaviour::Conversion for PaymentAttempt {
customer_acceptance: storage_model.customer_acceptance,
profile_id: storage_model.profile_id,
organization_id: storage_model.organization_id,
- order_tax_amount: storage_model.order_tax_amount,
- shipping_cost: storage_model.shipping_cost,
})
}
.await
@@ -915,14 +1363,14 @@ impl behaviour::Conversion for PaymentAttempt {
merchant_id: self.merchant_id,
attempt_id: self.attempt_id,
status: self.status,
- amount: self.amount,
+ amount: self.net_amount.get_order_amount(),
currency: self.currency,
save_to_locker: self.save_to_locker,
connector: self.connector,
error_message: self.error_message,
offer_amount: self.offer_amount,
- surcharge_amount: self.surcharge_amount,
- tax_amount: self.tax_amount,
+ surcharge_amount: self.net_amount.get_surcharge_amount(),
+ tax_amount: self.net_amount.get_tax_on_surcharge(),
payment_method_id: self.payment_method_id,
payment_method: self.payment_method,
capture_method: self.capture_method,
@@ -956,7 +1404,7 @@ impl behaviour::Conversion for PaymentAttempt {
encoded_data: self.encoded_data,
unified_code: self.unified_code,
unified_message: self.unified_message,
- net_amount: Some(self.net_amount),
+ net_amount: Some(self.net_amount.get_total_amount()),
external_three_ds_authentication_attempted: self
.external_three_ds_authentication_attempted,
authentication_connector: self.authentication_connector,
@@ -971,8 +1419,8 @@ impl behaviour::Conversion for PaymentAttempt {
profile_id: self.profile_id,
organization_id: self.organization_id,
card_network,
- order_tax_amount: self.order_tax_amount,
- shipping_cost: self.shipping_cost,
+ order_tax_amount: self.net_amount.get_order_tax_amount(),
+ shipping_cost: self.net_amount.get_shipping_cost(),
})
}
}
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index d26f1975b7..b67621e9f0 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -512,8 +512,6 @@ pub struct SurchargeDetails {
pub surcharge_amount: MinorUnit,
/// tax on surcharge amount for this payment
pub tax_on_surcharge_amount: MinorUnit,
- /// sum of original amount,
- pub final_amount: MinorUnit,
}
impl SurchargeDetails {
@@ -546,14 +544,13 @@ impl
let surcharge_amount = request_surcharge_details.surcharge_amount;
let tax_on_surcharge_amount = request_surcharge_details.tax_amount.unwrap_or_default();
Self {
- original_amount: payment_attempt.amount,
+ original_amount: payment_attempt.net_amount.get_order_amount(),
surcharge: common_utils::types::Surcharge::Fixed(
request_surcharge_details.surcharge_amount,
),
tax_on_surcharge: None,
surcharge_amount,
tax_on_surcharge_amount,
- final_amount: payment_attempt.amount + surcharge_amount + tax_on_surcharge_amount,
}
}
}
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 92dc2a99e8..64c8694a5b 100644
--- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
@@ -93,7 +93,11 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
amount_captured: None,
minor_amount_captured: None,
request: FraudCheckCheckoutData {
- amount: self.payment_attempt.amount.get_amount_as_i64(),
+ amount: self
+ .payment_attempt
+ .net_amount
+ .get_total_amount()
+ .get_amount_as_i64(),
order_details: self.order_details.clone(),
currency: self.payment_attempt.currency,
browser_info,
diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
index a47ca2e09a..9beff27200 100644
--- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
@@ -89,7 +89,10 @@ pub async fn construct_fulfillment_router_data<'a>(
minor_amount_captured: payment_intent.amount_captured,
payment_method_status: None,
request: FraudCheckFulfillmentData {
- amount: payment_attempt.amount.get_amount_as_i64(),
+ amount: payment_attempt
+ .net_amount
+ .get_total_amount()
+ .get_amount_as_i64(),
order_details: payment_intent.order_details.clone(),
fulfillment_req: fulfillment_request,
},
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 e4d002931e..1c55bffeb8 100644
--- a/crates/router/src/core/fraud_check/flows/record_return.rs
+++ b/crates/router/src/core/fraud_check/flows/record_return.rs
@@ -88,7 +88,11 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
amount_captured: None,
minor_amount_captured: None,
request: FraudCheckRecordReturnData {
- amount: self.payment_attempt.amount.get_amount_as_i64(),
+ amount: self
+ .payment_attempt
+ .net_amount
+ .get_total_amount()
+ .get_amount_as_i64(),
refund_method: RefundMethod::OriginalPaymentInstrument, //we dont consume this data now in payments...hence hardcoded
currency,
refund_transaction_id: self.refund.clone().map(|refund| refund.refund_id),
diff --git a/crates/router/src/core/fraud_check/flows/sale_flow.rs b/crates/router/src/core/fraud_check/flows/sale_flow.rs
index 56f6545cfd..9a1899df42 100644
--- a/crates/router/src/core/fraud_check/flows/sale_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/sale_flow.rs
@@ -84,7 +84,11 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
amount_captured: None,
minor_amount_captured: None,
request: FraudCheckSaleData {
- amount: self.payment_attempt.amount.get_amount_as_i64(),
+ amount: self
+ .payment_attempt
+ .net_amount
+ .get_total_amount()
+ .get_amount_as_i64(),
order_details: self.order_details.clone(),
currency: self.payment_attempt.currency,
email: customer
diff --git a/crates/router/src/core/fraud_check/flows/transaction_flow.rs b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
index ebd967e751..6b25be7318 100644
--- a/crates/router/src/core/fraud_check/flows/transaction_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
@@ -96,7 +96,11 @@ impl
amount_captured: None,
minor_amount_captured: None,
request: FraudCheckTransactionData {
- amount: self.payment_attempt.amount.get_amount_as_i64(),
+ amount: self
+ .payment_attempt
+ .net_amount
+ .get_total_amount()
+ .get_amount_as_i64(),
order_details: self.order_details.clone(),
currency,
payment_method,
diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs
index 100e7abc85..ebc522b30a 100644
--- a/crates/router/src/core/payment_link.rs
+++ b/crates/router/src/core/payment_link.rs
@@ -744,7 +744,7 @@ pub async fn get_payment_link_status(
let required_conversion_type = StringMajorUnitForCore;
let amount = required_conversion_type
- .convert(payment_attempt.net_amount, currency)
+ .convert(payment_attempt.get_total_amount(), currency)
.change_context(errors::ApiErrorResponse::AmountConversionFailed {
amount_type: "StringMajorUnit",
})?;
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 3c09db61a3..abcdf504e1 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -2915,7 +2915,7 @@ pub async fn list_payment_methods(
.transpose()?;
let setup_future_usage = payment_intent.as_ref().and_then(|pi| pi.setup_future_usage);
let payment_type = payment_attempt.as_ref().map(|pa| {
- let amount = api::Amount::from(pa.amount);
+ let amount = api::Amount::from(pa.net_amount.get_order_amount());
let mandate_type = if pa.mandate_id.is_some() {
Some(api::MandateTransactionType::RecurringMandateTransaction)
} else if pa.mandate_details.is_some()
diff --git a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
index 982d13b54b..7de4f15adb 100644
--- a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
+++ b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
@@ -457,7 +457,7 @@ fn get_surcharge_details_from_surcharge_output(
let surcharge_amount = match surcharge_details.surcharge.clone() {
surcharge_decision_configs::SurchargeOutput::Fixed { amount } => amount,
surcharge_decision_configs::SurchargeOutput::Rate(percentage) => percentage
- .apply_and_ceil_result(payment_attempt.amount)
+ .apply_and_ceil_result(payment_attempt.net_amount.get_total_amount())
.change_context(ConfigError::DslExecutionError)
.attach_printable("Failed to Calculate surcharge amount by applying percentage")?,
};
@@ -473,7 +473,7 @@ fn get_surcharge_details_from_surcharge_output(
.transpose()?
.unwrap_or_default();
Ok(types::SurchargeDetails {
- original_amount: payment_attempt.amount,
+ original_amount: payment_attempt.net_amount.get_order_amount(),
surcharge: match surcharge_details.surcharge {
surcharge_decision_configs::SurchargeOutput::Fixed { amount } => {
common_utils_types::Surcharge::Fixed(amount)
@@ -485,7 +485,6 @@ fn get_surcharge_details_from_surcharge_output(
tax_on_surcharge: surcharge_details.tax_on_surcharge,
surcharge_amount,
tax_on_surcharge_amount,
- final_amount: payment_attempt.amount + surcharge_amount + tax_on_surcharge_amount,
})
}
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 363d52cd8b..d6877fb88d 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -802,7 +802,13 @@ where
}
};
- payment_data.surcharge_details = calculated_surcharge_details;
+ payment_data.surcharge_details = calculated_surcharge_details.clone();
+
+ //Update payment_attempt net_amount with surcharge details
+ payment_data
+ .payment_attempt
+ .net_amount
+ .set_surcharge_details(calculated_surcharge_details);
} else {
let surcharge_details =
payment_data
@@ -855,17 +861,17 @@ pub async fn call_surcharge_decision_management_for_session_flow(
billing_address: Option<api_models::payments::Address>,
session_connector_data: &[api::SessionConnectorData],
) -> RouterResult<Option<api::SessionSurchargeDetails>> {
- if let Some(surcharge_amount) = payment_attempt.surcharge_amount {
- let tax_on_surcharge_amount = payment_attempt.tax_amount.unwrap_or_default();
- let final_amount = payment_attempt.amount + surcharge_amount + tax_on_surcharge_amount;
+ if let Some(surcharge_amount) = payment_attempt.net_amount.get_surcharge_amount() {
Ok(Some(api::SessionSurchargeDetails::PreDetermined(
types::SurchargeDetails {
- original_amount: payment_attempt.amount,
+ original_amount: payment_attempt.net_amount.get_order_amount(),
surcharge: Surcharge::Fixed(surcharge_amount),
tax_on_surcharge: None,
surcharge_amount,
- tax_on_surcharge_amount,
- final_amount,
+ tax_on_surcharge_amount: payment_attempt
+ .net_amount
+ .get_tax_on_surcharge()
+ .unwrap_or_default(),
},
)))
} else {
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index a39b151bd2..b159971fdf 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -476,13 +476,13 @@ pub async fn get_token_pm_type_mandate_details(
}
}
RecurringDetails::MandateId(mandate_id) => {
- let mandate_generic_data = get_token_for_recurring_mandate(
+ let mandate_generic_data = Box::pin(get_token_for_recurring_mandate(
state,
request,
merchant_account,
merchant_key_store,
mandate_id.to_owned(),
- )
+ ))
.await?;
(
@@ -535,13 +535,13 @@ pub async fn get_token_pm_type_mandate_details(
}
None => {
if let Some(mandate_id) = request.mandate_id.clone() {
- let mandate_generic_data = get_token_for_recurring_mandate(
+ let mandate_generic_data = Box::pin(get_token_for_recurring_mandate(
state,
request,
merchant_account,
merchant_key_store,
mandate_id,
- )
+ ))
.await?;
(
mandate_generic_data.token,
@@ -723,9 +723,26 @@ pub async fn get_token_for_recurring_mandate(
.await
.flatten();
- let original_payment_authorized_amount = original_payment_intent
+ let original_payment_attempt = original_payment_intent
+ .as_ref()
+ .async_map(|payment_intent| async {
+ db.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
+ &payment_intent.payment_id,
+ &mandate.merchant_id,
+ payment_intent.active_attempt.get_id().as_str(),
+ merchant_account.storage_scheme,
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)
+ .map_err(|err| logger::error!(mandate_original_payment_attempt_not_found=?err))
+ .ok()
+ })
+ .await
+ .flatten();
+
+ let original_payment_authorized_amount = original_payment_attempt
.clone()
- .map(|pi| pi.amount.get_amount_as_i64());
+ .map(|pa| pa.net_amount.get_total_amount().get_amount_as_i64());
let original_payment_authorized_currency =
original_payment_intent.clone().and_then(|pi| pi.currency);
let customer = req.get_customer_id().get_required_value("customer_id")?;
@@ -891,28 +908,18 @@ pub fn validate_amount_to_capture_and_capture_method(
payment_attempt: Option<&PaymentAttempt>,
request: &api_models::payments::PaymentsRequest,
) -> CustomResult<(), errors::ApiErrorResponse> {
+ let option_net_amount = hyperswitch_domain_models::payments::payment_attempt::NetAmount::from_payments_request_and_payment_attempt(
+ request,
+ payment_attempt,
+ );
let capture_method = request
.capture_method
.or(payment_attempt
.map(|payment_attempt| payment_attempt.capture_method.unwrap_or_default()))
.unwrap_or_default();
if capture_method == api_enums::CaptureMethod::Automatic {
- let original_amount = request
- .amount
- .map(MinorUnit::from)
- .or(payment_attempt.map(|payment_attempt| payment_attempt.amount));
- let surcharge_amount = request
- .surcharge_details
- .map(|surcharge_details| surcharge_details.get_total_surcharge_amount())
- .or_else(|| {
- payment_attempt.map(|payment_attempt| {
- payment_attempt.surcharge_amount.unwrap_or_default()
- + payment_attempt.tax_amount.unwrap_or_default()
- })
- })
- .unwrap_or_default();
let total_capturable_amount =
- original_amount.map(|original_amount| original_amount + surcharge_amount);
+ option_net_amount.map(|net_amount| net_amount.get_total_amount());
let amount_to_capture = request
.amount_to_capture
@@ -3892,7 +3899,6 @@ impl AttemptType {
// A new payment attempt is getting created so, used the same function which is used to populate status in PaymentCreate Flow.
status: payment_attempt_status_fsm(payment_method_data, Some(true)),
- amount: old_payment_attempt.amount,
currency: old_payment_attempt.currency,
save_to_locker: old_payment_attempt.save_to_locker,
@@ -3900,8 +3906,6 @@ impl AttemptType {
error_message: None,
offer_amount: old_payment_attempt.offer_amount,
- surcharge_amount: None,
- tax_amount: None,
payment_method_id: None,
payment_method: None,
capture_method: old_payment_attempt.capture_method,
@@ -3937,14 +3941,14 @@ impl AttemptType {
error_reason: None,
multiple_capture_count: None,
connector_response_reference_id: None,
- amount_capturable: old_payment_attempt.amount,
+ amount_capturable: old_payment_attempt.net_amount.get_total_amount(),
updated_by: storage_scheme.to_string(),
authentication_data: None,
encoded_data: None,
merchant_connector_id: None,
unified_code: None,
unified_message: None,
- net_amount: old_payment_attempt.amount,
+ net_amount: old_payment_attempt.net_amount,
external_three_ds_authentication_attempted: old_payment_attempt
.external_three_ds_authentication_attempted,
authentication_connector: None,
@@ -3959,8 +3963,6 @@ impl AttemptType {
customer_acceptance: old_payment_attempt.customer_acceptance,
organization_id: old_payment_attempt.organization_id,
profile_id: old_payment_attempt.profile_id,
- shipping_cost: old_payment_attempt.shipping_cost,
- order_tax_amount: None,
}
}
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index 99d8df2dfe..92e462c78b 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -125,7 +125,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
recurring_mandate_payment_data,
mandate_connector,
payment_method_info,
- } = helpers::get_token_pm_type_mandate_details(
+ } = Box::pin(helpers::get_token_pm_type_mandate_details(
state,
request,
mandate_type.to_owned(),
@@ -133,7 +133,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
key_store,
payment_attempt.payment_method_id.clone(),
payment_intent.customer_id.as_ref(),
- )
+ ))
.await?;
let customer_acceptance: Option<CustomerAcceptance> = request
.customer_acceptance
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index fb8f94405e..81451d1aff 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -540,7 +540,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
let mandate_details_fut = tokio::spawn(
async move {
- helpers::get_token_pm_type_mandate_details(
+ Box::pin(helpers::get_token_pm_type_mandate_details(
&m_state,
&m_request,
m_mandate_type,
@@ -548,7 +548,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
&m_key_store,
None,
payment_intent_customer_id.as_ref(),
- )
+ ))
.await
}
.in_current_span(),
@@ -695,6 +695,26 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
_ => None,
});
+ let pmt_order_tax_amount = payment_intent.tax_details.clone().and_then(|tax| {
+ if tax.payment_method_type.clone().map(|a| a.pmt) == payment_attempt.payment_method_type
+ {
+ tax.payment_method_type.map(|a| a.order_tax_amount)
+ } else {
+ None
+ }
+ });
+
+ let order_tax_amount = pmt_order_tax_amount.or_else(|| {
+ payment_intent
+ .tax_details
+ .clone()
+ .and_then(|tax| tax.default.map(|a| a.order_tax_amount))
+ });
+
+ payment_attempt
+ .net_amount
+ .set_order_tax_amount(order_tax_amount);
+
let payment_data = PaymentData {
flow: PhantomData,
payment_intent,
@@ -1231,11 +1251,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
let order_details = payment_data.payment_intent.order_details.clone();
let metadata = payment_data.payment_intent.metadata.clone();
let frm_metadata = payment_data.payment_intent.frm_metadata.clone();
- let authorized_amount = payment_data
- .surcharge_details
- .as_ref()
- .map(|surcharge_details| surcharge_details.final_amount)
- .unwrap_or(payment_data.payment_attempt.amount);
+ let authorized_amount = payment_data.payment_attempt.get_total_amount();
let client_source = header_payload
.client_source
@@ -1291,37 +1307,11 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
None => (None, None, None),
};
- let shipping_cost = payment_data.payment_intent.shipping_cost;
-
- let pmt_order_tax_amount =
- payment_data
- .payment_intent
- .tax_details
- .clone()
- .and_then(|tax| {
- if tax.payment_method_type.clone().map(|a| a.pmt)
- == payment_data.payment_attempt.payment_method_type
- {
- tax.payment_method_type.map(|a| a.order_tax_amount)
- } else {
- None
- }
- });
-
- let order_tax_amount = pmt_order_tax_amount.or_else(|| {
- payment_data
- .payment_intent
- .tax_details
- .clone()
- .and_then(|tax| tax.default.map(|a| a.order_tax_amount))
- });
-
let payment_attempt_fut = tokio::spawn(
async move {
m_db.update_payment_attempt_with_attempt_id(
m_payment_data_payment_attempt,
storage::PaymentAttemptUpdate::ConfirmUpdate {
- amount: payment_data.payment_attempt.amount,
currency: payment_data.currency,
status: attempt_status,
payment_method,
@@ -1340,8 +1330,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
amount_capturable: Some(authorized_amount),
updated_by: storage_scheme.to_string(),
merchant_connector_id,
- surcharge_amount,
- tax_amount,
external_three_ds_authentication_attempted,
authentication_connector,
authentication_id,
@@ -1351,8 +1339,17 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
client_source,
client_version,
customer_acceptance: payment_data.payment_attempt.customer_acceptance,
- shipping_cost,
- order_tax_amount,
+ net_amount:
+ hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
+ payment_data.payment_attempt.net_amount.get_order_amount(),
+ payment_data.payment_intent.shipping_cost,
+ payment_data
+ .payment_attempt
+ .net_amount
+ .get_order_tax_amount(),
+ surcharge_amount,
+ tax_amount,
+ ),
},
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 f23405e355..267eeaa040 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -804,7 +804,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
.payment_attempt
.straight_through_algorithm
.clone();
- let authorized_amount = payment_data.payment_attempt.amount;
+ let authorized_amount = payment_data.payment_attempt.get_total_amount();
let merchant_connector_id = payment_data.payment_attempt.merchant_connector_id.clone();
let surcharge_amount = payment_data
@@ -1118,12 +1118,6 @@ impl PaymentCreate {
} else {
payment_id.get_attempt_id(1)
};
- let surcharge_amount = request
- .surcharge_details
- .map(|surcharge_details| surcharge_details.surcharge_amount);
- let tax_amount = request
- .surcharge_details
- .and_then(|surcharge_details| surcharge_details.tax_amount);
if request.mandate_data.as_ref().map_or(false, |mandate_data| {
mandate_data.update_mandate_id.is_some() && mandate_data.mandate_type.is_some()
@@ -1151,7 +1145,6 @@ impl PaymentCreate {
attempt_id,
status,
currency,
- amount: MinorUnit::from(amount),
payment_method,
capture_method: request.capture_method,
capture_on: request.capture_on,
@@ -1168,8 +1161,6 @@ impl PaymentCreate {
payment_token: request.payment_token.clone(),
mandate_id: request.mandate_id.clone(),
business_sub_label: request.business_sub_label.clone(),
- surcharge_amount,
- tax_amount,
mandate_details: request
.mandate_data
.as_ref()
@@ -1177,7 +1168,10 @@ impl PaymentCreate {
external_three_ds_authentication_attempted: None,
mandate_data,
payment_method_billing_address_id,
- net_amount: MinorUnit::new(i64::default()),
+ net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::from_payments_request(
+ request,
+ MinorUnit::from(amount),
+ ),
save_to_locker: None,
connector: None,
error_message: None,
@@ -1215,8 +1209,6 @@ impl PaymentCreate {
.map(Secret::new),
organization_id: organization_id.clone(),
profile_id,
- shipping_cost: request.shipping_cost,
- order_tax_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 6a5299db8c..fd5c544b28 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -371,18 +371,25 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsIncrementalAu
.attach_printable("missing incremental_authorization_details in payment_data")
})?;
// Update payment_intent and payment_attempt 'amount' if incremental_authorization is successful
- let (option_payment_attempt_update, option_payment_intent_update) =
- match router_data.response.clone() {
- Err(_) => (None, None),
- Ok(types::PaymentsResponseData::IncrementalAuthorizationResponse {
- status,
- ..
- }) => {
- if status == AuthorizationStatus::Success {
- (
+ let (option_payment_attempt_update, option_payment_intent_update) = match router_data
+ .response
+ .clone()
+ {
+ Err(_) => (None, None),
+ Ok(types::PaymentsResponseData::IncrementalAuthorizationResponse {
+ status, ..
+ }) => {
+ if status == AuthorizationStatus::Success {
+ (
Some(
storage::PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
- amount: incremental_authorization_details.total_amount,
+ net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
+ incremental_authorization_details.total_amount,
+ None,
+ None,
+ None,
+ None,
+ ),
amount_capturable: incremental_authorization_details.total_amount,
},
),
@@ -392,13 +399,13 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsIncrementalAu
},
),
)
- } else {
- (None, None)
- }
+ } else {
+ (None, None)
}
- _ => Err(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("unexpected response in incremental_authorization flow")?,
- };
+ }
+ _ => Err(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("unexpected response in incremental_authorization flow")?,
+ };
//payment_attempt update
if let Some(payment_attempt_update) = option_payment_attempt_update {
#[cfg(feature = "v1")]
@@ -1657,7 +1664,13 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
tokenization::update_connector_mandate_details_in_payment_method(
payment_method.clone(),
payment_method.payment_method_type,
- Some(payment_data.payment_attempt.amount.get_amount_as_i64()),
+ Some(
+ payment_data
+ .payment_attempt
+ .net_amount
+ .get_total_amount()
+ .get_amount_as_i64(),
+ ),
payment_data.payment_attempt.currency,
payment_data.payment_attempt.merchant_connector_id.clone(),
connector_mandate_id,
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 3fa44868f0..a436100dc0 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -150,7 +150,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
recurring_mandate_payment_data,
mandate_connector,
payment_method_info,
- } = helpers::get_token_pm_type_mandate_details(
+ } = Box::pin(helpers::get_token_pm_type_mandate_details(
state,
request,
mandate_type.to_owned(),
@@ -158,7 +158,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
key_store,
None,
payment_intent.customer_id.as_ref(),
- )
+ ))
.await?;
helpers::validate_amount_to_capture_and_capture_method(Some(&payment_attempt), request)?;
@@ -186,7 +186,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
let amount = request
.amount
- .unwrap_or_else(|| payment_attempt.amount.into());
+ .unwrap_or_else(|| payment_attempt.net_amount.get_order_amount().into());
if request.confirm.unwrap_or(false) {
helpers::validate_customer_id_mandatory_cases(
@@ -348,8 +348,8 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
let amount = request
.amount
.map(Into::into)
- .unwrap_or(payment_attempt.amount);
- payment_attempt.amount = amount;
+ .unwrap_or(payment_attempt.net_amount.get_order_amount());
+ payment_attempt.net_amount.set_order_amount(amount);
payment_intent.amount = amount;
let surcharge_amount = request
.surcharge_details
@@ -783,7 +783,6 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
.update_payment_attempt_with_attempt_id(
payment_data.payment_attempt,
storage::PaymentAttemptUpdate::Update {
- amount: payment_data.amount.into(),
currency: payment_data.currency,
status: get_attempt_status(),
authentication_type: None,
@@ -795,11 +794,17 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
business_sub_label,
amount_to_capture,
capture_method,
- surcharge_amount,
- tax_amount,
fingerprint_id: None,
payment_method_billing_address_id,
updated_by: storage_scheme.to_string(),
+ net_amount:
+ hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
+ payment_data.amount.into(),
+ None,
+ None,
+ surcharge_amount,
+ tax_amount,
+ ),
},
storage_scheme,
)
diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
index 4e020c788b..758a17d3fa 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -89,12 +89,6 @@ impl<F: Send + Clone>
})?
}
- if payment_intent.amount > request.amount {
- Err(errors::ApiErrorResponse::PreconditionFailed {
- message: "Amount should be greater than original authorized amount".to_owned(),
- })?
- }
-
let attempt_id = payment_intent.active_attempt.get_id().clone();
let payment_attempt = db
.find_payment_attempt_by_payment_id_merchant_id_attempt_id(
@@ -106,6 +100,14 @@ impl<F: Send + Clone>
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
+ // Incremental authorization should be performed on an amount greater than the original authorized amount (in this case, greater than the net_amount which is sent for authorization)
+ // request.amount is the total amount that should be authorized in incremental authorization which should be greater than the original authorized amount
+ if payment_attempt.get_total_amount() > request.amount {
+ Err(errors::ApiErrorResponse::PreconditionFailed {
+ message: "Amount should be greater than original authorized amount".to_owned(),
+ })?
+ }
+
let currency = payment_attempt.currency.get_required_value("currency")?;
let amount = payment_attempt.get_total_amount();
@@ -232,7 +234,7 @@ impl<F: Clone> UpdateTracker<F, payments::PaymentData<F>, PaymentsIncrementalAut
error_code: None,
error_message: None,
connector_authorization_id: None,
- previously_authorized_amount: payment_data.payment_intent.amount,
+ previously_authorized_amount: payment_data.payment_attempt.get_total_amount(),
};
let authorization = state
.store
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index c3c4a6d01a..374c568068 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -588,12 +588,9 @@ pub fn make_new_payment_attempt(
payment_id: old_payment_attempt.payment_id,
merchant_id: old_payment_attempt.merchant_id,
status: old_payment_attempt.status,
- amount: old_payment_attempt.amount,
currency: old_payment_attempt.currency,
save_to_locker: old_payment_attempt.save_to_locker,
offer_amount: old_payment_attempt.offer_amount,
- surcharge_amount: old_payment_attempt.surcharge_amount,
- tax_amount: old_payment_attempt.tax_amount,
payment_method_id: old_payment_attempt.payment_method_id,
payment_method: old_payment_attempt.payment_method,
payment_method_type: old_payment_attempt.payment_method_type,
@@ -616,8 +613,7 @@ pub fn make_new_payment_attempt(
last_synced,
profile_id: old_payment_attempt.profile_id,
organization_id: old_payment_attempt.organization_id,
- shipping_cost: old_payment_attempt.shipping_cost,
- net_amount: Default::default(),
+ net_amount: old_payment_attempt.net_amount,
error_message: Default::default(),
cancellation_reason: Default::default(),
error_code: Default::default(),
@@ -646,7 +642,6 @@ pub fn make_new_payment_attempt(
fingerprint_id: Default::default(),
charge_id: Default::default(),
customer_acceptance: Default::default(),
- order_tax_amount: Default::default(),
}
}
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index 04080a4273..c3a7900b43 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -232,7 +232,7 @@ pub fn make_dsl_input(
};
let payment_input = dsl_inputs::PaymentInput {
- amount: payments_dsl_input.payment_intent.amount,
+ amount: payments_dsl_input.payment_attempt.get_total_amount(),
card_bin: payments_dsl_input.payment_method_data.as_ref().and_then(
|pm_data| match pm_data {
domain::PaymentMethodData::Card(card) => {
@@ -864,7 +864,7 @@ pub async fn perform_session_flow_routing(
#[cfg(feature = "v1")]
let payment_input = dsl_inputs::PaymentInput {
- amount: session_input.payment_intent.amount,
+ amount: session_input.payment_attempt.get_total_amount(),
currency: session_input
.payment_intent
.currency
@@ -1159,7 +1159,7 @@ pub fn make_dsl_input_for_surcharge(
};
let payment_input = dsl_inputs::PaymentInput {
- amount: payment_attempt.amount,
+ amount: payment_attempt.get_total_amount(),
// currency is always populated in payment_attempt during payment create
currency: payment_attempt
.currency
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index f96ead676a..0d8322854f 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -703,7 +703,12 @@ where
.as_ref()
.get_required_value("currency")?;
let amount = currency
- .to_currency_base_unit(payment_attempt.amount.get_amount_as_i64())
+ .to_currency_base_unit(
+ payment_attempt
+ .net_amount
+ .get_total_amount()
+ .get_amount_as_i64(),
+ )
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "amount",
})?;
@@ -777,10 +782,11 @@ where
let surcharge_details =
payment_attempt
- .surcharge_amount
+ .net_amount
+ .get_surcharge_amount()
.map(|surcharge_amount| RequestSurchargeDetails {
surcharge_amount,
- tax_amount: payment_attempt.tax_amount,
+ tax_amount: payment_attempt.net_amount.get_tax_on_surcharge(),
});
let merchant_decision = payment_intent.merchant_decision.to_owned();
let frm_message = payment_data.get_frm_message().map(FrmMessage::foreign_from);
@@ -1041,7 +1047,7 @@ where
))?;
Some(PaymentChargeResponse {
- charge_id: payment_attempt.charge_id,
+ charge_id: payment_attempt.charge_id.clone(),
charge_type: payment_charges.charge_type,
application_fees: payment_charges.fees,
transfer_account_id: payment_charges.transfer_account_id,
@@ -1096,7 +1102,8 @@ where
let order_tax_amount = payment_data
.get_payment_attempt()
- .order_tax_amount
+ .net_amount
+ .get_order_tax_amount()
.or_else(|| {
payment_data
.get_payment_intent()
@@ -1124,8 +1131,8 @@ where
payment_id: payment_intent.payment_id,
merchant_id: payment_intent.merchant_id,
status: payment_intent.status,
- amount: payment_attempt.amount,
- net_amount: payment_attempt.net_amount,
+ amount: payment_attempt.net_amount.get_order_amount(),
+ net_amount: payment_attempt.get_total_amount(),
amount_capturable: payment_attempt.amount_capturable,
amount_received: payment_intent.amount_captured,
connector: routed_through,
@@ -1424,7 +1431,7 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay
}
),
// TODO: fill in details based on requirement
- net_amount: pa.net_amount,
+ net_amount: pa.net_amount.get_total_amount(),
amount_received: None,
refunds: None,
disputes: None,
@@ -1690,11 +1697,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
None
}
});
- let amount = payment_data
- .surcharge_details
- .as_ref()
- .map(|surcharge_details| surcharge_details.final_amount)
- .unwrap_or(payment_data.amount.into());
+ let amount = payment_data.payment_attempt.get_total_amount();
let customer_name = additional_data
.customer_data
@@ -1791,11 +1794,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData
fn try_from(additional_data: PaymentAdditionalData<'_, F>) -> Result<Self, Self::Error> {
let payment_data = additional_data.payment_data;
let capture_method = payment_data.get_capture_method();
- let amount = payment_data
- .surcharge_details
- .as_ref()
- .map(|surcharge_details| surcharge_details.final_amount)
- .unwrap_or(payment_data.amount.into());
+ let amount = payment_data.payment_attempt.get_total_amount();
let payment_method_type = payment_data
.payment_attempt
@@ -1936,7 +1935,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCaptureD
let amount_to_capture = payment_data
.payment_attempt
.amount_to_capture
- .map_or(payment_data.amount.into(), |capture_amount| capture_amount);
+ .unwrap_or(payment_data.payment_attempt.get_total_amount());
let browser_info: Option<types::BrowserInformation> = payment_data
.payment_attempt
.browser_info
@@ -1946,7 +1945,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCaptureD
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "browser_info",
})?;
- let amount = MinorUnit::from(payment_data.amount);
+ let amount = payment_data.payment_attempt.get_total_amount();
Ok(Self {
amount_to_capture: amount_to_capture.get_amount_as_i64(), // This should be removed once we start moving to connector module
minor_amount_to_capture: amount_to_capture,
@@ -2005,7 +2004,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsCancelDa
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "browser_info",
})?;
- let amount = MinorUnit::from(payment_data.amount);
+ let amount = payment_data.payment_attempt.get_total_amount();
Ok(Self {
amount: Some(amount.get_amount_as_i64()), // This should be removed once we start moving to connector module
minor_amount: Some(amount),
@@ -2027,7 +2026,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsApproveD
fn try_from(additional_data: PaymentAdditionalData<'_, F>) -> Result<Self, Self::Error> {
let payment_data = additional_data.payment_data;
- let amount = MinorUnit::from(payment_data.amount);
+ let amount = payment_data.payment_attempt.get_total_amount();
Ok(Self {
amount: Some(amount.get_amount_as_i64()), //need to change after we move to connector module
currency: Some(payment_data.currency),
@@ -2058,10 +2057,22 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SdkPaymentsSessi
.ok_or(errors::ApiErrorResponse::MissingRequiredField {
field_name: "order_tax_amount",
})?;
- let amount = payment_data.payment_intent.amount;
-
+ let surcharge_amount = payment_data
+ .surcharge_details
+ .as_ref()
+ .map(|surcharge_details| surcharge_details.get_total_surcharge_amount())
+ .unwrap_or_default();
+ let shipping_cost = payment_data
+ .payment_intent
+ .shipping_cost
+ .unwrap_or_default();
+ // net_amount here would include amount, order_tax_amount, surcharge_amount and shipping_cost
+ let net_amount = payment_data.payment_intent.amount
+ + order_tax_amount
+ + shipping_cost
+ + surcharge_amount;
Ok(Self {
- net_amount: amount + order_tax_amount, //need to change after we move to connector module
+ net_amount,
order_tax_amount,
})
}
@@ -2072,7 +2083,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsRejectDa
fn try_from(additional_data: PaymentAdditionalData<'_, F>) -> Result<Self, Self::Error> {
let payment_data = additional_data.payment_data;
- let amount = MinorUnit::from(payment_data.amount);
+ let amount = payment_data.payment_attempt.get_total_amount();
Ok(Self {
amount: Some(amount.get_amount_as_i64()), //need to change after we move to connector module
currency: Some(payment_data.currency),
@@ -2103,14 +2114,31 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
.collect::<Result<Vec<_>, _>>()
})
.transpose()?;
- let amount = payment_data
+ let surcharge_amount = payment_data
.surcharge_details
.as_ref()
- .map(|surcharge_details| surcharge_details.final_amount)
- .unwrap_or(payment_data.amount.into());
+ .map(|surcharge_details| surcharge_details.get_total_surcharge_amount())
+ .unwrap_or_default();
+ #[cfg(feature = "v1")]
+ let amount = payment_data.payment_intent.amount;
+ #[cfg(feature = "v2")]
+ let amount = payment_data.payment_intent.amount_details.order_amount;
+ #[cfg(feature = "v1")]
+ let shipping_cost = payment_data
+ .payment_intent
+ .shipping_cost
+ .unwrap_or_default();
+ #[cfg(feature = "v2")]
+ let shipping_cost = payment_data
+ .payment_intent
+ .amount_details
+ .shipping_cost
+ .unwrap_or_default();
+ // net_amount here would include amount, surcharge_amount and shipping_cost
+ let net_amount = amount + surcharge_amount + shipping_cost;
Ok(Self {
- amount: amount.get_amount_as_i64(), //need to change once we move to connector module
+ amount: net_amount.get_amount_as_i64(), //need to change once we move to connector module
minor_amount: amount,
currency: payment_data.currency,
country: payment_data.address.get_payment_method_billing().and_then(
@@ -2160,7 +2188,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::SetupMandateRequ
.as_ref()
.map(|customer| customer.clone().into_inner())
});
- let amount = MinorUnit::from(payment_data.amount);
+ let amount = payment_data.payment_attempt.get_total_amount();
Ok(Self {
currency: payment_data.currency,
confirm: true,
@@ -2269,11 +2297,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::CompleteAuthoriz
payload: redirect.json_payload,
}
});
- let amount = payment_data
- .surcharge_details
- .as_ref()
- .map(|surcharge_details| surcharge_details.final_amount)
- .unwrap_or(payment_data.amount.into());
+ let amount = payment_data.payment_attempt.get_total_amount();
let complete_authorize_url = Some(helpers::create_complete_authorize_url(
router_base_url,
attempt,
@@ -2375,11 +2399,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsPreProce
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "browser_info",
})?;
- let amount = payment_data
- .surcharge_details
- .as_ref()
- .map(|surcharge_details| surcharge_details.final_amount)
- .unwrap_or(payment_data.amount.into());
+ let amount = payment_data.payment_attempt.get_total_amount();
Ok(Self {
payment_method_data: payment_method_data.map(From::from),
diff --git a/crates/router/src/core/payments/types.rs b/crates/router/src/core/payments/types.rs
index 01533cefa5..3034b74db4 100644
--- a/crates/router/src/core/payments/types.rs
+++ b/crates/router/src/core/payments/types.rs
@@ -212,8 +212,6 @@ impl ForeignTryFrom<(&SurchargeDetails, &PaymentAttempt)> for SurchargeDetailsRe
.tax_on_surcharge_amount
.get_amount_as_i64(),
)?;
- let display_final_amount = currency
- .to_currency_base_unit_asf64(surcharge_details.final_amount.get_amount_as_i64())?;
let display_total_surcharge_amount = currency.to_currency_base_unit_asf64(
(surcharge_details.surcharge_amount + surcharge_details.tax_on_surcharge_amount)
.get_amount_as_i64(),
@@ -224,7 +222,6 @@ impl ForeignTryFrom<(&SurchargeDetails, &PaymentAttempt)> for SurchargeDetailsRe
display_surcharge_amount,
display_tax_on_surcharge_amount,
display_total_surcharge_amount,
- display_final_amount,
})
}
}
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 7a26048a4d..cf0374fe82 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -178,7 +178,7 @@ pub async fn trigger_refund_to_gateway(
&routed_through,
merchant_account,
key_store,
- (payment_attempt.amount, currency),
+ (payment_attempt.get_total_amount(), currency),
payment_intent,
payment_attempt,
refund,
@@ -521,7 +521,7 @@ pub async fn sync_refund_with_gateway(
&connector_id,
merchant_account,
key_store,
- (payment_attempt.amount, currency),
+ (payment_attempt.get_total_amount(), currency),
payment_intent,
payment_attempt,
refund,
@@ -780,7 +780,7 @@ pub async fn validate_and_create_refund(
let total_amount_captured = payment_intent
.amount_captured
- .unwrap_or(payment_attempt.amount);
+ .unwrap_or(payment_attempt.get_total_amount());
validator::validate_refund_amount(
total_amount_captured.get_amount_as_i64(),
@@ -809,7 +809,7 @@ pub async fn validate_and_create_refund(
connector_transaction_id: connecter_transaction_id.to_string(),
connector,
refund_type: req.refund_type.unwrap_or_default().foreign_into(),
- total_amount: payment_attempt.amount,
+ total_amount: payment_attempt.get_total_amount(),
refund_amount,
currency,
created_at: common_utils::date_time::now(),
diff --git a/crates/router/src/services/kafka/payment_attempt.rs b/crates/router/src/services/kafka/payment_attempt.rs
index 7689492843..e585b21d4b 100644
--- a/crates/router/src/services/kafka/payment_attempt.rs
+++ b/crates/router/src/services/kafka/payment_attempt.rs
@@ -67,14 +67,14 @@ impl<'a> KafkaPaymentAttempt<'a> {
merchant_id: &attempt.merchant_id,
attempt_id: &attempt.attempt_id,
status: attempt.status,
- amount: attempt.amount,
+ amount: attempt.net_amount.get_order_amount(),
currency: attempt.currency,
save_to_locker: attempt.save_to_locker,
connector: attempt.connector.as_ref(),
error_message: attempt.error_message.as_ref(),
offer_amount: attempt.offer_amount,
- surcharge_amount: attempt.surcharge_amount,
- tax_amount: attempt.tax_amount,
+ surcharge_amount: attempt.net_amount.get_surcharge_amount(),
+ tax_amount: attempt.net_amount.get_tax_on_surcharge(),
payment_method_id: attempt.payment_method_id.as_ref(),
payment_method: attempt.payment_method,
connector_transaction_id: attempt.connector_transaction_id.as_ref(),
@@ -98,7 +98,7 @@ impl<'a> KafkaPaymentAttempt<'a> {
multiple_capture_count: attempt.multiple_capture_count,
amount_capturable: attempt.amount_capturable,
merchant_connector_id: attempt.merchant_connector_id.as_ref(),
- net_amount: attempt.net_amount,
+ net_amount: attempt.net_amount.get_total_amount(),
unified_code: attempt.unified_code.as_ref(),
unified_message: attempt.unified_message.as_ref(),
mandate_data: attempt.mandate_data.as_ref(),
diff --git a/crates/router/src/services/kafka/payment_attempt_event.rs b/crates/router/src/services/kafka/payment_attempt_event.rs
index b4d6cd8835..cbce46ad9c 100644
--- a/crates/router/src/services/kafka/payment_attempt_event.rs
+++ b/crates/router/src/services/kafka/payment_attempt_event.rs
@@ -68,14 +68,14 @@ impl<'a> KafkaPaymentAttemptEvent<'a> {
merchant_id: &attempt.merchant_id,
attempt_id: &attempt.attempt_id,
status: attempt.status,
- amount: attempt.amount,
+ amount: attempt.net_amount.get_order_amount(),
currency: attempt.currency,
save_to_locker: attempt.save_to_locker,
connector: attempt.connector.as_ref(),
error_message: attempt.error_message.as_ref(),
offer_amount: attempt.offer_amount,
- surcharge_amount: attempt.surcharge_amount,
- tax_amount: attempt.tax_amount,
+ surcharge_amount: attempt.net_amount.get_surcharge_amount(),
+ tax_amount: attempt.net_amount.get_tax_on_surcharge(),
payment_method_id: attempt.payment_method_id.as_ref(),
payment_method: attempt.payment_method,
connector_transaction_id: attempt.connector_transaction_id.as_ref(),
@@ -99,7 +99,7 @@ impl<'a> KafkaPaymentAttemptEvent<'a> {
multiple_capture_count: attempt.multiple_capture_count,
amount_capturable: attempt.amount_capturable,
merchant_connector_id: attempt.merchant_connector_id.as_ref(),
- net_amount: attempt.net_amount,
+ net_amount: attempt.net_amount.get_total_amount(),
unified_code: attempt.unified_code.as_ref(),
unified_message: attempt.unified_message.as_ref(),
mandate_data: attempt.mandate_data.as_ref(),
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 548d216d6e..11f63d6c02 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -252,15 +252,16 @@ pub trait Capturable {
}
impl Capturable for PaymentsAuthorizeData {
- fn get_captured_amount<F>(&self, _payment_data: &PaymentData<F>) -> Option<i64>
+ fn get_captured_amount<F>(&self, payment_data: &PaymentData<F>) -> Option<i64>
where
F: Clone,
{
- let final_amount = self
- .surcharge_details
- .as_ref()
- .map(|surcharge_details| surcharge_details.final_amount.get_amount_as_i64());
- final_amount.or(Some(self.amount))
+ Some(
+ payment_data
+ .payment_attempt
+ .get_total_amount()
+ .get_amount_as_i64(),
+ )
}
fn get_amount_capturable<F>(
@@ -331,11 +332,16 @@ impl Capturable for PaymentsCaptureData {
}
impl Capturable for CompleteAuthorizeData {
- fn get_captured_amount<F>(&self, _payment_data: &PaymentData<F>) -> Option<i64>
+ fn get_captured_amount<F>(&self, payment_data: &PaymentData<F>) -> Option<i64>
where
F: Clone,
{
- Some(self.amount)
+ Some(
+ payment_data
+ .payment_attempt
+ .get_total_amount()
+ .get_amount_as_i64(),
+ )
}
fn get_amount_capturable<F>(
&self,
diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs
index f6caa64fe6..88d9b433ec 100644
--- a/crates/router/src/types/storage/payment_attempt.rs
+++ b/crates/router/src/types/storage/payment_attempt.rs
@@ -79,12 +79,14 @@ impl PaymentAttemptExt for PaymentAttempt {
#[cfg(feature = "v1")]
fn get_surcharge_details(&self) -> Option<api_models::payments::RequestSurchargeDetails> {
- self.surcharge_amount.map(|surcharge_amount| {
- api_models::payments::RequestSurchargeDetails {
- surcharge_amount,
- tax_amount: self.tax_amount,
- }
- })
+ self.net_amount
+ .get_surcharge_amount()
+ .map(
+ |surcharge_amount| api_models::payments::RequestSurchargeDetails {
+ surcharge_amount,
+ tax_amount: self.net_amount.get_tax_on_surcharge(),
+ },
+ )
}
#[cfg(feature = "v2")]
@@ -94,9 +96,7 @@ impl PaymentAttemptExt for PaymentAttempt {
#[cfg(feature = "v1")]
fn get_total_amount(&self) -> MinorUnit {
- self.amount
- + self.surcharge_amount.unwrap_or_default()
- + self.tax_amount.unwrap_or_default()
+ self.net_amount.get_total_amount()
}
#[cfg(feature = "v2")]
@@ -167,14 +167,11 @@ mod tests {
merchant_id: Default::default(),
attempt_id: Default::default(),
status: Default::default(),
- amount: Default::default(),
net_amount: Default::default(),
currency: Default::default(),
save_to_locker: Default::default(),
error_message: Default::default(),
offer_amount: Default::default(),
- surcharge_amount: Default::default(),
- tax_amount: Default::default(),
payment_method_id: Default::default(),
payment_method: Default::default(),
capture_method: Default::default(),
@@ -218,8 +215,6 @@ mod tests {
customer_acceptance: Default::default(),
profile_id: common_utils::generate_profile_id_of_default_length(),
organization_id: Default::default(),
- shipping_cost: Default::default(),
- order_tax_amount: Default::default(),
};
let store = state
@@ -255,14 +250,11 @@ mod tests {
modified_at: current_time.into(),
attempt_id: attempt_id.clone(),
status: Default::default(),
- amount: Default::default(),
net_amount: Default::default(),
currency: Default::default(),
save_to_locker: Default::default(),
error_message: Default::default(),
offer_amount: Default::default(),
- surcharge_amount: Default::default(),
- tax_amount: Default::default(),
payment_method_id: Default::default(),
payment_method: Default::default(),
capture_method: Default::default(),
@@ -306,8 +298,6 @@ mod tests {
customer_acceptance: Default::default(),
profile_id: common_utils::generate_profile_id_of_default_length(),
organization_id: Default::default(),
- shipping_cost: Default::default(),
- order_tax_amount: Default::default(),
};
let store = state
.stores
@@ -357,14 +347,11 @@ mod tests {
mandate_id: Some("man_121212".to_string()),
attempt_id: uuid.clone(),
status: Default::default(),
- amount: Default::default(),
net_amount: Default::default(),
currency: Default::default(),
save_to_locker: Default::default(),
error_message: Default::default(),
offer_amount: Default::default(),
- surcharge_amount: Default::default(),
- tax_amount: Default::default(),
payment_method_id: Default::default(),
payment_method: Default::default(),
capture_method: Default::default(),
@@ -407,8 +394,6 @@ mod tests {
customer_acceptance: Default::default(),
profile_id: common_utils::generate_profile_id_of_default_length(),
organization_id: Default::default(),
- shipping_cost: Default::default(),
- order_tax_amount: Default::default(),
};
let store = state
.stores
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 49d8d50442..4d753b59bc 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -1295,7 +1295,7 @@ impl ForeignFrom<storage::PaymentAttempt> for payments::PaymentAttemptResponse {
Self {
attempt_id: payment_attempt.attempt_id,
status: payment_attempt.status,
- amount: payment_attempt.amount,
+ amount: payment_attempt.net_amount.get_order_amount(),
currency: payment_attempt.currency,
connector: payment_attempt.connector,
error_message: payment_attempt.error_reason,
@@ -1550,7 +1550,8 @@ impl
currency: payment_attempt.map(|pa| pa.currency.unwrap_or_default()),
shipping: shipping.map(api_types::Address::from),
billing: billing_address,
- amount: payment_attempt.map(|pa| api_types::Amount::from(pa.amount)),
+ amount: payment_attempt
+ .map(|pa| api_types::Amount::from(pa.net_amount.get_order_amount())),
email: customer
.and_then(|cust| cust.email.as_ref().map(|em| pii::Email::from(em.clone())))
.or(customer_details_from_pi.clone().and_then(|cd| cd.email)),
diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs
index c37f9f6d3d..13c75e005c 100644
--- a/crates/storage_impl/src/mock_db/payment_attempt.rs
+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs
@@ -123,21 +123,17 @@ impl PaymentAttemptInterface for MockDb {
) -> CustomResult<PaymentAttempt, StorageError> {
let mut payment_attempts = self.payment_attempts.lock().await;
let time = common_utils::date_time::now();
- let payment_attempt = payment_attempt.populate_derived_fields();
let payment_attempt = PaymentAttempt {
payment_id: payment_attempt.payment_id,
merchant_id: payment_attempt.merchant_id,
attempt_id: payment_attempt.attempt_id,
status: payment_attempt.status,
- amount: payment_attempt.amount,
net_amount: payment_attempt.net_amount,
currency: payment_attempt.currency,
save_to_locker: payment_attempt.save_to_locker,
connector: payment_attempt.connector,
error_message: payment_attempt.error_message,
offer_amount: payment_attempt.offer_amount,
- surcharge_amount: payment_attempt.surcharge_amount,
- tax_amount: payment_attempt.tax_amount,
payment_method_id: payment_attempt.payment_method_id,
payment_method: payment_attempt.payment_method,
connector_transaction_id: None,
@@ -185,8 +181,6 @@ impl PaymentAttemptInterface for MockDb {
customer_acceptance: payment_attempt.customer_acceptance,
organization_id: payment_attempt.organization_id,
profile_id: payment_attempt.profile_id,
- shipping_cost: payment_attempt.shipping_cost,
- order_tax_amount: payment_attempt.order_tax_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 63f5a0ff9f..9053b7561a 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -9,7 +9,6 @@ use diesel_models::{
kv,
payment_attempt::{
PaymentAttempt as DieselPaymentAttempt, PaymentAttemptNew as DieselPaymentAttemptNew,
- PaymentAttemptUpdate as DieselPaymentAttemptUpdate,
},
reverse_lookup::{ReverseLookup, ReverseLookupNew},
};
@@ -459,7 +458,6 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
.await
}
MerchantStorageScheme::RedisKv => {
- let payment_attempt = payment_attempt.populate_derived_fields();
let merchant_id = payment_attempt.merchant_id.clone();
let payment_id = payment_attempt.payment_id.clone();
let key = PartitionKey::MerchantIdPaymentId {
@@ -472,15 +470,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
merchant_id: payment_attempt.merchant_id.clone(),
attempt_id: payment_attempt.attempt_id.clone(),
status: payment_attempt.status,
- amount: payment_attempt.amount,
- net_amount: payment_attempt.net_amount,
+ net_amount: payment_attempt.net_amount.clone(),
currency: payment_attempt.currency,
save_to_locker: payment_attempt.save_to_locker,
connector: payment_attempt.connector.clone(),
error_message: payment_attempt.error_message.clone(),
offer_amount: payment_attempt.offer_amount,
- surcharge_amount: payment_attempt.surcharge_amount,
- tax_amount: payment_attempt.tax_amount,
payment_method_id: payment_attempt.payment_method_id.clone(),
payment_method: payment_attempt.payment_method,
connector_transaction_id: None,
@@ -534,8 +529,6 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
customer_acceptance: payment_attempt.customer_acceptance.clone(),
organization_id: payment_attempt.organization_id.clone(),
profile_id: payment_attempt.profile_id.clone(),
- shipping_cost: payment_attempt.shipping_cost,
- order_tax_amount: payment_attempt.order_tax_amount,
};
let field = format!("pa_{}", created_attempt.attempt_id);
@@ -1379,15 +1372,15 @@ impl DataModelExt for PaymentAttempt {
merchant_id: self.merchant_id,
attempt_id: self.attempt_id,
status: self.status,
- amount: self.amount,
- net_amount: Some(self.net_amount),
+ amount: self.net_amount.get_order_amount(),
+ net_amount: Some(self.net_amount.get_total_amount()),
currency: self.currency,
save_to_locker: self.save_to_locker,
connector: self.connector,
error_message: self.error_message,
offer_amount: self.offer_amount,
- surcharge_amount: self.surcharge_amount,
- tax_amount: self.tax_amount,
+ surcharge_amount: self.net_amount.get_surcharge_amount(),
+ tax_amount: self.net_amount.get_tax_on_surcharge(),
payment_method_id: self.payment_method_id,
payment_method: self.payment_method,
connector_transaction_id: self.connector_transaction_id,
@@ -1444,26 +1437,29 @@ impl DataModelExt for PaymentAttempt {
customer_acceptance: self.customer_acceptance,
organization_id: self.organization_id,
profile_id: self.profile_id,
- shipping_cost: self.shipping_cost,
- order_tax_amount: self.order_tax_amount,
+ shipping_cost: self.net_amount.get_shipping_cost(),
+ order_tax_amount: self.net_amount.get_order_tax_amount(),
}
}
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
Self {
- net_amount: storage_model.get_or_calculate_net_amount(),
+ net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
+ storage_model.amount,
+ storage_model.shipping_cost,
+ storage_model.order_tax_amount,
+ storage_model.surcharge_amount,
+ storage_model.tax_amount,
+ ),
payment_id: storage_model.payment_id,
merchant_id: storage_model.merchant_id,
attempt_id: storage_model.attempt_id,
status: storage_model.status,
- amount: storage_model.amount,
currency: storage_model.currency,
save_to_locker: storage_model.save_to_locker,
connector: storage_model.connector,
error_message: storage_model.error_message,
offer_amount: storage_model.offer_amount,
- surcharge_amount: storage_model.surcharge_amount,
- tax_amount: storage_model.tax_amount,
payment_method_id: storage_model.payment_method_id,
payment_method: storage_model.payment_method,
connector_transaction_id: storage_model.connector_transaction_id,
@@ -1515,8 +1511,6 @@ impl DataModelExt for PaymentAttempt {
customer_acceptance: storage_model.customer_acceptance,
organization_id: storage_model.organization_id,
profile_id: storage_model.profile_id,
- shipping_cost: storage_model.shipping_cost,
- order_tax_amount: storage_model.order_tax_amount,
}
}
}
@@ -1527,19 +1521,19 @@ impl DataModelExt for PaymentAttemptNew {
fn to_storage_model(self) -> Self::StorageModel {
DieselPaymentAttemptNew {
- net_amount: Some(self.net_amount),
+ net_amount: Some(self.net_amount.get_total_amount()),
payment_id: self.payment_id,
merchant_id: self.merchant_id,
attempt_id: self.attempt_id,
status: self.status,
- amount: self.amount,
+ amount: self.net_amount.get_order_amount(),
currency: self.currency,
save_to_locker: self.save_to_locker,
connector: self.connector,
error_message: self.error_message,
offer_amount: self.offer_amount,
- surcharge_amount: self.surcharge_amount,
- tax_amount: self.tax_amount,
+ surcharge_amount: self.net_amount.get_surcharge_amount(),
+ tax_amount: self.net_amount.get_tax_on_surcharge(),
payment_method_id: self.payment_method_id,
payment_method: self.payment_method,
capture_method: self.capture_method,
@@ -1597,26 +1591,29 @@ impl DataModelExt for PaymentAttemptNew {
customer_acceptance: self.customer_acceptance,
organization_id: self.organization_id,
profile_id: self.profile_id,
- shipping_cost: self.shipping_cost,
- order_tax_amount: self.order_tax_amount,
+ shipping_cost: self.net_amount.get_shipping_cost(),
+ order_tax_amount: self.net_amount.get_order_tax_amount(),
}
}
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
Self {
- net_amount: storage_model.get_or_calculate_net_amount(),
+ net_amount: hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
+ storage_model.amount,
+ storage_model.shipping_cost,
+ storage_model.order_tax_amount,
+ storage_model.surcharge_amount,
+ storage_model.tax_amount,
+ ),
payment_id: storage_model.payment_id,
merchant_id: storage_model.merchant_id,
attempt_id: storage_model.attempt_id,
status: storage_model.status,
- amount: storage_model.amount,
currency: storage_model.currency,
save_to_locker: storage_model.save_to_locker,
connector: storage_model.connector,
error_message: storage_model.error_message,
offer_amount: storage_model.offer_amount,
- surcharge_amount: storage_model.surcharge_amount,
- tax_amount: storage_model.tax_amount,
payment_method_id: storage_model.payment_method_id,
payment_method: storage_model.payment_method,
capture_method: storage_model.capture_method,
@@ -1667,725 +1664,6 @@ impl DataModelExt for PaymentAttemptNew {
customer_acceptance: storage_model.customer_acceptance,
organization_id: storage_model.organization_id,
profile_id: storage_model.profile_id,
- shipping_cost: storage_model.shipping_cost,
- order_tax_amount: storage_model.order_tax_amount,
- }
- }
-}
-
-#[cfg(feature = "v1")]
-impl DataModelExt for PaymentAttemptUpdate {
- type StorageModel = DieselPaymentAttemptUpdate;
-
- fn to_storage_model(self) -> Self::StorageModel {
- match self {
- Self::Update {
- amount,
- currency,
- status,
- authentication_type,
- payment_method,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- amount_to_capture,
- capture_method,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- payment_method_billing_address_id,
- updated_by,
- } => DieselPaymentAttemptUpdate::Update {
- amount,
- currency,
- status,
- authentication_type,
- payment_method,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- amount_to_capture,
- capture_method,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- payment_method_billing_address_id,
- updated_by,
- },
- Self::UpdateTrackers {
- payment_token,
- connector,
- straight_through_algorithm,
- amount_capturable,
- updated_by,
- surcharge_amount,
- tax_amount,
- merchant_connector_id,
- } => DieselPaymentAttemptUpdate::UpdateTrackers {
- payment_token,
- connector,
- straight_through_algorithm,
- amount_capturable,
- surcharge_amount,
- tax_amount,
- updated_by,
- merchant_connector_id,
- },
- Self::AuthenticationTypeUpdate {
- authentication_type,
- updated_by,
- } => DieselPaymentAttemptUpdate::AuthenticationTypeUpdate {
- authentication_type,
- updated_by,
- },
- Self::BlocklistUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- } => DieselPaymentAttemptUpdate::BlocklistUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- },
- Self::PaymentMethodDetailsUpdate {
- payment_method_id,
- updated_by,
- } => DieselPaymentAttemptUpdate::PaymentMethodDetailsUpdate {
- payment_method_id,
- updated_by,
- },
- Self::ConfirmUpdate {
- amount,
- currency,
- status,
- authentication_type,
- capture_method,
- payment_method,
- browser_info,
- connector,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- straight_through_algorithm,
- error_code,
- error_message,
- amount_capturable,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- updated_by,
- merchant_connector_id: connector_id,
- payment_method_id,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- payment_method_billing_address_id,
- client_source,
- client_version,
- customer_acceptance,
- shipping_cost,
- order_tax_amount,
- } => DieselPaymentAttemptUpdate::ConfirmUpdate {
- amount,
- currency,
- status,
- authentication_type,
- capture_method,
- payment_method,
- browser_info,
- connector,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- straight_through_algorithm,
- error_code,
- error_message,
- amount_capturable,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- updated_by,
- merchant_connector_id: connector_id,
- payment_method_id,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- payment_method_billing_address_id,
- client_source,
- client_version,
- customer_acceptance,
- shipping_cost,
- order_tax_amount,
- },
- Self::VoidUpdate {
- status,
- cancellation_reason,
- updated_by,
- } => DieselPaymentAttemptUpdate::VoidUpdate {
- status,
- cancellation_reason,
- updated_by,
- },
- Self::ResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- authentication_type,
- payment_method_id,
- mandate_id,
- connector_metadata,
- payment_token,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- amount_capturable,
- updated_by,
- authentication_data,
- encoded_data,
- unified_code,
- unified_message,
- payment_method_data,
- charge_id,
- } => DieselPaymentAttemptUpdate::ResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- authentication_type,
- payment_method_id,
- mandate_id,
- connector_metadata,
- payment_token,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- amount_capturable,
- updated_by,
- authentication_data,
- encoded_data,
- unified_code,
- unified_message,
- payment_method_data,
- charge_id,
- },
- Self::UnresolvedResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- payment_method_id,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- updated_by,
- } => DieselPaymentAttemptUpdate::UnresolvedResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- payment_method_id,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- updated_by,
- },
- Self::StatusUpdate { status, updated_by } => {
- DieselPaymentAttemptUpdate::StatusUpdate { status, updated_by }
- }
- Self::ErrorUpdate {
- connector,
- status,
- error_code,
- error_message,
- error_reason,
- amount_capturable,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- payment_method_data,
- authentication_type,
- } => DieselPaymentAttemptUpdate::ErrorUpdate {
- connector,
- status,
- error_code,
- error_message,
- error_reason,
- amount_capturable,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- payment_method_data,
- authentication_type,
- },
- Self::CaptureUpdate {
- multiple_capture_count,
- updated_by,
- amount_to_capture,
- } => DieselPaymentAttemptUpdate::CaptureUpdate {
- multiple_capture_count,
- updated_by,
- amount_to_capture,
- },
- Self::PreprocessingUpdate {
- status,
- payment_method_id,
- connector_metadata,
- preprocessing_step_id,
- connector_transaction_id,
- connector_response_reference_id,
- updated_by,
- } => DieselPaymentAttemptUpdate::PreprocessingUpdate {
- status,
- payment_method_id,
- connector_metadata,
- preprocessing_step_id,
- connector_transaction_id,
- connector_response_reference_id,
- updated_by,
- },
- Self::RejectUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- } => DieselPaymentAttemptUpdate::RejectUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- },
- Self::AmountToCaptureUpdate {
- status,
- amount_capturable,
- updated_by,
- } => DieselPaymentAttemptUpdate::AmountToCaptureUpdate {
- status,
- amount_capturable,
- updated_by,
- },
- Self::ConnectorResponse {
- authentication_data,
- encoded_data,
- connector_transaction_id,
- connector,
- charge_id,
- updated_by,
- } => DieselPaymentAttemptUpdate::ConnectorResponse {
- authentication_data,
- encoded_data,
- connector_transaction_id,
- connector,
- charge_id,
- updated_by,
- },
- Self::IncrementalAuthorizationAmountUpdate {
- amount,
- amount_capturable,
- } => DieselPaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
- amount,
- amount_capturable,
- },
- Self::AuthenticationUpdate {
- status,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- updated_by,
- } => DieselPaymentAttemptUpdate::AuthenticationUpdate {
- status,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- updated_by,
- },
- Self::ManualUpdate {
- status,
- error_code,
- error_message,
- error_reason,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- } => DieselPaymentAttemptUpdate::ManualUpdate {
- status,
- error_code,
- error_message,
- error_reason,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- },
- }
- }
-
- fn from_storage_model(storage_model: Self::StorageModel) -> Self {
- match storage_model {
- DieselPaymentAttemptUpdate::Update {
- amount,
- currency,
- status,
- authentication_type,
- payment_method,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- amount_to_capture,
- capture_method,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- updated_by,
- payment_method_billing_address_id,
- } => Self::Update {
- amount,
- currency,
- status,
- authentication_type,
- payment_method,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- amount_to_capture,
- capture_method,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- payment_method_billing_address_id,
- updated_by,
- },
- DieselPaymentAttemptUpdate::UpdateTrackers {
- payment_token,
- connector,
- straight_through_algorithm,
- amount_capturable,
- updated_by,
- surcharge_amount,
- tax_amount,
- merchant_connector_id: connector_id,
- } => Self::UpdateTrackers {
- payment_token,
- connector,
- straight_through_algorithm,
- amount_capturable,
- surcharge_amount,
- tax_amount,
- updated_by,
- merchant_connector_id: connector_id,
- },
- DieselPaymentAttemptUpdate::AuthenticationTypeUpdate {
- authentication_type,
- updated_by,
- } => Self::AuthenticationTypeUpdate {
- authentication_type,
- updated_by,
- },
- DieselPaymentAttemptUpdate::ConfirmUpdate {
- amount,
- currency,
- status,
- authentication_type,
- capture_method,
- payment_method,
- browser_info,
- connector,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- straight_through_algorithm,
- error_code,
- error_message,
- amount_capturable,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- updated_by,
- merchant_connector_id: connector_id,
- payment_method_id,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- payment_method_billing_address_id,
- client_source,
- client_version,
- customer_acceptance,
- shipping_cost,
- order_tax_amount,
- } => Self::ConfirmUpdate {
- amount,
- currency,
- status,
- authentication_type,
- capture_method,
- payment_method,
- browser_info,
- connector,
- payment_token,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- straight_through_algorithm,
- error_code,
- error_message,
- amount_capturable,
- surcharge_amount,
- tax_amount,
- fingerprint_id,
- updated_by,
- merchant_connector_id: connector_id,
- payment_method_id,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- payment_method_billing_address_id,
- client_source,
- client_version,
- customer_acceptance,
- shipping_cost,
- order_tax_amount,
- },
- DieselPaymentAttemptUpdate::VoidUpdate {
- status,
- cancellation_reason,
- updated_by,
- } => Self::VoidUpdate {
- status,
- cancellation_reason,
- updated_by,
- },
- DieselPaymentAttemptUpdate::BlocklistUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- } => Self::BlocklistUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- },
- DieselPaymentAttemptUpdate::PaymentMethodDetailsUpdate {
- payment_method_id,
- updated_by,
- } => Self::PaymentMethodDetailsUpdate {
- payment_method_id,
- updated_by,
- },
- DieselPaymentAttemptUpdate::ResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- authentication_type,
- payment_method_id,
- mandate_id,
- connector_metadata,
- payment_token,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- amount_capturable,
- updated_by,
- authentication_data,
- encoded_data,
- unified_code,
- unified_message,
- payment_method_data,
- charge_id,
- } => Self::ResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- authentication_type,
- payment_method_id,
- mandate_id,
- connector_metadata,
- payment_token,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- amount_capturable,
- updated_by,
- authentication_data,
- encoded_data,
- unified_code,
- unified_message,
- payment_method_data,
- charge_id,
- },
- DieselPaymentAttemptUpdate::UnresolvedResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- payment_method_id,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- updated_by,
- } => Self::UnresolvedResponseUpdate {
- status,
- connector,
- connector_transaction_id,
- payment_method_id,
- error_code,
- error_message,
- error_reason,
- connector_response_reference_id,
- updated_by,
- },
- DieselPaymentAttemptUpdate::StatusUpdate { status, updated_by } => {
- Self::StatusUpdate { status, updated_by }
- }
- DieselPaymentAttemptUpdate::ErrorUpdate {
- connector,
- status,
- error_code,
- error_message,
- error_reason,
- amount_capturable,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- payment_method_data,
- authentication_type,
- } => Self::ErrorUpdate {
- connector,
- status,
- error_code,
- error_message,
- error_reason,
- amount_capturable,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- payment_method_data,
- authentication_type,
- },
- DieselPaymentAttemptUpdate::CaptureUpdate {
- amount_to_capture,
- multiple_capture_count,
- updated_by,
- } => Self::CaptureUpdate {
- amount_to_capture,
- multiple_capture_count,
- updated_by,
- },
- DieselPaymentAttemptUpdate::PreprocessingUpdate {
- status,
- payment_method_id,
- connector_metadata,
- preprocessing_step_id,
- connector_transaction_id,
- connector_response_reference_id,
- updated_by,
- } => Self::PreprocessingUpdate {
- status,
- payment_method_id,
- connector_metadata,
- preprocessing_step_id,
- connector_transaction_id,
- connector_response_reference_id,
- updated_by,
- },
- DieselPaymentAttemptUpdate::RejectUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- } => Self::RejectUpdate {
- status,
- error_code,
- error_message,
- updated_by,
- },
- DieselPaymentAttemptUpdate::AmountToCaptureUpdate {
- status,
- amount_capturable,
- updated_by,
- } => Self::AmountToCaptureUpdate {
- status,
- amount_capturable,
- updated_by,
- },
- DieselPaymentAttemptUpdate::ConnectorResponse {
- authentication_data,
- encoded_data,
- connector_transaction_id,
- connector,
- charge_id,
- updated_by,
- } => Self::ConnectorResponse {
- authentication_data,
- encoded_data,
- connector_transaction_id,
- connector,
- charge_id,
- updated_by,
- },
- DieselPaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
- amount,
- amount_capturable,
- } => Self::IncrementalAuthorizationAmountUpdate {
- amount,
- amount_capturable,
- },
- DieselPaymentAttemptUpdate::AuthenticationUpdate {
- status,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- updated_by,
- } => Self::AuthenticationUpdate {
- status,
- external_three_ds_authentication_attempted,
- authentication_connector,
- authentication_id,
- updated_by,
- },
- DieselPaymentAttemptUpdate::ManualUpdate {
- status,
- error_code,
- error_message,
- error_reason,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- } => Self::ManualUpdate {
- status,
- error_code,
- error_message,
- error_reason,
- updated_by,
- unified_code,
- unified_message,
- connector_transaction_id,
- },
}
}
}