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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
use error_stack::report;
use router_env::instrument;
use storage_impl::MockDb;
use super::Store;
use crate::{
connection,
core::errors::{self, CustomResult},
db::kafka_store::KafkaStore,
types::storage,
};
#[router_derive::track_async_interface]
#[async_trait::async_trait]
pub trait BlocklistLookupInterface {
async fn insert_blocklist_lookup_entry(
&self,
blocklist_lookup_new: storage::BlocklistLookupNew,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError>;
async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
merchant_id: &common_utils::id_type::MerchantId,
fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError>;
async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
merchant_id: &common_utils::id_type::MerchantId,
fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError>;
}
#[async_trait::async_trait]
impl BlocklistLookupInterface for Store {
#[instrument(skip_all)]
async fn insert_blocklist_lookup_entry(
&self,
blocklist_lookup_entry: storage::BlocklistLookupNew,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
blocklist_lookup_entry
.insert(&conn)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
}
#[instrument(skip_all)]
async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
merchant_id: &common_utils::id_type::MerchantId,
fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
let conn = connection::pg_connection_read(self).await?;
storage::BlocklistLookup::find_by_merchant_id_fingerprint(&conn, merchant_id, fingerprint)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
}
#[instrument(skip_all)]
async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
merchant_id: &common_utils::id_type::MerchantId,
fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
let conn = connection::pg_connection_write(self).await?;
storage::BlocklistLookup::delete_by_merchant_id_fingerprint(&conn, merchant_id, fingerprint)
.await
.map_err(|error| report!(errors::StorageError::from(error)))
}
}
#[async_trait::async_trait]
impl BlocklistLookupInterface for MockDb {
#[instrument(skip_all)]
async fn insert_blocklist_lookup_entry(
&self,
_blocklist_lookup_entry: storage::BlocklistLookupNew,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
Err(errors::StorageError::MockDbError)?
}
async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
_merchant_id: &common_utils::id_type::MerchantId,
_fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
Err(errors::StorageError::MockDbError)?
}
async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
_merchant_id: &common_utils::id_type::MerchantId,
_fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
Err(errors::StorageError::MockDbError)?
}
}
#[async_trait::async_trait]
impl BlocklistLookupInterface for KafkaStore {
#[instrument(skip_all)]
async fn insert_blocklist_lookup_entry(
&self,
blocklist_lookup_entry: storage::BlocklistLookupNew,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
BlocklistLookupInterface::insert_blocklist_lookup_entry(
&self.diesel_store,
blocklist_lookup_entry,
)
.await
}
#[instrument(skip_all)]
async fn find_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
merchant_id: &common_utils::id_type::MerchantId,
fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
BlocklistLookupInterface::find_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self.diesel_store,
merchant_id,
fingerprint,
)
.await
}
#[instrument(skip_all)]
async fn delete_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self,
merchant_id: &common_utils::id_type::MerchantId,
fingerprint: &str,
) -> CustomResult<storage::BlocklistLookup, errors::StorageError> {
BlocklistLookupInterface::delete_blocklist_lookup_entry_by_merchant_id_fingerprint(
&self.diesel_store,
merchant_id,
fingerprint,
)
.await
}
}