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(core): Update shipping_cost and order_tax_amount to net_amount of payment_attempt (#5844)

Swangi Kumari840609af61ad
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json
index b80319add8..bda5fab29c 100644
--- a/api-reference-v2/openapi_spec.json
+++ b/api-reference-v2/openapi_spec.json
@@ -13030,7 +13030,7 @@
"net_amount": {
"type": "integer",
"format": "int64",
- "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount,\nIf no surcharge_details, net_amount = amount",
+ "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount + shipping_cost + order_tax_amount,\nIf no surcharge_details, shipping_cost, order_tax_amount, net_amount = amount",
"example": 6540
},
"amount_capturable": {
@@ -13502,6 +13502,66 @@
"example": "Custom_Order_id_123",
"nullable": true,
"maxLength": 255
+ },
+ "order_tax_amount": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
+ }
+ }
+ },
+ "PaymentsDynamicTaxCalculationRequest": {
+ "type": "object",
+ "required": [
+ "shipping",
+ "client_secret",
+ "payment_method_type"
+ ],
+ "properties": {
+ "shipping": {
+ "$ref": "#/components/schemas/Address"
+ },
+ "client_secret": {
+ "type": "string",
+ "description": "Client Secret"
+ },
+ "payment_method_type": {
+ "$ref": "#/components/schemas/PaymentMethodType"
+ }
+ }
+ },
+ "PaymentsDynamicTaxCalculationResponse": {
+ "type": "object",
+ "required": [
+ "payment_id",
+ "net_amount"
+ ],
+ "properties": {
+ "payment_id": {
+ "type": "string",
+ "description": "The identifier for the payment"
+ },
+ "net_amount": {
+ "$ref": "#/components/schemas/MinorUnit"
+ },
+ "order_tax_amount": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
+ },
+ "shipping_cost": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -14095,7 +14155,7 @@
"net_amount": {
"type": "integer",
"format": "int64",
- "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount,\nIf no surcharge_details, net_amount = amount",
+ "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount + shipping_cost + order_tax_amount,\nIf no surcharge_details, shipping_cost, order_tax_amount, net_amount = amount",
"example": 6540
},
"amount_capturable": {
@@ -14592,6 +14652,14 @@
"example": "Custom_Order_id_123",
"nullable": true,
"maxLength": 255
+ },
+ "order_tax_amount": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
}
}
},
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 58d11fc49a..9d6074fe16 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -17028,7 +17028,7 @@
"net_amount": {
"type": "integer",
"format": "int64",
- "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount,\nIf no surcharge_details, net_amount = amount",
+ "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount + shipping_cost + order_tax_amount,\nIf no surcharge_details, shipping_cost, order_tax_amount, net_amount = amount",
"example": 6540
},
"amount_capturable": {
@@ -17500,6 +17500,14 @@
"example": "Custom_Order_id_123",
"nullable": true,
"maxLength": 255
+ },
+ "order_tax_amount": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -17523,6 +17531,38 @@
}
}
},
+ "PaymentsDynamicTaxCalculationResponse": {
+ "type": "object",
+ "required": [
+ "payment_id",
+ "net_amount"
+ ],
+ "properties": {
+ "payment_id": {
+ "type": "string",
+ "description": "The identifier for the payment"
+ },
+ "net_amount": {
+ "$ref": "#/components/schemas/MinorUnit"
+ },
+ "order_tax_amount": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
+ },
+ "shipping_cost": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
+ }
+ }
+ },
"PaymentsExternalAuthenticationRequest": {
"type": "object",
"required": [
@@ -18113,7 +18153,7 @@
"net_amount": {
"type": "integer",
"format": "int64",
- "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount,\nIf no surcharge_details, net_amount = amount",
+ "description": "The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount + shipping_cost + order_tax_amount,\nIf no surcharge_details, shipping_cost, order_tax_amount, net_amount = amount",
"example": 6540
},
"amount_capturable": {
@@ -18610,6 +18650,14 @@
"example": "Custom_Order_id_123",
"nullable": true,
"maxLength": 255
+ },
+ "order_tax_amount": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/MinorUnit"
+ }
+ ],
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index d09df597d8..abd795361b 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -3719,8 +3719,8 @@ pub struct PaymentsResponse {
#[schema(value_type = i64, example = 6540)]
pub amount: MinorUnit,
- /// The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount,
- /// If no surcharge_details, net_amount = amount
+ /// The payment net amount. net_amount = amount + surcharge_details.surcharge_amount + surcharge_details.tax_amount + shipping_cost + order_tax_amount,
+ /// If no surcharge_details, shipping_cost, order_tax_amount, net_amount = amount
#[schema(value_type = i64, example = 6540)]
pub net_amount: MinorUnit,
@@ -4020,6 +4020,8 @@ pub struct PaymentsResponse {
example = "Custom_Order_id_123"
)]
pub merchant_order_reference_id: Option<String>,
+ /// order tax amount calculated by tax connectors
+ pub order_tax_amount: Option<MinorUnit>,
}
/// Fee information to be charged on the payment being collected
@@ -4608,8 +4610,15 @@ pub struct PaymentsDynamicTaxCalculationRequest {
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct PaymentsDynamicTaxCalculationResponse {
- /// net amount
+ /// The identifier for the payment
+ #[schema(value_type = String)]
+ pub payment_id: id_type::PaymentId,
+ /// net amount = amount + order_tax_amount + shipping_cost
pub net_amount: MinorUnit,
+ /// order tax amount calculated by tax connectors
+ pub order_tax_amount: Option<MinorUnit>,
+ /// shipping cost for the order
+ pub shipping_cost: Option<MinorUnit>,
}
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 4e57ec3420..152037d55f 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -1,4 +1,4 @@
-use common_utils::{id_type, pii};
+use common_utils::{id_type, pii, types::MinorUnit};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
@@ -81,6 +81,8 @@ pub struct PaymentAttempt {
pub profile_id: id_type::ProfileId,
pub organization_id: id_type::OrganizationId,
pub card_network: Option<String>,
+ pub shipping_cost: Option<MinorUnit>,
+ pub order_tax_amount: Option<MinorUnit>,
}
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
@@ -155,12 +157,27 @@ pub struct PaymentAttempt {
pub profile_id: id_type::ProfileId,
pub organization_id: id_type::OrganizationId,
pub card_network: Option<String>,
+ pub shipping_cost: Option<MinorUnit>,
+ pub order_tax_amount: Option<MinorUnit>,
}
impl PaymentAttempt {
pub fn get_or_calculate_net_amount(&self) -> i64 {
+ let shipping_cost = self
+ .shipping_cost
+ .unwrap_or(MinorUnit::new(0))
+ .get_amount_as_i64();
+ let order_tax_amount = self
+ .order_tax_amount
+ .unwrap_or(MinorUnit::new(0))
+ .get_amount_as_i64();
+
self.net_amount.unwrap_or(
- self.amount + self.surcharge_amount.unwrap_or(0) + self.tax_amount.unwrap_or(0),
+ self.amount
+ + self.surcharge_amount.unwrap_or(0)
+ + self.tax_amount.unwrap_or(0)
+ + shipping_cost
+ + order_tax_amount,
)
}
}
@@ -240,12 +257,22 @@ pub struct PaymentAttemptNew {
pub profile_id: id_type::ProfileId,
pub organization_id: id_type::OrganizationId,
pub card_network: Option<String>,
+ pub shipping_cost: Option<MinorUnit>,
+ pub order_tax_amount: Option<MinorUnit>,
}
impl PaymentAttemptNew {
- /// returns amount + surcharge_amount + tax_amount
+ /// returns amount + surcharge_amount + tax_amount (surcharge) + shipping_cost + order_tax_amount
pub fn calculate_net_amount(&self) -> i64 {
- self.amount + self.surcharge_amount.unwrap_or(0) + self.tax_amount.unwrap_or(0)
+ let shipping_cost = self
+ .shipping_cost
+ .unwrap_or(MinorUnit::new(0))
+ .get_amount_as_i64();
+
+ self.amount
+ + self.surcharge_amount.unwrap_or(0)
+ + self.tax_amount.unwrap_or(0)
+ + shipping_cost
}
pub fn get_or_calculate_net_amount(&self) -> i64 {
@@ -326,6 +353,8 @@ 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>,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
@@ -499,11 +528,23 @@ pub struct PaymentAttemptUpdateInternal {
client_version: Option<String>,
customer_acceptance: Option<pii::SecretSerdeValue>,
card_network: Option<String>,
+ shipping_cost: Option<MinorUnit>,
+ order_tax_amount: Option<MinorUnit>,
}
impl PaymentAttemptUpdateInternal {
pub fn populate_derived_fields(self, source: &PaymentAttempt) -> Self {
let mut update_internal = self;
+ let shipping_cost = update_internal
+ .shipping_cost
+ .or(source.shipping_cost)
+ .unwrap_or(MinorUnit::new(0))
+ .get_amount_as_i64();
+ let order_tax_amount = update_internal
+ .order_tax_amount
+ .or(source.order_tax_amount)
+ .unwrap_or(MinorUnit::new(0))
+ .get_amount_as_i64();
update_internal.net_amount = Some(
update_internal.amount.unwrap_or(source.amount)
+ update_internal
@@ -513,7 +554,9 @@ impl PaymentAttemptUpdateInternal {
+ update_internal
.tax_amount
.or(source.tax_amount)
- .unwrap_or(0),
+ .unwrap_or(0)
+ + shipping_cost
+ + order_tax_amount,
);
update_internal.card_network = update_internal
.payment_method_data
@@ -578,6 +621,8 @@ impl PaymentAttemptUpdate {
client_version,
customer_acceptance,
card_network,
+ shipping_cost,
+ order_tax_amount,
} = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source);
PaymentAttempt {
amount: amount.unwrap_or(source.amount),
@@ -631,6 +676,8 @@ impl PaymentAttemptUpdate {
client_version: client_version.or(source.client_version),
customer_acceptance: customer_acceptance.or(source.customer_acceptance),
card_network: card_network.or(source.card_network),
+ shipping_cost: shipping_cost.or(source.shipping_cost),
+ order_tax_amount: order_tax_amount.or(source.order_tax_amount),
..source
}
}
@@ -707,6 +754,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::AuthenticationTypeUpdate {
authentication_type,
@@ -759,6 +808,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::ConfirmUpdate {
amount,
@@ -791,6 +842,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_source,
client_version,
customer_acceptance,
+ shipping_cost,
+ order_tax_amount,
} => Self {
amount: Some(amount),
currency: Some(currency),
@@ -839,6 +892,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
unified_message: None,
charge_id: None,
card_network: None,
+ shipping_cost,
+ order_tax_amount,
},
PaymentAttemptUpdate::VoidUpdate {
status,
@@ -892,6 +947,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::RejectUpdate {
status,
@@ -946,6 +1003,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::BlocklistUpdate {
status,
@@ -1000,6 +1059,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::PaymentMethodDetailsUpdate {
payment_method_id,
@@ -1052,6 +1113,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::ResponseUpdate {
status,
@@ -1122,6 +1185,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::ErrorUpdate {
connector,
@@ -1184,6 +1249,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::StatusUpdate { status, updated_by } => Self {
status: Some(status),
@@ -1233,6 +1300,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::UpdateTrackers {
payment_token,
@@ -1291,6 +1360,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::UnresolvedResponseUpdate {
status,
@@ -1350,6 +1421,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::PreprocessingUpdate {
status,
@@ -1407,6 +1480,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::CaptureUpdate {
multiple_capture_count,
@@ -1460,6 +1535,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::AmountToCaptureUpdate {
status,
@@ -1513,6 +1590,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::ConnectorResponse {
authentication_data,
@@ -1569,6 +1648,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
amount,
@@ -1621,6 +1702,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::AuthenticationUpdate {
status,
@@ -1676,6 +1759,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
PaymentAttemptUpdate::ManualUpdate {
status,
@@ -1734,6 +1819,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ shipping_cost: None,
+ order_tax_amount: None,
},
}
}
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 8e6c72eb5b..6e8918f02a 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -840,6 +840,8 @@ diesel::table! {
organization_id -> Varchar,
#[max_length = 32]
card_network -> Nullable<Varchar>,
+ shipping_cost -> Nullable<Int8>,
+ order_tax_amount -> Nullable<Int8>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 2deaa3d4ee..95550068f0 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -820,6 +820,8 @@ diesel::table! {
organization_id -> Varchar,
#[max_length = 32]
card_network -> Nullable<Varchar>,
+ shipping_cost -> Nullable<Int8>,
+ order_tax_amount -> Nullable<Int8>,
}
}
diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs
index 2b1359968f..f4c8cf30fa 100644
--- a/crates/diesel_models/src/user/sample_data.rs
+++ b/crates/diesel_models/src/user/sample_data.rs
@@ -2,6 +2,7 @@ use common_enums::{
AttemptStatus, AuthenticationType, CaptureMethod, Currency, PaymentExperience, PaymentMethod,
PaymentMethodType,
};
+use common_utils::types::MinorUnit;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
@@ -82,6 +83,8 @@ pub struct PaymentAttemptBatchNew {
pub customer_acceptance: Option<common_utils::pii::SecretSerdeValue>,
pub profile_id: common_utils::id_type::ProfileId,
pub organization_id: common_utils::id_type::OrganizationId,
+ pub shipping_cost: Option<MinorUnit>,
+ pub order_tax_amount: Option<MinorUnit>,
}
#[allow(dead_code)]
@@ -157,6 +160,8 @@ impl PaymentAttemptBatchNew {
customer_acceptance: self.customer_acceptance,
profile_id: self.profile_id,
organization_id: self.organization_id,
+ shipping_cost: self.shipping_cost,
+ order_tax_amount: self.order_tax_amount,
}
}
}
diff --git a/crates/hyperswitch_connectors/src/connectors/taxjar.rs b/crates/hyperswitch_connectors/src/connectors/taxjar.rs
index ef8631004a..009a9cb0c9 100644
--- a/crates/hyperswitch_connectors/src/connectors/taxjar.rs
+++ b/crates/hyperswitch_connectors/src/connectors/taxjar.rs
@@ -65,7 +65,7 @@ impl api::Refund for Taxjar {}
impl api::RefundExecute for Taxjar {}
impl api::RefundSync for Taxjar {}
impl api::PaymentToken for Taxjar {}
-impl api::PaymentTaxCalculation for Taxjar {}
+impl api::TaxCalculation for Taxjar {}
impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, PaymentsResponseData>
for Taxjar
diff --git a/crates/hyperswitch_connectors/src/default_implementations.rs b/crates/hyperswitch_connectors/src/default_implementations.rs
index ce1140394b..1f50150c08 100644
--- a/crates/hyperswitch_connectors/src/default_implementations.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations.rs
@@ -66,8 +66,8 @@ use hyperswitch_interfaces::{
payments::{
ConnectorCustomer, PaymentApprove, PaymentAuthorizeSessionToken,
PaymentIncrementalAuthorization, PaymentReject, PaymentSessionUpdate,
- PaymentTaxCalculation, PaymentsCompleteAuthorize, PaymentsPostProcessing,
- PaymentsPreProcessing,
+ PaymentsCompleteAuthorize, PaymentsPostProcessing, PaymentsPreProcessing,
+ TaxCalculation,
},
ConnectorIntegration, ConnectorMandateRevoke, ConnectorRedirectResponse,
},
@@ -109,7 +109,7 @@ default_imp_for_authorize_session_token!(
macro_rules! default_imp_for_calculate_tax {
($($path:ident::$connector:ident),*) => {
- $( impl PaymentTaxCalculation for $path::$connector {}
+ $( impl TaxCalculation for $path::$connector {}
impl
ConnectorIntegration<
CalculateTax,
diff --git a/crates/hyperswitch_connectors/src/default_implementations_v2.rs b/crates/hyperswitch_connectors/src/default_implementations_v2.rs
index 95c7ffec00..82ac725de3 100644
--- a/crates/hyperswitch_connectors/src/default_implementations_v2.rs
+++ b/crates/hyperswitch_connectors/src/default_implementations_v2.rs
@@ -75,8 +75,8 @@ use hyperswitch_interfaces::{
ConnectorCustomerV2, MandateSetupV2, PaymentApproveV2, PaymentAuthorizeSessionTokenV2,
PaymentAuthorizeV2, PaymentCaptureV2, PaymentIncrementalAuthorizationV2,
PaymentRejectV2, PaymentSessionUpdateV2, PaymentSessionV2, PaymentSyncV2,
- PaymentTaxCalculationV2, PaymentTokenV2, PaymentV2, PaymentVoidV2,
- PaymentsCompleteAuthorizeV2, PaymentsPostProcessingV2, PaymentsPreProcessingV2,
+ PaymentTokenV2, PaymentV2, PaymentVoidV2, PaymentsCompleteAuthorizeV2,
+ PaymentsPostProcessingV2, PaymentsPreProcessingV2, TaxCalculationV2,
},
refunds_v2::{RefundExecuteV2, RefundSyncV2, RefundV2},
ConnectorAccessTokenV2, ConnectorMandateRevokeV2, ConnectorVerifyWebhookSourceV2,
@@ -105,7 +105,7 @@ macro_rules! default_imp_for_new_connector_integration_payment {
impl ConnectorCustomerV2 for $path::$connector{}
impl PaymentsPreProcessingV2 for $path::$connector{}
impl PaymentsPostProcessingV2 for $path::$connector{}
- impl PaymentTaxCalculationV2 for $path::$connector{}
+ impl TaxCalculationV2 for $path::$connector{}
impl PaymentSessionUpdateV2 for $path::$connector{}
impl
ConnectorIntegrationV2<Authorize,PaymentFlowData, PaymentsAuthorizeData, PaymentsResponseData>
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 427ca967b9..1aaf5218af 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -184,6 +184,8 @@ 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>,
}
impl PaymentAttempt {
@@ -276,6 +278,8 @@ 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>,
}
impl PaymentAttemptNew {
@@ -284,6 +288,8 @@ impl PaymentAttemptNew {
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 {
@@ -359,6 +365,8 @@ 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,
diff --git a/crates/hyperswitch_interfaces/src/api/payments.rs b/crates/hyperswitch_interfaces/src/api/payments.rs
index 530dd51645..43409680dc 100644
--- a/crates/hyperswitch_interfaces/src/api/payments.rs
+++ b/crates/hyperswitch_interfaces/src/api/payments.rs
@@ -112,8 +112,8 @@ pub trait PaymentIncrementalAuthorization:
{
}
-/// trait PaymentTaxCalculation
-pub trait PaymentTaxCalculation:
+/// trait TaxCalculation
+pub trait TaxCalculation:
api::ConnectorIntegration<CalculateTax, PaymentsTaxCalculationData, TaxCalculationResponseData>
{
}
diff --git a/crates/hyperswitch_interfaces/src/api/payments_v2.rs b/crates/hyperswitch_interfaces/src/api/payments_v2.rs
index 29bc6eee06..cc5fd01f9f 100644
--- a/crates/hyperswitch_interfaces/src/api/payments_v2.rs
+++ b/crates/hyperswitch_interfaces/src/api/payments_v2.rs
@@ -90,8 +90,8 @@ pub trait PaymentIncrementalAuthorizationV2:
{
}
-///trait PaymentTaxCalculationV2
-pub trait PaymentTaxCalculationV2:
+///trait TaxCalculationV2
+pub trait TaxCalculationV2:
ConnectorIntegrationV2<
CalculateTax,
PaymentFlowData,
@@ -186,7 +186,7 @@ pub trait PaymentV2:
+ PaymentsPostProcessingV2
+ ConnectorCustomerV2
+ PaymentIncrementalAuthorizationV2
- + PaymentTaxCalculationV2
+ + TaxCalculationV2
+ PaymentSessionUpdateV2
{
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 93975cc57c..3b63b7ac20 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -605,6 +605,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::additional_info::UpiAdditionalData,
api_models::payments::additional_info::UpiCollectAdditionalData,
api_models::payments::PaymentsDynamicTaxCalculationRequest,
+ api_models::payments::PaymentsDynamicTaxCalculationResponse,
)),
modifiers(&SecurityAddon)
)]
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index dd25884331..5393e8d6fa 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -520,6 +520,8 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::additional_info::GivexGiftCardAdditionalData,
api_models::payments::additional_info::UpiAdditionalData,
api_models::payments::additional_info::UpiCollectAdditionalData,
+ api_models::payments::PaymentsDynamicTaxCalculationRequest,
+ api_models::payments::PaymentsDynamicTaxCalculationResponse,
)),
modifiers(&SecurityAddon)
)]
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index c0cb446b38..996224d7be 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -1457,7 +1457,10 @@ impl<'a> ConnectorAuthTypeAndMetadataValidation<'a> {
stax::transformers::StaxAuthType::try_from(self.auth_type)?;
Ok(())
}
- api_enums::Connector::Taxjar => Ok(()),
+ api_enums::Connector::Taxjar => {
+ taxjar::transformers::TaxjarAuthType::try_from(self.auth_type)?;
+ Ok(())
+ }
api_enums::Connector::Stripe => {
stripe::transformers::StripeAuthType::try_from(self.auth_type)?;
Ok(())
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 390ea8e017..bf52bad4ed 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -265,7 +265,6 @@ where
.payments_dynamic_tax_calculation(
state,
&mut payment_data,
- &mut should_continue_transaction,
&connector_details,
&business_profile,
&key_store,
diff --git a/crates/router/src/core/payments/connector_integration_v2_impls.rs b/crates/router/src/core/payments/connector_integration_v2_impls.rs
index a1a3cecd8f..19d67733d3 100644
--- a/crates/router/src/core/payments/connector_integration_v2_impls.rs
+++ b/crates/router/src/core/payments/connector_integration_v2_impls.rs
@@ -42,7 +42,7 @@ mod dummy_connector_default_impl {
impl<const T: u8> api::PaymentsPostProcessingV2 for connector::DummyConnector<T> {}
- impl<const T: u8> api::PaymentTaxCalculationV2 for connector::DummyConnector<T> {}
+ impl<const T: u8> api::TaxCalculationV2 for connector::DummyConnector<T> {}
impl<const T: u8> api::PaymentSessionUpdateV2 for connector::DummyConnector<T> {}
@@ -579,7 +579,7 @@ macro_rules! default_imp_for_new_connector_integration_payment {
impl api::ConnectorCustomerV2 for $path::$connector{}
impl api::PaymentsPreProcessingV2 for $path::$connector{}
impl api::PaymentsPostProcessingV2 for $path::$connector{}
- impl api::PaymentTaxCalculationV2 for $path::$connector{}
+ impl api::TaxCalculationV2 for $path::$connector{}
impl api::PaymentSessionUpdateV2 for $path::$connector{}
impl
services::ConnectorIntegrationV2<api::Authorize,types::PaymentFlowData, types::PaymentsAuthorizeData, types::PaymentsResponseData>
diff --git a/crates/router/src/core/payments/flows.rs b/crates/router/src/core/payments/flows.rs
index 6a1d88a583..1dec8911d3 100644
--- a/crates/router/src/core/payments/flows.rs
+++ b/crates/router/src/core/payments/flows.rs
@@ -7,8 +7,8 @@ pub mod incremental_authorization_flow;
pub mod psync_flow;
pub mod reject_flow;
pub mod session_flow;
+pub mod session_update_flow;
pub mod setup_mandate_flow;
-pub mod tax_calculation_flow;
use async_trait::async_trait;
@@ -3088,7 +3088,7 @@ default_imp_for_authorize_session_token!(
macro_rules! default_imp_for_calculate_tax {
($($path:ident::$connector:ident),*) => {
- $( impl api::PaymentTaxCalculation for $path::$connector {}
+ $( impl api::TaxCalculation for $path::$connector {}
impl
services::ConnectorIntegration<
api::CalculateTax,
@@ -3100,7 +3100,7 @@ macro_rules! default_imp_for_calculate_tax {
};
}
#[cfg(feature = "dummy_connector")]
-impl<const T: u8> api::PaymentTaxCalculation for connector::DummyConnector<T> {}
+impl<const T: u8> api::TaxCalculation for connector::DummyConnector<T> {}
#[cfg(feature = "dummy_connector")]
impl<const T: u8>
services::ConnectorIntegration<
diff --git a/crates/router/src/core/payments/flows/tax_calculation_flow.rs b/crates/router/src/core/payments/flows/session_update_flow.rs
similarity index 100%
rename from crates/router/src/core/payments/flows/tax_calculation_flow.rs
rename to crates/router/src/core/payments/flows/session_update_flow.rs
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index f8a58158d0..7636801663 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3679,6 +3679,8 @@ 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.rs b/crates/router/src/core/payments/operations.rs
index f002310ab8..841be780e6 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -188,7 +188,6 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
&'a self,
_state: &SessionState,
_payment_data: &mut D,
- _should_continue_confirm_transaction: &mut bool,
_connector_call_type: &ConnectorCallType,
_business_profile: &domain::BusinessProfile,
_key_store: &domain::MerchantKeyStore,
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index c4abe7ff86..95e254f341 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1279,6 +1279,31 @@ 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(
@@ -1314,6 +1339,8 @@ 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,
},
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 88489f4a03..d66565e84e 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -580,13 +580,17 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest, PaymentData<F>> for Paymen
&'a self,
state: &SessionState,
payment_data: &mut PaymentData<F>,
- _should_continue_confirm_transaction: &mut bool,
_connector_call_type: &ConnectorCallType,
business_profile: &domain::BusinessProfile,
key_store: &domain::MerchantKeyStore,
merchant_account: &domain::MerchantAccount,
) -> CustomResult<(), errors::ApiErrorResponse> {
- if business_profile.is_tax_connector_enabled {
+ let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled();
+ let skip_external_tax_calculation = payment_data
+ .payment_intent
+ .skip_external_tax_calculation
+ .unwrap_or(false);
+ if is_tax_connector_enabled && !skip_external_tax_calculation {
let db = state.store.as_ref();
let key_manager_state: &KeyManagerState = &state.into();
@@ -1151,6 +1155,8 @@ 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_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 3b243e8613..484bec14f4 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -521,13 +521,17 @@ impl<F: Clone + Send> Domain<F, api::PaymentsRequest, PaymentData<F>> for Paymen
&'a self,
state: &SessionState,
payment_data: &mut PaymentData<F>,
- _should_continue_confirm_transaction: &mut bool,
_connector_call_type: &ConnectorCallType,
business_profile: &domain::BusinessProfile,
key_store: &domain::MerchantKeyStore,
merchant_account: &domain::MerchantAccount,
) -> CustomResult<(), errors::ApiErrorResponse> {
- if business_profile.is_tax_connector_enabled {
+ let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled();
+ let skip_external_tax_calculation = payment_data
+ .payment_intent
+ .skip_external_tax_calculation
+ .unwrap_or(false);
+ if is_tax_connector_enabled && !skip_external_tax_calculation {
let db = state.store.as_ref();
let key_manager_state: &KeyManagerState = &state.into();
diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rs
index 70514dc778..1df8361244 100644
--- a/crates/router/src/core/payments/operations/tax_calculation.rs
+++ b/crates/router/src/core/payments/operations/tax_calculation.rs
@@ -215,14 +215,17 @@ impl<F: Clone + Send> Domain<F, api::PaymentsDynamicTaxCalculationRequest, Payme
&'a self,
state: &SessionState,
payment_data: &mut PaymentData<F>,
- should_continue_confirm_transaction: &mut bool,
_connector_call_type: &ConnectorCallType,
business_profile: &domain::BusinessProfile,
key_store: &domain::MerchantKeyStore,
merchant_account: &domain::MerchantAccount,
) -> errors::CustomResult<(), errors::ApiErrorResponse> {
- if business_profile.is_tax_connector_enabled {
- *should_continue_confirm_transaction = false;
+ let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled();
+ let skip_external_tax_calculation = payment_data
+ .payment_intent
+ .skip_external_tax_calculation
+ .unwrap_or(false);
+ if is_tax_connector_enabled && !skip_external_tax_calculation {
let db = state.store.as_ref();
let key_manager_state: &KeyManagerState = &state.into();
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index 57aba020e8..a96fb08e23 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -571,6 +571,8 @@ pub fn make_new_payment_attempt(
customer_acceptance: Default::default(),
profile_id: old_payment_attempt.profile_id,
organization_id: old_payment_attempt.organization_id,
+ shipping_cost: old_payment_attempt.shipping_cost,
+ order_tax_amount: None,
}
}
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index f0039eb49c..36961f3375 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -487,19 +487,29 @@ where
) -> RouterResponse<Self> {
let mut amount = payment_data.get_payment_intent().amount;
let shipping_cost = payment_data.get_payment_intent().shipping_cost;
+ if let Some(shipping_cost) = shipping_cost {
+ amount = amount + shipping_cost;
+ }
let order_tax_amount = payment_data
.get_payment_intent()
.tax_details
.clone()
- .and_then(|tax| tax.payment_method_type.map(|a| a.order_tax_amount));
- if let Some(shipping_cost) = shipping_cost {
- amount = amount + shipping_cost;
- }
- if let Some(order_tax_amount) = order_tax_amount {
- amount = amount + order_tax_amount;
+ .and_then(|tax| {
+ tax.payment_method_type
+ .map(|a| a.order_tax_amount)
+ .or_else(|| tax.default.map(|a| a.order_tax_amount))
+ });
+ if let Some(tax_amount) = order_tax_amount {
+ amount = amount + tax_amount;
}
+
Ok(services::ApplicationResponse::JsonWithHeaders((
- Self { net_amount: amount },
+ Self {
+ net_amount: amount,
+ payment_id: payment_data.get_payment_attempt().payment_id.clone(),
+ order_tax_amount,
+ shipping_cost,
+ },
vec![],
)))
}
@@ -1029,6 +1039,21 @@ where
update_mandate_id: d.update_mandate_id.clone(),
});
+ let order_tax_amount = payment_data
+ .get_payment_attempt()
+ .order_tax_amount
+ .or_else(|| {
+ payment_data
+ .get_payment_intent()
+ .tax_details
+ .clone()
+ .and_then(|tax| {
+ tax.payment_method_type
+ .map(|a| a.order_tax_amount)
+ .or_else(|| tax.default.map(|a| a.order_tax_amount))
+ })
+ });
+
let payments_response = api::PaymentsResponse {
payment_id: payment_intent.payment_id,
merchant_id: payment_intent.merchant_id,
@@ -1126,6 +1151,7 @@ where
charges: charges_response,
frm_metadata: payment_intent.frm_metadata,
merchant_order_reference_id: payment_intent.merchant_order_reference_id,
+ order_tax_amount,
};
services::ApplicationResponse::JsonWithHeaders((payments_response, headers))
@@ -1377,6 +1403,7 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay
updated: None,
charges: None,
frm_metadata: None,
+ order_tax_amount: None,
}
}
}
diff --git a/crates/router/src/db/address.rs b/crates/router/src/db/address.rs
index af2fffa509..335110248a 100644
--- a/crates/router/src/db/address.rs
+++ b/crates/router/src/db/address.rs
@@ -375,9 +375,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, storage_types::Address>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Address>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let address = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -458,11 +461,11 @@ mod storage {
payment_id: &payment_id,
};
let field = format!("add_{}", address.address_id);
- let storage_scheme = decide_storage_scheme::<_, storage_types::Address>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Address>(
self,
storage_scheme,
Op::Update(key.clone(), &field, Some(address.updated_by.as_str())),
- )
+ ))
.await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
@@ -539,11 +542,11 @@ mod storage {
.await
.change_context(errors::StorageError::EncryptionError)?;
let merchant_id = address_new.merchant_id.clone();
- let storage_scheme = decide_storage_scheme::<_, storage_types::Address>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Address>(
self,
storage_scheme,
Op::Insert,
- )
+ ))
.await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
diff --git a/crates/router/src/db/customers.rs b/crates/router/src/db/customers.rs
index 01bfc7ce0a..9cd044f69e 100644
--- a/crates/router/src/db/customers.rs
+++ b/crates/router/src/db/customers.rs
@@ -202,9 +202,12 @@ mod storage {
.await
.map_err(|err| report!(errors::StorageError::from(err)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let maybe_customer = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -273,9 +276,12 @@ mod storage {
.await
.map_err(|err| report!(errors::StorageError::from(err)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let maybe_customer = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -338,9 +344,12 @@ mod storage {
.await
.map_err(|err| report!(errors::StorageError::from(err)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let maybe_customer = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -419,11 +428,11 @@ mod storage {
customer_id: &customer_id,
};
let field = format!("cust_{}", customer_id.get_string_repr());
- let storage_scheme = decide_storage_scheme::<_, diesel_models::Customer>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
self,
storage_scheme,
Op::Update(key.clone(), &field, customer.updated_by.as_deref()),
- )
+ ))
.await;
let updated_object = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
@@ -491,9 +500,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let customer = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -556,9 +568,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let customer = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -653,11 +668,11 @@ mod storage {
.construct_new()
.await
.change_context(errors::StorageError::EncryptionError)?;
- let storage_scheme = decide_storage_scheme::<_, diesel_models::Customer>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
self,
storage_scheme,
Op::Insert,
- )
+ ))
.await;
new_customer.update_storage_scheme(storage_scheme);
let create_customer = match storage_scheme {
@@ -729,11 +744,11 @@ mod storage {
.construct_new()
.await
.change_context(errors::StorageError::EncryptionError)?;
- let storage_scheme = decide_storage_scheme::<_, diesel_models::Customer>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
self,
storage_scheme,
Op::Insert,
- )
+ ))
.await;
new_customer.update_storage_scheme(storage_scheme);
let create_customer = match storage_scheme {
@@ -826,9 +841,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Customer>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let customer = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -895,11 +913,11 @@ mod storage {
};
let key = PartitionKey::GlobalId { id: &id };
let field = format!("cust_{}", id);
- let storage_scheme = decide_storage_scheme::<_, diesel_models::Customer>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Customer>(
self,
storage_scheme,
Op::Update(key.clone(), &field, customer.updated_by.as_deref()),
- )
+ ))
.await;
let updated_object = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
diff --git a/crates/router/src/db/mandate.rs b/crates/router/src/db/mandate.rs
index f59ac2a80b..2435649447 100644
--- a/crates/router/src/db/mandate.rs
+++ b/crates/router/src/db/mandate.rs
@@ -97,9 +97,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Mandate>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Mandate>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -143,9 +146,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, diesel_models::Mandate>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Mandate>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -220,11 +226,11 @@ mod storage {
mandate_id,
};
let field = format!("mandate_{}", mandate_id);
- let storage_scheme = decide_storage_scheme::<_, diesel_models::Mandate>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Mandate>(
self,
storage_scheme,
Op::Update(key.clone(), &field, mandate.updated_by.as_deref()),
- )
+ ))
.await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
@@ -312,11 +318,11 @@ mod storage {
storage_scheme: MerchantStorageScheme,
) -> CustomResult<storage_types::Mandate, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
- let storage_scheme = decide_storage_scheme::<_, diesel_models::Mandate>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, diesel_models::Mandate>(
self,
storage_scheme,
Op::Insert,
- )
+ ))
.await;
mandate.update_storage_scheme(storage_scheme);
match storage_scheme {
diff --git a/crates/router/src/db/payment_method.rs b/crates/router/src/db/payment_method.rs
index 695ed68b79..0541491ab9 100644
--- a/crates/router/src/db/payment_method.rs
+++ b/crates/router/src/db/payment_method.rs
@@ -173,12 +173,13 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
- self,
- storage_scheme,
- Op::Find,
- )
- .await;
+ let storage_scheme =
+ Box::pin(decide_storage_scheme::<_, storage_types::PaymentMethod>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let get_pm = || async {
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
@@ -239,12 +240,13 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
- self,
- storage_scheme,
- Op::Find,
- )
- .await;
+ let storage_scheme =
+ Box::pin(decide_storage_scheme::<_, storage_types::PaymentMethod>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let get_pm = || async {
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
@@ -308,12 +310,13 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
- self,
- storage_scheme,
- Op::Find,
- )
- .await;
+ let storage_scheme =
+ Box::pin(decide_storage_scheme::<_, storage_types::PaymentMethod>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let get_pm = || async {
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
@@ -390,12 +393,13 @@ mod storage {
payment_method: domain::PaymentMethod,
storage_scheme: MerchantStorageScheme,
) -> CustomResult<domain::PaymentMethod, errors::StorageError> {
- let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
- self,
- storage_scheme,
- Op::Insert,
- )
- .await;
+ let storage_scheme =
+ Box::pin(decide_storage_scheme::<_, storage_types::PaymentMethod>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
let mut payment_method_new = payment_method
.construct_new()
@@ -507,12 +511,13 @@ mod storage {
customer_id: &customer_id,
};
let field = format!("payment_method_id_{}", payment_method.get_id());
- let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
- self,
- storage_scheme,
- Op::Update(key.clone(), &field, payment_method.updated_by.as_deref()),
- )
- .await;
+ let storage_scheme =
+ Box::pin(decide_storage_scheme::<_, storage_types::PaymentMethod>(
+ self,
+ storage_scheme,
+ Op::Update(key.clone(), &field, payment_method.updated_by.as_deref()),
+ ))
+ .await;
let pm = match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
@@ -593,12 +598,13 @@ mod storage {
customer_id: &customer_id,
};
let field = format!("payment_method_id_{}", payment_method.get_id());
- let storage_scheme = decide_storage_scheme::<_, storage_types::PaymentMethod>(
- self,
- storage_scheme,
- Op::Update(key.clone(), &field, payment_method.updated_by.as_deref()),
- )
- .await;
+ let storage_scheme =
+ Box::pin(decide_storage_scheme::<_, storage_types::PaymentMethod>(
+ self,
+ storage_scheme,
+ Op::Update(key.clone(), &field, payment_method.updated_by.as_deref()),
+ ))
+ .await;
let pm = match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs
index e8cebc43ae..808f82b00a 100644
--- a/crates/router/src/db/refund.rs
+++ b/crates/router/src/db/refund.rs
@@ -333,9 +333,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Refund>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => database_call().await,
enums::MerchantStorageScheme::RedisKv => {
@@ -375,9 +378,12 @@ mod storage {
new: storage_types::RefundNew,
storage_scheme: enums::MerchantStorageScheme,
) -> CustomResult<storage_types::Refund, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Insert)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Refund>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
@@ -525,9 +531,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Refund>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => database_call().await,
enums::MerchantStorageScheme::RedisKv => {
@@ -578,11 +587,11 @@ mod storage {
payment_id: &payment_id,
};
let field = format!("pa_{}_ref_{}", &this.attempt_id, &this.refund_id);
- let storage_scheme = decide_storage_scheme::<_, storage_types::Refund>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Refund>(
self,
storage_scheme,
Op::Update(key.clone(), &field, Some(&this.updated_by)),
- )
+ ))
.await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => {
@@ -639,9 +648,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Refund>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => database_call().await,
enums::MerchantStorageScheme::RedisKv => {
@@ -692,9 +704,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Refund>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => database_call().await,
enums::MerchantStorageScheme::RedisKv => {
@@ -745,9 +760,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, storage_types::Refund>(self, storage_scheme, Op::Find)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, storage_types::Refund>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => database_call().await,
enums::MerchantStorageScheme::RedisKv => {
diff --git a/crates/router/src/db/reverse_lookup.rs b/crates/router/src/db/reverse_lookup.rs
index fcf38ca420..d51ed5ed38 100644
--- a/crates/router/src/db/reverse_lookup.rs
+++ b/crates/router/src/db/reverse_lookup.rs
@@ -93,8 +93,12 @@ mod storage {
new: ReverseLookupNew,
storage_scheme: enums::MerchantStorageScheme,
) -> CustomResult<ReverseLookup, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, ReverseLookup>(self, storage_scheme, Op::Insert).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, ReverseLookup>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => {
let conn = connection::pg_connection_write(self).await?;
@@ -154,8 +158,12 @@ mod storage {
.await
.map_err(|error| report!(errors::StorageError::from(error)))
};
- let storage_scheme =
- decide_storage_scheme::<_, ReverseLookup>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, ReverseLookup>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
enums::MerchantStorageScheme::PostgresOnly => database_call().await,
enums::MerchantStorageScheme::RedisKv => {
diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs
index 18f6276495..ca86003f4b 100644
--- a/crates/router/src/types/api.rs
+++ b/crates/router/src/types/api.rs
@@ -112,7 +112,7 @@ pub trait Connector:
+ ConnectorMandateRevokeV2
+ ExternalAuthentication
+ ExternalAuthenticationV2
- + PaymentTaxCalculation
+ + TaxCalculation
{
}
@@ -141,7 +141,7 @@ impl<
+ ConnectorMandateRevokeV2
+ ExternalAuthentication
+ ExternalAuthenticationV2
- + PaymentTaxCalculation,
+ + TaxCalculation,
> Connector for T
{
}
diff --git a/crates/router/src/types/api/payments.rs b/crates/router/src/types/api/payments.rs
index bbdbb05907..449d1c725c 100644
--- a/crates/router/src/types/api/payments.rs
+++ b/crates/router/src/types/api/payments.rs
@@ -24,16 +24,16 @@ pub use hyperswitch_domain_models::router_flow_types::payments::{
pub use hyperswitch_interfaces::api::payments::{
ConnectorCustomer, MandateSetup, Payment, PaymentApprove, PaymentAuthorize,
PaymentAuthorizeSessionToken, PaymentCapture, PaymentIncrementalAuthorization, PaymentReject,
- PaymentSession, PaymentSessionUpdate, PaymentSync, PaymentTaxCalculation, PaymentToken,
- PaymentVoid, PaymentsCompleteAuthorize, PaymentsPostProcessing, PaymentsPreProcessing,
+ PaymentSession, PaymentSessionUpdate, PaymentSync, PaymentToken, PaymentVoid,
+ PaymentsCompleteAuthorize, PaymentsPostProcessing, PaymentsPreProcessing, TaxCalculation,
};
pub use super::payments_v2::{
ConnectorCustomerV2, MandateSetupV2, PaymentApproveV2, PaymentAuthorizeSessionTokenV2,
PaymentAuthorizeV2, PaymentCaptureV2, PaymentIncrementalAuthorizationV2, PaymentRejectV2,
- PaymentSessionUpdateV2, PaymentSessionV2, PaymentSyncV2, PaymentTaxCalculationV2,
- PaymentTokenV2, PaymentV2, PaymentVoidV2, PaymentsCompleteAuthorizeV2,
- PaymentsPostProcessingV2, PaymentsPreProcessingV2,
+ PaymentSessionUpdateV2, PaymentSessionV2, PaymentSyncV2, PaymentTokenV2, PaymentV2,
+ PaymentVoidV2, PaymentsCompleteAuthorizeV2, PaymentsPostProcessingV2, PaymentsPreProcessingV2,
+ TaxCalculationV2,
};
use crate::core::errors;
diff --git a/crates/router/src/types/api/payments_v2.rs b/crates/router/src/types/api/payments_v2.rs
index cfcabadee5..59f132c015 100644
--- a/crates/router/src/types/api/payments_v2.rs
+++ b/crates/router/src/types/api/payments_v2.rs
@@ -1,7 +1,7 @@
pub use hyperswitch_interfaces::api::payments_v2::{
ConnectorCustomerV2, MandateSetupV2, PaymentApproveV2, PaymentAuthorizeSessionTokenV2,
PaymentAuthorizeV2, PaymentCaptureV2, PaymentIncrementalAuthorizationV2, PaymentRejectV2,
- PaymentSessionUpdateV2, PaymentSessionV2, PaymentSyncV2, PaymentTaxCalculationV2,
- PaymentTokenV2, PaymentV2, PaymentVoidV2, PaymentsCompleteAuthorizeV2,
- PaymentsPostProcessingV2, PaymentsPreProcessingV2,
+ PaymentSessionUpdateV2, PaymentSessionV2, PaymentSyncV2, PaymentTokenV2, PaymentV2,
+ PaymentVoidV2, PaymentsCompleteAuthorizeV2, PaymentsPostProcessingV2, PaymentsPreProcessingV2,
+ TaxCalculationV2,
};
diff --git a/crates/router/src/types/storage/payment_attempt.rs b/crates/router/src/types/storage/payment_attempt.rs
index 950a666dd6..782d5ae76a 100644
--- a/crates/router/src/types/storage/payment_attempt.rs
+++ b/crates/router/src/types/storage/payment_attempt.rs
@@ -184,6 +184,8 @@ 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
@@ -270,6 +272,8 @@ 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
@@ -369,6 +373,8 @@ 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/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs
index 32728fd8fc..40dd3dad93 100644
--- a/crates/router/src/utils/user/sample_data.rs
+++ b/crates/router/src/utils/user/sample_data.rs
@@ -330,6 +330,8 @@ pub async fn generate_sample_data(
customer_acceptance: None,
profile_id: profile_id.clone(),
organization_id: org_id.clone(),
+ shipping_cost: None,
+ order_tax_amount: None,
};
let refund = if refunds_count < number_of_refunds && !is_failed_payment {
diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs
index 60c0fed7bb..f5d5e3d1ae 100644
--- a/crates/router/tests/payments.rs
+++ b/crates/router/tests/payments.rs
@@ -443,6 +443,7 @@ async fn payments_create_core() {
charges: None,
frm_metadata: None,
merchant_order_reference_id: None,
+ order_tax_amount: None,
};
let expected_response =
services::ApplicationResponse::JsonWithHeaders((expected_response, vec![]));
@@ -698,6 +699,7 @@ async fn payments_create_core_adyen_no_redirect() {
charges: None,
frm_metadata: None,
merchant_order_reference_id: None,
+ order_tax_amount: None,
},
vec![],
));
diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs
index c216f1e95e..e2c86a9b91 100644
--- a/crates/router/tests/payments2.rs
+++ b/crates/router/tests/payments2.rs
@@ -203,6 +203,7 @@ async fn payments_create_core() {
charges: None,
frm_metadata: None,
merchant_order_reference_id: None,
+ order_tax_amount: None,
};
let expected_response =
services::ApplicationResponse::JsonWithHeaders((expected_response, vec![]));
@@ -466,6 +467,7 @@ async fn payments_create_core_adyen_no_redirect() {
charges: None,
frm_metadata: None,
merchant_order_reference_id: None,
+ order_tax_amount: None,
},
vec![],
));
diff --git a/crates/storage_impl/src/lookup.rs b/crates/storage_impl/src/lookup.rs
index 67b8635aba..943ef1f36f 100644
--- a/crates/storage_impl/src/lookup.rs
+++ b/crates/storage_impl/src/lookup.rs
@@ -71,8 +71,12 @@ impl<T: DatabaseStore> ReverseLookupInterface for KVRouterStore<T> {
new: DieselReverseLookupNew,
storage_scheme: storage_enums::MerchantStorageScheme,
) -> CustomResult<DieselReverseLookup, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselReverseLookup>(self, storage_scheme, Op::Insert).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselReverseLookup>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
match storage_scheme {
storage_enums::MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -126,8 +130,12 @@ impl<T: DatabaseStore> ReverseLookupInterface for KVRouterStore<T> {
.get_lookup_by_lookup_id(id, storage_scheme)
.await
};
- let storage_scheme =
- decide_storage_scheme::<_, DieselReverseLookup>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselReverseLookup>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
storage_enums::MerchantStorageScheme::PostgresOnly => database_call().await,
storage_enums::MerchantStorageScheme::RedisKv => {
diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs
index 11205b94db..6558c14ace 100644
--- a/crates/storage_impl/src/mock_db/payment_attempt.rs
+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs
@@ -161,6 +161,8 @@ 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 3cc04e8af5..85fe2b22d3 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -338,9 +338,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
payment_attempt: PaymentAttemptNew,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Insert)
- .await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -423,6 +426,8 @@ 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);
@@ -487,11 +492,11 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
payment_id: &this.payment_id,
};
let field = format!("pa_{}", this.attempt_id);
- let storage_scheme = decide_storage_scheme::<_, DieselPaymentAttempt>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
self,
storage_scheme,
Op::Update(key.clone(), &field, Some(&this.updated_by)),
- )
+ ))
.await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
@@ -606,8 +611,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -668,8 +677,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
storage_scheme,
)
};
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -722,8 +735,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
storage_scheme,
)
};
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -771,8 +788,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
connector_txn_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -836,8 +857,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
attempt_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -884,8 +909,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -945,8 +974,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
merchant_id: &common_utils::id_type::MerchantId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PaymentAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -1009,8 +1042,12 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
payment_id: &common_utils::id_type::PaymentId,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -1232,6 +1269,8 @@ 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,
}
}
@@ -1301,6 +1340,8 @@ 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,
}
}
}
@@ -1386,6 +1427,8 @@ 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,
}
}
@@ -1455,6 +1498,8 @@ 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,
}
}
}
@@ -1540,6 +1585,8 @@ 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,
}
}
@@ -1608,6 +1655,8 @@ 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,
}
}
}
@@ -1733,6 +1782,8 @@ impl DataModelExt for PaymentAttemptUpdate {
client_source,
client_version,
customer_acceptance,
+ shipping_cost,
+ order_tax_amount,
} => DieselPaymentAttemptUpdate::ConfirmUpdate {
amount: amount.get_amount_as_i64(),
currency,
@@ -1766,6 +1817,8 @@ impl DataModelExt for PaymentAttemptUpdate {
client_source,
client_version,
customer_acceptance,
+ shipping_cost,
+ order_tax_amount,
},
Self::VoidUpdate {
status,
@@ -2072,6 +2125,8 @@ impl DataModelExt for PaymentAttemptUpdate {
client_source,
client_version,
customer_acceptance,
+ shipping_cost,
+ order_tax_amount,
} => Self::ConfirmUpdate {
amount: MinorUnit::new(amount),
currency,
@@ -2103,6 +2158,8 @@ impl DataModelExt for PaymentAttemptUpdate {
client_source,
client_version,
customer_acceptance,
+ shipping_cost,
+ order_tax_amount,
},
DieselPaymentAttemptUpdate::VoidUpdate {
status,
diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs
index 90395e15da..6a29e41569 100644
--- a/crates/storage_impl/src/payments/payment_intent.rs
+++ b/crates/storage_impl/src/payments/payment_intent.rs
@@ -79,8 +79,12 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
merchant_id: &merchant_id,
payment_id: &payment_id,
};
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentIntent>(self, storage_scheme, Op::Insert).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentIntent>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -154,11 +158,11 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
payment_id: &payment_id,
};
let field = format!("pi_{}", this.payment_id.get_string_repr());
- let storage_scheme = decide_storage_scheme::<_, DieselPaymentIntent>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentIntent>(
self,
storage_scheme,
Op::Update(key.clone(), &field, Some(&this.updated_by)),
- )
+ ))
.await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
@@ -243,8 +247,12 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
er.change_context(new_err)
})
};
- let storage_scheme =
- decide_storage_scheme::<_, DieselPaymentIntent>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPaymentIntent>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
let diesel_payment_intent = match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
diff --git a/crates/storage_impl/src/payouts/payout_attempt.rs b/crates/storage_impl/src/payouts/payout_attempt.rs
index 08843a060a..697b5d91c9 100644
--- a/crates/storage_impl/src/payouts/payout_attempt.rs
+++ b/crates/storage_impl/src/payouts/payout_attempt.rs
@@ -44,8 +44,12 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
payouts: &Payouts,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PayoutAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPayoutAttempt>(self, storage_scheme, Op::Insert).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPayoutAttempt>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
@@ -144,11 +148,11 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
payout_attempt_id: &this.payout_id,
};
let field = format!("poa_{}", this.payout_attempt_id);
- let storage_scheme = decide_storage_scheme::<_, DieselPayoutAttempt>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPayoutAttempt>(
self,
storage_scheme,
Op::Update(key.clone(), &field, None),
- )
+ ))
.await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
@@ -240,8 +244,12 @@ impl<T: DatabaseStore> PayoutAttemptInterface for KVRouterStore<T> {
payout_attempt_id: &str,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<PayoutAttempt, errors::StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPayoutAttempt>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPayoutAttempt>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store
diff --git a/crates/storage_impl/src/payouts/payouts.rs b/crates/storage_impl/src/payouts/payouts.rs
index 7307de7c3f..b6e1c1ac35 100644
--- a/crates/storage_impl/src/payouts/payouts.rs
+++ b/crates/storage_impl/src/payouts/payouts.rs
@@ -82,8 +82,12 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
new: PayoutsNew,
storage_scheme: MerchantStorageScheme,
) -> error_stack::Result<Payouts, StorageError> {
- let storage_scheme =
- decide_storage_scheme::<_, DieselPayouts>(self, storage_scheme, Op::Insert).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPayouts>(
+ self,
+ storage_scheme,
+ Op::Insert,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
self.router_store.insert_payout(new, storage_scheme).await
@@ -168,11 +172,11 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
payout_id: &this.payout_id,
};
let field = format!("po_{}", this.payout_id);
- let storage_scheme = decide_storage_scheme::<_, DieselPayouts>(
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPayouts>(
self,
storage_scheme,
Op::Update(key.clone(), &field, None),
- )
+ ))
.await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
@@ -235,8 +239,12 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
er.change_context(new_err)
})
};
- let storage_scheme =
- decide_storage_scheme::<_, DieselPayouts>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPayouts>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => database_call().await,
MerchantStorageScheme::RedisKv => {
@@ -279,8 +287,12 @@ impl<T: DatabaseStore> PayoutsInterface for KVRouterStore<T> {
er.change_context(new_err)
})
};
- let storage_scheme =
- decide_storage_scheme::<_, DieselPayouts>(self, storage_scheme, Op::Find).await;
+ let storage_scheme = Box::pin(decide_storage_scheme::<_, DieselPayouts>(
+ self,
+ storage_scheme,
+ Op::Find,
+ ))
+ .await;
match storage_scheme {
MerchantStorageScheme::PostgresOnly => {
let maybe_payouts = database_call().await?;
diff --git a/migrations/2024-09-10-080050_add_shipping_cost_and_order_tax_amount_to_payment_attempt/down.sql b/migrations/2024-09-10-080050_add_shipping_cost_and_order_tax_amount_to_payment_attempt/down.sql
new file mode 100644
index 0000000000..8ad0af96f0
--- /dev/null
+++ b/migrations/2024-09-10-080050_add_shipping_cost_and_order_tax_amount_to_payment_attempt/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_attempt DROP COLUMN IF EXISTS shipping_cost;
+ALTER TABLE payment_attempt DROP COLUMN IF EXISTS order_tax_amount;
\ No newline at end of file
diff --git a/migrations/2024-09-10-080050_add_shipping_cost_and_order_tax_amount_to_payment_attempt/up.sql b/migrations/2024-09-10-080050_add_shipping_cost_and_order_tax_amount_to_payment_attempt/up.sql
new file mode 100644
index 0000000000..2122db364c
--- /dev/null
+++ b/migrations/2024-09-10-080050_add_shipping_cost_and_order_tax_amount_to_payment_attempt/up.sql
@@ -0,0 +1,4 @@
+-- Your SQL goes here
+ALTER TABLE payment_attempt ADD COLUMN IF NOT EXISTS shipping_cost BIGINT;
+ALTER TABLE payment_attempt
+ADD COLUMN IF NOT EXISTS order_tax_amount BIGINT;