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 payment_attempt to storage_impl crate (#11810)

Anurag Thakurbb0ba58d978f
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 89f17dafc5..31fa0c2b1d 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -16,23 +16,17 @@ use common_types::primitive_wrappers::{
};
#[cfg(feature = "v2")]
use common_utils::ext_traits::Encode;
-#[cfg(feature = "v1")]
-use common_utils::types::{
- keymanager::{self, KeyManagerState},
- ConnectorTransactionIdTrait,
-};
use common_utils::{
crypto::Encryptable,
encryption::Encryption,
errors::{CustomResult, ValidationError},
ext_traits::{OptionExt, ValueExt},
id_type, pii,
- types::{keymanager::ToEncryptable, ConnectorTransactionId, CreatedBy, MinorUnit},
+ types::{keymanager::ToEncryptable, CreatedBy, MinorUnit},
};
#[cfg(feature = "v1")]
use diesel_models::{
ConnectorMandateReferenceId, ErrorDetails as DieselErrorDetails, NetworkDetails,
- PaymentAttempt as DieselPaymentAttempt, PaymentAttemptNew as DieselPaymentAttemptNew,
PaymentAttemptUpdate as DieselPaymentAttemptUpdate,
};
#[cfg(feature = "v2")]
@@ -61,14 +55,12 @@ use crate::{
address::Address, consts, payment_method_data::PaymentMethodData, platform,
router_response_types,
};
+use crate::{errors, merchant_key_store::MerchantKeyStore, ForeignIDRef};
#[cfg(feature = "v1")]
use crate::{
- behaviour,
mandates::{MandateDataType, MandateDetails, MandateTransactionType},
router_request_types,
- type_encryption::{crypto_operation, CryptoOperation},
};
-use crate::{errors, merchant_key_store::MerchantKeyStore, ForeignIDRef};
#[async_trait::async_trait]
pub trait PaymentAttemptInterface {
@@ -3021,731 +3013,6 @@ impl ForeignIDRef for PaymentAttempt {
}
}
-#[cfg(feature = "v1")]
-#[async_trait::async_trait]
-impl behaviour::Conversion for PaymentAttempt {
- type DstType = DieselPaymentAttempt;
- type NewDstType = DieselPaymentAttemptNew;
-
- async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
- let card_network = self
- .extract_card_network()
- .map(|network| network.to_string());
- let (connector_transaction_id, processor_transaction_data) = self
- .connector_transaction_id
- .map(ConnectorTransactionId::form_id_and_data)
- .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
- .unwrap_or((None, None));
- Ok(DieselPaymentAttempt {
- payment_id: self.payment_id,
- merchant_id: self.merchant_id,
- attempt_id: self.attempt_id,
- status: self.status,
- amount: self.net_amount.get_order_amount(),
- currency: self.currency,
- save_to_locker: self.save_to_locker,
- connector: self.connector,
- error_message: self.error_message,
- offer_amount: self.offer_amount,
- surcharge_amount: self.net_amount.get_surcharge_amount(),
- tax_amount: self.net_amount.get_tax_on_surcharge(),
- payment_method_id: self.payment_method_id,
- payment_method: self.payment_method,
- connector_transaction_id,
- capture_method: self.capture_method,
- capture_on: self.capture_on,
- confirm: self.confirm,
- authentication_type: self.authentication_type,
- created_at: self.created_at,
- modified_at: self.modified_at,
- last_synced: self.last_synced,
- cancellation_reason: self.cancellation_reason,
- amount_to_capture: self.amount_to_capture,
- mandate_id: self.mandate_id,
- browser_info: self.browser_info,
- error_code: self.error_code,
- payment_token: self.payment_token,
- connector_metadata: self.connector_metadata,
- payment_experience: self.payment_experience,
- payment_method_type: self.payment_method_type,
- payment_method_data: self.payment_method_data,
- business_sub_label: self.business_sub_label,
- straight_through_algorithm: self.straight_through_algorithm,
- preprocessing_step_id: self.preprocessing_step_id,
- mandate_details: self.mandate_details.map(Into::into),
- error_reason: self.error_reason,
- multiple_capture_count: self.multiple_capture_count,
- connector_response_reference_id: self.connector_response_reference_id,
- amount_capturable: self.amount_capturable,
- updated_by: self.updated_by,
- merchant_connector_id: self.merchant_connector_id,
- authentication_data: self.authentication_data,
- encoded_data: self.encoded_data,
- unified_code: self.unified_code,
- unified_message: self.unified_message,
- net_amount: Some(self.net_amount.get_total_amount()),
- external_three_ds_authentication_attempted: self
- .external_three_ds_authentication_attempted,
- external_threeds_authentication_type: self.external_threeds_authentication_type,
- authentication_connector: self.authentication_connector,
- authentication_id: self.authentication_id,
- mandate_data: self.mandate_data.map(Into::into),
- fingerprint_id: self.fingerprint_id,
- fingerprint_type: self.fingerprint_type,
- payment_method_billing_address_id: self.payment_method_billing_address_id,
- charge_id: self.charge_id,
- client_source: self.client_source,
- client_version: self.client_version,
- customer_acceptance: self.customer_acceptance,
- profile_id: self.profile_id,
- organization_id: self.organization_id,
- card_network,
- order_tax_amount: self.net_amount.get_order_tax_amount(),
- shipping_cost: self.net_amount.get_shipping_cost(),
- installment_data: self.installment_data,
- connector_mandate_detail: self.connector_mandate_detail,
- tokenization: self.tokenization,
- request_extended_authorization: self.request_extended_authorization,
- extended_authorization_applied: self.extended_authorization_applied,
- extended_authorization_last_applied_at: self.extended_authorization_last_applied_at,
- capture_before: self.capture_before,
- processor_transaction_data,
- card_discovery: self.card_discovery,
- charges: self.charges,
- issuer_error_code: self.issuer_error_code,
- issuer_error_message: self.issuer_error_message,
- setup_future_usage_applied: self.setup_future_usage_applied,
- error_details: self.error_details.map(Into::into),
- // Below fields are deprecated. Please add any new fields above this line.
- connector_transaction_data: None,
- processor_merchant_id: Some(self.processor_merchant_id),
- created_by: self.created_by.map(|created_by| created_by.to_string()),
- routing_approach: self.routing_approach,
- connector_request_reference_id: self.connector_request_reference_id,
- network_transaction_id: self.network_transaction_id,
- network_transaction_link_id: self.network_transaction_link_id,
- is_overcapture_enabled: self.is_overcapture_enabled,
- network_details: self.network_details,
- is_stored_credential: self.is_stored_credential,
- authorized_amount: self.authorized_amount,
- encrypted_payment_method_data: self.encrypted_payment_method_data.map(Encryption::from),
- retry_type: self.retry_type,
- external_surcharge_details: self.external_surcharge_details,
- applied_offer_details: self.applied_offer_details,
- payment_account_reference: self.payment_account_reference,
- sender_payment_instrument_id: self.sender_payment_instrument_id,
- active_frm_id: self.active_frm_id,
- })
- }
-
- async fn convert_back(
- state: &KeyManagerState,
- storage_model: Self::DstType,
- key: &Secret<Vec<u8>>,
- key_manager_identifier: keymanager::Identifier,
- ) -> CustomResult<Self, ValidationError>
- where
- Self: Sized,
- {
- async {
- let connector_transaction_id = storage_model
- .get_optional_connector_transaction_id()
- .cloned();
- let decrypted_data = crypto_operation(
- state,
- common_utils::type_name!(Self::DstType),
- CryptoOperation::BatchDecrypt(EncryptedPaymentAttempt::to_encryptable(
- EncryptedPaymentAttempt {
- encrypted_payment_method_data: storage_model.encrypted_payment_method_data,
- },
- )),
- key_manager_identifier,
- key.peek(),
- )
- .await
- .and_then(|val| val.try_into_batchoperation())?;
-
- let decrypted_data = EncryptedPaymentAttempt::from_encryptable(decrypted_data)
- .change_context(common_utils::errors::CryptoError::DecodingFailed)
- .attach_printable("Invalid batch operation data")?;
-
- let encrypted_payment_method_data = decrypted_data.encrypted_payment_method_data;
- Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
- payment_id: storage_model.payment_id,
- merchant_id: storage_model.merchant_id.clone(),
- attempt_id: storage_model.attempt_id,
- status: storage_model.status,
- net_amount: NetAmount::new(
- storage_model.amount,
- storage_model.shipping_cost,
- storage_model.order_tax_amount,
- storage_model.surcharge_amount,
- storage_model.tax_amount,
- storage_model
- .installment_data
- .as_ref()
- .and_then(|d| d.installment_interest),
- storage_model
- .applied_offer_details
- .as_ref()
- .map(|applied_offer_details| applied_offer_details.inner().offer_amount),
- ),
- currency: storage_model.currency,
- save_to_locker: storage_model.save_to_locker,
- connector: storage_model.connector,
- error_message: storage_model.error_message,
- offer_amount: storage_model.offer_amount,
- payment_method_id: storage_model.payment_method_id,
- payment_method: storage_model.payment_method,
- connector_transaction_id,
- capture_method: storage_model.capture_method,
- capture_on: storage_model.capture_on,
- confirm: storage_model.confirm,
- authentication_type: storage_model.authentication_type,
- created_at: storage_model.created_at,
- modified_at: storage_model.modified_at,
- last_synced: storage_model.last_synced,
- cancellation_reason: storage_model.cancellation_reason,
- amount_to_capture: storage_model.amount_to_capture,
- mandate_id: storage_model.mandate_id,
- browser_info: storage_model.browser_info,
- error_code: storage_model.error_code,
- payment_token: storage_model.payment_token,
- connector_metadata: storage_model.connector_metadata,
- payment_experience: storage_model.payment_experience,
- payment_method_type: storage_model.payment_method_type,
- payment_method_data: storage_model.payment_method_data,
- business_sub_label: storage_model.business_sub_label,
- straight_through_algorithm: storage_model.straight_through_algorithm,
- preprocessing_step_id: storage_model.preprocessing_step_id,
- mandate_details: storage_model.mandate_details.map(Into::into),
- error_reason: storage_model.error_reason,
- multiple_capture_count: storage_model.multiple_capture_count,
- connector_response_reference_id: storage_model.connector_response_reference_id,
- amount_capturable: storage_model.amount_capturable,
- updated_by: storage_model.updated_by,
- authentication_data: storage_model.authentication_data,
- encoded_data: storage_model.encoded_data,
- merchant_connector_id: storage_model.merchant_connector_id,
- unified_code: storage_model.unified_code,
- unified_message: storage_model.unified_message,
- external_three_ds_authentication_attempted: storage_model
- .external_three_ds_authentication_attempted,
- external_threeds_authentication_type: storage_model
- .external_threeds_authentication_type,
- authentication_connector: storage_model.authentication_connector,
- authentication_id: storage_model.authentication_id,
- mandate_data: storage_model.mandate_data.map(Into::into),
- payment_method_billing_address_id: storage_model.payment_method_billing_address_id,
- fingerprint_id: storage_model.fingerprint_id,
- fingerprint_type: storage_model.fingerprint_type,
- charge_id: storage_model.charge_id,
- client_source: storage_model.client_source,
- client_version: storage_model.client_version,
- customer_acceptance: storage_model.customer_acceptance,
- profile_id: storage_model.profile_id,
- organization_id: storage_model.organization_id,
- connector_mandate_detail: storage_model.connector_mandate_detail,
- tokenization: storage_model.tokenization,
- request_extended_authorization: storage_model.request_extended_authorization,
- extended_authorization_applied: storage_model.extended_authorization_applied,
- extended_authorization_last_applied_at: storage_model
- .extended_authorization_last_applied_at,
- capture_before: storage_model.capture_before,
- card_discovery: storage_model.card_discovery,
- charges: storage_model.charges,
- issuer_error_code: storage_model.issuer_error_code,
- issuer_error_message: storage_model.issuer_error_message,
- processor_merchant_id: storage_model
- .processor_merchant_id
- .unwrap_or(storage_model.merchant_id),
- created_by: storage_model
- .created_by
- .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
- setup_future_usage_applied: storage_model.setup_future_usage_applied,
- routing_approach: storage_model.routing_approach,
- connector_request_reference_id: storage_model.connector_request_reference_id,
- debit_routing_savings: None,
- network_transaction_id: storage_model.network_transaction_id,
- network_transaction_link_id: storage_model.network_transaction_link_id,
- is_overcapture_enabled: storage_model.is_overcapture_enabled,
- network_details: storage_model.network_details,
- is_stored_credential: storage_model.is_stored_credential,
- authorized_amount: storage_model.authorized_amount,
- encrypted_payment_method_data,
- error_details: storage_model.error_details.map(Into::into),
- retry_type: storage_model.retry_type,
- installment_data: storage_model.installment_data,
- external_surcharge_details: storage_model.external_surcharge_details,
- applied_offer_details: storage_model.applied_offer_details,
- payment_account_reference: storage_model.payment_account_reference,
- sender_payment_instrument_id: storage_model.sender_payment_instrument_id,
- active_frm_id: storage_model.active_frm_id,
- })
- }
- .await
- .change_context(ValidationError::InvalidValue {
- message: "Failed while decrypting payment attempt".to_string(),
- })
- }
-
- async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
- let card_network = self
- .extract_card_network()
- .map(|network| network.to_string());
- Ok(DieselPaymentAttemptNew {
- payment_id: self.payment_id,
- merchant_id: self.merchant_id,
- attempt_id: self.attempt_id,
- status: self.status,
- amount: self.net_amount.get_order_amount(),
- currency: self.currency,
- save_to_locker: self.save_to_locker,
- connector: self.connector,
- error_message: self.error_message,
- offer_amount: self.offer_amount,
- surcharge_amount: self.net_amount.get_surcharge_amount(),
- tax_amount: self.net_amount.get_tax_on_surcharge(),
- payment_method_id: self.payment_method_id,
- payment_method: self.payment_method,
- capture_method: self.capture_method,
- capture_on: self.capture_on,
- confirm: self.confirm,
- authentication_type: self.authentication_type,
- created_at: self.created_at,
- modified_at: self.modified_at,
- last_synced: self.last_synced,
- cancellation_reason: self.cancellation_reason,
- amount_to_capture: self.amount_to_capture,
- mandate_id: self.mandate_id,
- browser_info: self.browser_info,
- payment_token: self.payment_token,
- error_code: self.error_code,
- connector_metadata: self.connector_metadata,
- payment_experience: self.payment_experience,
- payment_method_type: self.payment_method_type,
- payment_method_data: self.payment_method_data,
- business_sub_label: self.business_sub_label,
- straight_through_algorithm: self.straight_through_algorithm,
- preprocessing_step_id: self.preprocessing_step_id,
- mandate_details: self.mandate_details.map(Into::into),
- error_reason: self.error_reason,
- connector_response_reference_id: self.connector_response_reference_id,
- multiple_capture_count: self.multiple_capture_count,
- amount_capturable: self.amount_capturable,
- updated_by: self.updated_by,
- merchant_connector_id: self.merchant_connector_id,
- authentication_data: self.authentication_data,
- encoded_data: self.encoded_data,
- unified_code: self.unified_code,
- unified_message: self.unified_message,
- net_amount: Some(self.net_amount.get_total_amount()),
- external_three_ds_authentication_attempted: self
- .external_three_ds_authentication_attempted,
- external_threeds_authentication_type: self.external_threeds_authentication_type,
- authentication_connector: self.authentication_connector,
- authentication_id: self.authentication_id,
- mandate_data: self.mandate_data.map(Into::into),
- fingerprint_id: self.fingerprint_id,
- fingerprint_type: self.fingerprint_type,
- payment_method_billing_address_id: self.payment_method_billing_address_id,
- client_source: self.client_source,
- client_version: self.client_version,
- customer_acceptance: self.customer_acceptance,
- profile_id: self.profile_id,
- organization_id: self.organization_id,
- card_network,
- order_tax_amount: self.net_amount.get_order_tax_amount(),
- shipping_cost: self.net_amount.get_shipping_cost(),
- connector_mandate_detail: self.connector_mandate_detail,
- tokenization: self.tokenization,
- request_extended_authorization: self.request_extended_authorization,
- extended_authorization_applied: self.extended_authorization_applied,
- extended_authorization_last_applied_at: self.extended_authorization_last_applied_at,
- capture_before: self.capture_before,
- card_discovery: self.card_discovery,
- processor_merchant_id: Some(self.processor_merchant_id),
- created_by: self.created_by.map(|created_by| created_by.to_string()),
- setup_future_usage_applied: self.setup_future_usage_applied,
- routing_approach: self.routing_approach,
- connector_request_reference_id: self.connector_request_reference_id,
- network_transaction_id: self.network_transaction_id,
- network_transaction_link_id: self.network_transaction_link_id,
- network_details: self.network_details,
- is_stored_credential: self.is_stored_credential,
- authorized_amount: self.authorized_amount,
- encrypted_payment_method_data: self.encrypted_payment_method_data.map(Encryption::from),
- error_details: self.error_details.map(Into::into),
- retry_type: self.retry_type,
- installment_data: self.installment_data,
- external_surcharge_details: self.external_surcharge_details,
- applied_offer_details: self.applied_offer_details,
- payment_account_reference: self.payment_account_reference,
- sender_payment_instrument_id: self.sender_payment_instrument_id,
- active_frm_id: self.active_frm_id,
- })
- }
-}
-
-#[cfg(feature = "v2")]
-impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal {
- fn from(update: PaymentAttemptUpdate) -> Self {
- match update {
- PaymentAttemptUpdate::ConfirmIntent {
- status,
- updated_by,
- connector,
- merchant_connector_id,
- authentication_type,
- connector_request_reference_id,
- connector_response_reference_id,
- } => Self {
- status: Some(status),
- payment_method_id: None,
- error_message: None,
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_code: None,
- error_reason: None,
- updated_by,
- merchant_connector_id,
- unified_code: None,
- unified_message: None,
- connector_payment_id: None,
- connector_payment_data: None,
- connector: Some(connector),
- redirection_data: None,
- connector_metadata: None,
- amount_capturable: None,
- amount_to_capture: None,
- connector_token_details: None,
- authentication_type: Some(authentication_type),
- feature_metadata: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id,
- connector_response_reference_id,
- cancellation_reason: None,
- amount_captured: None,
- payment_method_data: None,
- },
- PaymentAttemptUpdate::ErrorUpdate {
- status,
- error,
- connector_payment_id,
- connector_response_reference_id,
- amount_capturable,
- updated_by,
- payment_method_data,
- } => {
- // Apply automatic hashing for long connector payment IDs
- let (connector_payment_id, connector_payment_data) = connector_payment_id
- .map(ConnectorTransactionId::form_id_and_data)
- .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
- .unwrap_or((None, None));
-
- Self {
- status: Some(status),
- payment_method_id: None,
- error_message: Some(error.message),
- error_code: Some(error.code),
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_reason: error.reason,
- updated_by,
- merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
- connector_payment_id,
- connector_payment_data,
- connector: None,
- redirection_data: None,
- connector_metadata: None,
- amount_capturable,
- amount_to_capture: None,
- connector_token_details: None,
- authentication_type: None,
- feature_metadata: None,
- network_advice_code: error.network_advice_code,
- network_decline_code: error.network_decline_code,
- network_error_message: error.network_error_message,
- connector_request_reference_id: None,
- connector_response_reference_id,
- cancellation_reason: None,
- amount_captured: None,
- payment_method_data,
- }
- }
- PaymentAttemptUpdate::ConfirmIntentResponse(confirm_intent_response_update) => {
- let ConfirmIntentResponseUpdate {
- status,
- connector_payment_id,
- updated_by,
- redirection_data,
- connector_metadata,
- amount_capturable,
- connector_token_details,
- connector_response_reference_id,
- amount_captured,
- payment_method_data,
- } = *confirm_intent_response_update;
-
- // Apply automatic hashing for long connector payment IDs
- let (connector_payment_id, connector_payment_data) = connector_payment_id
- .map(ConnectorTransactionId::form_id_and_data)
- .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
- .unwrap_or((None, None));
- Self {
- status: Some(status),
- payment_method_id: None,
- amount_capturable,
- error_message: None,
- error_code: None,
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_reason: None,
- updated_by,
- merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
- connector_payment_id,
- connector_payment_data,
- connector: None,
- redirection_data: redirection_data
- .map(diesel_models::payment_attempt::RedirectForm::from),
- connector_metadata,
- amount_to_capture: None,
- connector_token_details,
- authentication_type: None,
- feature_metadata: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id: None,
- connector_response_reference_id,
- cancellation_reason: None,
- amount_captured: None,
- payment_method_data,
- }
- }
- PaymentAttemptUpdate::SyncUpdate {
- status,
- amount_capturable,
- updated_by,
- amount_captured,
- payment_method_data,
- } => Self {
- status: Some(status),
- payment_method_id: None,
- amount_capturable,
- error_message: None,
- error_code: None,
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_reason: None,
- updated_by,
- merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
- connector_payment_id: None,
- connector_payment_data: None,
- connector: None,
- redirection_data: None,
- connector_metadata: None,
- amount_to_capture: None,
- connector_token_details: None,
- authentication_type: None,
- feature_metadata: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id: None,
- connector_response_reference_id: None,
- cancellation_reason: None,
- amount_captured,
- payment_method_data: payment_method_data.map(pii::SecretSerdeValue::new),
- },
- PaymentAttemptUpdate::CaptureUpdate {
- status,
- amount_capturable,
- updated_by,
- } => Self {
- status: Some(status),
- payment_method_id: None,
- amount_capturable,
- amount_to_capture: None,
- error_message: None,
- error_code: None,
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_reason: None,
- updated_by,
- merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
- connector_payment_id: None,
- connector_payment_data: None,
- connector: None,
- redirection_data: None,
- connector_metadata: None,
- connector_token_details: None,
- authentication_type: None,
- feature_metadata: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id: None,
- connector_response_reference_id: None,
- cancellation_reason: None,
- amount_captured: None,
- payment_method_data: None,
- },
- PaymentAttemptUpdate::RecordBackUpdate {
- feature_metadata,
- updated_by,
- } => Self {
- feature_metadata: feature_metadata.as_ref().map(From::from),
- updated_by,
- modified_at: common_utils::date_time::now(),
- amount_to_capture: None,
- payment_method_id: None,
- error_message: None,
- browser_info: None,
- error_code: None,
- error_reason: None,
- merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
- connector_payment_id: None,
- connector_payment_data: None,
- connector: None,
- redirection_data: None,
- status: None,
- connector_metadata: None,
- amount_capturable: None,
- connector_token_details: None,
- authentication_type: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id: None,
- connector_response_reference_id: None,
- cancellation_reason: None,
- amount_captured: None,
- payment_method_data: None,
- },
- PaymentAttemptUpdate::PreCaptureUpdate {
- amount_to_capture,
- updated_by,
- } => Self {
- amount_to_capture,
- payment_method_id: None,
- error_message: None,
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_code: None,
- error_reason: None,
- updated_by,
- merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
- connector_payment_id: None,
- connector_payment_data: None,
- connector: None,
- redirection_data: None,
- status: None,
- connector_metadata: None,
- amount_capturable: None,
- connector_token_details: None,
- authentication_type: None,
- feature_metadata: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id: None,
- connector_response_reference_id: None,
- cancellation_reason: None,
- amount_captured: None,
- payment_method_data: None,
- },
- PaymentAttemptUpdate::ConfirmIntentTokenized {
- status,
- updated_by,
- connector,
- merchant_connector_id,
- authentication_type,
- payment_method_id,
- connector_request_reference_id,
- } => Self {
- status: Some(status),
- payment_method_id: Some(payment_method_id),
- error_message: None,
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_code: None,
- error_reason: None,
- updated_by,
- merchant_connector_id: Some(merchant_connector_id),
- unified_code: None,
- unified_message: None,
- connector_payment_id: None,
- connector_payment_data: None,
- connector: Some(connector),
- redirection_data: None,
- connector_metadata: None,
- amount_capturable: None,
- amount_to_capture: None,
- connector_token_details: None,
- authentication_type: Some(authentication_type),
- feature_metadata: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id,
- connector_response_reference_id: None,
- cancellation_reason: None,
- amount_captured: None,
- payment_method_data: None,
- },
- PaymentAttemptUpdate::VoidUpdate {
- status,
- cancellation_reason,
- updated_by,
- } => Self {
- status: Some(status),
- cancellation_reason,
- error_message: None,
- error_code: None,
- modified_at: common_utils::date_time::now(),
- browser_info: None,
- error_reason: None,
- updated_by,
- merchant_connector_id: None,
- unified_code: None,
- unified_message: None,
- connector_payment_id: None,
- connector_payment_data: None,
- connector: None,
- redirection_data: None,
- connector_metadata: None,
- amount_capturable: None,
- amount_to_capture: None,
- connector_token_details: None,
- authentication_type: None,
- feature_metadata: None,
- network_advice_code: None,
- network_decline_code: None,
- network_error_message: None,
- connector_request_reference_id: None,
- connector_response_reference_id: None,
- payment_method_id: None,
- amount_captured: None,
- payment_method_data: None,
- },
- }
- }
-}
#[cfg(feature = "v2")]
#[derive(Debug, Clone, serde::Serialize, PartialEq)]
pub struct PaymentAttemptFeatureMetadata {
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 5fb222013e..43df6abea7 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -23,7 +23,6 @@ use hyperswitch_domain_models::payments::{
PaymentConfirmData, PaymentIntentData, PaymentStatusData,
};
use hyperswitch_domain_models::{
- behaviour::Conversion,
mandates::{self, ConnectorMandateReferenceId, MandateReferenceId},
payments::payment_attempt::PaymentAttempt,
};
@@ -32,6 +31,7 @@ use hyperswitch_masking::ExposeInterface;
use hyperswitch_masking::PeekInterface;
use router_derive;
use router_env::{instrument, logger, tracing};
+use storage_impl::behaviour::Conversion;
#[cfg(feature = "v1")]
use tracing_futures::Instrument;
diff --git a/crates/router/src/db/user/sample_data.rs b/crates/router/src/db/user/sample_data.rs
index 15973ec277..568d9d9b4d 100644
--- a/crates/router/src/db/user/sample_data.rs
+++ b/crates/router/src/db/user/sample_data.rs
@@ -120,6 +120,7 @@ impl BatchSampleDataInterface for Store {
state: &KeyManagerState,
key_store: &MerchantKeyStore,
) -> CustomResult<Vec<PaymentAttempt>, StorageError> {
+ use storage_impl::behaviour::Conversion;
let conn = pg_connection_write(self)
.await
.change_context(StorageError::DatabaseConnectionError)?;
@@ -200,9 +201,12 @@ impl BatchSampleDataInterface for Store {
state: &KeyManagerState,
key_store: &MerchantKeyStore,
) -> CustomResult<Vec<PaymentAttempt>, StorageError> {
+ use storage_impl::behaviour::Conversion;
+
let conn = pg_connection_write(self)
.await
.change_context(StorageError::DatabaseConnectionError)?;
+
sample_data_queries::delete_payment_attempts(&conn, merchant_id)
.await
.map_err(diesel_error_to_data_error)
diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rs
index 3306cb1763..e6b960edc4 100644
--- a/crates/storage_impl/src/mock_db/payment_attempt.rs
+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs
@@ -3,14 +3,14 @@ use common_utils::errors::CustomResult;
use common_utils::id_type;
use diesel_models::enums as storage_enums;
use error_stack::ResultExt;
-#[cfg(feature = "v1")]
-use hyperswitch_domain_models::behaviour::Conversion;
use hyperswitch_domain_models::{
merchant_key_store::MerchantKeyStore,
payments::payment_attempt::{PaymentAttempt, PaymentAttemptInterface, PaymentAttemptUpdate},
};
use super::MockDb;
+#[cfg(feature = "v1")]
+use crate::behaviour::Conversion;
use crate::errors::StorageError;
#[async_trait::async_trait]
diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs
index 6d484f920d..e163ad39fe 100644
--- a/crates/storage_impl/src/payments/payment_attempt.rs
+++ b/crates/storage_impl/src/payments/payment_attempt.rs
@@ -1,21 +1,24 @@
#[cfg(feature = "v1")]
use common_utils::fallback_reverse_lookup_not_found;
-use common_utils::{errors::CustomResult, ext_traits::AsyncExt};
-#[cfg(feature = "v2")]
-use diesel_models::payment_attempt::PaymentAttemptNew as DieselPaymentAttemptNew;
+use common_utils::{
+ encryption::Encryption, errors::CustomResult, ext_traits::AsyncExt,
+ types::ConnectorTransactionId,
+};
use diesel_models::{
enums::{
MandateAmountData as DieselMandateAmountData, MandateDataType as DieselMandateType,
MandateDetails as DieselMandateDetails, MerchantStorageScheme,
},
- payment_attempt::PaymentAttempt as DieselPaymentAttempt,
+ payment_attempt::{
+ PaymentAttempt as DieselPaymentAttempt, PaymentAttemptNew as DieselPaymentAttemptNew,
+ },
reverse_lookup::{ReverseLookup, ReverseLookupNew},
};
use error_stack::ResultExt;
#[cfg(all(feature = "v1", feature = "olap"))]
use futures::future::{try_join_all, FutureExt};
-#[cfg(feature = "v1")]
-use hyperswitch_domain_models::behaviour::Conversion;
+#[cfg(feature = "v2")]
+use hyperswitch_domain_models::payments::payment_attempt::ConfirmIntentResponseUpdate;
use hyperswitch_domain_models::{
mandates::{MandateAmountData, MandateDataType, MandateDetails},
merchant_key_store::MerchantKeyStore,
@@ -31,10 +34,11 @@ use redis_interface::HsetnxReply;
use router_env::{instrument, tracing};
#[cfg(feature = "v2")]
-use crate::behaviour::{Conversion, ReverseConversion};
+use crate::behaviour::ReverseConversion;
#[cfg(feature = "v2")]
use crate::kv_router_store::{FilterResourceParams, FindResourceBy, UpdateResourceParams};
use crate::{
+ behaviour::Conversion,
diesel_error_to_data_error, errors,
errors::RedisErrorExt,
kv_router_store::KVRouterStore,
@@ -171,7 +175,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
.change_context(errors::StorageError::EncryptionError)?
.update_with_attempt_id(
&conn,
- diesel_models::PaymentAttemptUpdateInternal::from(payment_attempt),
+ diesel_models::PaymentAttemptUpdateInternal::foreign_from(payment_attempt),
),
)
.await
@@ -400,11 +404,9 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {
processor_merchant_id: &common_utils::id_type::MerchantId,
_storage_scheme: MerchantStorageScheme,
) -> CustomResult<PaymentListFilters, errors::StorageError> {
- use hyperswitch_domain_models::behaviour::Conversion;
-
let conn = pg_connection_read(self).await?;
let intents = try_join_all(pi.iter().map(|pi| async {
- Conversion::convert(pi.clone())
+ hyperswitch_domain_models::behaviour::Conversion::convert(pi.clone())
.await
.change_context(errors::StorageError::EncryptionError)
}))
@@ -1148,7 +1150,7 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {
let conn = pg_connection_write(self).await?;
let payment_attempt_internal =
- diesel_models::PaymentAttemptUpdateInternal::from(payment_attempt_update);
+ diesel_models::PaymentAttemptUpdateInternal::foreign_from(payment_attempt_update);
let updated_payment_attempt = payment_attempt_internal
.clone()
.apply_changeset(payment_attempt.clone());
@@ -2079,27 +2081,395 @@ mod label {
}
#[cfg(feature = "v2")]
+use common_utils::ext_traits::ValueExt;
+#[cfg(feature = "v2")]
+use common_utils::pii;
use common_utils::{
errors::ValidationError,
- ext_traits::ValueExt,
- types::{
- keymanager::{self, ToEncryptable},
- ConnectorTransactionId, ConnectorTransactionIdTrait, CreatedBy,
- },
+ types::{keymanager, keymanager::ToEncryptable, ConnectorTransactionIdTrait, CreatedBy},
};
#[cfg(feature = "v2")]
+use hyperswitch_domain_models::payments::payment_attempt::AttemptAmountDetailsSetter;
+#[cfg(feature = "v2")]
+use hyperswitch_domain_models::payments::payment_attempt::ErrorDetails;
+#[cfg(feature = "v1")]
+use hyperswitch_domain_models::payments::payment_attempt::NetAmount;
use hyperswitch_domain_models::{
- payments::payment_attempt::{
- AttemptAmountDetails, AttemptAmountDetailsSetter, EncryptedPaymentAttempt, ErrorDetails,
- },
+ payments::payment_attempt::EncryptedPaymentAttempt,
type_encryption::{crypto_operation, CryptoOperation},
};
-#[cfg(feature = "v2")]
use hyperswitch_masking::{PeekInterface, Secret};
#[cfg(feature = "v2")]
+use crate::behaviour::ForeignFrom;
use crate::KeyManagerState;
+#[cfg(feature = "v1")]
+#[async_trait::async_trait]
+impl Conversion for PaymentAttempt {
+ type DstType = DieselPaymentAttempt;
+ type NewDstType = DieselPaymentAttemptNew;
+
+ async fn convert(self) -> CustomResult<Self::DstType, ValidationError> {
+ let card_network = self
+ .extract_card_network()
+ .map(|network| network.to_string());
+ let (connector_transaction_id, processor_transaction_data) = self
+ .connector_transaction_id
+ .map(ConnectorTransactionId::form_id_and_data)
+ .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
+ .unwrap_or((None, None));
+ Ok(DieselPaymentAttempt {
+ payment_id: self.payment_id,
+ merchant_id: self.merchant_id,
+ attempt_id: self.attempt_id,
+ status: self.status,
+ amount: self.net_amount.get_order_amount(),
+ currency: self.currency,
+ save_to_locker: self.save_to_locker,
+ connector: self.connector,
+ error_message: self.error_message,
+ offer_amount: self.offer_amount,
+ surcharge_amount: self.net_amount.get_surcharge_amount(),
+ tax_amount: self.net_amount.get_tax_on_surcharge(),
+ payment_method_id: self.payment_method_id,
+ payment_method: self.payment_method,
+ connector_transaction_id,
+ capture_method: self.capture_method,
+ capture_on: self.capture_on,
+ confirm: self.confirm,
+ authentication_type: self.authentication_type,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ last_synced: self.last_synced,
+ cancellation_reason: self.cancellation_reason,
+ amount_to_capture: self.amount_to_capture,
+ mandate_id: self.mandate_id,
+ browser_info: self.browser_info,
+ error_code: self.error_code,
+ payment_token: self.payment_token,
+ connector_metadata: self.connector_metadata,
+ payment_experience: self.payment_experience,
+ payment_method_type: self.payment_method_type,
+ payment_method_data: self.payment_method_data,
+ business_sub_label: self.business_sub_label,
+ straight_through_algorithm: self.straight_through_algorithm,
+ preprocessing_step_id: self.preprocessing_step_id,
+ mandate_details: self.mandate_details.map(Into::into),
+ error_reason: self.error_reason,
+ multiple_capture_count: self.multiple_capture_count,
+ connector_response_reference_id: self.connector_response_reference_id,
+ amount_capturable: self.amount_capturable,
+ updated_by: self.updated_by,
+ merchant_connector_id: self.merchant_connector_id,
+ authentication_data: self.authentication_data,
+ encoded_data: self.encoded_data,
+ unified_code: self.unified_code,
+ unified_message: self.unified_message,
+ net_amount: Some(self.net_amount.get_total_amount()),
+ external_three_ds_authentication_attempted: self
+ .external_three_ds_authentication_attempted,
+ external_threeds_authentication_type: self.external_threeds_authentication_type,
+ authentication_connector: self.authentication_connector,
+ authentication_id: self.authentication_id,
+ mandate_data: self.mandate_data.map(Into::into),
+ fingerprint_id: self.fingerprint_id,
+ fingerprint_type: self.fingerprint_type,
+ payment_method_billing_address_id: self.payment_method_billing_address_id,
+ charge_id: self.charge_id,
+ client_source: self.client_source,
+ client_version: self.client_version,
+ customer_acceptance: self.customer_acceptance,
+ profile_id: self.profile_id,
+ organization_id: self.organization_id,
+ card_network,
+ order_tax_amount: self.net_amount.get_order_tax_amount(),
+ shipping_cost: self.net_amount.get_shipping_cost(),
+ installment_data: self.installment_data,
+ connector_mandate_detail: self.connector_mandate_detail,
+ tokenization: self.tokenization,
+ request_extended_authorization: self.request_extended_authorization,
+ extended_authorization_applied: self.extended_authorization_applied,
+ extended_authorization_last_applied_at: self.extended_authorization_last_applied_at,
+ capture_before: self.capture_before,
+ processor_transaction_data,
+ card_discovery: self.card_discovery,
+ charges: self.charges,
+ issuer_error_code: self.issuer_error_code,
+ issuer_error_message: self.issuer_error_message,
+ setup_future_usage_applied: self.setup_future_usage_applied,
+ error_details: self.error_details.map(Into::into),
+ // Below fields are deprecated. Please add any new fields above this line.
+ connector_transaction_data: None,
+ processor_merchant_id: Some(self.processor_merchant_id),
+ created_by: self.created_by.map(|created_by| created_by.to_string()),
+ routing_approach: self.routing_approach,
+ connector_request_reference_id: self.connector_request_reference_id,
+ network_transaction_id: self.network_transaction_id,
+ network_transaction_link_id: self.network_transaction_link_id,
+ is_overcapture_enabled: self.is_overcapture_enabled,
+ network_details: self.network_details,
+ is_stored_credential: self.is_stored_credential,
+ authorized_amount: self.authorized_amount,
+ encrypted_payment_method_data: self.encrypted_payment_method_data.map(Encryption::from),
+ retry_type: self.retry_type,
+ external_surcharge_details: self.external_surcharge_details,
+ applied_offer_details: self.applied_offer_details,
+ payment_account_reference: self.payment_account_reference,
+ sender_payment_instrument_id: self.sender_payment_instrument_id,
+ active_frm_id: self.active_frm_id,
+ })
+ }
+
+ async fn convert_back(
+ state: &KeyManagerState,
+ storage_model: Self::DstType,
+ key: &Secret<Vec<u8>>,
+ key_manager_identifier: keymanager::Identifier,
+ ) -> CustomResult<Self, ValidationError>
+ where
+ Self: Sized,
+ {
+ async {
+ let connector_transaction_id = storage_model
+ .get_optional_connector_transaction_id()
+ .cloned();
+ let decrypted_data = crypto_operation(
+ state,
+ common_utils::type_name!(Self::DstType),
+ CryptoOperation::BatchDecrypt(EncryptedPaymentAttempt::to_encryptable(
+ EncryptedPaymentAttempt {
+ encrypted_payment_method_data: storage_model.encrypted_payment_method_data,
+ },
+ )),
+ key_manager_identifier,
+ key.peek(),
+ )
+ .await
+ .and_then(|val| val.try_into_batchoperation())?;
+
+ let decrypted_data = EncryptedPaymentAttempt::from_encryptable(decrypted_data)
+ .change_context(common_utils::errors::CryptoError::DecodingFailed)
+ .attach_printable("Invalid batch operation data")?;
+
+ let encrypted_payment_method_data = decrypted_data.encrypted_payment_method_data;
+ Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
+ payment_id: storage_model.payment_id,
+ merchant_id: storage_model.merchant_id.clone(),
+ attempt_id: storage_model.attempt_id,
+ status: storage_model.status,
+ net_amount: NetAmount::new(
+ storage_model.amount,
+ storage_model.shipping_cost,
+ storage_model.order_tax_amount,
+ storage_model.surcharge_amount,
+ storage_model.tax_amount,
+ storage_model
+ .installment_data
+ .as_ref()
+ .and_then(|d| d.installment_interest),
+ storage_model
+ .applied_offer_details
+ .as_ref()
+ .map(|applied_offer_details| applied_offer_details.inner().offer_amount),
+ ),
+ currency: storage_model.currency,
+ save_to_locker: storage_model.save_to_locker,
+ connector: storage_model.connector,
+ error_message: storage_model.error_message,
+ offer_amount: storage_model.offer_amount,
+ payment_method_id: storage_model.payment_method_id,
+ payment_method: storage_model.payment_method,
+ connector_transaction_id,
+ capture_method: storage_model.capture_method,
+ capture_on: storage_model.capture_on,
+ confirm: storage_model.confirm,
+ authentication_type: storage_model.authentication_type,
+ created_at: storage_model.created_at,
+ modified_at: storage_model.modified_at,
+ last_synced: storage_model.last_synced,
+ cancellation_reason: storage_model.cancellation_reason,
+ amount_to_capture: storage_model.amount_to_capture,
+ mandate_id: storage_model.mandate_id,
+ browser_info: storage_model.browser_info,
+ error_code: storage_model.error_code,
+ payment_token: storage_model.payment_token,
+ connector_metadata: storage_model.connector_metadata,
+ payment_experience: storage_model.payment_experience,
+ payment_method_type: storage_model.payment_method_type,
+ payment_method_data: storage_model.payment_method_data,
+ business_sub_label: storage_model.business_sub_label,
+ straight_through_algorithm: storage_model.straight_through_algorithm,
+ preprocessing_step_id: storage_model.preprocessing_step_id,
+ mandate_details: storage_model.mandate_details.map(Into::into),
+ error_reason: storage_model.error_reason,
+ multiple_capture_count: storage_model.multiple_capture_count,
+ connector_response_reference_id: storage_model.connector_response_reference_id,
+ amount_capturable: storage_model.amount_capturable,
+ updated_by: storage_model.updated_by,
+ authentication_data: storage_model.authentication_data,
+ encoded_data: storage_model.encoded_data,
+ merchant_connector_id: storage_model.merchant_connector_id,
+ unified_code: storage_model.unified_code,
+ unified_message: storage_model.unified_message,
+ external_three_ds_authentication_attempted: storage_model
+ .external_three_ds_authentication_attempted,
+ external_threeds_authentication_type: storage_model
+ .external_threeds_authentication_type,
+ authentication_connector: storage_model.authentication_connector,
+ authentication_id: storage_model.authentication_id,
+ mandate_data: storage_model.mandate_data.map(Into::into),
+ payment_method_billing_address_id: storage_model.payment_method_billing_address_id,
+ fingerprint_id: storage_model.fingerprint_id,
+ fingerprint_type: storage_model.fingerprint_type,
+ charge_id: storage_model.charge_id,
+ client_source: storage_model.client_source,
+ client_version: storage_model.client_version,
+ customer_acceptance: storage_model.customer_acceptance,
+ profile_id: storage_model.profile_id,
+ organization_id: storage_model.organization_id,
+ connector_mandate_detail: storage_model.connector_mandate_detail,
+ tokenization: storage_model.tokenization,
+ request_extended_authorization: storage_model.request_extended_authorization,
+ extended_authorization_applied: storage_model.extended_authorization_applied,
+ extended_authorization_last_applied_at: storage_model
+ .extended_authorization_last_applied_at,
+ capture_before: storage_model.capture_before,
+ card_discovery: storage_model.card_discovery,
+ charges: storage_model.charges,
+ issuer_error_code: storage_model.issuer_error_code,
+ issuer_error_message: storage_model.issuer_error_message,
+ processor_merchant_id: storage_model
+ .processor_merchant_id
+ .unwrap_or(storage_model.merchant_id),
+ created_by: storage_model
+ .created_by
+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
+ setup_future_usage_applied: storage_model.setup_future_usage_applied,
+ routing_approach: storage_model.routing_approach,
+ connector_request_reference_id: storage_model.connector_request_reference_id,
+ debit_routing_savings: None,
+ network_transaction_id: storage_model.network_transaction_id,
+ network_transaction_link_id: storage_model.network_transaction_link_id,
+ is_overcapture_enabled: storage_model.is_overcapture_enabled,
+ network_details: storage_model.network_details,
+ is_stored_credential: storage_model.is_stored_credential,
+ authorized_amount: storage_model.authorized_amount,
+ encrypted_payment_method_data,
+ error_details: storage_model.error_details.map(Into::into),
+ retry_type: storage_model.retry_type,
+ installment_data: storage_model.installment_data,
+ external_surcharge_details: storage_model.external_surcharge_details,
+ applied_offer_details: storage_model.applied_offer_details,
+ payment_account_reference: storage_model.payment_account_reference,
+ sender_payment_instrument_id: storage_model.sender_payment_instrument_id,
+ active_frm_id: storage_model.active_frm_id,
+ })
+ }
+ .await
+ .change_context(ValidationError::InvalidValue {
+ message: "Failed while decrypting payment attempt".to_string(),
+ })
+ }
+
+ async fn construct_new(self) -> CustomResult<Self::NewDstType, ValidationError> {
+ let card_network = self
+ .extract_card_network()
+ .map(|network| network.to_string());
+ Ok(DieselPaymentAttemptNew {
+ payment_id: self.payment_id,
+ merchant_id: self.merchant_id,
+ attempt_id: self.attempt_id,
+ status: self.status,
+ amount: self.net_amount.get_order_amount(),
+ currency: self.currency,
+ save_to_locker: self.save_to_locker,
+ connector: self.connector,
+ error_message: self.error_message,
+ offer_amount: self.offer_amount,
+ surcharge_amount: self.net_amount.get_surcharge_amount(),
+ tax_amount: self.net_amount.get_tax_on_surcharge(),
+ payment_method_id: self.payment_method_id,
+ payment_method: self.payment_method,
+ capture_method: self.capture_method,
+ capture_on: self.capture_on,
+ confirm: self.confirm,
+ authentication_type: self.authentication_type,
+ created_at: self.created_at,
+ modified_at: self.modified_at,
+ last_synced: self.last_synced,
+ cancellation_reason: self.cancellation_reason,
+ amount_to_capture: self.amount_to_capture,
+ mandate_id: self.mandate_id,
+ browser_info: self.browser_info,
+ payment_token: self.payment_token,
+ error_code: self.error_code,
+ connector_metadata: self.connector_metadata,
+ payment_experience: self.payment_experience,
+ payment_method_type: self.payment_method_type,
+ payment_method_data: self.payment_method_data,
+ business_sub_label: self.business_sub_label,
+ straight_through_algorithm: self.straight_through_algorithm,
+ preprocessing_step_id: self.preprocessing_step_id,
+ mandate_details: self.mandate_details.map(Into::into),
+ error_reason: self.error_reason,
+ connector_response_reference_id: self.connector_response_reference_id,
+ multiple_capture_count: self.multiple_capture_count,
+ amount_capturable: self.amount_capturable,
+ updated_by: self.updated_by,
+ merchant_connector_id: self.merchant_connector_id,
+ authentication_data: self.authentication_data,
+ encoded_data: self.encoded_data,
+ unified_code: self.unified_code,
+ unified_message: self.unified_message,
+ net_amount: Some(self.net_amount.get_total_amount()),
+ external_three_ds_authentication_attempted: self
+ .external_three_ds_authentication_attempted,
+ external_threeds_authentication_type: self.external_threeds_authentication_type,
+ authentication_connector: self.authentication_connector,
+ authentication_id: self.authentication_id,
+ mandate_data: self.mandate_data.map(Into::into),
+ fingerprint_id: self.fingerprint_id,
+ fingerprint_type: self.fingerprint_type,
+ payment_method_billing_address_id: self.payment_method_billing_address_id,
+ client_source: self.client_source,
+ client_version: self.client_version,
+ customer_acceptance: self.customer_acceptance,
+ profile_id: self.profile_id,
+ organization_id: self.organization_id,
+ card_network,
+ order_tax_amount: self.net_amount.get_order_tax_amount(),
+ shipping_cost: self.net_amount.get_shipping_cost(),
+ connector_mandate_detail: self.connector_mandate_detail,
+ tokenization: self.tokenization,
+ request_extended_authorization: self.request_extended_authorization,
+ extended_authorization_applied: self.extended_authorization_applied,
+ extended_authorization_last_applied_at: self.extended_authorization_last_applied_at,
+ capture_before: self.capture_before,
+ card_discovery: self.card_discovery,
+ processor_merchant_id: Some(self.processor_merchant_id),
+ created_by: self.created_by.map(|created_by| created_by.to_string()),
+ setup_future_usage_applied: self.setup_future_usage_applied,
+ routing_approach: self.routing_approach,
+ connector_request_reference_id: self.connector_request_reference_id,
+ network_transaction_id: self.network_transaction_id,
+ network_transaction_link_id: self.network_transaction_link_id,
+ network_details: self.network_details,
+ is_stored_credential: self.is_stored_credential,
+ authorized_amount: self.authorized_amount,
+ encrypted_payment_method_data: self.encrypted_payment_method_data.map(Encryption::from),
+ error_details: self.error_details.map(Into::into),
+ retry_type: self.retry_type,
+ installment_data: self.installment_data,
+ external_surcharge_details: self.external_surcharge_details,
+ applied_offer_details: self.applied_offer_details,
+ payment_account_reference: self.payment_account_reference,
+ sender_payment_instrument_id: self.sender_payment_instrument_id,
+ active_frm_id: self.active_frm_id,
+ })
+ }
+}
+
#[cfg(feature = "v2")]
#[async_trait::async_trait]
impl Conversion for PaymentAttempt {
@@ -2596,3 +2966,363 @@ impl Conversion for PaymentAttempt {
})
}
}
+
+#[cfg(feature = "v2")]
+impl ForeignFrom<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal {
+ fn foreign_from(update: PaymentAttemptUpdate) -> Self {
+ match update {
+ PaymentAttemptUpdate::ConfirmIntent {
+ status,
+ updated_by,
+ connector,
+ merchant_connector_id,
+ authentication_type,
+ connector_request_reference_id,
+ connector_response_reference_id,
+ } => Self {
+ status: Some(status),
+ payment_method_id: None,
+ error_message: None,
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_code: None,
+ error_reason: None,
+ updated_by,
+ merchant_connector_id,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id: None,
+ connector_payment_data: None,
+ connector: Some(connector),
+ redirection_data: None,
+ connector_metadata: None,
+ amount_capturable: None,
+ amount_to_capture: None,
+ connector_token_details: None,
+ authentication_type: Some(authentication_type),
+ feature_metadata: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id,
+ connector_response_reference_id,
+ cancellation_reason: None,
+ amount_captured: None,
+ payment_method_data: None,
+ },
+ PaymentAttemptUpdate::ErrorUpdate {
+ status,
+ error,
+ connector_payment_id,
+ connector_response_reference_id,
+ amount_capturable,
+ updated_by,
+ payment_method_data,
+ } => {
+ // Apply automatic hashing for long connector payment IDs
+ let (connector_payment_id, connector_payment_data) = connector_payment_id
+ .map(ConnectorTransactionId::form_id_and_data)
+ .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
+ .unwrap_or((None, None));
+
+ Self {
+ status: Some(status),
+ payment_method_id: None,
+ error_message: Some(error.message),
+ error_code: Some(error.code),
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_reason: error.reason,
+ updated_by,
+ merchant_connector_id: None,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id,
+ connector_payment_data,
+ connector: None,
+ redirection_data: None,
+ connector_metadata: None,
+ amount_capturable,
+ amount_to_capture: None,
+ connector_token_details: None,
+ authentication_type: None,
+ feature_metadata: None,
+ network_advice_code: error.network_advice_code,
+ network_decline_code: error.network_decline_code,
+ network_error_message: error.network_error_message,
+ connector_request_reference_id: None,
+ connector_response_reference_id,
+ cancellation_reason: None,
+ amount_captured: None,
+ payment_method_data,
+ }
+ }
+ PaymentAttemptUpdate::ConfirmIntentResponse(confirm_intent_response_update) => {
+ let ConfirmIntentResponseUpdate {
+ status,
+ connector_payment_id,
+ updated_by,
+ redirection_data,
+ connector_metadata,
+ amount_capturable,
+ connector_token_details,
+ connector_response_reference_id,
+ amount_captured,
+ payment_method_data,
+ } = *confirm_intent_response_update;
+
+ // Apply automatic hashing for long connector payment IDs
+ let (connector_payment_id, connector_payment_data) = connector_payment_id
+ .map(ConnectorTransactionId::form_id_and_data)
+ .map(|(txn_id, txn_data)| (Some(txn_id), txn_data))
+ .unwrap_or((None, None));
+ Self {
+ status: Some(status),
+ payment_method_id: None,
+ amount_capturable,
+ error_message: None,
+ error_code: None,
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_reason: None,
+ updated_by,
+ merchant_connector_id: None,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id,
+ connector_payment_data,
+ connector: None,
+ redirection_data: redirection_data
+ .map(diesel_models::payment_attempt::RedirectForm::from),
+ connector_metadata,
+ amount_to_capture: None,
+ connector_token_details,
+ authentication_type: None,
+ feature_metadata: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id: None,
+ connector_response_reference_id,
+ cancellation_reason: None,
+ amount_captured: None,
+ payment_method_data,
+ }
+ }
+ PaymentAttemptUpdate::SyncUpdate {
+ status,
+ amount_capturable,
+ updated_by,
+ amount_captured,
+ payment_method_data,
+ } => Self {
+ status: Some(status),
+ payment_method_id: None,
+ amount_capturable,
+ error_message: None,
+ error_code: None,
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_reason: None,
+ updated_by,
+ merchant_connector_id: None,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id: None,
+ connector_payment_data: None,
+ connector: None,
+ redirection_data: None,
+ connector_metadata: None,
+ amount_to_capture: None,
+ connector_token_details: None,
+ authentication_type: None,
+ feature_metadata: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id: None,
+ connector_response_reference_id: None,
+ cancellation_reason: None,
+ amount_captured,
+ payment_method_data: payment_method_data.map(pii::SecretSerdeValue::new),
+ },
+ PaymentAttemptUpdate::CaptureUpdate {
+ status,
+ amount_capturable,
+ updated_by,
+ } => Self {
+ status: Some(status),
+ payment_method_id: None,
+ amount_capturable,
+ amount_to_capture: None,
+ error_message: None,
+ error_code: None,
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_reason: None,
+ updated_by,
+ merchant_connector_id: None,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id: None,
+ connector_payment_data: None,
+ connector: None,
+ redirection_data: None,
+ connector_metadata: None,
+ connector_token_details: None,
+ authentication_type: None,
+ feature_metadata: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id: None,
+ connector_response_reference_id: None,
+ cancellation_reason: None,
+ amount_captured: None,
+ payment_method_data: None,
+ },
+ PaymentAttemptUpdate::RecordBackUpdate {
+ feature_metadata,
+ updated_by,
+ } => Self {
+ feature_metadata: feature_metadata.as_ref().map(From::from),
+ updated_by,
+ modified_at: common_utils::date_time::now(),
+ amount_to_capture: None,
+ payment_method_id: None,
+ error_message: None,
+ browser_info: None,
+ error_code: None,
+ error_reason: None,
+ merchant_connector_id: None,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id: None,
+ connector_payment_data: None,
+ connector: None,
+ redirection_data: None,
+ status: None,
+ connector_metadata: None,
+ amount_capturable: None,
+ connector_token_details: None,
+ authentication_type: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id: None,
+ connector_response_reference_id: None,
+ cancellation_reason: None,
+ amount_captured: None,
+ payment_method_data: None,
+ },
+ PaymentAttemptUpdate::PreCaptureUpdate {
+ amount_to_capture,
+ updated_by,
+ } => Self {
+ amount_to_capture,
+ payment_method_id: None,
+ error_message: None,
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_code: None,
+ error_reason: None,
+ updated_by,
+ merchant_connector_id: None,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id: None,
+ connector_payment_data: None,
+ connector: None,
+ redirection_data: None,
+ status: None,
+ connector_metadata: None,
+ amount_capturable: None,
+ connector_token_details: None,
+ authentication_type: None,
+ feature_metadata: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id: None,
+ connector_response_reference_id: None,
+ cancellation_reason: None,
+ amount_captured: None,
+ payment_method_data: None,
+ },
+ PaymentAttemptUpdate::ConfirmIntentTokenized {
+ status,
+ updated_by,
+ connector,
+ merchant_connector_id,
+ authentication_type,
+ payment_method_id,
+ connector_request_reference_id,
+ } => Self {
+ status: Some(status),
+ payment_method_id: Some(payment_method_id),
+ error_message: None,
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_code: None,
+ error_reason: None,
+ updated_by,
+ merchant_connector_id: Some(merchant_connector_id),
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id: None,
+ connector_payment_data: None,
+ connector: Some(connector),
+ redirection_data: None,
+ connector_metadata: None,
+ amount_capturable: None,
+ amount_to_capture: None,
+ connector_token_details: None,
+ authentication_type: Some(authentication_type),
+ feature_metadata: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id,
+ connector_response_reference_id: None,
+ cancellation_reason: None,
+ amount_captured: None,
+ payment_method_data: None,
+ },
+ PaymentAttemptUpdate::VoidUpdate {
+ status,
+ cancellation_reason,
+ updated_by,
+ } => Self {
+ status: Some(status),
+ cancellation_reason,
+ error_message: None,
+ error_code: None,
+ modified_at: common_utils::date_time::now(),
+ browser_info: None,
+ error_reason: None,
+ updated_by,
+ merchant_connector_id: None,
+ unified_code: None,
+ unified_message: None,
+ connector_payment_id: None,
+ connector_payment_data: None,
+ connector: None,
+ redirection_data: None,
+ connector_metadata: None,
+ amount_capturable: None,
+ amount_to_capture: None,
+ connector_token_details: None,
+ authentication_type: None,
+ feature_metadata: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_request_reference_id: None,
+ connector_response_reference_id: None,
+ payment_method_id: None,
+ amount_captured: None,
+ payment_method_data: None,
+ },
+ }
+ }
+}
diff --git a/crates/storage_impl/src/payments/payment_intent.rs b/crates/storage_impl/src/payments/payment_intent.rs
index 2244d62af9..d8eb3b2a17 100644
--- a/crates/storage_impl/src/payments/payment_intent.rs
+++ b/crates/storage_impl/src/payments/payment_intent.rs
@@ -1182,6 +1182,8 @@ impl<T: DatabaseStore> PaymentIntentInterface for crate::RouterStore<T> {
.get_keymanager_state()
.attach_printable("Missing KeyManagerState")?;
+ use crate::behaviour::Conversion;
+
query
.get_results_async::<(
DieselPaymentIntent,