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

feat(router): add config-based disablement of integrity checks for amount mismatches (#14429)

Akshaya Shankar1200dba7b62b
diff --git a/Cargo.lock b/Cargo.lock
index 8ac23cedb0..a40ba1d2b7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8432,6 +8432,7 @@ dependencies = [
"events",
"external_services",
"futures 0.3.31",
+ "heck 0.5.0",
"hex",
"hkdf",
"http 0.2.12",
diff --git a/config/superposition_seed.toml b/config/superposition_seed.toml
index 05c6b6d0cf..12ee501a98 100644
--- a/config/superposition_seed.toml
+++ b/config/superposition_seed.toml
@@ -2667,6 +2667,7 @@ pt_mapping_outgoing_connector_webhooks = { value = { default_mapping = { frequen
[86400, 4], # 24 hour * 4 = 96 hours
], start_after = 60 }, max_retries_count = 17 }, schema = { type = "object" }, description = "Refund sync retry process tracker mapping configuration", change_reason = "Initial setup" }
"payments.requires_cvv" = { value = true, schema = { type = "boolean" }, description = "Whether CVV is required for payments", change_reason = "Initial setup" }
+"payments.accept_payment_amount_mismatch" = { value = false, schema = { type = "boolean" }, description = "Whether to accept a connector-reported payment amount that differs from the requested amount for a merchant and payment method type (payments only, not refunds). When true, the amount mismatch does not fail the integrity check and the payment is updated with the amount actually received instead of being moved to conflicted", change_reason = "Initial setup" }
"routing.routing_result_source" = { value = "hyperswitch_routing", schema = { enum = [
"decision_engine",
"hyperswitch_routing",
diff --git a/crates/common_types/src/primitive_wrappers.rs b/crates/common_types/src/primitive_wrappers.rs
index 4bf44cfab6..4e8a794bee 100644
--- a/crates/common_types/src/primitive_wrappers.rs
+++ b/crates/common_types/src/primitive_wrappers.rs
@@ -401,6 +401,34 @@ mod bool_wrappers {
bool::from_sql(value).map(Self)
}
}
+
+ /// Bool that represents if the merchant accepts a connector-reported amount that differs
+ /// from the requested amount (resolved from the `payments.accept_payment_amount_mismatch` config,
+ /// scoped by merchant and payment method type)
+ #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
+ pub struct AcceptAmountMismatchBool(bool);
+
+ impl AcceptAmountMismatchBool {
+ /// Creates a new instance of `AcceptAmountMismatchBool`
+ pub fn new(value: bool) -> Self {
+ Self(value)
+ }
+ }
+
+ impl Default for AcceptAmountMismatchBool {
+ /// Default for `AcceptAmountMismatchBool` is `false`
+ fn default() -> Self {
+ Self(false)
+ }
+ }
+
+ impl Deref for AcceptAmountMismatchBool {
+ type Target = bool;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
}
mod u32_wrappers {
diff --git a/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rs b/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rs
index 86582fd917..e72fbeeb8b 100644
--- a/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/gigadat/transformers.rs
@@ -9,7 +9,7 @@ use common_utils::{
id_type,
pii::{self, Email, IpAddress},
request::Method,
- types::FloatMajorUnit,
+ types::{FloatMajorUnit, FloatMajorUnitForConnector},
};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
@@ -358,8 +358,30 @@ impl<F, T> TryFrom<ResponseRouterData<F, GigadatTransactionStatusResponse, T, Pa
},
)
});
+ let status = enums::AttemptStatus::from(item.response.status);
+ // Record the connector-reported amount against the resulting status so a payment
+ // accepted despite an amount mismatch reflects what was actually captured / authorized.
+ let amount = item
+ .response
+ .amount
+ .zip(item.response.currency)
+ .map(|(amount, currency)| {
+ utils::convert_back_amount_to_minor_units(
+ &FloatMajorUnitForConnector,
+ amount,
+ currency,
+ )
+ })
+ .transpose()?;
+ let amount_captured = utils::get_amount_captured(status, amount);
+ let amount_capturable = utils::get_amount_capturable(status, amount);
Ok(Self {
- status: enums::AttemptStatus::from(item.response.status),
+ status,
+ amount_captured: amount_captured
+ .map(|amount| amount.get_amount_as_i64())
+ .or(item.data.amount_captured),
+ minor_amount_captured: amount_captured.or(item.data.minor_amount_captured),
+ minor_amount_capturable: amount_capturable.or(item.data.minor_amount_capturable),
response: Ok(PaymentsResponseData::TransactionResponse {
resource_id: ResponseId::NoResponseId,
redirection_data: Box::new(None),
diff --git a/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs b/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs
index a257a4683a..4fd93e439e 100644
--- a/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/loonio/transformers.rs
@@ -4,7 +4,12 @@ use std::collections::HashMap;
use api_models::payouts::{BankRedirect, PayoutMethodData};
use api_models::webhooks;
use common_enums::{enums, Currency};
-use common_utils::{id_type, pii::Email, request::Method, types::FloatMajorUnit};
+use common_utils::{
+ id_type,
+ pii::Email,
+ request::Method,
+ types::{FloatMajorUnit, FloatMajorUnitForConnector},
+};
use hyperswitch_domain_models::{
payment_method_data::{BankRedirectData, PaymentMethodData},
router_data::{
@@ -259,8 +264,28 @@ impl<F, T> TryFrom<ResponseRouterData<F, LoonioPaymentResponseData, T, PaymentsR
},
)
});
+ let status = enums::AttemptStatus::from(sync_response.state);
+ let amount = sync_response
+ .amount
+ .zip(sync_response.currency_code)
+ .map(|(amount, currency)| {
+ utils::convert_back_amount_to_minor_units(
+ &FloatMajorUnitForConnector,
+ amount,
+ currency,
+ )
+ })
+ .transpose()?;
+ let amount_captured = utils::get_amount_captured(status, amount);
+ let amount_capturable = utils::get_amount_capturable(status, amount);
Ok(Self {
- status: enums::AttemptStatus::from(sync_response.state),
+ status,
+ amount_captured: amount_captured
+ .map(|amount| amount.get_amount_as_i64())
+ .or(item.data.amount_captured),
+ minor_amount_captured: amount_captured.or(item.data.minor_amount_captured),
+ minor_amount_capturable: amount_capturable
+ .or(item.data.minor_amount_capturable),
response: Ok(PaymentsResponseData::TransactionResponse {
resource_id: ResponseId::ConnectorTransactionId(
sync_response.transaction_id,
@@ -295,8 +320,27 @@ impl<F, T> TryFrom<ResponseRouterData<F, LoonioPaymentResponseData, T, PaymentsR
},
)
});
+
+ let amount = webhook_body
+ .currency_code
+ .map(|currency| {
+ utils::convert_back_amount_to_minor_units(
+ &FloatMajorUnitForConnector,
+ webhook_body.amount,
+ currency,
+ )
+ })
+ .transpose()?;
+ let amount_captured = utils::get_amount_captured(payment_status, amount);
+ let amount_capturable = utils::get_amount_capturable(payment_status, amount);
Ok(Self {
status: payment_status,
+ amount_captured: amount_captured
+ .map(|amount| amount.get_amount_as_i64())
+ .or(item.data.amount_captured),
+ minor_amount_captured: amount_captured.or(item.data.minor_amount_captured),
+ minor_amount_capturable: amount_capturable
+ .or(item.data.minor_amount_capturable),
response: Ok(PaymentsResponseData::TransactionResponse {
resource_id: ResponseId::ConnectorTransactionId(
webhook_body.api_transaction_id,
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index 814956db45..e9fc868e76 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -7824,6 +7824,7 @@ pub(crate) fn convert_payment_authorize_router_response<F1, F2, T1, T2>(
payout_id: data.payout_id.clone(),
connector_response: data.connector_response.clone(),
integrity_check: Ok(()),
+ accept_amount_mismatch: data.accept_amount_mismatch,
additional_merchant_data: data.additional_merchant_data.clone(),
header_payload: data.header_payload.clone(),
connector_mandate_request_reference_id: data.connector_mandate_request_reference_id.clone(),
@@ -8077,6 +8078,80 @@ pub fn get_authorise_integrity_object<T>(
})
}
+/// Returns the connector-reported amount as the captured amount when the payment is charged
+/// (fully or partially), `None` otherwise.
+pub fn get_amount_captured(status: AttemptStatus, amount: Option<MinorUnit>) -> Option<MinorUnit> {
+ match status {
+ AttemptStatus::Charged
+ | AttemptStatus::PartialCharged
+ | AttemptStatus::PartialChargedAndChargeable => amount,
+ AttemptStatus::Started
+ | AttemptStatus::AuthenticationFailed
+ | AttemptStatus::RouterDeclined
+ | AttemptStatus::AuthenticationPending
+ | AttemptStatus::AuthenticationSuccessful
+ | AttemptStatus::Authorized
+ | AttemptStatus::AuthorizationFailed
+ | AttemptStatus::Authorizing
+ | AttemptStatus::CodInitiated
+ | AttemptStatus::Voided
+ | AttemptStatus::VoidedPostCharge
+ | AttemptStatus::VoidInitiated
+ | AttemptStatus::CaptureInitiated
+ | AttemptStatus::CaptureFailed
+ | AttemptStatus::CaptureReview
+ | AttemptStatus::VoidFailed
+ | AttemptStatus::AutoRefunded
+ | AttemptStatus::PartiallyAuthorized
+ | AttemptStatus::Unresolved
+ | AttemptStatus::Pending
+ | AttemptStatus::Failure
+ | AttemptStatus::PaymentMethodAwaited
+ | AttemptStatus::ConfirmationAwaited
+ | AttemptStatus::DeviceDataCollectionPending
+ | AttemptStatus::IntegrityFailure
+ | AttemptStatus::Expired => None,
+ }
+}
+
+/// Returns the connector-reported amount as the capturable amount when the payment is
+/// authorized (fully or partially), `None` otherwise.
+pub fn get_amount_capturable(
+ status: AttemptStatus,
+ amount: Option<MinorUnit>,
+) -> Option<MinorUnit> {
+ match status {
+ AttemptStatus::Authorized | AttemptStatus::PartiallyAuthorized => amount,
+ AttemptStatus::Started
+ | AttemptStatus::AuthenticationFailed
+ | AttemptStatus::RouterDeclined
+ | AttemptStatus::AuthenticationPending
+ | AttemptStatus::AuthenticationSuccessful
+ | AttemptStatus::AuthorizationFailed
+ | AttemptStatus::Charged
+ | AttemptStatus::Authorizing
+ | AttemptStatus::CodInitiated
+ | AttemptStatus::Voided
+ | AttemptStatus::VoidedPostCharge
+ | AttemptStatus::VoidInitiated
+ | AttemptStatus::CaptureInitiated
+ | AttemptStatus::CaptureFailed
+ | AttemptStatus::CaptureReview
+ | AttemptStatus::VoidFailed
+ | AttemptStatus::AutoRefunded
+ | AttemptStatus::PartialCharged
+ | AttemptStatus::PartialChargedAndChargeable
+ | AttemptStatus::Unresolved
+ | AttemptStatus::Pending
+ | AttemptStatus::Failure
+ | AttemptStatus::PaymentMethodAwaited
+ | AttemptStatus::ConfirmationAwaited
+ | AttemptStatus::DeviceDataCollectionPending
+ | AttemptStatus::IntegrityFailure
+ | AttemptStatus::Expired => None,
+ }
+}
+
pub fn get_sync_integrity_object<T>(
amount_convertor: &dyn AmountConvertor<Output = T>,
amount: T,
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
index c29c9e3386..c702b44854 100644
--- a/crates/hyperswitch_domain_models/src/router_data.rs
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -103,6 +103,11 @@ pub struct RouterData<Flow, Request, Response> {
pub integrity_check: Result<(), IntegrityCheckError>,
+ /// Whether a connector-reported amount that differs from the requested amount should be
+ /// accepted by the integrity check, resolved from the `payments.accept_payment_amount_mismatch`
+ /// config for the processor merchant and payment method type
+ pub accept_amount_mismatch: Option<primitive_wrappers::AcceptAmountMismatchBool>,
+
pub additional_merchant_data: Option<api_models::admin::AdditionalMerchantData>,
pub header_payload: Option<payments::HeaderPayload>,
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index 99d71354d7..077aa3b8a1 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -1062,6 +1062,13 @@ pub struct PaymentsSyncData {
pub setup_future_usage: Option<storage_enums::FutureUsage>,
pub feature_metadata: Option<api_models::payments::FeatureMetadata>,
pub connector_mandate_id: Option<String>,
+ /// Whether partial authorization was enabled for this payment. Used to avoid treating a
+ /// legitimately lower authorized amount as an integrity mismatch on sync.
+ pub enable_partial_authorization:
+ Option<common_types::primitive_wrappers::EnablePartialAuthorizationBool>,
+ /// Whether overcapture was applied for this payment by the connector. Used to avoid treating
+ /// a legitimate overcapture as an integrity mismatch on sync.
+ pub is_overcapture_enabled: Option<common_types::primitive_wrappers::OvercaptureEnabledBool>,
}
#[derive(Debug, Default, Clone, Serialize)]
diff --git a/crates/hyperswitch_interfaces/src/conversion_impls.rs b/crates/hyperswitch_interfaces/src/conversion_impls.rs
index 97b8936c22..a07ba066ca 100644
--- a/crates/hyperswitch_interfaces/src/conversion_impls.rs
+++ b/crates/hyperswitch_interfaces/src/conversion_impls.rs
@@ -86,6 +86,7 @@ fn get_default_router_data<F, Req, Resp>(
payment_method_status: None,
minor_amount_captured: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/hyperswitch_interfaces/src/integrity.rs b/crates/hyperswitch_interfaces/src/integrity.rs
index 6b4095e775..af8c904666 100644
--- a/crates/hyperswitch_interfaces/src/integrity.rs
+++ b/crates/hyperswitch_interfaces/src/integrity.rs
@@ -1,3 +1,4 @@
+use common_types::primitive_wrappers::AcceptAmountMismatchBool;
use common_utils::{errors::IntegrityCheckError, types::MinorUnit};
use hyperswitch_domain_models::router_request_types::{
AuthoriseIntegrityObject, CaptureIntegrityObject, PaymentsAuthorizeData, PaymentsCaptureData,
@@ -95,6 +96,7 @@ pub trait CheckIntegrity<Request, T> {
&self,
request: &Request,
connector_transaction_id: Option<String>,
+ accept_amount_mismatch: AcceptAmountMismatchBool,
) -> Result<(), IntegrityCheckError>;
}
@@ -107,6 +109,9 @@ where
&self,
request: &Request,
connector_refund_id: Option<String>,
+ // The merchant's accept-amount-mismatch config applies to payments only; refunds are
+ // always checked strictly.
+ _accept_amount_mismatch: AcceptAmountMismatchBool,
) -> Result<(), IntegrityCheckError> {
match request.get_response_integrity_object() {
Some(res_integrity_object) => {
@@ -132,18 +137,22 @@ where
&self,
request: &Request,
connector_transaction_id: Option<String>,
+ accept_amount_mismatch: AcceptAmountMismatchBool,
) -> Result<(), IntegrityCheckError> {
match request.get_response_integrity_object() {
Some(res_integrity_object) => {
let req_integrity_object = request.get_request_integrity_object();
// Partial authorization: the connector may legitimately authorize less than
- // requested. It must never authorize more, so `allow_higher` stays false.
+ // requested. Authorizing more is only accepted when the merchant has opted into
+ // `accept_amount_mismatch`, which permits a difference in either direction.
let amount_tolerance = AmountMismatchTolerance {
allow_lower: AllowLowerAmount::new(
- self.enable_partial_authorization
- .is_some_and(|enabled| enabled.is_true()),
+ *accept_amount_mismatch
+ || self
+ .enable_partial_authorization
+ .is_some_and(|enabled| enabled.is_true()),
),
- allow_higher: AllowHigherAmount::new(false),
+ allow_higher: AllowHigherAmount::new(*accept_amount_mismatch),
};
T::compare(
req_integrity_object,
@@ -166,17 +175,19 @@ where
&self,
request: &Request,
connector_transaction_id: Option<String>,
+ accept_amount_mismatch: AcceptAmountMismatchBool,
) -> Result<(), IntegrityCheckError> {
match request.get_response_integrity_object() {
Some(res_integrity_object) => {
let req_integrity_object = request.get_request_integrity_object();
// Overcapture: the merchant may be allowed to capture more than the originally
- // requested amount. Capturing less is a separate, unrelated concern, so
- // `allow_lower` stays false.
+ // requested amount. Capturing less is only accepted when the merchant has opted
+ // into `accept_amount_mismatch`, which permits a difference in either direction.
let amount_tolerance = AmountMismatchTolerance {
- allow_lower: AllowLowerAmount::new(false),
+ allow_lower: AllowLowerAmount::new(*accept_amount_mismatch),
allow_higher: AllowHigherAmount::new(
- self.is_overcapture_enabled.is_some_and(|enabled| *enabled),
+ *accept_amount_mismatch
+ || self.is_overcapture_enabled.is_some_and(|enabled| *enabled),
),
};
T::compare(
@@ -200,20 +211,31 @@ where
&self,
request: &Request,
connector_transaction_id: Option<String>,
+ accept_amount_mismatch: AcceptAmountMismatchBool,
) -> Result<(), IntegrityCheckError> {
match request.get_response_integrity_object() {
Some(res_integrity_object) => {
let req_integrity_object = request.get_request_integrity_object();
- // TODO: `PaymentsSyncData` has no `enable_partial_authorization`/
- // `is_overcapture_enabled` field today, so a payment left partially
- // authorized or overcaptured will keep failing every subsequent sync's
- // integrity check with strict tolerance. Needs the same plumbing added to
- // `PaymentsSyncData` as was done for `PaymentsAuthorizeData`/`PaymentsCaptureData`.
+ // A sync may report a partially authorized (lower) or overcaptured (higher)
+ // amount, so both feature tolerances apply here, in addition to the merchant's
+ // `accept_amount_mismatch` opt-in which permits a difference in either direction.
+ let amount_tolerance = AmountMismatchTolerance {
+ allow_lower: AllowLowerAmount::new(
+ *accept_amount_mismatch
+ || self
+ .enable_partial_authorization
+ .is_some_and(|enabled| enabled.is_true()),
+ ),
+ allow_higher: AllowHigherAmount::new(
+ *accept_amount_mismatch
+ || self.is_overcapture_enabled.is_some_and(|enabled| *enabled),
+ ),
+ };
T::compare(
req_integrity_object,
res_integrity_object,
connector_transaction_id,
- AmountMismatchTolerance::strict(),
+ amount_tolerance,
)
}
None => Ok(()),
diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml
index a6a5a54b97..901615881b 100644
--- a/crates/router/Cargo.toml
+++ b/crates/router/Cargo.toml
@@ -192,6 +192,7 @@ async-bb8-diesel = "0.2.1"
async-trait = "0.1.88"
base64 = "0.22.1"
bb8 = "0.8"
+heck = "0.5.0"
open-feature = { version = "0.2.5" }
blake3 = "1.8.2"
bytes = "1.10.1"
diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs
index 8d78c8cbd3..ec1e715dd7 100644
--- a/crates/router/src/connector/utils.rs
+++ b/crates/router/src/connector/utils.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashMap, ops::Deref, str::FromStr, sync::LazyLock};
+use std::{collections::HashMap, str::FromStr, sync::LazyLock};
#[cfg(feature = "payouts")]
use api_models::payouts::{self, PayoutVendorAccountDetails};
@@ -197,19 +197,8 @@ where
payment_data.payment_attempt.status,
);
let total_capturable_amount = payment_data.payment_attempt.get_total_amount();
- let is_overcapture_enabled = *payment_data
- .payment_attempt
- .is_overcapture_enabled
- .unwrap_or_default()
- .deref();
-
- if Some(total_capturable_amount) == capturable_amount.map(MinorUnit::new)
- || (capturable_amount.is_some_and(|capturable_amount| {
- MinorUnit::new(capturable_amount) > total_capturable_amount
- }) && is_overcapture_enabled)
- {
- Ok(enums::AttemptStatus::Authorized)
- } else if capturable_amount.is_some_and(|capturable_amount| {
+
+ if capturable_amount.is_some_and(|capturable_amount| {
MinorUnit::new(capturable_amount) < total_capturable_amount
}) && payment_data
.payment_intent
@@ -217,39 +206,8 @@ where
.is_some_and(|val| val.is_true())
{
Ok(enums::AttemptStatus::PartiallyAuthorized)
- } else if capturable_amount.is_some_and(|capturable_amount| {
- MinorUnit::new(capturable_amount) < total_capturable_amount
- }) && !payment_data
- .payment_intent
- .enable_partial_authorization
- .is_some_and(|val| val.is_true())
- {
- Err(ApiErrorResponse::IntegrityCheckFailed {
- reason: "capturable_amount is less than the total attempt amount"
- .to_string(),
- field_names: "amount_capturable".to_string(),
- connector_transaction_id: payment_data
- .payment_attempt
- .connector_transaction_id
- .clone(),
- payment_id: Some(payment_data.payment_intent.payment_id.clone()),
- })?
- } else if capturable_amount.is_some_and(|capturable_amount| {
- MinorUnit::new(capturable_amount) > total_capturable_amount
- }) && !is_overcapture_enabled
- {
- Err(ApiErrorResponse::IntegrityCheckFailed {
- reason: "capturable_amount is greater than the total attempt amount"
- .to_string(),
- field_names: "amount_capturable".to_string(),
- connector_transaction_id: payment_data
- .payment_attempt
- .connector_transaction_id
- .clone(),
- payment_id: Some(payment_data.payment_intent.payment_id.clone()),
- })?
} else {
- Ok(self.status)
+ Ok(enums::AttemptStatus::Authorized)
}
}
enums::AttemptStatus::CaptureFailed => {
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 754f169560..a88270f88a 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -541,6 +541,10 @@ pub mod superposition {
"routing.preferred_connectors_enabled_payment_method_types";
/// Payout blocklist guard configuration key
pub const PAYOUT_BLOCKLIST_GUARD: &str = "payouts.payout_blocklist_guard";
+ /// Accept connector payment amount mismatch configuration key (scoped by processor merchant
+ /// and payment method type). When enabled, a connector-reported payment amount that differs
+ /// from the requested amount does not fail the integrity check. Refunds are not affected.
+ pub const ACCEPT_PAYMENT_AMOUNT_MISMATCH: &str = "payments.accept_payment_amount_mismatch";
}
/// The value substituted for sensitive webhook header values in event retrieval responses.
diff --git a/crates/router/src/core/authentication/transformers.rs b/crates/router/src/core/authentication/transformers.rs
index 73aa1ea219..57525e988d 100644
--- a/crates/router/src/core/authentication/transformers.rs
+++ b/crates/router/src/core/authentication/transformers.rs
@@ -205,6 +205,7 @@ pub fn construct_router_data<F: Clone, Req, Res>(
payment_method_status: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/configs/dimension_config.rs b/crates/router/src/core/configs/dimension_config.rs
index 59e4151f31..52f5ae48e5 100644
--- a/crates/router/src/core/configs/dimension_config.rs
+++ b/crates/router/src/core/configs/dimension_config.rs
@@ -1101,3 +1101,15 @@ config! {
impl DatabaseBackedConfig for PayoutBlocklistGuard {
const KEY: &'static str = "payout_blocklist_guard";
}
+
+config! {
+ superposition_key = ACCEPT_PAYMENT_AMOUNT_MISMATCH,
+ output = bool,
+ default = false,
+ requires = dimension_state::DimensionsWithProcessorMerchantIdAndPaymentMethodType,
+ targeting_key = id_type::MerchantId
+}
+
+impl DatabaseBackedConfig for AcceptPaymentAmountMismatch {
+ const KEY: &'static str = "accept_payment_amount_mismatch";
+}
diff --git a/crates/router/src/core/configs/dimension_state.rs b/crates/router/src/core/configs/dimension_state.rs
index d129b56237..bd37cf8de1 100644
--- a/crates/router/src/core/configs/dimension_state.rs
+++ b/crates/router/src/core/configs/dimension_state.rs
@@ -1,9 +1,10 @@
use std::marker::PhantomData;
use api_models::webhooks::IncomingWebhookEvent;
-use common_enums::{connector_enums::Connector, PayoutRetryType};
+use common_enums::{connector_enums::Connector, PaymentMethodType, PayoutRetryType};
use common_utils::id_type;
use external_services::superposition;
+use heck::ToPascalCase;
pub use hyperswitch_domain_models::platform::{ProcessorMerchantId, ProviderMerchantId};
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
@@ -18,6 +19,8 @@ pub enum DimensionError {
MissingProfileId,
#[error("connector not available in dimension state")]
MissingConnector,
+ #[error("payment_method_type not available in dimension state")]
+ MissingPaymentMethodType,
}
/// Marker for state WITHOUT provider_merchant_id
@@ -76,8 +79,19 @@ pub struct NoWebhookEvent;
#[derive(Clone)]
pub struct HasWebhookEvent;
+/// Marker for state WITHOUT payment_method_type
+#[derive(Clone)]
+pub struct NoPaymentMethodType;
+
+/// Marker for state WITH payment_method_type
+#[derive(Clone)]
+pub struct HasPaymentMethodType;
+
// Dimensional State with type parameters
+/// Zero-sized type-state markers, one per dimension.
+type DimensionMarkers<Pm, M, O, P, Cn, PRT, Ev, Pmt> = PhantomData<(Pm, M, O, P, Cn, PRT, Ev, Pmt)>;
+
/// Dimensional state with type-level guarantees about which dimensions are present.
///
/// Uses the type-state pattern where type parameters indicate which fields are available.
@@ -90,8 +104,9 @@ pub struct HasWebhookEvent;
/// * `Cn` - Connector: `HasConnector` or `NoConnector`
/// * `PRT` - Payout Retry Type: `HasPayoutRetryType` or `NoPayoutRetryType`
/// * `Ev` - Webhook Event type: `HasWebhookEvent` (present) or `NoWebhookEvent` (absent)
+/// * `Pmt` - Payment Method Type: `HasPaymentMethodType` or `NoPaymentMethodType`
#[derive(Clone)]
-pub struct Dimensions<Pm, M, O, P, Cn, PRT, Ev> {
+pub struct Dimensions<Pm, M, O, P, Cn, PRT, Ev, Pmt> {
provider_merchant_id: Option<ProviderMerchantId>,
processor_merchant_id: Option<ProcessorMerchantId>,
organization_id: Option<id_type::OrganizationId>,
@@ -99,7 +114,8 @@ pub struct Dimensions<Pm, M, O, P, Cn, PRT, Ev> {
connector: Option<Connector>,
payout_retry_type: Option<PayoutRetryType>,
incoming_webhook_event: Option<IncomingWebhookEvent>,
- _phantom: PhantomData<(Pm, M, O, P, Cn, PRT, Ev)>,
+ payment_method_type: Option<PaymentMethodType>,
+ _phantom: DimensionMarkers<Pm, M, O, P, Cn, PRT, Ev, Pmt>,
}
impl
@@ -111,6 +127,7 @@ impl
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>
{
pub fn new() -> Self {
@@ -122,17 +139,18 @@ impl
connector: None,
payout_retry_type: None,
incoming_webhook_event: None,
+ payment_method_type: None,
_phantom: PhantomData,
}
}
}
/// Can only add provider_merchant_id if not already present
-impl<M, O, P, Cn, PRT, Ev> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT, Ev> {
+impl<M, O, P, Cn, PRT, Ev, Pmt> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT, Ev, Pmt> {
pub fn with_provider_merchant_id(
&self,
id: ProviderMerchantId,
- ) -> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev> {
+ ) -> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: Some(id),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -141,17 +159,18 @@ impl<M, O, P, Cn, PRT, Ev> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT, Ev
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only add processor_merchant_id if not already present
-impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT, Ev> {
+impl<Pm, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT, Ev, Pmt> {
pub fn with_processor_merchant_id(
&self,
id: ProcessorMerchantId,
- ) -> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev> {
+ ) -> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: Some(id),
@@ -160,17 +179,18 @@ impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT,
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only add organization_id if not already present
-impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev> {
+impl<Pm, M, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev, Pmt> {
pub fn with_organization_id(
&self,
id: id_type::OrganizationId,
- ) -> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {
+ ) -> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -179,17 +199,18 @@ impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev> {
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only add profile_id if not already present
-impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev> {
+impl<Pm, M, O, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev, Pmt> {
pub fn with_profile_id(
&self,
id: id_type::ProfileId,
- ) -> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {
+ ) -> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -198,17 +219,18 @@ impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev> {
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only add connector if not already present
-impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev> {
+impl<Pm, M, O, P, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev, Pmt> {
pub fn with_connector(
&self,
connector: Connector,
- ) -> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev> {
+ ) -> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -217,17 +239,18 @@ impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev> {
connector: Some(connector),
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only add payout_retry_type if not already present
-impl<Pm, M, O, P, Cn, Ev> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType, Ev> {
+impl<Pm, M, O, P, Cn, Ev, Pmt> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType, Ev, Pmt> {
pub fn with_payout_retry_type(
&self,
retry_type: PayoutRetryType,
- ) -> Dimensions<Pm, M, O, P, Cn, HasPayoutRetryType, Ev> {
+ ) -> Dimensions<Pm, M, O, P, Cn, HasPayoutRetryType, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -236,17 +259,18 @@ impl<Pm, M, O, P, Cn, Ev> Dimensions<Pm, M, O, P, Cn, NoPayoutRetryType, Ev> {
connector: self.connector,
payout_retry_type: Some(retry_type),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only add incoming_webhook_event if not already present
-impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent> {
+impl<Pm, M, O, P, Cn, PRT, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent, Pmt> {
pub fn with_incoming_webhook_event(
&self,
event: IncomingWebhookEvent,
- ) -> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent> {
+ ) -> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -255,16 +279,37 @@ impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent> {
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: Some(event),
+ payment_method_type: self.payment_method_type,
+ _phantom: PhantomData,
+ }
+ }
+}
+
+/// Can only add payment_method_type if not already present
+impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev, NoPaymentMethodType> {
+ pub fn with_payment_method_type(
+ &self,
+ payment_method_type: PaymentMethodType,
+ ) -> Dimensions<Pm, M, O, P, Cn, PRT, Ev, HasPaymentMethodType> {
+ Dimensions {
+ provider_merchant_id: self.provider_merchant_id.clone(),
+ processor_merchant_id: self.processor_merchant_id.clone(),
+ organization_id: self.organization_id.clone(),
+ profile_id: self.profile_id.clone(),
+ connector: self.connector,
+ payout_retry_type: self.payout_retry_type.clone(),
+ incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: Some(payment_method_type),
_phantom: PhantomData,
}
}
}
/// Can only remove provider_merchant_id if currently present
-impl<M, O, P, Cn, PRT, Ev> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev> {
+impl<M, O, P, Cn, PRT, Ev, Pmt> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev, Pmt> {
pub fn without_provider_merchant_id(
&self,
- ) -> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT, Ev> {
+ ) -> Dimensions<NoProviderMerchantId, M, O, P, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: None,
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -273,16 +318,17 @@ impl<M, O, P, Cn, PRT, Ev> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, E
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only remove processor_merchant_id if currently present
-impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev> {
+impl<Pm, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev, Pmt> {
pub fn without_processor_merchant_id(
&self,
- ) -> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT, Ev> {
+ ) -> Dimensions<Pm, NoProcessorMerchantId, O, P, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: None,
@@ -291,14 +337,15 @@ impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only remove organization_id if currently present
-impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {
- pub fn without_organization_id(&self) -> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev> {
+impl<Pm, M, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev, Pmt> {
+ pub fn without_organization_id(&self) -> Dimensions<Pm, M, NoOrgId, P, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -307,14 +354,15 @@ impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only remove profile_id if currently present
-impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {
- pub fn without_profile_id(&self) -> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev> {
+impl<Pm, M, O, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev, Pmt> {
+ pub fn without_profile_id(&self) -> Dimensions<Pm, M, O, NoProfileId, Cn, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -323,14 +371,15 @@ impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only remove connector if currently present
-impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev> {
- pub fn without_connector(&self) -> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev> {
+impl<Pm, M, O, P, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev, Pmt> {
+ pub fn without_connector(&self) -> Dimensions<Pm, M, O, P, NoConnector, PRT, Ev, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -339,16 +388,17 @@ impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev> {
connector: None,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: self.incoming_webhook_event,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// Can only remove incoming_webhook_event if currently present
-impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent> {
+impl<Pm, M, O, P, Cn, PRT, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent, Pmt> {
pub fn without_incoming_webhook_event(
&self,
- ) -> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent> {
+ ) -> Dimensions<Pm, M, O, P, Cn, PRT, NoWebhookEvent, Pmt> {
Dimensions {
provider_merchant_id: self.provider_merchant_id.clone(),
processor_merchant_id: self.processor_merchant_id.clone(),
@@ -357,13 +407,14 @@ impl<Pm, M, O, P, Cn, PRT> Dimensions<Pm, M, O, P, Cn, PRT, HasWebhookEvent> {
connector: self.connector,
payout_retry_type: self.payout_retry_type.clone(),
incoming_webhook_event: None,
+ payment_method_type: self.payment_method_type,
_phantom: PhantomData,
}
}
}
/// provider_merchant_id getter - only available if HasProviderMerchantId
-impl<M, O, P, Cn, PRT, Ev> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev> {
+impl<M, O, P, Cn, PRT, Ev, Pmt> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, Ev, Pmt> {
pub fn provider_merchant_id(&self) -> Result<&id_type::MerchantId, DimensionError> {
self.provider_merchant_id
.as_ref()
@@ -373,7 +424,7 @@ impl<M, O, P, Cn, PRT, Ev> Dimensions<HasProviderMerchantId, M, O, P, Cn, PRT, E
}
/// processor_merchant_id getter - only available if HasProcessorMerchantId
-impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev> {
+impl<Pm, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT, Ev, Pmt> {
pub fn processor_merchant_id(&self) -> Result<&id_type::MerchantId, DimensionError> {
self.processor_merchant_id
.as_ref()
@@ -383,7 +434,7 @@ impl<Pm, O, P, Cn, PRT, Ev> Dimensions<Pm, HasProcessorMerchantId, O, P, Cn, PRT
}
/// organization_id getter - only available if HasOrgId
-impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {
+impl<Pm, M, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev, Pmt> {
pub fn organization_id(&self) -> Result<&id_type::OrganizationId, DimensionError> {
self.organization_id
.as_ref()
@@ -392,7 +443,7 @@ impl<Pm, M, P, Cn, PRT, Ev> Dimensions<Pm, M, HasOrgId, P, Cn, PRT, Ev> {
}
/// profile_id getter - only available if HasProfileId
-impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {
+impl<Pm, M, O, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev, Pmt> {
pub fn profile_id(&self) -> Result<&id_type::ProfileId, DimensionError> {
self.profile_id
.as_ref()
@@ -401,14 +452,22 @@ impl<Pm, M, O, Cn, PRT, Ev> Dimensions<Pm, M, O, HasProfileId, Cn, PRT, Ev> {
}
/// connector getter - only available if HasConnector
-impl<Pm, M, O, P, PRT, Ev> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev> {
+impl<Pm, M, O, P, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, HasConnector, PRT, Ev, Pmt> {
pub fn connector(&self) -> Result<Connector, DimensionError> {
self.connector.ok_or(DimensionError::MissingConnector)
}
}
+/// payment_method_type getter - only available if HasPaymentMethodType
+impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev, HasPaymentMethodType> {
+ pub fn payment_method_type(&self) -> Result<PaymentMethodType, DimensionError> {
+ self.payment_method_type
+ .ok_or(DimensionError::MissingPaymentMethodType)
+ }
+}
+
// Optional getters (available in any state)
-impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev> {
+impl<Pm, M, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, Ev, Pmt> {
pub fn get_provider_merchant_id(&self) -> Option<&id_type::MerchantId> {
self.provider_merchant_id.as_ref().map(|id| id.inner())
}
@@ -436,10 +495,14 @@ impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev> {
pub fn get_incoming_webhook_event(&self) -> Option<IncomingWebhookEvent> {
self.incoming_webhook_event
}
+
+ pub fn get_payment_method_type(&self) -> Option<PaymentMethodType> {
+ self.payment_method_type
+ }
}
// Superposition context conversion
-impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev> {
+impl<Pm, M, O, P, Cn, PRT, Ev, Pmt> Dimensions<Pm, M, O, P, Cn, PRT, Ev, Pmt> {
/// Converts dimension state to Superposition config context
pub fn to_superposition_context(&self) -> Option<superposition::ConfigContext> {
let mut ctx = superposition::ConfigContext::new();
@@ -474,6 +537,14 @@ impl<Pm, M, O, P, Cn, PRT, Ev> Dimensions<Pm, M, O, P, Cn, PRT, Ev> {
}
}
+ // Superposition lists payment method types in PascalCase (e.g. `apple_pay` -> `ApplePay`)
+ if let Some(pmt) = self.payment_method_type {
+ ctx = ctx.with(
+ "payment_method_type",
+ pmt.to_string().to_pascal_case().as_str(),
+ );
+ }
+
Some(ctx)
}
}
@@ -487,6 +558,7 @@ impl Default
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>
{
fn default() -> Self {
@@ -519,9 +591,12 @@ pub trait DimensionsBase {
/// Get incoming_webhook_event (if available)
fn get_incoming_webhook_event(&self) -> Option<IncomingWebhookEvent>;
+
+ /// Get payment_method_type (if available)
+ fn get_payment_method_type(&self) -> Option<PaymentMethodType>;
}
-impl<Pm, M, O, P, Cn, PRT, Ev> DimensionsBase for Dimensions<Pm, M, O, P, Cn, PRT, Ev> {
+impl<Pm, M, O, P, Cn, PRT, Ev, Pmt> DimensionsBase for Dimensions<Pm, M, O, P, Cn, PRT, Ev, Pmt> {
fn to_superposition_context(&self) -> Option<superposition::ConfigContext> {
self.to_superposition_context()
}
@@ -553,6 +628,10 @@ impl<Pm, M, O, P, Cn, PRT, Ev> DimensionsBase for Dimensions<Pm, M, O, P, Cn, PR
fn get_incoming_webhook_event(&self) -> Option<IncomingWebhookEvent> {
self.get_incoming_webhook_event()
}
+
+ fn get_payment_method_type(&self) -> Option<PaymentMethodType> {
+ self.get_payment_method_type()
+ }
}
// Type aliases
@@ -566,6 +645,7 @@ pub type DimensionsGlobal = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProviderMerchantId = Dimensions<
@@ -576,6 +656,7 @@ pub type DimensionsWithProviderMerchantId = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
// Type alias - provider merchant ID and organization ID present
@@ -587,6 +668,7 @@ pub type DimensionsWithProviderMerchantIdAndOrgId = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
// Type alias - only processor merchant ID present
@@ -598,6 +680,7 @@ pub type DimensionsWithProcessorMerchantId = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
// Type alias - processor merchant ID and connector present
@@ -609,6 +692,7 @@ pub type DimensionsWithProcessorMerchantIdAndConnector = Dimensions<
HasConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
// Type aliases - both provider and processor merchant IDs present
@@ -620,6 +704,7 @@ pub type DimensionsWithProcessorAndProviderMerchantId = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileId = Dimensions<
HasProviderMerchantId,
@@ -629,6 +714,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileId = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithOrgId = Dimensions<
NoProviderMerchantId,
@@ -638,6 +724,7 @@ pub type DimensionsWithOrgId = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndConnector = Dimensions<
HasProviderMerchantId,
@@ -647,6 +734,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndConnector = Dimensions<
HasConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileIdAndConnector = Dimensions<
HasProviderMerchantId,
@@ -656,6 +744,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndProfileIdAndConnector =
HasConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgId = Dimensions<
HasProviderMerchantId,
@@ -665,6 +754,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgId = Dimensions<
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId = Dimensions<
HasProviderMerchantId,
@@ -674,6 +764,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndOrgIdAndProfileId = Dime
NoConnector,
NoPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndPayoutRetryType = Dimensions<
HasProviderMerchantId,
@@ -683,6 +774,7 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndPayoutRetryType = Dimens
NoConnector,
HasPayoutRetryType,
NoWebhookEvent,
+ NoPaymentMethodType,
>;
pub type DimensionsWithProcessorAndProviderMerchantIdAndConnectorAndWebhookEvent = Dimensions<
HasProviderMerchantId,
@@ -692,4 +784,15 @@ pub type DimensionsWithProcessorAndProviderMerchantIdAndConnectorAndWebhookEvent
HasConnector,
NoPayoutRetryType,
HasWebhookEvent,
+ NoPaymentMethodType,
+>;
+pub type DimensionsWithProcessorMerchantIdAndPaymentMethodType = Dimensions<
+ NoProviderMerchantId,
+ HasProcessorMerchantId,
+ NoOrgId,
+ NoProfileId,
+ NoConnector,
+ NoPayoutRetryType,
+ NoWebhookEvent,
+ HasPaymentMethodType,
>;
diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
index 0448020377..8f877b4f49 100644
--- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
@@ -182,6 +182,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
index 3c7b164490..3f00c3c898 100644
--- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
@@ -127,6 +127,7 @@ pub async fn construct_fulfillment_router_data<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/fraud_check/flows/po_frm_flow.rs b/crates/router/src/core/fraud_check/flows/po_frm_flow.rs
index ce4bc3fc37..aaf63fce77 100644
--- a/crates/router/src/core/fraud_check/flows/po_frm_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/po_frm_flow.rs
@@ -122,6 +122,7 @@ impl ConstructFlowSpecificData<frm_api::PoFrm, FraudCheckPayoutData, FraudCheckR
minor_amount_capturable: None,
authorized_amount: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs
index 54c9680301..2a40933571 100644
--- a/crates/router/src/core/fraud_check/flows/record_return.rs
+++ b/crates/router/src/core/fraud_check/flows/record_return.rs
@@ -128,6 +128,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/fraud_check/flows/sale_flow.rs b/crates/router/src/core/fraud_check/flows/sale_flow.rs
index 5d9e3e4121..ff18d19b25 100644
--- a/crates/router/src/core/fraud_check/flows/sale_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/sale_flow.rs
@@ -180,6 +180,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/fraud_check/flows/transaction_flow.rs b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
index a3ad51fef8..8528189919 100644
--- a/crates/router/src/core/fraud_check/flows/transaction_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
@@ -147,6 +147,7 @@ impl
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/mandate/utils.rs b/crates/router/src/core/mandate/utils.rs
index 0aab1b611b..9792db8189 100644
--- a/crates/router/src/core/mandate/utils.rs
+++ b/crates/router/src/core/mandate/utils.rs
@@ -82,6 +82,7 @@ pub async fn construct_mandate_revoke_router_data(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/merchant_connector_webhook_management/transformers.rs b/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
index 2091a1aac9..f0243854ce 100644
--- a/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
+++ b/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
@@ -122,6 +122,7 @@ pub async fn construct_webhook_register_router_data<'a>(
payment_method_status: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -203,6 +204,7 @@ pub async fn construct_generate_secret_router_data<'a>(
payment_method_status: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs
index 4d27dcdc2d..102ff63d71 100644
--- a/crates/router/src/core/payments/flows/authorize_flow.rs
+++ b/crates/router/src/core/payments/flows/authorize_flow.rs
@@ -241,6 +241,9 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
if self.should_proceed_with_authorize() {
self.decide_authentication_type();
logger::debug!(auth_type=?self.auth_type);
+ // Read before the connector call: connectors on the V2 interface rebuild the returned
+ // router data from `PaymentFlowData`, which does not carry this flag.
+ let accept_amount_mismatch = self.accept_amount_mismatch;
let mut auth_router_data = gateway::execute_payment_gateway(
state,
connector_integration,
@@ -257,6 +260,7 @@ impl Feature<api::Authorize, types::PaymentsAuthorizeData> for types::PaymentsAu
let integrity_result = helpers::check_integrity_based_on_flow(
&auth_router_data.request,
&auth_router_data.response,
+ accept_amount_mismatch,
);
auth_router_data.integrity_check = integrity_result;
metrics::PAYMENT_COUNT.add(1, &[]); // Move outside of the if block
diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rs
index 888759b509..30c329538c 100644
--- a/crates/router/src/core/payments/flows/capture_flow.rs
+++ b/crates/router/src/core/payments/flows/capture_flow.rs
@@ -96,6 +96,9 @@ impl Feature<api::Capture, types::PaymentsCaptureData>
return_raw_connector_response: Option<bool>,
gateway_context: payments::gateway::context::RouterGatewayContext,
) -> RouterResult<Self> {
+ // Read before the connector call: connectors on the V2 interface rebuild the returned
+ // router data from `PaymentFlowData`, which does not carry this flag.
+ let accept_amount_mismatch = self.accept_amount_mismatch;
let mut new_router_data =
payments::gateway::handle_gateway_call::<_, _, _, PaymentFlowData, _>(
state,
@@ -112,6 +115,7 @@ impl Feature<api::Capture, types::PaymentsCaptureData>
let integrity_result = helpers::check_integrity_based_on_flow(
&new_router_data.request,
&new_router_data.response,
+ accept_amount_mismatch,
);
new_router_data.integrity_check = integrity_result;
diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs
index ad5da95013..cf57dc0ee1 100644
--- a/crates/router/src/core/payments/flows/psync_flow.rs
+++ b/crates/router/src/core/payments/flows/psync_flow.rs
@@ -111,6 +111,9 @@ impl Feature<api::PSync, types::PaymentsSyncData>
.get_multiple_capture_sync_method()
.to_payment_failed_response();
+ // Read before the connector call: connectors on the V2 interface rebuild the returned
+ // router data from `PaymentFlowData`, which does not carry this flag.
+ let accept_amount_mismatch = self.accept_amount_mismatch;
match (self.request.sync_type.clone(), capture_sync_method_result) {
(
types::SyncRequestType::MultipleCaptureSync(pending_connector_capture_id_list),
@@ -130,6 +133,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>
let integrity_result = helpers::check_integrity_based_on_flow(
&new_router_data.request,
&new_router_data.response,
+ accept_amount_mismatch,
);
new_router_data.integrity_check = integrity_result;
@@ -155,6 +159,7 @@ impl Feature<api::PSync, types::PaymentsSyncData>
let integrity_result = helpers::check_integrity_based_on_flow(
&new_router_data.request,
&new_router_data.response,
+ accept_amount_mismatch,
);
new_router_data.integrity_check = integrity_result;
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index f0f2830e60..2391d17308 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -5484,6 +5484,7 @@ pub fn router_data_type_conversion<F1, F2, Req1, Req2, Res1, Res2>(
payout_id: router_data.payout_id,
connector_response: router_data.connector_response,
integrity_check: Ok(()),
+ accept_amount_mismatch: router_data.accept_amount_mismatch,
connector_wallets_details: router_data.connector_wallets_details,
additional_merchant_data: router_data.additional_merchant_data,
header_payload: router_data.header_payload,
@@ -9326,6 +9327,7 @@ pub async fn fetch_active_surcharge_mca(
pub fn check_integrity_based_on_flow<T, Request>(
request: &Request,
payment_response_data: &Result<PaymentsResponseData, ErrorResponse>,
+ accept_amount_mismatch: Option<common_types::primitive_wrappers::AcceptAmountMismatchBool>,
) -> Result<(), common_utils::errors::IntegrityCheckError>
where
T: FlowIntegrity,
@@ -9349,7 +9351,12 @@ where
},
Err(_) => &None,
};
- request.check_integrity(request, connector_transaction_id.to_owned())
+ request.check_integrity(
+ request,
+ connector_transaction_id.to_owned(),
+ // `None` (not resolved for this router data) defaults to `false`: a strict check.
+ accept_amount_mismatch.unwrap_or_default(),
+ )
}
pub async fn config_skip_saving_wallet_at_connector(
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 157d34bdbe..e8b17846cd 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -229,6 +229,7 @@ where
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id,
@@ -601,6 +602,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id,
@@ -1018,6 +1020,7 @@ pub async fn construct_external_vault_proxy_payment_router_data_v1<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id,
@@ -1192,6 +1195,7 @@ pub async fn construct_payment_router_data_for_capture<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id,
@@ -1273,6 +1277,9 @@ pub async fn construct_router_data_for_psync<'a>(
setup_future_usage: Some(payment_intent.setup_future_usage),
feature_metadata: None,
connector_mandate_id: None,
+ enable_partial_authorization: Some(payment_intent.enable_partial_authorization),
+ // The v2 payment attempt does not track overcapture yet
+ is_overcapture_enabled: None,
};
// TODO: evaluate the fields in router data, if they are required or not
@@ -1333,6 +1340,7 @@ pub async fn construct_router_data_for_psync<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
@@ -1691,6 +1699,7 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id: None,
@@ -1931,6 +1940,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload,
connector_mandate_request_reference_id,
@@ -2191,6 +2201,10 @@ where
processor.get_account().storage_scheme,
)
.await;
+
+ let accept_amount_mismatch =
+ core_utils::get_accept_payment_amount_mismatch(state, processor, payment_method_type).await;
+
let router_data = types::RouterData {
flow: PhantomData,
merchant_id,
@@ -2265,6 +2279,7 @@ where
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch,
additional_merchant_data: merchant_recipient_data.map(|data| {
api_models::admin::AdditionalMerchantData::foreign_from(
types::AdditionalMerchantData::OpenBankingRecipientData(data),
@@ -2496,6 +2511,7 @@ pub async fn construct_payment_router_data_for_update_metadata<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: merchant_recipient_data.map(|data| {
api_models::admin::AdditionalMerchantData::foreign_from(
types::AdditionalMerchantData::OpenBankingRecipientData(data),
@@ -5703,6 +5719,8 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSyncData
.connector_mandate_detail
.as_ref()
.and_then(|d| d.get_connector_mandate_id()),
+ enable_partial_authorization: payment_data.payment_intent.enable_partial_authorization,
+ is_overcapture_enabled: payment_data.payment_attempt.is_overcapture_enabled,
})
}
}
@@ -8339,6 +8357,7 @@ pub async fn construct_payment_router_data_for_update_post_confirm<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id,
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 8c94001277..958f94a3f6 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -1029,7 +1029,11 @@ where
.map(|resp_data| resp_data.connector_refund_id.clone())
.ok();
- request.check_integrity(request, connector_refund_id.to_owned())
+ request.check_integrity(
+ request,
+ connector_refund_id.to_owned(),
+ common_types::primitive_wrappers::AcceptAmountMismatchBool::default(),
+ )
}
// ********************************************** REFUND SYNC **********************************************
diff --git a/crates/router/src/core/refunds_v2.rs b/crates/router/src/core/refunds_v2.rs
index 51cb5d4210..557b98e4ca 100644
--- a/crates/router/src/core/refunds_v2.rs
+++ b/crates/router/src/core/refunds_v2.rs
@@ -631,7 +631,11 @@ where
.map(|resp_data| resp_data.connector_refund_id.clone())
.ok();
- request.check_integrity(request, connector_refund_id.to_owned())
+ request.check_integrity(
+ request,
+ connector_refund_id.to_owned(),
+ common_types::primitive_wrappers::AcceptAmountMismatchBool::default(),
+ )
}
// ********************************************** REFUND UPDATE **********************************************
diff --git a/crates/router/src/core/relay/utils.rs b/crates/router/src/core/relay/utils.rs
index 7e5cdd8949..248d9059e3 100644
--- a/crates/router/src/core/relay/utils.rs
+++ b/crates/router/src/core/relay/utils.rs
@@ -141,6 +141,7 @@ pub async fn construct_relay_refund_router_data<F>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -285,6 +286,7 @@ pub async fn construct_relay_capture_router_data(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -412,6 +414,7 @@ pub async fn construct_relay_incremental_authorization_router_data(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -548,6 +551,7 @@ pub async fn construct_relay_void_router_data(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -671,6 +675,8 @@ pub async fn construct_relay_payments_retrieve_router_data(
setup_future_usage: None,
feature_metadata: None,
connector_mandate_id: None,
+ enable_partial_authorization: None,
+ is_overcapture_enabled: None,
},
response: Err(ErrorResponse::default()),
@@ -698,6 +704,7 @@ pub async fn construct_relay_payments_retrieve_router_data(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs
index 5b7dedf94a..4083b53a72 100644
--- a/crates/router/src/core/unified_authentication_service/utils.rs
+++ b/crates/router/src/core/unified_authentication_service/utils.rs
@@ -138,6 +138,7 @@ pub fn construct_uas_router_data<F: Clone, Req, Res>(
payment_method_status: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -709,6 +710,7 @@ pub fn construct_uas_webhook_router_data<F: Clone, Req, Res>(
payment_method_status: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 35b4e5a855..f825327ed4 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -354,6 +354,7 @@ pub async fn construct_payout_router_data<'a, F>(
payout_id: Some(payouts.payout_id.get_string_repr().to_string()),
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -539,6 +540,7 @@ pub async fn construct_refund_router_data<'a, F>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -559,6 +561,27 @@ pub async fn construct_refund_router_data<'a, F>(
Ok(router_data)
}
+/// Resolves the `payments.accept_payment_amount_mismatch` config for the processor merchant and payment
+/// method type. Without a payment method type the config cannot be scoped, so `None` is returned and
+/// the integrity check stays strict.
+#[cfg(feature = "v1")]
+pub async fn get_accept_payment_amount_mismatch(
+ state: &SessionState,
+ processor: &domain::Processor,
+ payment_method_type: Option<enums::PaymentMethodType>,
+) -> Option<common_types::primitive_wrappers::AcceptAmountMismatchBool> {
+ let accept_amount_mismatch = dimension_state::Dimensions::new()
+ .with_processor_merchant_id(processor.get_processor_merchant_id())
+ .with_payment_method_type(payment_method_type?)
+ .get_accept_payment_amount_mismatch(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ Some(processor.get_account().get_id()),
+ )
+ .await;
+ Some(common_types::primitive_wrappers::AcceptAmountMismatchBool::new(accept_amount_mismatch))
+}
+
#[cfg(feature = "v1")]
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
@@ -740,6 +763,7 @@ pub async fn construct_refund_router_data<'a, F>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -1263,6 +1287,7 @@ pub async fn construct_accept_dispute_router_data<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -1377,6 +1402,7 @@ pub async fn construct_submit_evidence_router_data<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -1500,6 +1526,7 @@ pub async fn construct_upload_file_router_data<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -1581,6 +1608,7 @@ pub async fn construct_dispute_list_router_data<'a>(
payment_method_status: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -1694,6 +1722,7 @@ pub async fn construct_dispute_sync_router_data<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -1833,6 +1862,7 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>(
payment_method_status: None,
minor_amount_captured: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -1950,6 +1980,7 @@ pub async fn construct_defend_dispute_router_data<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
@@ -2060,6 +2091,7 @@ pub async fn construct_retrieve_file_router_data<'a>(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs
index 2c1d2393e7..e4732fad78 100644
--- a/crates/router/src/core/webhooks/utils.rs
+++ b/crates/router/src/core/webhooks/utils.rs
@@ -136,6 +136,7 @@ pub async fn construct_webhook_router_data(
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index e191770ec1..1d14538569 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -1504,6 +1504,7 @@ impl<F1, F2, T1, T2> ForeignFrom<(&RouterData<F1, T1, PaymentsResponseData>, T2)
payout_id: data.payout_id.clone(),
connector_response: data.connector_response.clone(),
integrity_check: Ok(()),
+ accept_amount_mismatch: data.accept_amount_mismatch,
additional_merchant_data: data.additional_merchant_data.clone(),
header_payload: data.header_payload.clone(),
connector_mandate_request_reference_id: data
@@ -1584,6 +1585,7 @@ impl<F1, F2>
payout_id: data.payout_id.clone(),
connector_response: data.connector_response.clone(),
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
header_payload: data.header_payload.clone(),
authentication_id: None,
psd2_sca_exemption_type: None,
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index bf377e9b99..2a7f557ca9 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -140,6 +140,7 @@ impl VerifyConnectorData {
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index e83f041001..9869a807d3 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -562,6 +562,7 @@ pub trait ConnectorActions: Connector {
payout_id: None,
connector_response: None,
integrity_check: Ok(()),
+ accept_amount_mismatch: None,
additional_merchant_data: None,
header_payload: None,
connector_mandate_request_reference_id: None,