Skip to content

Commit

Permalink
refactor(gsm): add error_category column to gsm table (#6648)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
Chethan-rao and hyperswitch-bot[bot] authored Dec 4, 2024
1 parent 938b2a8 commit fd82cf6
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 9 deletions.
34 changes: 34 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -7776,6 +7776,16 @@
}
}
},
"ErrorCategory": {
"type": "string",
"enum": [
"frm_decline",
"processor_downtime",
"processor_decline_unauthorized",
"issue_with_payment_method",
"processor_decline_incorrect_data"
]
},
"ErrorDetails": {
"type": "object",
"description": "Error details for the payment",
Expand Down Expand Up @@ -9162,6 +9172,14 @@
"type": "string",
"description": "error message unified across the connectors",
"nullable": true
},
"error_category": {
"allOf": [
{
"$ref": "#/components/schemas/ErrorCategory"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -9295,6 +9313,14 @@
"type": "string",
"description": "error message unified across the connectors",
"nullable": true
},
"error_category": {
"allOf": [
{
"$ref": "#/components/schemas/ErrorCategory"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -9391,6 +9417,14 @@
"type": "string",
"description": "error message unified across the connectors",
"nullable": true
},
"error_category": {
"allOf": [
{
"$ref": "#/components/schemas/ErrorCategory"
}
],
"nullable": true
}
}
},
Expand Down
34 changes: 34 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -10296,6 +10296,16 @@
}
}
},
"ErrorCategory": {
"type": "string",
"enum": [
"frm_decline",
"processor_downtime",
"processor_decline_unauthorized",
"issue_with_payment_method",
"processor_decline_incorrect_data"
]
},
"EventClass": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -11639,6 +11649,14 @@
"type": "string",
"description": "error message unified across the connectors",
"nullable": true
},
"error_category": {
"allOf": [
{
"$ref": "#/components/schemas/ErrorCategory"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -11772,6 +11790,14 @@
"type": "string",
"description": "error message unified across the connectors",
"nullable": true
},
"error_category": {
"allOf": [
{
"$ref": "#/components/schemas/ErrorCategory"
}
],
"nullable": true
}
}
},
Expand Down Expand Up @@ -11868,6 +11894,14 @@
"type": "string",
"description": "error message unified across the connectors",
"nullable": true
},
"error_category": {
"allOf": [
{
"$ref": "#/components/schemas/ErrorCategory"
}
],
"nullable": true
}
}
},
Expand Down
7 changes: 7 additions & 0 deletions crates/api_models/src/gsm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use common_enums::ErrorCategory;
use utoipa::ToSchema;

use crate::enums::Connector;
Expand Down Expand Up @@ -26,6 +27,8 @@ pub struct GsmCreateRequest {
pub unified_code: Option<String>,
/// error message unified across the connectors
pub unified_message: Option<String>,
/// category in which error belongs to
pub error_category: Option<ErrorCategory>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -88,6 +91,8 @@ pub struct GsmUpdateRequest {
pub unified_code: Option<String>,
/// error message unified across the connectors
pub unified_message: Option<String>,
/// category in which error belongs to
pub error_category: Option<ErrorCategory>,
}

#[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -141,4 +146,6 @@ pub struct GsmResponse {
pub unified_code: Option<String>,
/// error message unified across the connectors
pub unified_message: Option<String>,
/// category in which error belongs to
pub error_category: Option<ErrorCategory>,
}
25 changes: 25 additions & 0 deletions crates/common_enums/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3372,3 +3372,28 @@ pub enum ConnectorMandateStatus {
/// Indicates that the connector mandate is not active and hence cannot be used for payments.
Inactive,
}

