Skip to content

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

refactor(storage_impl): Move Conversion impl for authentication to storage_impl crate (#11805)

Anurag Thakurddfcedfe0e9e
diff --git a/crates/hyperswitch_domain_models/src/authentication.rs b/crates/hyperswitch_domain_models/src/authentication.rs
index 26d28fc0f0..ce154117e8 100644
--- a/crates/hyperswitch_domain_models/src/authentication.rs
+++ b/crates/hyperswitch_domain_models/src/authentication.rs
@@ -1,25 +1,20 @@
use std::str::FromStr;
-use async_trait::async_trait;
use common_enums::MerchantCategoryCode;
use common_utils::{
crypto::Encryptable,
encryption::Encryption,
errors::{CustomResult, ValidationError},
pii,
- types::keymanager::{Identifier, KeyManagerState, ToEncryptable},
+ types::keymanager::ToEncryptable,
};
use error_stack::ResultExt;
-use hyperswitch_masking::{PeekInterface, Secret};
+use hyperswitch_masking::Secret;
use rustc_hash::FxHashMap;
use serde_json::Value;
-use super::behaviour;
-use crate::{
- router_request_types::unified_authentication_service::{
- DynamicData, PostAuthenticationDetails,
- },
- type_encryption::{crypto_operation, AsyncLift, CryptoOperation},
+use crate::router_request_types::unified_authentication_service::{
+ DynamicData, PostAuthenticationDetails,
};
#[derive(Clone, Debug, router_derive::ToEncryption, serde::Serialize)]
@@ -157,312 +152,6 @@ pub struct PgRedirectResponseForAuthentication {
pub amount: Option<common_utils::types::MinorUnit>,
}
-#[async_trait]
-impl behaviour::Conversion for Authentication {
- type DstType = diesel_models::authentication::Authentication;
- type NewDstType = diesel_models::authentication::AuthenticationNew;
-
- async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
- Ok(Self::DstType {
- authentication_id: self.authentication_id,
- merchant_id: self.merchant_id,
- authentication_connector: self.authentication_connector,
- connector_authentication_id: self.connector_authentication_id,
- authentication_data: self.authentication_data,
- payment_method_id: self.payment_method_id,
- authentication_type: self.authentication_type,
- authentication_status: self.authentication_status,
- authentication_lifecycle_status: self.authentication_lifecycle_status,
- created_at: self.created_at,
- modified_at: self.modified_at,
- error_message: self.error_message,
- error_code: self.error_code,
- connector_metadata: self.connector_metadata,
- maximum_supported_version: self.maximum_supported_version,
- threeds_server_transaction_id: self.threeds_server_transaction_id,
- cavv: self.cavv,
- authentication_flow_type: self.authentication_flow_type,
- message_version: self.message_version,
- eci: self.eci,
- trans_status: self.trans_status,
- acquirer_bin: self.acquirer_bin,
- acquirer_merchant_id: self.acquirer_merchant_id,
- three_ds_method_data: self.three_ds_method_data,
- three_ds_method_url: self.three_ds_method_url,
- acs_url: self.acs_url,
- challenge_request: self.challenge_request,
- acs_reference_number: self.acs_reference_number,
- acs_trans_id: self.acs_trans_id,
- acs_signed_content: self.acs_signed_content,
- profile_id: self.profile_id,
- payment_id: self.payment_id,
- merchant_connector_id: self.merchant_connector_id,
- ds_trans_id: self.ds_trans_id,
- directory_server_id: self.directory_server_id,
- acquirer_country_code: self.acquirer_country_code,
- service_details: self.service_details,
- organization_id: self.organization_id,
- authentication_client_secret: self.authentication_client_secret,
- force_3ds_challenge: self.force_3ds_challenge,
- psd2_sca_exemption_type: self.psd2_sca_exemption_type,
- return_url: self.return_url,
- amount: self.amount,
- currency: self.currency,
- billing_address: self.billing_address.map(Encryption::from),
- shipping_address: self.shipping_address.map(Encryption::from),
- browser_info: self.browser_info,
- email: self.email.map(|email| email.into()),
- profile_acquirer_id: self.profile_acquirer_id,
- challenge_code: self.challenge_code,
- challenge_cancel: self.challenge_cancel,
- challenge_code_reason: self.challenge_code_reason,
- message_extension: self.message_extension,
- challenge_request_key: self.challenge_request_key,
- customer_details: self.customer_details,
- earliest_supported_version: self.earliest_supported_version,
- latest_supported_version: self.latest_supported_version,
- mcc: self.mcc,
- platform: self.platform.map(|platform| platform.to_string()),
- device_type: self.device_type,
- device_brand: self.device_brand,
- device_os: self.device_os,
- device_display: self.device_display,
- browser_name: self.browser_name,
- browser_version: self.browser_version,
- scheme_name: self.scheme_name,
- exemption_requested: self.exemption_requested,
- exemption_accepted: self.exemption_accepted,
- issuer_id: self.issuer_id,
- issuer_country: self.issuer_country,
- merchant_country_code: self.merchant_country_code,
- billing_country: self.billing_country,
- shipping_country: self.shipping_country,
- processor_merchant_id: self.processor_merchant_id,
- created_by: self.created_by.map(|created_by| created_by.to_string()),
- })
- }
-
- async fn convert_back(
- state: &KeyManagerState,
- other: Self::DstType,
- key: &Secret<Vec<u8>>,
- _key_manager_identifier: Identifier,
- ) -> CustomResult<Self, ValidationError> {
- let encrypted_data = crypto_operation(
- state,
- common_utils::type_name!(Self),
- CryptoOperation::BatchDecrypt(EncryptedAuthentication::to_encryptable(
- EncryptedAuthentication {
- billing_address: other.billing_address,
- shipping_address: other.shipping_address,
- },
- )),
- Identifier::Merchant(other.merchant_id.clone()),
- key.peek(),
- )
- .await
- .and_then(|val| val.try_into_batchoperation())
- .change_context(ValidationError::InvalidValue {
- message: "Failed while decrypting authentication data".to_string(),
- })?;
-
- let decrypted_data = FromRequestEncryptableAuthentication::from_encryptable(encrypted_data)
- .change_context(ValidationError::InvalidValue {
- message: "Failed while decrypting authentication data".to_string(),
- })?;
-
- let email_decrypted = other
- .email
- .clone()
- .async_lift(|inner| async {
- crypto_operation::<String, pii::EmailStrategy>(
- state,
- common_utils::type_name!(Self),
- CryptoOperation::DecryptOptional(inner),
- Identifier::Merchant(other.merchant_id.clone()),
- key.peek(),
- )
- .await
- .and_then(|val| val.try_into_optionaloperation())
- })
- .await
- .change_context(ValidationError::InvalidValue {
- message: "Failed while decrypting authentication email".to_string(),
- })?;
-
- Ok(Self {
- authentication_id: other.authentication_id,
- merchant_id: other.merchant_id,
- authentication_connector: other.authentication_connector,
- connector_authentication_id: other.connector_authentication_id,
- authentication_data: other.authentication_data,
- payment_method_id: other.payment_method_id,
- authentication_type: other.authentication_type,
- authentication_status: other.authentication_status,
- authentication_lifecycle_status: other.authentication_lifecycle_status,
- created_at: other.created_at,
- modified_at: other.modified_at,
- error_message: other.error_message,
- error_code: other.error_code,
- connector_metadata: other.connector_metadata,
- maximum_supported_version: other.maximum_supported_version,
- threeds_server_transaction_id: other.threeds_server_transaction_id,
- cavv: other.cavv,
- authentication_flow_type: other.authentication_flow_type,
- message_version: other.message_version,
- eci: other.eci,
- trans_status: other.trans_status,
- acquirer_bin: other.acquirer_bin,
- acquirer_merchant_id: other.acquirer_merchant_id,
- three_ds_method_data: other.three_ds_method_data,
- three_ds_method_url: other.three_ds_method_url,
- acs_url: other.acs_url,
- challenge_request: other.challenge_request,
- acs_reference_number: other.acs_reference_number,
- acs_trans_id: other.acs_trans_id,
- acs_signed_content: other.acs_signed_content,
- profile_id: other.profile_id,
- payment_id: other.payment_id,
- merchant_connector_id: other.merchant_connector_id,
- ds_trans_id: other.ds_trans_id,
- directory_server_id: other.directory_server_id,
- acquirer_country_code: other.acquirer_country_code,
- organization_id: other.organization_id,
- mcc: other.mcc,
- amount: other.amount,
- currency: other.currency,
- issuer_country: other.issuer_country,
- earliest_supported_version: other.earliest_supported_version,
- latest_supported_version: other.latest_supported_version,
- platform: other
- .platform
- .as_deref()
- .map(|s| {
- api_models::payments::DeviceChannel::from_str(s).change_context(
- ValidationError::InvalidValue {
- message: "Invalid device channel".into(),
- },
- )
- })
- .transpose()?,
- device_type: other.device_type,
- device_brand: other.device_brand,
- device_os: other.device_os,
- device_display: other.device_display,
- browser_name: other.browser_name,
- browser_version: other.browser_version,
- issuer_id: other.issuer_id,
- scheme_name: other.scheme_name,
- exemption_requested: other.exemption_requested,
- exemption_accepted: other.exemption_accepted,
- service_details: other.service_details,
- authentication_client_secret: other.authentication_client_secret,
- force_3ds_challenge: other.force_3ds_challenge,
- psd2_sca_exemption_type: other.psd2_sca_exemption_type,
- return_url: other.return_url,
- billing_address: decrypted_data.billing_address,
- shipping_address: decrypted_data.shipping_address,
- browser_info: other.browser_info,
- email: email_decrypted,
- profile_acquirer_id: other.profile_acquirer_id,
- challenge_code: other.challenge_code,
- challenge_cancel: other.challenge_cancel,
- challenge_code_reason: other.challenge_code_reason,
- message_extension: other.message_extension,
- challenge_request_key: other.challenge_request_key,
- customer_details: other.customer_details,
- billing_country: other.billing_country,
- shipping_country: other.shipping_country,
- merchant_country_code: other.merchant_country_code,
- processor_merchant_id: other.processor_merchant_id,
- created_by: other
- .created_by
- .and_then(|created_by| created_by.parse::<common_utils::types::CreatedBy>().ok()),
- })
- }
-
- async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
- Ok(Self::NewDstType {
- authentication_id: __self.authentication_id,
- merchant_id: __self.merchant_id,
- authentication_connector: __self.authentication_connector,
- connector_authentication_id: __self.connector_authentication_id,
- payment_method_id: __self.payment_method_id,
- authentication_type: __self.authentication_type,
- authentication_status: __self.authentication_status,
- authentication_lifecycle_status: __self.authentication_lifecycle_status,
- error_message: __self.error_message,
- error_code: __self.error_code,
- connector_metadata: __self.connector_metadata,
- maximum_supported_version: __self.maximum_supported_version,
- threeds_server_transaction_id: __self.threeds_server_transaction_id,
- cavv: __self.cavv,
- authentication_flow_type: __self.authentication_flow_type,
- message_version: __self.message_version,
- eci: __self.eci,
- trans_status: __self.trans_status,
- acquirer_bin: __self.acquirer_bin,
- acquirer_merchant_id: __self.acquirer_merchant_id,
- three_ds_method_data: __self.three_ds_method_data,
- three_ds_method_url: __self.three_ds_method_url,
- acs_url: __self.acs_url,
- challenge_request: __self.challenge_request,
- acs_reference_number: __self.acs_reference_number,
- acs_trans_id: __self.acs_trans_id,
- acs_signed_content: __self.acs_signed_content,
- profile_id: __self.profile_id,
- payment_id: __self.payment_id,
- merchant_connector_id: __self.merchant_connector_id,
- ds_trans_id: __self.ds_trans_id,
- directory_server_id: __self.directory_server_id,
- acquirer_country_code: __self.acquirer_country_code,
- service_details: __self.service_details,
- organization_id: __self.organization_id,
- authentication_client_secret: __self.authentication_client_secret,
- force_3ds_challenge: __self.force_3ds_challenge,
- psd2_sca_exemption_type: __self.psd2_sca_exemption_type,
- return_url: __self.return_url,
- amount: __self.amount,
- currency: __self.currency,
- billing_address: __self.billing_address.map(Encryption::from),
- shipping_address: __self.shipping_address.map(Encryption::from),
- browser_info: __self.browser_info,
- email: __self.email.map(|email| email.into()),
- profile_acquirer_id: __self.profile_acquirer_id,
- challenge_code: __self.challenge_code,
- challenge_cancel: __self.challenge_cancel,
- challenge_code_reason: __self.challenge_code_reason,
- message_extension: __self.message_extension,
- challenge_request_key: __self.challenge_request_key,
- customer_details: __self.customer_details,
- earliest_supported_version: __self.earliest_supported_version,
- latest_supported_version: __self.latest_supported_version,
- mcc: __self.mcc,
- platform: __self.platform.map(|platform| platform.to_string()),
- device_type: __self.device_type,
- device_brand: __self.device_brand,
- device_os: __self.device_os,
- device_display: __self.device_display,
- browser_name: __self.browser_name,
- browser_version: __self.browser_version,
- scheme_name: __self.scheme_name,
- exemption_requested: __self.exemption_requested,
- exemption_accepted: __self.exemption_accepted,
- issuer_id: __self.issuer_id,
- issuer_country: __self.issuer_country,
- merchant_country_code: __self.merchant_country_code,
- created_at: __self.created_at,
- modified_at: __self.modified_at,
- authentication_data: __self.authentication_data,
- billing_country: __self.billing_country,
- shipping_country: __self.shipping_country,
- processor_merchant_id: __self.processor_merchant_id,
- created_by: __self.created_by.map(|created_by| created_by.to_string()),
- })
- }
-}
-
-#[derive(Debug)]
pub enum AuthenticationUpdate {
PreAuthenticationVersionCallUpdate {
maximum_supported_3ds_version: common_utils::types::SemanticVersion,
@@ -551,169 +240,3 @@ pub enum AuthenticationUpdate {
acquirer_country_code: Option<String>,
},
}
-
-impl From<AuthenticationUpdate> for diesel_models::authentication::AuthenticationUpdate {
- fn from(authentication_update: AuthenticationUpdate) -> Self {
- match authentication_update {
- AuthenticationUpdate::PreAuthenticationVersionCallUpdate {
- maximum_supported_3ds_version,
- message_version,
- } => Self::PreAuthenticationVersionCallUpdate {
- maximum_supported_3ds_version,
- message_version,
- },
- AuthenticationUpdate::PreAuthenticationThreeDsMethodCall {
- threeds_server_transaction_id,
- three_ds_method_data,
- three_ds_method_url,
- acquirer_bin,
- acquirer_merchant_id,
- connector_metadata,
- } => Self::PreAuthenticationThreeDsMethodCall {
- threeds_server_transaction_id,
- three_ds_method_data,
- three_ds_method_url,
- acquirer_bin,
- acquirer_merchant_id,
- connector_metadata,
- },
- AuthenticationUpdate::PreAuthenticationUpdate {
- threeds_server_transaction_id,
- maximum_supported_3ds_version,
- connector_authentication_id,
- three_ds_method_data,
- three_ds_method_url,
- message_version,
- connector_metadata,
- authentication_status,
- acquirer_bin,
- acquirer_merchant_id,
- directory_server_id,
- acquirer_country_code,
- billing_address,
- shipping_address,
- browser_info,
- email,
- scheme_id,
- merchant_category_code,
- merchant_country_code,
- billing_country,
- shipping_country,
- earliest_supported_version,
- latest_supported_version,
- } => Self::PreAuthenticationUpdate {
- threeds_server_transaction_id,
- maximum_supported_3ds_version,
- connector_authentication_id,
- three_ds_method_data,
- three_ds_method_url,
- message_version,
- connector_metadata,
- authentication_status,
- acquirer_bin,
- acquirer_merchant_id,
- directory_server_id,
- acquirer_country_code,
- billing_address: billing_address.map(|billing_address| billing_address.into()),
- shipping_address: shipping_address.map(|shipping_address| shipping_address.into()),
- browser_info,
- email: email.map(|email| email.into()),
- scheme_id,
- merchant_category_code,
- merchant_country_code,
- billing_country,
- shipping_country,
- earliest_supported_version,
- latest_supported_version,
- },
- AuthenticationUpdate::AuthenticationUpdate {
- trans_status,
- authentication_type,
- acs_url,
- challenge_request,
- acs_reference_number,
- acs_trans_id,
- acs_signed_content,
- connector_metadata,
- authentication_status,
- ds_trans_id,
- eci,
- challenge_code,
- challenge_cancel,
- challenge_code_reason,
- message_extension,
- challenge_request_key,
- device_type,
- device_brand,
- device_os,
- device_display,
- } => Self::AuthenticationUpdate {
- trans_status,
- authentication_type,
- acs_url,
- challenge_request,
- acs_reference_number,
- acs_trans_id,
- acs_signed_content,
- connector_metadata,
- authentication_status,
- ds_trans_id,
- eci,
- challenge_code,
- challenge_cancel,
- challenge_code_reason,
- message_extension,
- challenge_request_key,
- device_type,
- device_brand,
- device_os,
- device_display,
- },
- AuthenticationUpdate::PostAuthenticationUpdate {
- trans_status,
- eci,
- authentication_status,
- challenge_cancel,
- challenge_code_reason,
- } => Self::PostAuthenticationUpdate {
- trans_status,
- eci,
- authentication_status,
- challenge_cancel,
- challenge_code_reason,
- },
- AuthenticationUpdate::ErrorUpdate {
- error_message,
- error_code,
- authentication_status,
- connector_authentication_id,
- } => Self::ErrorUpdate {
- error_message,
- error_code,
- authentication_status,
- connector_authentication_id,
- },
- AuthenticationUpdate::PostAuthorizationUpdate {
- authentication_lifecycle_status,
- } => Self::PostAuthorizationUpdate {
- authentication_lifecycle_status,
- },
- AuthenticationUpdate::AuthenticationStatusUpdate {
- trans_status,
- authentication_status,
- } => Self::AuthenticationStatusUpdate {
- trans_status,
- authentication_status,
- },
- AuthenticationUpdate::AcquirerDetailsUpdate {
- acquirer_bin,
- acquirer_merchant_id,
- acquirer_country_code,
- } => Self::AcquirerDetailsUpdate {
- acquirer_bin,
- acquirer_merchant_id,
- acquirer_country_code,
- },
- }
- }
-}
diff --git a/crates/router/src/db/authentication.rs b/crates/router/src/db/authentication.rs
index 7cc6f17982..35a1f5f810 100644
--- a/crates/router/src/db/authentication.rs
+++ b/crates/router/src/db/authentication.rs
@@ -1,11 +1,11 @@
use common_utils::{ext_traits::AsyncExt, types::keymanager::KeyManagerState};
use error_stack::{report, ResultExt};
-use hyperswitch_domain_models::{
- behaviour::{Conversion, ReverseConversion},
- merchant_key_store::MerchantKeyStore,
-};
+use hyperswitch_domain_models::merchant_key_store::MerchantKeyStore;
use router_env::{instrument, tracing};
-use storage_impl::StorageError;
+use storage_impl::{
+ behaviour::{Conversion, ForeignInto, ReverseConversion},
+ StorageError,
+};
use super::{MockDb, Store};
use crate::{connection, core::errors::CustomResult, types::storage};
@@ -142,7 +142,7 @@ impl AuthenticationInterface for Store {
&conn,
previous_state.merchant_id,
previous_state.authentication_id,
- authentication_update.into(),
+ authentication_update.foreign_into(),
)
.await
.map_err(|error| report!(StorageError::from(error)))
diff --git a/crates/storage_impl/src/authentication.rs b/crates/storage_impl/src/authentication.rs
new file mode 100644
index 0000000000..d28ed572ed
--- /dev/null
+++ b/crates/storage_impl/src/authentication.rs
@@ -0,0 +1,490 @@
+use std::str::FromStr;
+
+use async_trait::async_trait;
+use common_utils::{
+ encryption::Encryption,
+ errors::{CustomResult, ValidationError},
+ pii,
+ types::keymanager::{Identifier, KeyManagerState, ToEncryptable},
+};
+use error_stack::ResultExt;
+use hyperswitch_domain_models::{
+ authentication::{
+ AuthenticationUpdate, EncryptedAuthentication, FromRequestEncryptableAuthentication,
+ },
+ type_encryption::{crypto_operation, AsyncLift, CryptoOperation},
+};
+use hyperswitch_masking::{PeekInterface, Secret};
+
+use crate::behaviour::{self, ForeignFrom};
+
+#[async_trait]
+impl behaviour::Conversion for hyperswitch_domain_models::authentication::Authentication {
+ type DstType = diesel_models::authentication::Authentication;
+ type NewDstType = diesel_models::authentication::AuthenticationNew;
+
+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
+ Ok(Self::DstType {
+ authentication_id: self.authentication_id,
+ merchant_id: self.merchant_id,
+ authentication_connector: self.authentication_connector,
+ connector_authentication_id: self.connector_authentication_id,
+ authentication_data: self.authentication_data,
+ payment_method_id: self.payment_method_id,
+ authentication_type: self.authentication_type,
+ authentication_status: self.authentication_status,
+ authentication_lifecycle_status: self.authentication_lifecycle_status,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ error_message: self.error_message,
+ error_code: self.error_code,
+ connector_metadata: self.connector_metadata,
+ maximum_supported_version: self.maximum_supported_version,
+ threeds_server_transaction_id: self.threeds_server_transaction_id,
+ cavv: self.cavv,
+ authentication_flow_type: self.authentication_flow_type,
+ message_version: self.message_version,
+ eci: self.eci,
+ trans_status: self.trans_status,
+ acquirer_bin: self.acquirer_bin,
+ acquirer_merchant_id: self.acquirer_merchant_id,
+ three_ds_method_data: self.three_ds_method_data,
+ three_ds_method_url: self.three_ds_method_url,
+ acs_url: self.acs_url,
+ challenge_request: self.challenge_request,
+ acs_reference_number: self.acs_reference_number,
+ acs_trans_id: self.acs_trans_id,
+ acs_signed_content: self.acs_signed_content,
+ profile_id: self.profile_id,
+ payment_id: self.payment_id,
+ merchant_connector_id: self.merchant_connector_id,
+ ds_trans_id: self.ds_trans_id,
+ directory_server_id: self.directory_server_id,
+ acquirer_country_code: self.acquirer_country_code,
+ service_details: self.service_details,
+ organization_id: self.organization_id,
+ authentication_client_secret: self.authentication_client_secret,
+ force_3ds_challenge: self.force_3ds_challenge,
+ psd2_sca_exemption_type: self.psd2_sca_exemption_type,
+ return_url: self.return_url,
+ amount: self.amount,
+ currency: self.currency,
+ billing_address: self.billing_address.map(Encryption::from),
+ shipping_address: self.shipping_address.map(Encryption::from),
+ browser_info: self.browser_info,
+ email: self.email.map(|email| email.into()),
+ profile_acquirer_id: self.profile_acquirer_id,
+ challenge_code: self.challenge_code,
+ challenge_cancel: self.challenge_cancel,
+ challenge_code_reason: self.challenge_code_reason,
+ message_extension: self.message_extension,
+ challenge_request_key: self.challenge_request_key,
+ customer_details: self.customer_details,
+ earliest_supported_version: self.earliest_supported_version,
+ latest_supported_version: self.latest_supported_version,
+ mcc: self.mcc,
+ platform: self.platform.map(|platform| platform.to_string()),
+ device_type: self.device_type,
+ device_brand: self.device_brand,
+ device_os: self.device_os,
+ device_display: self.device_display,
+ browser_name: self.browser_name,
+ browser_version: self.browser_version,
+ scheme_name: self.scheme_name,
+ exemption_requested: self.exemption_requested,
+ exemption_accepted: self.exemption_accepted,
+ issuer_id: self.issuer_id,
+ issuer_country: self.issuer_country,
+ merchant_country_code: self.merchant_country_code,
+ billing_country: self.billing_country,
+ shipping_country: self.shipping_country,
+ processor_merchant_id: self.processor_merchant_id,
+ created_by: self.created_by.map(|created_by| created_by.to_string()),
+ })
+ }
+
+ async fn convert_back(
+ state: &KeyManagerState,
+ other: Self::DstType,
+ key: &Secret<Vec<u8>>,
+ _key_manager_identifier: Identifier,
+ ) -> CustomResult<Self, ValidationError> {
+ let encrypted_data = crypto_operation(
+ state,
+ common_utils::type_name!(Self),
+ CryptoOperation::BatchDecrypt(EncryptedAuthentication::to_encryptable(
+ EncryptedAuthentication {
+ billing_address: other.billing_address.clone(),
+ shipping_address: other.shipping_address.clone(),
+ },
+ )),
+ Identifier::Merchant(other.merchant_id.clone()),
+ key.peek(),
+ )
+ .await
+ .and_then(|val| val.try_into_batchoperation())
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting authentication data".to_string(),
+ })?;
+
+ let decrypted_data = FromRequestEncryptableAuthentication::from_encryptable(encrypted_data)
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting authentication data".to_string(),
+ })?;
+
+ let email_decrypted = other
+ .email
+ .clone()
+ .async_lift(|inner| async {
+ crypto_operation::<String, pii::EmailStrategy>(
+ state,
+ common_utils::type_name!(Self),
+ CryptoOperation::DecryptOptional(inner),
+ Identifier::Merchant(other.merchant_id.clone()),
+ key.peek(),
+ )
+ .await
+ .and_then(|val| val.try_into_optionaloperation())
+ })
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting authentication email".to_string(),
+ })?;
+
+ Ok(Self {
+ authentication_id: other.authentication_id,
+ merchant_id: other.merchant_id,
+ authentication_connector: other.authentication_connector,
+ connector_authentication_id: other.connector_authentication_id,
+ authentication_data: other.authentication_data,
+ payment_method_id: other.payment_method_id,
+ authentication_type: other.authentication_type,
+ authentication_status: other.authentication_status,
+ authentication_lifecycle_status: other.authentication_lifecycle_status,
+ created_at: other.created_at,
+ modified_at: other.modified_at,
+ error_message: other.error_message,
+ error_code: other.error_code,
+ connector_metadata: other.connector_metadata,
+ maximum_supported_version: other.maximum_supported_version,
+ threeds_server_transaction_id: other.threeds_server_transaction_id,
+ cavv: other.cavv,
+ authentication_flow_type: other.authentication_flow_type,
+ message_version: other.message_version,
+ eci: other.eci,
+ trans_status: other.trans_status,
+ acquirer_bin: other.acquirer_bin,
+ acquirer_merchant_id: other.acquirer_merchant_id,
+ three_ds_method_data: other.three_ds_method_data,
+ three_ds_method_url: other.three_ds_method_url,
+ acs_url: other.acs_url,
+ challenge_request: other.challenge_request,
+ acs_reference_number: other.acs_reference_number,
+ acs_trans_id: other.acs_trans_id,
+ acs_signed_content: other.acs_signed_content,
+ profile_id: other.profile_id,
+ payment_id: other.payment_id,
+ merchant_connector_id: other.merchant_connector_id,
+ ds_trans_id: other.ds_trans_id,
+ directory_server_id: other.directory_server_id,
+ acquirer_country_code: other.acquirer_country_code,
+ organization_id: other.organization_id,
+ mcc: other.mcc,
+ amount: other.amount,
+ currency: other.currency,
+ issuer_country: other.issuer_country,
+ earliest_supported_version: other.earliest_supported_version,
+ latest_supported_version: other.latest_supported_version,
+ platform: other
+ .platform
+ .as_deref()
+ .map(|s| {
+ api_models::payments::DeviceChannel::from_str(s).change_context(
+ ValidationError::InvalidValue {
+ message: "Invalid device channel".into(),
+ },
+ )
+ })
+ .transpose()?,
+ device_type: other.device_type,
+ device_brand: other.device_brand,
+ device_os: other.device_os,
+ device_display: other.device_display,
+ browser_name: other.browser_name,
+ browser_version: other.browser_version,
+ issuer_id: other.issuer_id,
+ scheme_name: other.scheme_name,
+ exemption_requested: other.exemption_requested,
+ exemption_accepted: other.exemption_accepted,
+ service_details: other.service_details,
+ authentication_client_secret: other.authentication_client_secret,
+ force_3ds_challenge: other.force_3ds_challenge,
+ psd2_sca_exemption_type: other.psd2_sca_exemption_type,
+ return_url: other.return_url,
+ billing_address: decrypted_data.billing_address,
+ shipping_address: decrypted_data.shipping_address,
+ browser_info: other.browser_info,
+ email: email_decrypted,
+ profile_acquirer_id: other.profile_acquirer_id,
+ challenge_code: other.challenge_code,
+ challenge_cancel: other.challenge_cancel,
+ challenge_code_reason: other.challenge_code_reason,
+ message_extension: other.message_extension,
+ challenge_request_key: other.challenge_request_key,
+ customer_details: other.customer_details,
+ billing_country: other.billing_country,
+ shipping_country: other.shipping_country,
+ merchant_country_code: other.merchant_country_code,
+ processor_merchant_id: other.processor_merchant_id,
+ created_by: other
+ .created_by
+ .and_then(|created_by| created_by.parse::<common_utils::types::CreatedBy>().ok()),
+ })
+ }
+
+ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
+ Ok(Self::NewDstType {
+ authentication_id: self.authentication_id,
+ merchant_id: self.merchant_id,
+ authentication_connector: self.authentication_connector,
+ connector_authentication_id: self.connector_authentication_id,
+ authentication_data: self.authentication_data,
+ payment_method_id: self.payment_method_id,
+ authentication_type: self.authentication_type,
+ authentication_status: self.authentication_status,
+ authentication_lifecycle_status: self.authentication_lifecycle_status,
+ error_message: self.error_message,
+ error_code: self.error_code,
+ connector_metadata: self.connector_metadata,
+ maximum_supported_version: self.maximum_supported_version,
+ threeds_server_transaction_id: self.threeds_server_transaction_id,
+ cavv: self.cavv,
+ authentication_flow_type: self.authentication_flow_type,
+ message_version: self.message_version,
+ eci: self.eci,
+ trans_status: self.trans_status,
+ acquirer_bin: self.acquirer_bin,
+ acquirer_merchant_id: self.acquirer_merchant_id,
+ three_ds_method_data: self.three_ds_method_data,
+ three_ds_method_url: self.three_ds_method_url,
+ acs_url: self.acs_url,
+ challenge_request: self.challenge_request,
+ acs_reference_number: self.acs_reference_number,
+ acs_trans_id: self.acs_trans_id,
+ acs_signed_content: self.acs_signed_content,
+ profile_id: self.profile_id,
+ payment_id: self.payment_id,
+ merchant_connector_id: self.merchant_connector_id,
+ ds_trans_id: self.ds_trans_id,
+ directory_server_id: self.directory_server_id,
+ acquirer_country_code: self.acquirer_country_code,
+ service_details: self.service_details,
+ organization_id: self.organization_id,
+ authentication_client_secret: self.authentication_client_secret,
+ force_3ds_challenge: self.force_3ds_challenge,
+ psd2_sca_exemption_type: self.psd2_sca_exemption_type,
+ return_url: self.return_url,
+ amount: self.amount,
+ currency: self.currency,
+ billing_address: self.billing_address.map(Encryption::from),
+ shipping_address: self.shipping_address.map(Encryption::from),
+ browser_info: self.browser_info,
+ email: self.email.map(|email| email.into()),
+ profile_acquirer_id: self.profile_acquirer_id,
+ challenge_code: self.challenge_code,
+ challenge_cancel: self.challenge_cancel,
+ challenge_code_reason: self.challenge_code_reason,
+ message_extension: self.message_extension,
+ challenge_request_key: self.challenge_request_key,
+ customer_details: self.customer_details,
+ earliest_supported_version: self.earliest_supported_version,
+ latest_supported_version: self.latest_supported_version,
+ mcc: self.mcc,
+ platform: self.platform.map(|platform| platform.to_string()),
+ device_type: self.device_type,
+ device_brand: self.device_brand,
+ device_os: self.device_os,
+ device_display: self.device_display,
+ browser_name: self.browser_name,
+ browser_version: self.browser_version,
+ scheme_name: self.scheme_name,
+ exemption_requested: self.exemption_requested,
+ exemption_accepted: self.exemption_accepted,
+ issuer_id: self.issuer_id,
+ issuer_country: self.issuer_country,
+ merchant_country_code: self.merchant_country_code,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ billing_country: self.billing_country,
+ shipping_country: self.shipping_country,
+ processor_merchant_id: self.processor_merchant_id,
+ created_by: self.created_by.map(|created_by| created_by.to_string()),
+ })
+ }
+}
+
+impl ForeignFrom<AuthenticationUpdate> for diesel_models::authentication::AuthenticationUpdate {
+ fn foreign_from(authentication_update: AuthenticationUpdate) -> Self {
+ match authentication_update {
+ AuthenticationUpdate::PreAuthenticationVersionCallUpdate {
+ maximum_supported_3ds_version,
+ message_version,
+ } => Self::PreAuthenticationVersionCallUpdate {
+ maximum_supported_3ds_version,
+ message_version,
+ },
+ AuthenticationUpdate::PreAuthenticationThreeDsMethodCall {
+ threeds_server_transaction_id,
+ three_ds_method_data,
+ three_ds_method_url,
+ acquirer_bin,
+ acquirer_merchant_id,
+ connector_metadata,
+ } => Self::PreAuthenticationThreeDsMethodCall {
+ threeds_server_transaction_id,
+ three_ds_method_data,
+ three_ds_method_url,
+ acquirer_bin,
+ acquirer_merchant_id,
+ connector_metadata,
+ },
+ AuthenticationUpdate::PreAuthenticationUpdate {
+ threeds_server_transaction_id,
+ maximum_supported_3ds_version,
+ connector_authentication_id,
+ three_ds_method_data,
+ three_ds_method_url,
+ message_version,
+ connector_metadata,
+ authentication_status,
+ acquirer_bin,
+ acquirer_merchant_id,
+ directory_server_id,
+ acquirer_country_code,
+ billing_address,
+ shipping_address,
+ browser_info,
+ email,
+ scheme_id,
+ merchant_category_code,
+ merchant_country_code,
+ billing_country,
+ shipping_country,
+ earliest_supported_version,
+ latest_supported_version,
+ } => Self::PreAuthenticationUpdate {
+ threeds_server_transaction_id,
+ maximum_supported_3ds_version,
+ connector_authentication_id,
+ three_ds_method_data,
+ three_ds_method_url,
+ message_version,
+ connector_metadata,
+ authentication_status,
+ acquirer_bin,
+ acquirer_merchant_id,
+ directory_server_id,
+ acquirer_country_code,
+ billing_address: billing_address.map(|billing_address| billing_address.into()),
+ shipping_address: shipping_address.map(|shipping_address| shipping_address.into()),
+ browser_info,
+ email: email.map(|email| email.into()),
+ scheme_id,
+ merchant_category_code,
+ merchant_country_code,
+ billing_country,
+ shipping_country,
+ earliest_supported_version,
+ latest_supported_version,
+ },
+ AuthenticationUpdate::AuthenticationUpdate {
+ trans_status,
+ authentication_type,
+ acs_url,
+ challenge_request,
+ acs_reference_number,
+ acs_trans_id,
+ acs_signed_content,
+ connector_metadata,
+ authentication_status,
+ ds_trans_id,
+ eci,
+ challenge_code,
+ challenge_cancel,
+ challenge_code_reason,
+ message_extension,
+ challenge_request_key,
+ device_type,
+ device_brand,
+ device_os,
+ device_display,
+ } => Self::AuthenticationUpdate {
+ trans_status,
+ authentication_type,
+ acs_url,
+ challenge_request,
+ acs_reference_number,
+ acs_trans_id,
+ acs_signed_content,
+ connector_metadata,
+ authentication_status,
+ ds_trans_id,
+ eci,
+ challenge_code,
+ challenge_cancel,
+ challenge_code_reason,
+ message_extension,
+ challenge_request_key,
+ device_type,
+ device_brand,
+ device_os,
+ device_display,
+ },
+ AuthenticationUpdate::PostAuthenticationUpdate {
+ trans_status,
+ eci,
+ authentication_status,
+ challenge_cancel,
+ challenge_code_reason,
+ } => Self::PostAuthenticationUpdate {
+ trans_status,
+ eci,
+ authentication_status,
+ challenge_cancel,
+ challenge_code_reason,
+ },
+ AuthenticationUpdate::ErrorUpdate {
+ error_message,
+ error_code,
+ authentication_status,
+ connector_authentication_id,
+ } => Self::ErrorUpdate {
+ error_message,
+ error_code,
+ authentication_status,
+ connector_authentication_id,
+ },
+ AuthenticationUpdate::PostAuthorizationUpdate {
+ authentication_lifecycle_status,
+ } => Self::PostAuthorizationUpdate {
+ authentication_lifecycle_status,
+ },
+ AuthenticationUpdate::AuthenticationStatusUpdate {
+ trans_status,
+ authentication_status,
+ } => Self::AuthenticationStatusUpdate {
+ trans_status,
+ authentication_status,
+ },
+ AuthenticationUpdate::AcquirerDetailsUpdate {
+ acquirer_bin,
+ acquirer_merchant_id,
+ acquirer_country_code,
+ } => Self::AcquirerDetailsUpdate {
+ acquirer_bin,
+ acquirer_merchant_id,
+ acquirer_country_code,
+ },
+ }
+ }
+}
diff --git a/crates/storage_impl/src/behaviour.rs b/crates/storage_impl/src/behaviour.rs
new file mode 100644
index 0000000000..8f5fb76a85
--- /dev/null
+++ b/crates/storage_impl/src/behaviour.rs
@@ -0,0 +1,85 @@
+use common_utils::{
+ errors::{CustomResult, ValidationError},
+ types::keymanager::{Identifier, KeyManagerState},
+};
+use hyperswitch_masking::Secret;
+
+#[async_trait::async_trait]
+pub trait Conversion {
+ type DstType;
+ type NewDstType;
+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError>;
+
+ async fn convert_back(
+ state: &KeyManagerState,
+ item: Self::DstType,
+ key: &Secret<Vec<u8>>,
+ key_manager_identifier: Identifier,
+ ) -> CustomResult<Self, ValidationError>
+ where
+ Self: Sized;
+
+ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError>;
+}
+
+#[async_trait::async_trait]
+pub trait ReverseConversion<SrcType: Conversion> {
+ async fn convert(
+ self,
+ state: &KeyManagerState,
+ key: &Secret<Vec<u8>>,
+ key_manager_identifier: Identifier,
+ ) -> CustomResult<SrcType, ValidationError>;
+}
+
+#[async_trait::async_trait]
+impl<T: Send, U: Conversion<DstType = T>> ReverseConversion<U> for T {
+ async fn convert(
+ self,
+ state: &KeyManagerState,
+ key: &Secret<Vec<u8>>,
+ key_manager_identifier: Identifier,
+ ) -> CustomResult<U, ValidationError> {
+ U::convert_back(state, self, key, key_manager_identifier).await
+ }
+}
+
+pub trait ForeignInto<T> {
+ fn foreign_into(self) -> T;
+}
+
+pub trait ForeignTryInto<T> {
+ type Error;
+
+ fn foreign_try_into(self) -> Result<T, Self::Error>;
+}
+
+pub trait ForeignFrom<F> {
+ fn foreign_from(from: F) -> Self;
+}
+
+pub trait ForeignTryFrom<F>: Sized {
+ type Error;
+
+ fn foreign_try_from(from: F) -> Result<Self, Self::Error>;
+}
+
+impl<F, T> ForeignInto<T> for F
+where
+ T: ForeignFrom<F>,
+{
+ fn foreign_into(self) -> T {
+ T::foreign_from(self)
+ }
+}
+
+impl<F, T> ForeignTryInto<T> for F
+where
+ T: ForeignTryFrom<F>,
+{
+ type Error = <T as ForeignTryFrom<F>>::Error;
+
+ fn foreign_try_into(self) -> Result<T, Self::Error> {
+ T::foreign_try_from(self)
+ }
+}
diff --git a/crates/storage_impl/src/lib.rs b/crates/storage_impl/src/lib.rs
index 93277c0326..7be52bcd73 100644
--- a/crates/storage_impl/src/lib.rs
+++ b/crates/storage_impl/src/lib.rs
@@ -10,6 +10,8 @@ use hyperswitch_domain_models::{
use hyperswitch_masking::StrongSecret;
use redis::{kv_store::RedisConnInterface, pub_sub::PubSubInterface, RedisStore};
mod address;
+pub mod authentication;
+pub mod behaviour;
pub mod business_profile;
pub mod callback_mapper;
pub mod card_issuer;