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
pub use diesel_models::{CardInfo, UpdateCardInfo};
use error_stack::report;
use hyperswitch_domain_models::cards_info::CardsInfoInterface;
use router_env::instrument;
use crate::{
errors::StorageError,
kv_router_store::KVRouterStore,
redis::kv_store::KvStorePartition,
utils::{pg_connection_read, pg_connection_write},
CustomResult, DatabaseStore, MockDb, RouterStore,
};
impl KvStorePartition for CardInfo {}
#[async_trait::async_trait]
impl<T: DatabaseStore> CardsInfoInterface for RouterStore<T> {
type Error = StorageError;
#[instrument(skip_all)]
async fn get_card_info(&self, card_iin: &str) -> CustomResult<Option<CardInfo>, StorageError> {
let conn = pg_connection_read(self).await?;
CardInfo::find_by_iin(&conn, card_iin)
.await
.map_err(|error| report!(StorageError::from(error)))
}
#[instrument(skip_all)]
async fn add_card_info(&self, data: CardInfo) -> CustomResult<CardInfo, StorageError> {
let conn = pg_connection_write(self).await?;
data.insert(&conn)
.await
.map_err(|error| report!(StorageError::from(error)))
}
#[instrument(skip_all)]
async fn update_card_info(
&self,
card_iin: String,
data: UpdateCardInfo,
) -> CustomResult<CardInfo, StorageError> {
let conn = pg_connection_write(self).await?;
CardInfo::update(&conn, card_iin, data)
.await
.map_err(|error| report!(StorageError::from(error)))
}
}
#[async_trait::async_trait]
impl<T: DatabaseStore> CardsInfoInterface for KVRouterStore<T> {
type Error = StorageError;
#[instrument(skip_all)]
async fn get_card_info(&self, card_iin: &str) -> CustomResult<Option<CardInfo>, StorageError> {
let conn = pg_connection_read(self).await?;
CardInfo::find_by_iin(&conn, card_iin)
.await
.map_err(|error| report!(StorageError::from(error)))
}
#[instrument(skip_all)]
async fn add_card_info(&self, data: CardInfo) -> CustomResult<CardInfo, StorageError> {
let conn = pg_connection_write(self).await?;
data.insert(&conn)
.await
.map_err(|error| report!(StorageError::from(error)))
}
#[instrument(skip_all)]
async fn update_card_info(
&self,
card_iin: String,
data: UpdateCardInfo,
) -> CustomResult<CardInfo, StorageError> {
let conn = pg_connection_write(self).await?;
CardInfo::update(&conn, card_iin, data)
.await
.map_err(|error| report!(StorageError::from(error)))
}
}
#[async_trait::async_trait]
impl CardsInfoInterface for MockDb {
type Error = StorageError;
#[instrument(skip_all)]
async fn get_card_info(&self, card_iin: &str) -> CustomResult<Option<CardInfo>, StorageError> {
let cards_info = self.cards_info.lock().await;
Ok(cards_info
.iter()
.find(|ci| ci.card_iin == card_iin)
.or_else(|| {
card_iin
.get(..6)
.filter(|_| card_iin.len() == 8)
.and_then(|card_iin| cards_info.iter().find(|ci| ci.card_iin == card_iin))
})
.cloned())
}
async fn add_card_info(&self, _data: CardInfo) -> CustomResult<CardInfo, StorageError> {
Err(StorageError::MockDbError)?
}
async fn update_card_info(
&self,
_card_iin: String,
_data: UpdateCardInfo,
) -> CustomResult<CardInfo, StorageError> {
Err(StorageError::MockDbError)?
}
}