#[derive(
Clone,
Copy,
Debug,
strum::Display,
PartialEq,
Eq,
serde::Serialize,
serde::Deserialize,
strum::EnumString,
ToSchema,
PartialOrd,
Ord,
)]
#[router_derive::diesel_enum(storage_type = "text")]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum ErrorCategory {
FrmDecline,
ProcessorDowntime,
ProcessorDeclineUnauthorized,
IssueWithPaymentMethod,
ProcessorDeclineIncorrectData,
}
24 changes: 15 additions & 9 deletions crates/diesel_models/src/gsm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Gateway status mapping
use common_enums::ErrorCategory;
use common_utils::{
custom_serde,
events::{ApiEventMetric, ApiEventsType},
Expand Down Expand Up @@ -39,6 +40,7 @@ pub struct GatewayStatusMap {
pub step_up_possible: bool,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
pub error_category: Option<ErrorCategory>,
}

#[derive(Clone, Debug, Eq, PartialEq, Insertable)]
Expand All @@ -55,17 +57,11 @@ pub struct GatewayStatusMappingNew {
pub step_up_possible: bool,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
pub error_category: Option<ErrorCategory>,
}

#[derive(
Clone,
Debug,
PartialEq,
Eq,
AsChangeset,
router_derive::DebugAsDisplay,
Default,
serde::Deserialize,
Clone, Debug, PartialEq, Eq, AsChangeset, router_derive::DebugAsDisplay, serde::Deserialize,
)]
#[diesel(table_name = gateway_status_map)]
pub struct GatewayStatusMapperUpdateInternal {
Expand All @@ -80,6 +76,8 @@ pub struct GatewayStatusMapperUpdateInternal {
pub step_up_possible: Option<bool>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
pub error_category: Option<ErrorCategory>,
pub last_modified: PrimitiveDateTime,
}

#[derive(Debug)]
Expand All @@ -90,6 +88,7 @@ pub struct GatewayStatusMappingUpdate {
pub step_up_possible: Option<bool>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
pub error_category: Option<ErrorCategory>,
}

impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal {
Expand All @@ -101,6 +100,7 @@ impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal {
step_up_possible,
unified_code,
unified_message,
error_category,
} = value;
Self {
status,
Expand All @@ -109,7 +109,13 @@ impl From<GatewayStatusMappingUpdate> for GatewayStatusMapperUpdateInternal {
step_up_possible,
unified_code,
unified_message,
..Default::default()
error_category,
last_modified: common_utils::date_time::now(),
connector: None,
flow: None,
sub_flow: None,
code: None,
message: None,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ diesel::table! {
unified_code -> Nullable<Varchar>,
#[max_length = 1024]
unified_message -> Nullable<Varchar>,
#[max_length = 64]
error_category -> Nullable<Varchar>,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ diesel::table! {
unified_code -> Nullable<Varchar>,
#[max_length = 1024]
unified_message -> Nullable<Varchar>,
#[max_length = 64]
error_category -> Nullable<Varchar>,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::blocklist::ToggleBlocklistResponse,
api_models::blocklist::ListBlocklistQuery,
api_models::enums::BlocklistDataKind,
api_models::enums::ErrorCategory,
api_models::webhook_events::EventListItemResponse,
api_models::webhook_events::EventRetrieveResponse,
api_models::webhook_events::OutgoingWebhookRequestContent,
Expand Down
1 change: 1 addition & 0 deletions crates/openapi/src/openapi_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::blocklist::ToggleBlocklistResponse,
api_models::blocklist::ListBlocklistQuery,
api_models::enums::BlocklistDataKind,
api_models::enums::ErrorCategory,
api_models::webhook_events::EventListItemResponse,
api_models::webhook_events::EventRetrieveResponse,
api_models::webhook_events::OutgoingWebhookRequestContent,
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/gsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub async fn update_gsm_rule(
step_up_possible,
unified_code,
unified_message,
error_category,
} = gsm_request;
GsmInterface::update_gsm_rule(
db,
Expand All @@ -82,6 +83,7 @@ pub async fn update_gsm_rule(
step_up_possible,
unified_code,
unified_message,
error_category,
},
)
.await
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ impl ForeignFrom<gsm_api_types::GsmCreateRequest> for storage::GatewayStatusMapp
step_up_possible: value.step_up_possible,
unified_code: value.unified_code,
unified_message: value.unified_message,
error_category: value.error_category,
}
}
}
Expand All @@ -1708,6 +1709,7 @@ impl ForeignFrom<storage::GatewayStatusMap> for gsm_api_types::GsmResponse {
step_up_possible: value.step_up_possible,
unified_code: value.unified_code,
unified_message: value.unified_message,
error_category: value.error_category,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE gateway_status_map DROP COLUMN error_category;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE gateway_status_map ADD COLUMN error_category VARCHAR(64);

0 comments on commit fd82cf6

Please sign in to comment.