-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router): add
gateway_status_map
CRUD APIs (#2809)
- Loading branch information
1 parent
8b15189
commit 5c9e235
Showing
16 changed files
with
402 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod customer; | ||
pub mod gsm; | ||
pub mod payment; | ||
#[cfg(feature = "payouts")] | ||
pub mod payouts; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||
|
||
use crate::gsm; | ||
|
||
impl ApiEventMetric for gsm::GsmCreateRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmUpdateRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmRetrieveRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmDeleteRequest { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} | ||
|
||
impl ApiEventMetric for gsm::GsmDeleteResponse { | ||
fn get_api_event_type(&self) -> Option<ApiEventsType> { | ||
Some(ApiEventsType::Gsm) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use crate::enums; | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmCreateRequest { | ||
pub connector: enums::Connector, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
pub status: String, | ||
pub router_error: Option<String>, | ||
pub decision: GsmDecision, | ||
pub step_up_possible: bool, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmRetrieveRequest { | ||
pub connector: enums::Connector, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
} | ||
|
||
#[derive( | ||
Default, | ||
Clone, | ||
Copy, | ||
Debug, | ||
strum::Display, | ||
PartialEq, | ||
Eq, | ||
serde::Serialize, | ||
serde::Deserialize, | ||
strum::EnumString, | ||
)] | ||
#[serde(rename_all = "snake_case")] | ||
#[strum(serialize_all = "snake_case")] | ||
pub enum GsmDecision { | ||
Retry, | ||
Requeue, | ||
#[default] | ||
DoDefault, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmUpdateRequest { | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
pub status: Option<String>, | ||
pub router_error: Option<String>, | ||
pub decision: Option<GsmDecision>, | ||
pub step_up_possible: Option<bool>, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct GsmDeleteRequest { | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
pub message: String, | ||
} | ||
|
||
#[derive(Debug, serde::Serialize)] | ||
pub struct GsmDeleteResponse { | ||
pub gsm_rule_delete: bool, | ||
pub connector: String, | ||
pub flow: String, | ||
pub sub_flow: String, | ||
pub code: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
use api_models::gsm as gsm_api_types; | ||
use diesel_models::gsm as storage; | ||
use error_stack::{IntoReport, ResultExt}; | ||
use router_env::{instrument, tracing}; | ||
|
||
use crate::{ | ||
core::{ | ||
errors, | ||
errors::{RouterResponse, StorageErrorExt}, | ||
}, | ||
db::gsm::GsmInterface, | ||
services, | ||
types::{self, transformers::ForeignInto}, | ||
AppState, | ||
}; | ||
|
||
#[instrument(skip_all)] | ||
pub async fn create_gsm_rule( | ||
state: AppState, | ||
gsm_rule: gsm_api_types::GsmCreateRequest, | ||
) -> RouterResponse<types::GsmResponse> { | ||
let db = state.store.as_ref(); | ||
GsmInterface::add_gsm_rule(db, gsm_rule.foreign_into()) | ||
.await | ||
.to_duplicate_response(errors::ApiErrorResponse::GenericDuplicateError { | ||
message: "GSM with given key already exists in our records".to_string(), | ||
}) | ||
.map(services::ApplicationResponse::Json) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub async fn retrieve_gsm_rule( | ||
state: AppState, | ||
gsm_request: gsm_api_types::GsmRetrieveRequest, | ||
) -> RouterResponse<types::GsmResponse> { | ||
let db = state.store.as_ref(); | ||
let gsm_api_types::GsmRetrieveRequest { | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
} = gsm_request; | ||
GsmInterface::find_gsm_rule(db, connector.to_string(), flow, sub_flow, code, message) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { | ||
message: "GSM with given key does not exist in our records".to_string(), | ||
}) | ||
.map(services::ApplicationResponse::Json) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub async fn update_gsm_rule( | ||
state: AppState, | ||
gsm_request: gsm_api_types::GsmUpdateRequest, | ||
) -> RouterResponse<types::GsmResponse> { | ||
let db = state.store.as_ref(); | ||
let gsm_api_types::GsmUpdateRequest { | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
decision, | ||
status, | ||
router_error, | ||
step_up_possible, | ||
} = gsm_request; | ||
GsmInterface::update_gsm_rule( | ||
db, | ||
connector.to_string(), | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
storage::GatewayStatusMappingUpdate { | ||
decision: decision.map(|d| d.to_string()), | ||
status, | ||
router_error: Some(router_error), | ||
step_up_possible, | ||
}, | ||
) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { | ||
message: "GSM with given key does not exist in our records".to_string(), | ||
}) | ||
.attach_printable("Failed while updating Gsm rule") | ||
.map(services::ApplicationResponse::Json) | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub async fn delete_gsm_rule( | ||
state: AppState, | ||
gsm_request: gsm_api_types::GsmDeleteRequest, | ||
) -> RouterResponse<gsm_api_types::GsmDeleteResponse> { | ||
let db = state.store.as_ref(); | ||
let gsm_api_types::GsmDeleteRequest { | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
message, | ||
} = gsm_request; | ||
match GsmInterface::delete_gsm_rule( | ||
db, | ||
connector.to_string(), | ||
flow.to_owned(), | ||
sub_flow.to_owned(), | ||
code.to_owned(), | ||
message.to_owned(), | ||
) | ||
.await | ||
.to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { | ||
message: "GSM with given key does not exist in our records".to_string(), | ||
}) | ||
.attach_printable("Failed while Deleting Gsm rule") | ||
{ | ||
Ok(is_deleted) => { | ||
if is_deleted { | ||
Ok(services::ApplicationResponse::Json( | ||
gsm_api_types::GsmDeleteResponse { | ||
gsm_rule_delete: true, | ||
connector, | ||
flow, | ||
sub_flow, | ||
code, | ||
}, | ||
)) | ||
} else { | ||
Err(errors::ApiErrorResponse::InternalServerError) | ||
.into_report() | ||
.attach_printable("Failed while Deleting Gsm rule, got response as false") | ||
} | ||
} | ||
Err(err) => Err(err), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.