use api_models::enums::Connector; use common_enums as storage_enums; use serde::{Deserialize, Serialize}; use time::PrimitiveDateTime; use super::payment_intent::PaymentIntent; use crate::{errors, mandates::MandateDataType, MerchantStorageScheme}; #[async_trait::async_trait] pub trait PaymentAttemptInterface { async fn insert_payment_attempt( &self, payment_attempt: PaymentAttemptNew, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn update_payment_attempt_with_attempt_id( &self, this: PaymentAttempt, payment_attempt: PaymentAttemptUpdate, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn find_payment_attempt_by_connector_transaction_id_payment_id_merchant_id( &self, connector_transaction_id: &str, payment_id: &str, merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id( &self, payment_id: &str, merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn find_payment_attempt_by_merchant_id_connector_txn_id( &self, merchant_id: &str, connector_txn_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn find_payment_attempt_by_payment_id_merchant_id_attempt_id( &self, payment_id: &str, merchant_id: &str, attempt_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn find_payment_attempt_by_attempt_id_merchant_id( &self, attempt_id: &str, merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn find_payment_attempt_by_preprocessing_id_merchant_id( &self, preprocessing_id: &str, merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn find_attempts_by_merchant_id_payment_id( &self, merchant_id: &str, payment_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result, errors::StorageError>; async fn get_filters_for_payments( &self, pi: &[PaymentIntent], merchant_id: &str, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; async fn get_total_count_of_filtered_payment_attempts( &self, merchant_id: &str, active_attempt_ids: &[String], connector: Option>, payment_methods: Option>, storage_scheme: MerchantStorageScheme, ) -> error_stack::Result; } #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] pub struct PaymentAttempt { pub id: i32, pub payment_id: String, pub merchant_id: String, pub attempt_id: String, pub status: storage_enums::AttemptStatus, pub amount: i64, pub currency: Option, pub save_to_locker: Option, pub connector: Option, pub error_message: Option, pub offer_amount: Option, pub surcharge_amount: Option, pub tax_amount: Option, pub payment_method_id: Option, pub payment_method: Option, pub connector_transaction_id: Option, pub capture_method: Option, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub capture_on: Option, pub confirm: bool, pub authentication_type: Option, #[serde(with = "common_utils::custom_serde::iso8601")] pub created_at: PrimitiveDateTime, #[serde(with = "common_utils::custom_serde::iso8601")] pub modified_at: PrimitiveDateTime, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub last_synced: Option, pub cancellation_reason: Option, pub amount_to_capture: Option, pub mandate_id: Option, pub browser_info: Option, pub error_code: Option, pub payment_token: Option, pub connector_metadata: Option, pub payment_experience: Option, pub payment_method_type: Option, pub payment_method_data: Option, pub business_sub_label: Option, pub straight_through_algorithm: Option, pub preprocessing_step_id: Option, // providing a location to store mandate details intermediately for transaction pub mandate_details: Option, pub error_reason: Option, pub multiple_capture_count: Option, // reference to the payment at connector side pub connector_response_reference_id: Option, pub amount_capturable: i64, } #[derive(Clone, Debug, Eq, PartialEq)] pub struct PaymentListFilters { pub connector: Vec, pub currency: Vec, pub status: Vec, pub payment_method: Vec, } #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct PaymentAttemptNew { pub payment_id: String, pub merchant_id: String, pub attempt_id: String, pub status: storage_enums::AttemptStatus, pub amount: i64, pub currency: Option, // pub auto_capture: Option, pub save_to_locker: Option, pub connector: Option, pub error_message: Option, pub offer_amount: Option, pub surcharge_amount: Option, pub tax_amount: Option, pub payment_method_id: Option, pub payment_method: Option, pub capture_method: Option, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub capture_on: Option, pub confirm: bool, pub authentication_type: Option, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub created_at: Option, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub modified_at: Option, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub last_synced: Option, pub cancellation_reason: Option, pub amount_to_capture: Option, pub mandate_id: Option, pub browser_info: Option, pub payment_token: Option, pub error_code: Option, pub connector_metadata: Option, pub payment_experience: Option, pub payment_method_type: Option, pub payment_method_data: Option, pub business_sub_label: Option, pub straight_through_algorithm: Option, pub preprocessing_step_id: Option, pub mandate_details: Option, pub error_reason: Option, pub connector_response_reference_id: Option, pub multiple_capture_count: Option, pub amount_capturable: i64, } #[derive(Debug, Clone, Serialize, Deserialize)] pub enum PaymentAttemptUpdate { Update { amount: i64, currency: storage_enums::Currency, status: storage_enums::AttemptStatus, authentication_type: Option, payment_method: Option, payment_token: Option, payment_method_data: Option, payment_method_type: Option, payment_experience: Option, business_sub_label: Option, amount_to_capture: Option, capture_method: Option, }, UpdateTrackers { payment_token: Option, connector: Option, straight_through_algorithm: Option, }, AuthenticationTypeUpdate { authentication_type: storage_enums::AuthenticationType, }, ConfirmUpdate { amount: i64, currency: storage_enums::Currency, status: storage_enums::AttemptStatus, authentication_type: Option, payment_method: Option, browser_info: Option, connector: Option, payment_token: Option, payment_method_data: Option, payment_method_type: Option, payment_experience: Option, business_sub_label: Option, straight_through_algorithm: Option, error_code: Option>, error_message: Option>, }, RejectUpdate { status: storage_enums::AttemptStatus, error_code: Option>, error_message: Option>, }, VoidUpdate { status: storage_enums::AttemptStatus, cancellation_reason: Option, }, ResponseUpdate { status: storage_enums::AttemptStatus, connector: Option, connector_transaction_id: Option, authentication_type: Option, payment_method_id: Option>, mandate_id: Option, connector_metadata: Option, payment_token: Option, error_code: Option>, error_message: Option>, error_reason: Option>, connector_response_reference_id: Option, amount_capturable: Option, }, UnresolvedResponseUpdate { status: storage_enums::AttemptStatus, connector: Option, connector_transaction_id: Option, payment_method_id: Option>, error_code: Option>, error_message: Option>, error_reason: Option>, connector_response_reference_id: Option, }, StatusUpdate { status: storage_enums::AttemptStatus, }, ErrorUpdate { connector: Option, status: storage_enums::AttemptStatus, error_code: Option>, error_message: Option>, error_reason: Option>, amount_capturable: Option, }, MultipleCaptureCountUpdate { multiple_capture_count: i16, }, AmountToCaptureUpdate { status: storage_enums::AttemptStatus, amount_capturable: i64, }, PreprocessingUpdate { status: storage_enums::AttemptStatus, payment_method_id: Option>, connector_metadata: Option, preprocessing_step_id: Option, connector_transaction_id: Option, connector_response_reference_id: Option, }, }