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

feat(router): implement `CardsInfoInterface` for `MockDB` (#1262)

Derek Leverenzcbff605f2af2
diff --git a/crates/router/src/db.rs b/crates/router/src/db.rs
index 6863ddf1eb..ee9cd03e69 100644
--- a/crates/router/src/db.rs
+++ b/crates/router/src/db.rs
@@ -84,6 +84,7 @@ pub struct MockDb {
connector_response: Arc<Mutex<Vec<storage::ConnectorResponse>>>,
redis: Arc<redis_interface::RedisConnectionPool>,
api_keys: Arc<Mutex<Vec<storage::ApiKey>>>,
+ cards_info: Arc<Mutex<Vec<storage::CardInfo>>>,
}
impl MockDb {
@@ -100,6 +101,7 @@ impl MockDb {
connector_response: Default::default(),
redis: Arc::new(crate::connection::redis_connection(redis).await),
api_keys: Default::default(),
+ cards_info: Default::default(),
}
}
}
diff --git a/crates/router/src/db/cards_info.rs b/crates/router/src/db/cards_info.rs
index d088bd415d..029c3b7bab 100644
--- a/crates/router/src/db/cards_info.rs
+++ b/crates/router/src/db/cards_info.rs
@@ -34,8 +34,14 @@ impl CardsInfoInterface for Store {
impl CardsInfoInterface for MockDb {
async fn get_card_info(
&self,
- _card_iin: &str,
+ card_iin: &str,
) -> CustomResult<Option<CardInfo>, errors::StorageError> {
- Err(errors::StorageError::MockDbError)?
+ Ok(self
+ .cards_info
+ .lock()
+ .await
+ .iter()
+ .find(|ci| ci.card_iin == card_iin)
+ .cloned())
}
}