mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
feat(router): add gateway_status_map interface (#2804)
This commit is contained in:
committed by
GitHub
parent
7623ea93be
commit
a429b23c7f
@ -12,6 +12,7 @@ pub mod ephemeral_key;
|
||||
pub mod events;
|
||||
pub mod file;
|
||||
pub mod fraud_check;
|
||||
pub mod gsm;
|
||||
pub mod locker_mock_up;
|
||||
pub mod mandate;
|
||||
pub mod merchant_account;
|
||||
@ -80,6 +81,7 @@ pub trait StorageInterface:
|
||||
+ business_profile::BusinessProfileInterface
|
||||
+ organization::OrganizationInterface
|
||||
+ routing_algorithm::RoutingAlgorithmInterface
|
||||
+ gsm::GsmInterface
|
||||
+ 'static
|
||||
{
|
||||
fn get_scheduler_db(&self) -> Box<dyn scheduler::SchedulerInterface>;
|
||||
|
||||
180
crates/router/src/db/gsm.rs
Normal file
180
crates/router/src/db/gsm.rs
Normal file
@ -0,0 +1,180 @@
|
||||
use diesel_models::gsm as storage;
|
||||
use error_stack::IntoReport;
|
||||
|
||||
use super::MockDb;
|
||||
use crate::{
|
||||
connection,
|
||||
core::errors::{self, CustomResult},
|
||||
services::Store,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait GsmInterface {
|
||||
async fn add_gsm_rule(
|
||||
&self,
|
||||
rule: storage::GatewayStatusMappingNew,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError>;
|
||||
async fn find_gsm_decision(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
) -> CustomResult<String, errors::StorageError>;
|
||||
async fn find_gsm_rule(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError>;
|
||||
async fn update_gsm_rule(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
data: storage::GatewayStatusMappingUpdate,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError>;
|
||||
|
||||
async fn delete_gsm_rule(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
) -> CustomResult<bool, errors::StorageError>;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl GsmInterface for Store {
|
||||
async fn add_gsm_rule(
|
||||
&self,
|
||||
rule: storage::GatewayStatusMappingNew,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError> {
|
||||
let conn = connection::pg_connection_write(self).await?;
|
||||
rule.insert(&conn).await.map_err(Into::into).into_report()
|
||||
}
|
||||
|
||||
async fn find_gsm_decision(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
) -> CustomResult<String, errors::StorageError> {
|
||||
let conn = connection::pg_connection_read(self).await?;
|
||||
storage::GatewayStatusMap::retrieve_decision(
|
||||
&conn, connector, flow, sub_flow, code, message,
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn find_gsm_rule(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError> {
|
||||
let conn = connection::pg_connection_read(self).await?;
|
||||
storage::GatewayStatusMap::find(&conn, connector, flow, sub_flow, code, message)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn update_gsm_rule(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
data: storage::GatewayStatusMappingUpdate,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError> {
|
||||
let conn = connection::pg_connection_write(self).await?;
|
||||
storage::GatewayStatusMap::update(&conn, connector, flow, sub_flow, code, message, data)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
|
||||
async fn delete_gsm_rule(
|
||||
&self,
|
||||
connector: String,
|
||||
flow: String,
|
||||
sub_flow: String,
|
||||
code: String,
|
||||
message: String,
|
||||
) -> CustomResult<bool, errors::StorageError> {
|
||||
let conn = connection::pg_connection_write(self).await?;
|
||||
storage::GatewayStatusMap::delete(&conn, connector, flow, sub_flow, code, message)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl GsmInterface for MockDb {
|
||||
async fn add_gsm_rule(
|
||||
&self,
|
||||
_rule: storage::GatewayStatusMappingNew,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError> {
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn find_gsm_decision(
|
||||
&self,
|
||||
_connector: String,
|
||||
_flow: String,
|
||||
_sub_flow: String,
|
||||
_code: String,
|
||||
_message: String,
|
||||
) -> CustomResult<String, errors::StorageError> {
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn find_gsm_rule(
|
||||
&self,
|
||||
_connector: String,
|
||||
_flow: String,
|
||||
_sub_flow: String,
|
||||
_code: String,
|
||||
_message: String,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError> {
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn update_gsm_rule(
|
||||
&self,
|
||||
_connector: String,
|
||||
_flow: String,
|
||||
_sub_flow: String,
|
||||
_code: String,
|
||||
_message: String,
|
||||
_data: storage::GatewayStatusMappingUpdate,
|
||||
) -> CustomResult<storage::GatewayStatusMap, errors::StorageError> {
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
|
||||
async fn delete_gsm_rule(
|
||||
&self,
|
||||
_connector: String,
|
||||
_flow: String,
|
||||
_sub_flow: String,
|
||||
_code: String,
|
||||
_message: String,
|
||||
) -> CustomResult<bool, errors::StorageError> {
|
||||
Err(errors::StorageError::MockDbError)?
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,7 @@ pub mod enums;
|
||||
pub mod ephemeral_key;
|
||||
pub mod events;
|
||||
pub mod file;
|
||||
pub mod gsm;
|
||||
#[cfg(feature = "kv_store")]
|
||||
pub mod kv;
|
||||
pub mod locker_mock_up;
|
||||
@ -41,10 +42,10 @@ pub use data_models::payments::{
|
||||
|
||||
pub use self::{
|
||||
address::*, api_keys::*, capture::*, cards_info::*, configs::*, connector_response::*,
|
||||
customers::*, dispute::*, ephemeral_key::*, events::*, file::*, locker_mock_up::*, mandate::*,
|
||||
merchant_account::*, merchant_connector_account::*, merchant_key_store::*, payment_link::*,
|
||||
payment_method::*, payout_attempt::*, payouts::*, process_tracker::*, refund::*,
|
||||
reverse_lookup::*, routing_algorithm::*,
|
||||
customers::*, dispute::*, ephemeral_key::*, events::*, file::*, gsm::*, locker_mock_up::*,
|
||||
mandate::*, merchant_account::*, merchant_connector_account::*, merchant_key_store::*,
|
||||
payment_link::*, payment_method::*, payout_attempt::*, payouts::*, process_tracker::*,
|
||||
refund::*, reverse_lookup::*, routing_algorithm::*,
|
||||
};
|
||||
use crate::types::api::routing;
|
||||
|
||||
|
||||
4
crates/router/src/types/storage/gsm.rs
Normal file
4
crates/router/src/types/storage/gsm.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub use diesel_models::gsm::{
|
||||
GatewayStatusMap, GatewayStatusMapperUpdateInternal, GatewayStatusMappingNew,
|
||||
GatewayStatusMappingUpdate,
|
||||
};
|
||||
Reference in New Issue
Block a user