Files
Sampras Lopes ad4b7de628 refactor(storage_impl): split payment attempt models to domain + diesel (#2010)
Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
Co-authored-by: Mani Chandra <84711804+ThisIsMani@users.noreply.github.com>
Co-authored-by: Arjun Karthik <m.arjunkarthik@gmail.com>
Co-authored-by: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com>
Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
Co-authored-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com>
Co-authored-by: Prasunna Soppa <prasunna.soppa@juspay.in>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com>
Co-authored-by: Arvind Patel <52006565+arvindpatel24@users.noreply.github.com>
Co-authored-by: Jagan Elavarasan <jaganelavarasan@gmail.com>
Co-authored-by: arvindpatel24 <arvind.patel@juspay.in>
Co-authored-by: anji-reddy-j <125157119+anji-reddy-j@users.noreply.github.com>
Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com>
Co-authored-by: Apoorv Dixit <64925866+apoorvdixit88@users.noreply.github.com>
Co-authored-by: Pa1NarK <69745008+pixincreate@users.noreply.github.com>
2023-09-11 12:03:47 +00:00

132 lines
3.4 KiB
Rust

pub mod address;
pub mod api_keys;
pub mod business_profile;
pub mod cache;
pub mod capture;
pub mod cards_info;
pub mod configs;
pub mod connector_response;
pub mod customers;
pub mod dispute;
pub mod ephemeral_key;
pub mod events;
pub mod file;
pub mod fraud_check;
pub mod locker_mock_up;
pub mod mandate;
pub mod merchant_account;
pub mod merchant_connector_account;
pub mod merchant_key_store;
pub mod payment_method;
pub mod payout_attempt;
pub mod payouts;
pub mod refund;
pub mod reverse_lookup;
use data_models::payments::{
payment_attempt::PaymentAttemptInterface, payment_intent::PaymentIntentInterface,
};
use masking::PeekInterface;
use storage_impl::{redis::kv_store::RedisConnInterface, MockDb};
use crate::services::Store;
#[derive(PartialEq, Eq)]
pub enum StorageImpl {
Postgresql,
PostgresqlTest,
Mock,
}
#[async_trait::async_trait]
pub trait StorageInterface:
Send
+ Sync
+ dyn_clone::DynClone
+ address::AddressInterface
+ api_keys::ApiKeyInterface
+ configs::ConfigInterface
+ capture::CaptureInterface
+ connector_response::ConnectorResponseInterface
+ customers::CustomerInterface
+ dispute::DisputeInterface
+ ephemeral_key::EphemeralKeyInterface
+ events::EventInterface
+ file::FileMetadataInterface
+ fraud_check::FraudCheckInterface
+ locker_mock_up::LockerMockUpInterface
+ mandate::MandateInterface
+ merchant_account::MerchantAccountInterface
+ merchant_connector_account::ConnectorAccessToken
+ merchant_connector_account::MerchantConnectorAccountInterface
+ PaymentAttemptInterface
+ PaymentIntentInterface
+ payment_method::PaymentMethodInterface
+ scheduler::SchedulerInterface
+ payout_attempt::PayoutAttemptInterface
+ payouts::PayoutsInterface
+ refund::RefundInterface
+ reverse_lookup::ReverseLookupInterface
+ cards_info::CardsInfoInterface
+ merchant_key_store::MerchantKeyStoreInterface
+ MasterKeyInterface
+ RedisConnInterface
+ business_profile::BusinessProfileInterface
+ 'static
{
fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface>;
}
pub trait MasterKeyInterface {
fn get_master_key(&self) -> &[u8];
}
impl MasterKeyInterface for Store {
fn get_master_key(&self) -> &[u8] {
self.master_key().peek()
}
}
/// Default dummy key for MockDb
impl MasterKeyInterface for MockDb {
fn get_master_key(&self) -> &[u8] {
&[
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32,
]
}
}
#[async_trait::async_trait]
impl StorageInterface for Store {
fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface> {
Box::new(self.clone())
}
}
#[async_trait::async_trait]
impl StorageInterface for MockDb {
fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface> {
Box::new(self.clone())
}
}
pub async fn get_and_deserialize_key<T>(
db: &dyn StorageInterface,
key: &str,
type_name: &'static str,
) -> common_utils::errors::CustomResult<T, redis_interface::errors::RedisError>
where
T: serde::de::DeserializeOwned,
{
use common_utils::ext_traits::ByteSliceExt;
use error_stack::ResultExt;
let bytes = db.get_key(key).await?;
bytes
.parse_struct(type_name)
.change_context(redis_interface::errors::RedisError::JsonDeserializationFailed)
}
dyn_clone::clone_trait_object!(StorageInterface);