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

fix(core): consume shipping_cost and order_tax_amount in update operation (#10805)

Vani Gupta69104ca0a46e
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index ef8f4b14f0..6edffec33d 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -557,6 +557,8 @@ pub enum PaymentAttemptUpdate {
payment_method_billing_address_id: Option<String>,
network_transaction_id: Option<String>,
updated_by: String,
+ shipping_cost: Option<MinorUnit>,
+ order_tax_amount: Option<MinorUnit>,
},
UpdateTrackers {
payment_token: Option<String>,
@@ -2770,6 +2772,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
updated_by,
payment_method_billing_address_id,
network_transaction_id,
+ shipping_cost,
+ order_tax_amount,
} => Self {
amount: Some(amount),
currency: Some(currency),
@@ -2818,12 +2822,12 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
- shipping_cost: None,
+ shipping_cost,
capture_before: None,
extended_authorization_applied: None,
extended_authorization_last_applied_at: None,
tokenization: None,
- order_tax_amount: None,
+ order_tax_amount,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs
index c64bd7bc0b..a58c50fb01 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -667,6 +667,7 @@ pub struct PaymentIntentUpdateFields {
pub duty_amount: Option<MinorUnit>,
pub enable_partial_authorization: Option<EnablePartialAuthorizationBool>,
pub enable_overcapture: Option<common_types::primitive_wrappers::EnableOvercaptureBool>,
+ pub shipping_cost: Option<MinorUnit>,
}
// TODO: uncomment fields as necessary
@@ -903,6 +904,7 @@ pub struct PaymentIntentUpdateInternal {
pub duty_amount: Option<MinorUnit>,
pub enable_partial_authorization: Option<EnablePartialAuthorizationBool>,
pub enable_overcapture: Option<common_types::primitive_wrappers::EnableOvercaptureBool>,
+ pub shipping_cost: Option<MinorUnit>,
}
#[cfg(feature = "v1")]
@@ -957,6 +959,7 @@ impl PaymentIntentUpdate {
duty_amount,
enable_partial_authorization,
enable_overcapture,
+ shipping_cost,
} = self.into();
PaymentIntent {
amount: amount.unwrap_or(source.amount),
@@ -1018,6 +1021,7 @@ impl PaymentIntentUpdate {
enable_partial_authorization: enable_partial_authorization
.or(source.enable_partial_authorization),
enable_overcapture: enable_overcapture.or(source.enable_overcapture),
+ shipping_cost: shipping_cost.or(source.shipping_cost),
..source
}
}
@@ -1079,6 +1083,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::Update(value) => Self {
amount: Some(value.amount),
@@ -1117,7 +1122,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
incremental_authorization_allowed: None,
authorization_count: None,
is_payment_processor_token_flow: value.is_payment_processor_token_flow,
- tax_details: None,
+ tax_details: value.tax_details,
force_3ds_challenge: value.force_3ds_challenge,
is_iframe_redirection_enabled: value.is_iframe_redirection_enabled,
extended_return_url: value.return_url,
@@ -1130,6 +1135,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: value.duty_amount,
enable_partial_authorization: value.enable_partial_authorization,
enable_overcapture: value.enable_overcapture,
+ shipping_cost: value.shipping_cost,
},
PaymentIntentUpdate::PaymentCreateUpdate {
return_url,
@@ -1188,6 +1194,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::PGStatusUpdate {
status,
@@ -1243,6 +1250,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::MerchantStatusUpdate {
status,
@@ -1298,6 +1306,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::ResponseUpdate {
// amount,
@@ -1361,6 +1370,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
active_attempt_id,
@@ -1415,6 +1425,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::StatusAndAttemptUpdate {
status,
@@ -1470,6 +1481,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::ApproveUpdate {
status,
@@ -1524,6 +1536,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::RejectUpdate {
status,
@@ -1578,6 +1591,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::SurchargeApplicableUpdate {
surcharge_applicable,
@@ -1631,6 +1645,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::IncrementalAuthorizationAmountUpdate { amount } => Self {
amount: Some(amount),
@@ -1681,6 +1696,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::AuthorizationCountUpdate {
authorization_count,
@@ -1733,6 +1749,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::CompleteAuthorizeUpdate {
shipping_address_id,
@@ -1785,6 +1802,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::ManualUpdate { status, updated_by } => Self {
status,
@@ -1835,6 +1853,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
PaymentIntentUpdate::SessionResponseUpdate {
tax_details,
@@ -1890,6 +1909,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
duty_amount: None,
enable_partial_authorization: None,
enable_overcapture: None,
+ shipping_cost: None,
},
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index b8789320ac..98ef4937b7 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -1481,6 +1481,8 @@ pub enum PaymentAttemptUpdate {
payment_method_billing_address_id: Option<String>,
updated_by: String,
network_transaction_id: Option<String>,
+ shipping_cost: Option<MinorUnit>,
+ order_tax_amount: Option<MinorUnit>,
},
UpdateTrackers {
payment_token: Option<String>,
@@ -1704,6 +1706,8 @@ impl PaymentAttemptUpdate {
network_transaction_id,
payment_method_billing_address_id,
updated_by,
+ order_tax_amount,
+ shipping_cost,
} => DieselPaymentAttemptUpdate::Update {
amount: net_amount.get_order_amount(),
currency,
@@ -1723,6 +1727,8 @@ impl PaymentAttemptUpdate {
payment_method_billing_address_id,
network_transaction_id,
updated_by,
+ order_tax_amount,
+ shipping_cost,
},
Self::UpdateTrackers {
payment_token,
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
index 5d5d9b9124..ab3eaa602c 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
@@ -247,6 +247,7 @@ pub struct PaymentIntentUpdateFields {
pub feature_metadata: Option<Secret<serde_json::Value>>,
pub enable_partial_authorization: Option<primitive_wrappers::EnablePartialAuthorizationBool>,
pub enable_overcapture: Option<primitive_wrappers::EnableOvercaptureBool>,
+ pub shipping_cost: Option<MinorUnit>,
}
#[cfg(feature = "v1")]
@@ -459,6 +460,7 @@ pub struct PaymentIntentUpdateInternal {
pub duty_amount: Option<MinorUnit>,
pub enable_partial_authorization: Option<primitive_wrappers::EnablePartialAuthorizationBool>,
pub enable_overcapture: Option<primitive_wrappers::EnableOvercaptureBool>,
+ pub shipping_cost: Option<MinorUnit>,
}
// This conversion is used in the `update_payment_intent` function
@@ -1267,6 +1269,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
duty_amount: value.duty_amount,
enable_partial_authorization: value.enable_partial_authorization,
enable_overcapture: value.enable_overcapture,
+ shipping_cost: value.shipping_cost,
}))
}
PaymentIntentUpdate::PaymentCreateUpdate {
@@ -1436,6 +1439,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
duty_amount,
enable_partial_authorization,
enable_overcapture,
+ shipping_cost,
} = value;
Self {
amount,
@@ -1486,6 +1490,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
duty_amount,
enable_partial_authorization,
enable_overcapture,
+ shipping_cost,
}
}
}
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 0bc1e37cee..e87a6a74e8 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -2261,6 +2261,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
.payment_intent
.enable_partial_authorization,
enable_overcapture: payment_data.payment_intent.enable_overcapture,
+ shipping_cost: None,
})),
&m_key_store,
storage_scheme,
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 15935bbddd..05e89fb15e 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -464,6 +464,27 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
)?;
payment_intent.enable_overcapture = request.enable_overcapture;
+ 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_intent.shipping_cost = request.shipping_cost.or(payment_intent.shipping_cost);
+ payment_attempt
+ .net_amount
+ .set_order_tax_amount(request.order_tax_amount.or(order_tax_amount));
+
let payment_data = PaymentData {
flow: PhantomData,
payment_intent,
@@ -867,7 +888,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
payment_data.payment_attempt = state
.store
.update_payment_attempt_with_attempt_id(
- payment_data.payment_attempt,
+ payment_data.payment_attempt.clone(),
storage::PaymentAttemptUpdate::Update {
currency: payment_data.currency,
status: get_attempt_status(),
@@ -887,11 +908,19 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
net_amount:
hyperswitch_domain_models::payments::payment_attempt::NetAmount::new(
payment_data.amount.into(),
- None,
- None,
+ payment_data.payment_intent.shipping_cost,
+ payment_data
+ .payment_attempt
+ .net_amount
+ .get_order_tax_amount(),
surcharge_amount,
tax_amount,
),
+ shipping_cost: payment_data.payment_intent.shipping_cost,
+ order_tax_amount: payment_data
+ .payment_attempt
+ .net_amount
+ .get_order_tax_amount(),
},
storage_scheme,
key_store,
@@ -965,6 +994,18 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
.payment_intent
.merchant_order_reference_id
.clone();
+
+ let tax_details = payment_data
+ .payment_attempt
+ .net_amount
+ .get_order_tax_amount()
+ .map(|order_tax_amount| diesel_models::TaxDetails {
+ default: Some(diesel_models::DefaultTax { order_tax_amount }),
+ payment_method_type: None,
+ });
+
+ let shipping_cost = payment_data.payment_intent.shipping_cost;
+
payment_data.payment_intent = state
.store
.update_payment_intent(
@@ -998,7 +1039,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
billing_details,
shipping_details,
is_payment_processor_token_flow: None,
- tax_details: None,
+ tax_details,
force_3ds_challenge: payment_data.payment_intent.force_3ds_challenge,
is_iframe_redirection_enabled: payment_data
.payment_intent
@@ -1019,6 +1060,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
.payment_intent
.enable_partial_authorization,
enable_overcapture: payment_data.payment_intent.enable_overcapture,
+ shipping_cost,
})),
key_store,
storage_scheme,