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: core changes for extended authorization (#6766)

Hrithikeshc3c4f50fcf46
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index b3d21c5a0b..5e52263ef3 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -1,5 +1,7 @@
use std::collections::{HashMap, HashSet};
+#[cfg(feature = "v1")]
+use common_types::primitive_wrappers::AlwaysRequestExtendedAuthorization;
use common_utils::{
consts,
crypto::Encryptable,
@@ -8,10 +10,7 @@ use common_utils::{
id_type, link_utils, pii,
};
#[cfg(feature = "v1")]
-use common_utils::{
- crypto::OptionalEncryptableName, ext_traits::ValueExt,
- types::AlwaysRequestExtendedAuthorization,
-};
+use common_utils::{crypto::OptionalEncryptableName, ext_traits::ValueExt};
#[cfg(feature = "v2")]
use masking::ExposeInterface;
use masking::{PeekInterface, Secret};
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index b7d344317c..bcd11bb65e 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -9,6 +9,9 @@ use cards::CardNumber;
#[cfg(feature = "v2")]
use common_enums::enums::PaymentConnectorTransmission;
use common_enums::ProductType;
+use common_types::primitive_wrappers::{
+ ExtendedAuthorizationAppliedBool, RequestExtendedAuthorizationBool,
+};
use common_utils::{
consts::default_payments_list_limit,
crypto,
@@ -17,10 +20,7 @@ use common_utils::{
hashing::HashedString,
id_type,
pii::{self, Email},
- types::{
- ExtendedAuthorizationAppliedBool, MinorUnit, RequestExtendedAuthorizationBool,
- StringMajorUnit,
- },
+ types::{MinorUnit, StringMajorUnit},
};
use error_stack::ResultExt;
use masking::{PeekInterface, Secret, WithType};
diff --git a/crates/api_models/src/payments/trait_impls.rs b/crates/api_models/src/payments/trait_impls.rs
index 5df07a24a9..87b5661daf 100644
--- a/crates/api_models/src/payments/trait_impls.rs
+++ b/crates/api_models/src/payments/trait_impls.rs
@@ -8,7 +8,7 @@ use crate::payments;
#[cfg(feature = "v1")]
impl crate::ValidateFieldAndGet<payments::PaymentsRequest>
- for common_utils::types::RequestExtendedAuthorizationBool
+ for common_types::primitive_wrappers::RequestExtendedAuthorizationBool
{
fn validate_field_and_get(
&self,
diff --git a/crates/common_enums/src/connector_enums.rs b/crates/common_enums/src/connector_enums.rs
index 24c709a7e8..875dec5818 100644
--- a/crates/common_enums/src/connector_enums.rs
+++ b/crates/common_enums/src/connector_enums.rs
@@ -1,6 +1,9 @@
+use std::collections::HashSet;
+
use utoipa::ToSchema;
pub use super::enums::{PaymentMethod, PayoutType};
+pub use crate::PaymentMethodType;
#[derive(
Clone,
@@ -453,6 +456,15 @@ impl Connector {
matches!(self, Self::Airwallex)
}
+ pub fn get_payment_methods_supporting_extended_authorization(self) -> HashSet<PaymentMethod> {
+ HashSet::new()
+ }
+ pub fn get_payment_method_types_supporting_extended_authorization(
+ self,
+ ) -> HashSet<PaymentMethodType> {
+ HashSet::new()
+ }
+
pub fn should_acknowledge_webhook_for_resource_not_found_errors(self) -> bool {
matches!(self, Self::Adyenplatform)
}
diff --git a/crates/common_types/src/lib.rs b/crates/common_types/src/lib.rs
index 6139ddff16..4d3d2380e2 100644
--- a/crates/common_types/src/lib.rs
+++ b/crates/common_types/src/lib.rs
@@ -5,4 +5,6 @@
pub mod domain;
pub mod payment_methods;
pub mod payments;
+/// types that are wrappers around primitive types
+pub mod primitive_wrappers;
pub mod refunds;
diff --git a/crates/common_types/src/primitive_wrappers.rs b/crates/common_types/src/primitive_wrappers.rs
new file mode 100644
index 0000000000..d86a060784
--- /dev/null
+++ b/crates/common_types/src/primitive_wrappers.rs
@@ -0,0 +1,131 @@
+pub use bool_wrappers::*;
+
+mod bool_wrappers {
+ use std::ops::Deref;
+
+ use serde::{Deserialize, Serialize};
+ /// Bool that represents if Extended Authorization is Applied or not
+ #[derive(
+ Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, diesel::expression::AsExpression,
+ )]
+ #[diesel(sql_type = diesel::sql_types::Bool)]
+ pub struct ExtendedAuthorizationAppliedBool(bool);
+ impl Deref for ExtendedAuthorizationAppliedBool {
+ type Target = bool;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
+ impl From<bool> for ExtendedAuthorizationAppliedBool {
+ fn from(value: bool) -> Self {
+ Self(value)
+ }
+ }
+ impl<DB> diesel::serialize::ToSql<diesel::sql_types::Bool, DB> for ExtendedAuthorizationAppliedBool
+ where
+ DB: diesel::backend::Backend,
+ bool: diesel::serialize::ToSql<diesel::sql_types::Bool, DB>,
+ {
+ fn to_sql<'b>(
+ &'b self,
+ out: &mut diesel::serialize::Output<'b, '_, DB>,
+ ) -> diesel::serialize::Result {
+ self.0.to_sql(out)
+ }
+ }
+ impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>
+ for ExtendedAuthorizationAppliedBool
+ where
+ DB: diesel::backend::Backend,
+ bool: diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>,
+ {
+ fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
+ bool::from_sql(value).map(Self)
+ }
+ }
+
+ /// Bool that represents if Extended Authorization is Requested or not
+ #[derive(
+ Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, diesel::expression::AsExpression,
+ )]
+ #[diesel(sql_type = diesel::sql_types::Bool)]
+ pub struct RequestExtendedAuthorizationBool(bool);
+ impl Deref for RequestExtendedAuthorizationBool {
+ type Target = bool;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
+ impl From<bool> for RequestExtendedAuthorizationBool {
+ fn from(value: bool) -> Self {
+ Self(value)
+ }
+ }
+ impl RequestExtendedAuthorizationBool {
+ /// returns the inner bool value
+ pub fn is_true(&self) -> bool {
+ self.0
+ }
+ }
+ impl<DB> diesel::serialize::ToSql<diesel::sql_types::Bool, DB> for RequestExtendedAuthorizationBool
+ where
+ DB: diesel::backend::Backend,
+ bool: diesel::serialize::ToSql<diesel::sql_types::Bool, DB>,
+ {
+ fn to_sql<'b>(
+ &'b self,
+ out: &mut diesel::serialize::Output<'b, '_, DB>,
+ ) -> diesel::serialize::Result {
+ self.0.to_sql(out)
+ }
+ }
+ impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>
+ for RequestExtendedAuthorizationBool
+ where
+ DB: diesel::backend::Backend,
+ bool: diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>,
+ {
+ fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
+ bool::from_sql(value).map(Self)
+ }
+ }
+
+ /// Bool that represents if Extended Authorization is always Requested or not
+ #[derive(
+ Clone, Copy, Debug, Eq, PartialEq, diesel::expression::AsExpression, Serialize, Deserialize,
+ )]
+ #[diesel(sql_type = diesel::sql_types::Bool)]
+ pub struct AlwaysRequestExtendedAuthorization(bool);
+ impl Deref for AlwaysRequestExtendedAuthorization {
+ type Target = bool;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+ }
+ impl<DB> diesel::serialize::ToSql<diesel::sql_types::Bool, DB>
+ for AlwaysRequestExtendedAuthorization
+ where
+ DB: diesel::backend::Backend,
+ bool: diesel::serialize::ToSql<diesel::sql_types::Bool, DB>,
+ {
+ fn to_sql<'b>(
+ &'b self,
+ out: &mut diesel::serialize::Output<'b, '_, DB>,
+ ) -> diesel::serialize::Result {
+ self.0.to_sql(out)
+ }
+ }
+ impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>
+ for AlwaysRequestExtendedAuthorization
+ where
+ DB: diesel::backend::Backend,
+ bool: diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>,
+ {
+ fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
+ bool::from_sql(value).map(Self)
+ }
+ }
+}
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 384f7c7df2..00f1d8ec13 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -1,7 +1,8 @@
use std::collections::{HashMap, HashSet};
use common_enums::{AuthenticationConnectors, UIWidgetFormLayout};
-use common_utils::{encryption::Encryption, pii, types::AlwaysRequestExtendedAuthorization};
+use common_types::primitive_wrappers::AlwaysRequestExtendedAuthorization;
+use common_utils::{encryption::Encryption, pii};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use masking::Secret;
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 8fb4afeb8e..0fdb24119a 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -1,9 +1,9 @@
+use common_types::primitive_wrappers::{
+ ExtendedAuthorizationAppliedBool, RequestExtendedAuthorizationBool,
+};
use common_utils::{
id_type, pii,
- types::{
- ConnectorTransactionId, ConnectorTransactionIdTrait, ExtendedAuthorizationAppliedBool,
- MinorUnit, RequestExtendedAuthorizationBool,
- },
+ types::{ConnectorTransactionId, ConnectorTransactionIdTrait, MinorUnit},
};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
@@ -517,6 +517,8 @@ pub enum PaymentAttemptUpdate {
encoded_data: Option<String>,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
+ capture_before: Option<PrimitiveDateTime>,
+ extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,
payment_method_data: Option<serde_json::Value>,
connector_mandate_detail: Option<ConnectorMandateReferenceId>,
charges: Option<common_types::payments::ConnectorChargeResponseData>,
@@ -896,6 +898,8 @@ pub struct PaymentAttemptUpdateInternal {
pub client_version: Option<String>,
pub customer_acceptance: Option<pii::SecretSerdeValue>,
pub card_network: Option<String>,
+ pub capture_before: Option<PrimitiveDateTime>,
+ pub extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,
pub shipping_cost: Option<MinorUnit>,
pub order_tax_amount: Option<MinorUnit>,
pub connector_mandate_detail: Option<ConnectorMandateReferenceId>,
@@ -1086,6 +1090,8 @@ impl PaymentAttemptUpdate {
order_tax_amount,
processor_transaction_data,
connector_mandate_detail,
+ capture_before,
+ extended_authorization_applied,
card_discovery,
charges,
issuer_error_code,
@@ -1147,6 +1153,9 @@ impl PaymentAttemptUpdate {
processor_transaction_data: processor_transaction_data
.or(source.processor_transaction_data),
connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail),
+ capture_before: capture_before.or(source.capture_before),
+ extended_authorization_applied: extended_authorization_applied
+ .or(source.extended_authorization_applied),
card_discovery: card_discovery.or(source.card_discovery),
charges: charges.or(source.charges),
issuer_error_code: issuer_error_code.or(source.issuer_error_code),
@@ -2199,6 +2208,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
customer_acceptance: None,
card_network: None,
shipping_cost: None,
+ capture_before: None,
+ extended_authorization_applied: None,
order_tax_amount: None,
processor_transaction_data: None,
connector_mandate_detail: None,
@@ -2259,6 +2270,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -2350,6 +2363,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost,
order_tax_amount,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail,
card_discovery,
@@ -2410,6 +2425,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -2471,6 +2488,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -2532,6 +2551,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -2591,6 +2612,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail,
card_discovery: None,
@@ -2650,6 +2673,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -2676,6 +2701,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
encoded_data,
unified_code,
unified_message,
+ capture_before,
+ extended_authorization_applied,
payment_method_data,
connector_mandate_detail,
charges,
@@ -2735,6 +2762,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ capture_before,
+ extended_authorization_applied,
shipping_cost: None,
order_tax_amount: None,
card_discovery: None,
@@ -2813,6 +2842,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ capture_before: None,
+ extended_authorization_applied: None,
shipping_cost: None,
order_tax_amount: None,
connector_mandate_detail: None,
@@ -2868,6 +2899,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
customer_acceptance: None,
card_network: None,
shipping_cost: None,
+ capture_before: None,
+ extended_authorization_applied: None,
order_tax_amount: None,
processor_transaction_data: None,
connector_mandate_detail: None,
@@ -2933,6 +2966,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
customer_acceptance: None,
card_network: None,
shipping_cost: None,
+ capture_before: None,
+ extended_authorization_applied: None,
order_tax_amount: None,
processor_transaction_data: None,
connector_mandate_detail: None,
@@ -3006,6 +3041,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
customer_acceptance: None,
card_network: None,
shipping_cost: None,
+ capture_before: None,
+ extended_authorization_applied: None,
order_tax_amount: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -3076,6 +3113,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
client_version: None,
customer_acceptance: None,
card_network: None,
+ capture_before: None,
+ extended_authorization_applied: None,
shipping_cost: None,
order_tax_amount: None,
connector_mandate_detail: None,
@@ -3138,6 +3177,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -3197,6 +3238,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
customer_acceptance: None,
card_network: None,
shipping_cost: None,
+ capture_before: None,
+ extended_authorization_applied: None,
order_tax_amount: None,
processor_transaction_data: None,
connector_mandate_detail: None,
@@ -3268,6 +3311,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
customer_acceptance: None,
card_network: None,
shipping_cost: None,
+ capture_before: None,
+ extended_authorization_applied: None,
order_tax_amount: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -3327,6 +3372,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -3389,6 +3436,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
processor_transaction_data: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -3460,6 +3509,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
customer_acceptance: None,
card_network: None,
shipping_cost: None,
+ capture_before: None,
+ extended_authorization_applied: None,
order_tax_amount: None,
connector_mandate_detail: None,
card_discovery: None,
@@ -3520,6 +3571,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
card_network: None,
shipping_cost: None,
order_tax_amount: None,
+ capture_before: None,
+ extended_authorization_applied: None,
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 4f2f4c49ea..27a572fa8e 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -1,9 +1,6 @@
use common_enums::{PaymentMethodType, RequestIncrementalAuthorization};
-use common_utils::{
- encryption::Encryption,
- pii,
- types::{MinorUnit, RequestExtendedAuthorizationBool},
-};
+use common_types::primitive_wrappers::RequestExtendedAuthorizationBool;
+use common_utils::{encryption::Encryption, pii, types::MinorUnit};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
diff --git a/crates/diesel_models/src/user/sample_data.rs b/crates/diesel_models/src/user/sample_data.rs
index d6c8d5616f..e093d7775d 100644
--- a/crates/diesel_models/src/user/sample_data.rs
+++ b/crates/diesel_models/src/user/sample_data.rs
@@ -2,10 +2,10 @@ use common_enums::{
AttemptStatus, AuthenticationType, CaptureMethod, Currency, PaymentExperience, PaymentMethod,
PaymentMethodType,
};
-use common_utils::types::{
- ConnectorTransactionId, ExtendedAuthorizationAppliedBool, MinorUnit,
- RequestExtendedAuthorizationBool,
+use common_types::primitive_wrappers::{
+ ExtendedAuthorizationAppliedBool, RequestExtendedAuthorizationBool,
};
+use common_utils::types::{ConnectorTransactionId, MinorUnit};
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index fb7463d64e..fed943fbf4 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -5981,6 +5981,7 @@ pub(crate) fn convert_setup_mandate_router_data_to_authorize_router_data(
payment_method_type: None,
customer_id: None,
surcharge_details: None,
+ request_extended_authorization: None,
request_incremental_authorization: data.request.request_incremental_authorization,
metadata: None,
authentication_data: None,
diff --git a/crates/hyperswitch_domain_models/src/business_profile.rs b/crates/hyperswitch_domain_models/src/business_profile.rs
index d0b78ee180..810ff1bb9c 100644
--- a/crates/hyperswitch_domain_models/src/business_profile.rs
+++ b/crates/hyperswitch_domain_models/src/business_profile.rs
@@ -1,10 +1,11 @@
+use common_types::primitive_wrappers::AlwaysRequestExtendedAuthorization;
use common_utils::{
crypto::{OptionalEncryptableName, OptionalEncryptableValue},
date_time,
encryption::Encryption,
errors::{CustomResult, ValidationError},
pii, type_name,
- types::{keymanager, AlwaysRequestExtendedAuthorization},
+ types::keymanager,
};
use diesel_models::business_profile::{
AuthenticationConnectorDetails, BusinessPaymentLinkConfig, BusinessPayoutLinkConfig,
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index 9921cee8a6..8571184038 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -3,6 +3,9 @@ use std::marker::PhantomData;
#[cfg(feature = "v2")]
use api_models::payments::SessionToken;
+use common_types::primitive_wrappers::{
+ AlwaysRequestExtendedAuthorization, RequestExtendedAuthorizationBool,
+};
#[cfg(feature = "v2")]
use common_utils::ext_traits::{OptionExt, ValueExt};
use common_utils::{
@@ -11,7 +14,7 @@ use common_utils::{
encryption::Encryption,
errors::CustomResult,
id_type, pii,
- types::{keymanager::ToEncryptable, MinorUnit, RequestExtendedAuthorizationBool},
+ types::{keymanager::ToEncryptable, MinorUnit},
};
use diesel_models::payment_intent::TaxDetails;
#[cfg(feature = "v2")]
@@ -143,6 +146,51 @@ impl PaymentIntent {
.change_context(errors::api_error_response::ApiErrorResponse::InternalServerError)
.attach_printable("Error creating start redirection url")
}
+ #[cfg(feature = "v1")]
+ pub fn get_request_extended_authorization_bool_if_connector_supports(
+ &self,
+ connector: common_enums::connector_enums::Connector,
+ always_request_extended_authorization_optional: Option<AlwaysRequestExtendedAuthorization>,
+ payment_method_optional: Option<common_enums::PaymentMethod>,
+ payment_method_type_optional: Option<common_enums::PaymentMethodType>,
+ ) -> Option<RequestExtendedAuthorizationBool> {
+ use router_env::logger;
+
+ let is_extended_authorization_supported_by_connector = || {
+ let supported_pms = connector.get_payment_methods_supporting_extended_authorization();
+ let supported_pmts =
+ connector.get_payment_method_types_supporting_extended_authorization();
+ // check if payment method or payment method type is supported by the connector
+ logger::info!(
+ "Extended Authentication Connector:{:?}, Supported payment methods: {:?}, Supported payment method types: {:?}, Payment method Selected: {:?}, Payment method type Selected: {:?}",
+ connector,
+ supported_pms,
+ supported_pmts,
+ payment_method_optional,
+ payment_method_type_optional
+ );
+ match (payment_method_optional, payment_method_type_optional) {
+ (Some(payment_method), Some(payment_method_type)) => {
+ supported_pms.contains(&payment_method)
+ && supported_pmts.contains(&payment_method_type)
+ }
+ (Some(payment_method), None) => supported_pms.contains(&payment_method),
+ (None, Some(payment_method_type)) => supported_pmts.contains(&payment_method_type),
+ (None, None) => false,
+ }
+ };
+ let intent_request_extended_authorization_optional = self.request_extended_authorization;
+ if always_request_extended_authorization_optional.is_some_and(
+ |always_request_extended_authorization| *always_request_extended_authorization,
+ ) || intent_request_extended_authorization_optional.is_some_and(
+ |intent_request_extended_authorization| *intent_request_extended_authorization,
+ ) {
+ Some(is_extended_authorization_supported_by_connector())
+ } else {
+ None
+ }
+ .map(RequestExtendedAuthorizationBool::from)
+ }
#[cfg(feature = "v2")]
/// This is the url to which the customer will be redirected to, after completing the redirection flow
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 2dc4eec15f..25f93107c6 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -1,6 +1,9 @@
#[cfg(all(feature = "v1", feature = "olap"))]
use api_models::enums::Connector;
use common_enums as storage_enums;
+use common_types::primitive_wrappers::{
+ ExtendedAuthorizationAppliedBool, RequestExtendedAuthorizationBool,
+};
#[cfg(feature = "v2")]
use common_utils::{
crypto::Encryptable, encryption::Encryption, ext_traits::ValueExt,
@@ -12,8 +15,7 @@ use common_utils::{
id_type, pii,
types::{
keymanager::{self, KeyManagerState},
- ConnectorTransactionId, ConnectorTransactionIdTrait, ExtendedAuthorizationAppliedBool,
- MinorUnit, RequestExtendedAuthorizationBool,
+ ConnectorTransactionId, ConnectorTransactionIdTrait, MinorUnit,
},
};
use diesel_models::{
@@ -1209,6 +1211,8 @@ pub enum PaymentAttemptUpdate {
encoded_data: Option<String>,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
+ capture_before: Option<PrimitiveDateTime>,
+ extended_authorization_applied: Option<ExtendedAuthorizationAppliedBool>,
payment_method_data: Option<serde_json::Value>,
connector_mandate_detail: Option<ConnectorMandateReferenceId>,
charges: Option<common_types::payments::ConnectorChargeResponseData>,
@@ -1483,6 +1487,8 @@ impl PaymentAttemptUpdate {
encoded_data,
unified_code,
unified_message,
+ capture_before,
+ extended_authorization_applied,
payment_method_data,
connector_mandate_detail,
charges,
@@ -1505,6 +1511,8 @@ impl PaymentAttemptUpdate {
encoded_data,
unified_code,
unified_message,
+ capture_before,
+ extended_authorization_applied,
payment_method_data,
connector_mandate_detail,
charges,
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
index 6618d2fbc8..3953564da3 100644
--- a/crates/hyperswitch_domain_models/src/router_data.rs
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -1,5 +1,6 @@
use std::{collections::HashMap, marker::PhantomData};
+use common_types::primitive_wrappers;
use common_utils::{
errors::IntegrityCheckError,
ext_traits::{OptionExt, ValueExt},
@@ -361,6 +362,7 @@ pub struct PaymentMethodBalance {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ConnectorResponseData {
pub additional_payment_method_data: Option<AdditionalPaymentMethodConnectorResponse>,
+ extended_authorization_response_data: Option<ExtendedAuthorizationResponseData>,
}
impl ConnectorResponseData {
@@ -369,8 +371,14 @@ impl ConnectorResponseData {
) -> Self {
Self {
additional_payment_method_data: Some(additional_payment_method_data),
+ extended_authorization_response_data: None,
}
}
+ pub fn get_extended_authorization_response_data(
+ &self,
+ ) -> Option<&ExtendedAuthorizationResponseData> {
+ self.extended_authorization_response_data.as_ref()
+ }
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -386,6 +394,13 @@ pub enum AdditionalPaymentMethodConnectorResponse {
},
}
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
+pub struct ExtendedAuthorizationResponseData {
+ pub extended_authentication_applied:
+ Option<primitive_wrappers::ExtendedAuthorizationAppliedBool>,
+ pub capture_before: Option<time::PrimitiveDateTime>,
+}
+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct KlarnaSdkResponse {
pub payment_type: Option<String>,
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index 1e75e8ea45..750bad93e7 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -60,6 +60,8 @@ pub struct PaymentsAuthorizeData {
pub request_incremental_authorization: bool,
pub metadata: Option<serde_json::Value>,
pub authentication_data: Option<AuthenticationData>,
+ pub request_extended_authorization:
+ Option<common_types::primitive_wrappers::RequestExtendedAuthorizationBool>,
pub split_payments: Option<common_types::payments::SplitPaymentsRequest>,
// New amount for amount frame work
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index c50770b394..52e6397919 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -3028,7 +3028,13 @@ where
operation
.to_domain()?
- .populate_payment_data(state, payment_data, merchant_account)
+ .populate_payment_data(
+ state,
+ payment_data,
+ merchant_account,
+ business_profile,
+ &connector,
+ )
.await?;
let (pd, tokenization_action) = get_connector_tokenization_action_when_confirm_true(
diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs
index 294ec92e30..d914e59253 100644
--- a/crates/router/src/core/payments/operations.rs
+++ b/crates/router/src/core/payments/operations.rs
@@ -309,6 +309,8 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {
_state: &SessionState,
_payment_data: &mut D,
_merchant_account: &domain::MerchantAccount,
+ _business_profile: &domain::Profile,
+ _connector_data: &api::ConnectorData,
) -> CustomResult<(), errors::ApiErrorResponse> {
Ok(())
}
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 0953464f56..42f72b6c3c 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -985,8 +985,19 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
state: &SessionState,
payment_data: &mut PaymentData<F>,
_merchant_account: &domain::MerchantAccount,
+ business_profile: &domain::Profile,
+ connector_data: &api::ConnectorData,
) -> CustomResult<(), errors::ApiErrorResponse> {
- populate_surcharge_details(state, payment_data).await
+ populate_surcharge_details(state, payment_data).await?;
+ payment_data.payment_attempt.request_extended_authorization = payment_data
+ .payment_intent
+ .get_request_extended_authorization_bool_if_connector_supports(
+ connector_data.connector_name,
+ business_profile.always_request_extended_authorization,
+ payment_data.payment_attempt.payment_method,
+ payment_data.payment_attempt.payment_method_type,
+ );
+ Ok(())
}
#[allow(clippy::too_many_arguments)]
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index db5972b67a..7638eaec9a 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -1572,7 +1572,7 @@ impl PaymentCreate {
shipping_cost: request.shipping_cost,
tax_details,
skip_external_tax_calculation,
- request_extended_authorization: None,
+ request_extended_authorization: request.request_extended_authorization,
psd2_sca_exemption_type: request.psd2_sca_exemption_type,
platform_merchant_id: platform_merchant_account
.map(|platform_merchant_account| platform_merchant_account.get_id().to_owned()),
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 409fccf5e6..ff16d1c9f7 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -1666,6 +1666,19 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
payment_data.payment_attempt.connector.clone(),
payment_data.payment_attempt.merchant_id.clone(),
);
+ let (capture_before, extended_authorization_applied) = router_data
+ .connector_response
+ .as_ref()
+ .and_then(|connector_response| {
+ connector_response.get_extended_authorization_response_data()
+ })
+ .map(|extended_auth_resp| {
+ (
+ extended_auth_resp.capture_before,
+ extended_auth_resp.extended_authentication_applied,
+ )
+ })
+ .unwrap_or((None, None));
let (capture_updates, payment_attempt_update) = match payment_data
.multiple_capture_data
{
@@ -1727,6 +1740,8 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
authentication_data,
encoded_data,
payment_method_data: additional_payment_method_data,
+ capture_before,
+ extended_authorization_applied,
connector_mandate_detail: payment_data
.payment_attempt
.connector_mandate_detail
diff --git a/crates/router/src/core/payments/retry.rs b/crates/router/src/core/payments/retry.rs
index 24a3ac2ec8..05cba78856 100644
--- a/crates/router/src/core/payments/retry.rs
+++ b/crates/router/src/core/payments/retry.rs
@@ -485,6 +485,8 @@ where
encoded_data,
unified_code: None,
unified_message: None,
+ capture_before: None,
+ extended_authorization_applied: None,
payment_method_data: additional_payment_method_data,
connector_mandate_detail: None,
charges,
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 5186bb3220..0bbe5675c7 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -291,6 +291,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
complete_authorize_url,
customer_id: None,
surcharge_details: None,
+ request_extended_authorization: None,
request_incremental_authorization: matches!(
payment_data
.payment_intent
@@ -3271,6 +3272,7 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsAuthoriz
.map(AuthenticationData::foreign_try_from)
.transpose()?,
customer_acceptance: payment_data.customer_acceptance,
+ request_extended_authorization: attempt.request_extended_authorization,
split_payments,
merchant_order_reference_id,
integrity_object: None,
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index a6fe900b3c..ff9eef080a 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -904,6 +904,7 @@ impl ForeignFrom<&SetupMandateRouterData> for PaymentsAuthorizeData {
surcharge_details: None,
request_incremental_authorization: data.request.request_incremental_authorization,
metadata: None,
+ request_extended_authorization: None,
authentication_data: None,
customer_acceptance: data.request.customer_acceptance.clone(),
split_payments: None, // TODO: allow charges on mandates?
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index ed3c56787d..a2a4cf88f6 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -52,6 +52,7 @@ impl VerifyConnectorData {
complete_authorize_url: None,
related_transaction_id: None,
statement_descriptor_suffix: None,
+ request_extended_authorization: None,
request_incremental_authorization: false,
authentication_data: None,
customer_acceptance: None,
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index c874722551..4cc6f1b0e3 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -975,6 +975,7 @@ impl Default for PaymentAuthorizeType {
customer_id: None,
surcharge_details: None,
request_incremental_authorization: false,
+ request_extended_authorization: None,
metadata: None,
authentication_data: None,
customer_acceptance: None,