diff --git a/crates/api_models/src/refunds.rs b/crates/api_models/src/refunds.rs index b78d1521f8..ffa1c781a8 100644 --- a/crates/api_models/src/refunds.rs +++ b/crates/api_models/src/refunds.rs @@ -76,6 +76,7 @@ pub struct RefundResponse { #[schema(value_type = Option)] pub metadata: Option, pub error_message: Option, + pub error_code: Option, #[serde(with = "common_utils::custom_serde::iso8601::option")] pub created_at: Option, #[serde(with = "common_utils::custom_serde::iso8601::option")] diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 536c51cb3f..b1face64dd 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -145,6 +145,7 @@ pub async fn trigger_refund_to_gateway( Err(err) => storage::RefundUpdate::ErrorUpdate { refund_status: Some(enums::RefundStatus::Failure), refund_error_message: Some(err.message), + refund_error_code: Some(err.code), }, Ok(response) => storage::RefundUpdate::Update { connector_refund_id: response.connector_refund_id, @@ -292,6 +293,7 @@ pub async fn sync_refund_with_gateway( Err(error_message) => storage::RefundUpdate::ErrorUpdate { refund_status: None, refund_error_message: Some(error_message.message), + refund_error_code: Some(error_message.code), }, Ok(response) => storage::RefundUpdate::Update { connector_refund_id: response.connector_refund_id, @@ -538,6 +540,7 @@ impl From> for Foreign { status: refund.refund_status.foreign_into(), metadata: refund.metadata, error_message: refund.refund_error_message, + error_code: refund.refund_error_code, created_at: Some(refund.created_at), updated_at: Some(refund.updated_at), } diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs index 4615f60137..958adf728b 100644 --- a/crates/router/src/db/refund.rs +++ b/crates/router/src/db/refund.rs @@ -286,7 +286,8 @@ mod storage { refund_amount: new.refund_amount, refund_status: new.refund_status, sent_to_gateway: new.sent_to_gateway, - refund_error_message: new.refund_error_message.clone(), + refund_error_message: None, + refund_error_code: None, metadata: new.metadata.clone(), refund_arn: new.refund_arn.clone(), created_at: new.created_at.unwrap_or_else(date_time::now), @@ -637,7 +638,8 @@ impl RefundInterface for MockDb { refund_amount: new.refund_amount, refund_status: new.refund_status, sent_to_gateway: new.sent_to_gateway, - refund_error_message: new.refund_error_message, + refund_error_message: None, + refund_error_code: None, metadata: new.metadata, refund_arn: new.refund_arn.clone(), created_at: new.created_at.unwrap_or(current_time), diff --git a/crates/storage_models/src/refund.rs b/crates/storage_models/src/refund.rs index dc2636bc4b..e451acd131 100644 --- a/crates/storage_models/src/refund.rs +++ b/crates/storage_models/src/refund.rs @@ -25,6 +25,7 @@ pub struct Refund { pub refund_status: storage_enums::RefundStatus, pub sent_to_gateway: bool, pub refund_error_message: Option, + pub refund_error_code: Option, pub metadata: Option, pub refund_arn: Option, pub created_at: PrimitiveDateTime, @@ -62,7 +63,6 @@ pub struct RefundNew { pub refund_amount: i64, pub refund_status: storage_enums::RefundStatus, pub sent_to_gateway: bool, - pub refund_error_message: Option, pub metadata: Option, pub refund_arn: Option, pub created_at: Option, @@ -93,6 +93,7 @@ pub enum RefundUpdate { ErrorUpdate { refund_status: Option, refund_error_message: Option, + refund_error_code: Option, }, } @@ -103,6 +104,7 @@ pub struct RefundUpdateInternal { refund_status: Option, sent_to_gateway: Option, refund_error_message: Option, + refund_error_code: Option, refund_arn: Option, metadata: Option, refund_reason: Option, @@ -143,9 +145,11 @@ impl From for RefundUpdateInternal { RefundUpdate::ErrorUpdate { refund_status, refund_error_message, + refund_error_code, } => Self { refund_status, refund_error_message, + refund_error_code, ..Default::default() }, } @@ -160,6 +164,7 @@ impl RefundUpdate { refund_status: pa_update.refund_status.unwrap_or(source.refund_status), sent_to_gateway: pa_update.sent_to_gateway.unwrap_or(source.sent_to_gateway), refund_error_message: pa_update.refund_error_message, + refund_error_code: pa_update.refund_error_code, refund_arn: pa_update.refund_arn, metadata: pa_update.metadata, ..source diff --git a/crates/storage_models/src/schema.rs b/crates/storage_models/src/schema.rs index c4d6a143eb..7e0929cb51 100644 --- a/crates/storage_models/src/schema.rs +++ b/crates/storage_models/src/schema.rs @@ -322,6 +322,7 @@ diesel::table! { refund_status -> RefundStatus, sent_to_gateway -> Bool, refund_error_message -> Nullable, + refund_error_code -> Nullable, metadata -> Nullable, refund_arn -> Nullable, created_at -> Timestamp, diff --git a/migrations/2023-01-19-122511_add_refund_error_code/down.sql b/migrations/2023-01-19-122511_add_refund_error_code/down.sql new file mode 100644 index 0000000000..0c314ba081 --- /dev/null +++ b/migrations/2023-01-19-122511_add_refund_error_code/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE refund +DROP COLUMN IF EXISTS refund_error_code; diff --git a/migrations/2023-01-19-122511_add_refund_error_code/up.sql b/migrations/2023-01-19-122511_add_refund_error_code/up.sql new file mode 100644 index 0000000000..1f3c792947 --- /dev/null +++ b/migrations/2023-01-19-122511_add_refund_error_code/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE refund +ADD IF NOT EXISTS refund_error_code TEXT DEFAULT NULL;