From fd82cf610a15143559f8db1038c8c65ede6e7b7c Mon Sep 17 00:00:00 2001 From: Chethan Rao <70657455+Chethan-rao@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:03:27 +0530 Subject: [PATCH] refactor(gsm): add `error_category` column to gsm table (#6648) Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> --- api-reference-v2/openapi_spec.json | 34 +++++++++++++++++++ api-reference/openapi_spec.json | 34 +++++++++++++++++++ crates/api_models/src/gsm.rs | 7 ++++ crates/common_enums/src/enums.rs | 25 ++++++++++++++ crates/diesel_models/src/gsm.rs | 24 ++++++++----- crates/diesel_models/src/schema.rs | 2 ++ crates/diesel_models/src/schema_v2.rs | 2 ++ crates/openapi/src/openapi.rs | 1 + crates/openapi/src/openapi_v2.rs | 1 + crates/router/src/core/gsm.rs | 2 ++ crates/router/src/types/transformers.rs | 2 ++ .../down.sql | 2 ++ .../up.sql | 2 ++ 13 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 migrations/2024-11-24-104438_add_error_category_col_to_gsm/down.sql create mode 100644 migrations/2024-11-24-104438_add_error_category_col_to_gsm/up.sql diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index d9c27a2f0187..1af9284596d9 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -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", @@ -9162,6 +9172,14 @@ "type": "string", "description": "error message unified across the connectors", "nullable": true + }, + "error_category": { + "allOf": [ + { + "$ref": "#/components/schemas/ErrorCategory" + } + ], + "nullable": true } } }, @@ -9295,6 +9313,14 @@ "type": "string", "description": "error message unified across the connectors", "nullable": true + }, + "error_category": { + "allOf": [ + { + "$ref": "#/components/schemas/ErrorCategory" + } + ], + "nullable": true } } }, @@ -9391,6 +9417,14 @@ "type": "string", "description": "error message unified across the connectors", "nullable": true + }, + "error_category": { + "allOf": [ + { + "$ref": "#/components/schemas/ErrorCategory" + } + ], + "nullable": true } } }, diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json index 56b77bff1aa9..f2904dd4783c 100644 --- a/api-reference/openapi_spec.json +++ b/api-reference/openapi_spec.json @@ -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": [ @@ -11639,6 +11649,14 @@ "type": "string", "description": "error message unified across the connectors", "nullable": true + }, + "error_category": { + "allOf": [ + { + "$ref": "#/components/schemas/ErrorCategory" + } + ], + "nullable": true } } }, @@ -11772,6 +11790,14 @@ "type": "string", "description": "error message unified across the connectors", "nullable": true + }, + "error_category": { + "allOf": [ + { + "$ref": "#/components/schemas/ErrorCategory" + } + ], + "nullable": true } } }, @@ -11868,6 +11894,14 @@ "type": "string", "description": "error message unified across the connectors", "nullable": true + }, + "error_category": { + "allOf": [ + { + "$ref": "#/components/schemas/ErrorCategory" + } + ], + "nullable": true } } }, diff --git a/crates/api_models/src/gsm.rs b/crates/api_models/src/gsm.rs index 30e49062439f..b95794ef707b 100644 --- a/crates/api_models/src/gsm.rs +++ b/crates/api_models/src/gsm.rs @@ -1,3 +1,4 @@ +use common_enums::ErrorCategory; use utoipa::ToSchema; use crate::enums::Connector; @@ -26,6 +27,8 @@ pub struct GsmCreateRequest { pub unified_code: Option, /// error message unified across the connectors pub unified_message: Option, + /// category in which error belongs to + pub error_category: Option, } #[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)] @@ -88,6 +91,8 @@ pub struct GsmUpdateRequest { pub unified_code: Option, /// error message unified across the connectors pub unified_message: Option, + /// category in which error belongs to + pub error_category: Option, } #[derive(Debug, serde::Deserialize, serde::Serialize, ToSchema)] @@ -141,4 +146,6 @@ pub struct GsmResponse { pub unified_code: Option, /// error message unified across the connectors pub unified_message: Option, + /// category in which error belongs to + pub error_category: Option, } diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 844e9d019480..d966902af89b 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -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, +} diff --git a/crates/diesel_models/src/gsm.rs b/crates/diesel_models/src/gsm.rs index 6a444410fa8f..aba8d75a6ebb 100644 --- a/crates/diesel_models/src/gsm.rs +++ b/crates/diesel_models/src/gsm.rs @@ -1,5 +1,6 @@ //! Gateway status mapping +use common_enums::ErrorCategory; use common_utils::{ custom_serde, events::{ApiEventMetric, ApiEventsType}, @@ -39,6 +40,7 @@ pub struct GatewayStatusMap { pub step_up_possible: bool, pub unified_code: Option, pub unified_message: Option, + pub error_category: Option, } #[derive(Clone, Debug, Eq, PartialEq, Insertable)] @@ -55,17 +57,11 @@ pub struct GatewayStatusMappingNew { pub step_up_possible: bool, pub unified_code: Option, pub unified_message: Option, + pub error_category: Option, } #[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 { @@ -80,6 +76,8 @@ pub struct GatewayStatusMapperUpdateInternal { pub step_up_possible: Option, pub unified_code: Option, pub unified_message: Option, + pub error_category: Option, + pub last_modified: PrimitiveDateTime, } #[derive(Debug)] @@ -90,6 +88,7 @@ pub struct GatewayStatusMappingUpdate { pub step_up_possible: Option, pub unified_code: Option, pub unified_message: Option, + pub error_category: Option, } impl From for GatewayStatusMapperUpdateInternal { @@ -101,6 +100,7 @@ impl From for GatewayStatusMapperUpdateInternal { step_up_possible, unified_code, unified_message, + error_category, } = value; Self { status, @@ -109,7 +109,13 @@ impl From 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, } } } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index d3e560fc048c..b6f1a4f8d05e 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -508,6 +508,8 @@ diesel::table! { unified_code -> Nullable, #[max_length = 1024] unified_message -> Nullable, + #[max_length = 64] + error_category -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index f6bab9071cd0..470868ed82d4 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -520,6 +520,8 @@ diesel::table! { unified_code -> Nullable, #[max_length = 1024] unified_message -> Nullable, + #[max_length = 64] + error_category -> Nullable, } } diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs index 4ec1bb22b4b8..c7fa29a1b20e 100644 --- a/crates/openapi/src/openapi.rs +++ b/crates/openapi/src/openapi.rs @@ -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, diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs index a756d9fb1b10..2221055be5ab 100644 --- a/crates/openapi/src/openapi_v2.rs +++ b/crates/openapi/src/openapi_v2.rs @@ -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, diff --git a/crates/router/src/core/gsm.rs b/crates/router/src/core/gsm.rs index 4a678a5c4089..c7daee111a9a 100644 --- a/crates/router/src/core/gsm.rs +++ b/crates/router/src/core/gsm.rs @@ -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, @@ -82,6 +83,7 @@ pub async fn update_gsm_rule( step_up_possible, unified_code, unified_message, + error_category, }, ) .await diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index c16ead40d1f1..55a523b528eb 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -1690,6 +1690,7 @@ impl ForeignFrom 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, } } } @@ -1708,6 +1709,7 @@ impl ForeignFrom 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, } } } diff --git a/migrations/2024-11-24-104438_add_error_category_col_to_gsm/down.sql b/migrations/2024-11-24-104438_add_error_category_col_to_gsm/down.sql new file mode 100644 index 000000000000..609afbdfd753 --- /dev/null +++ b/migrations/2024-11-24-104438_add_error_category_col_to_gsm/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE gateway_status_map DROP COLUMN error_category; diff --git a/migrations/2024-11-24-104438_add_error_category_col_to_gsm/up.sql b/migrations/2024-11-24-104438_add_error_category_col_to_gsm/up.sql new file mode 100644 index 000000000000..298f6d263aa2 --- /dev/null +++ b/migrations/2024-11-24-104438_add_error_category_col_to_gsm/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE gateway_status_map ADD COLUMN error_category VARCHAR(64);