fix(refund): add error code in refund table (#427)

This commit is contained in:
Kartikeya Hegde
2023-01-20 13:44:08 +05:30
committed by GitHub
parent cf88718e69
commit dcfa7b0846
7 changed files with 19 additions and 3 deletions

View File

@ -76,6 +76,7 @@ pub struct RefundResponse {
#[schema(value_type = Option<Object>)]
pub metadata: Option<serde_json::Value>,
pub error_message: Option<String>,
pub error_code: Option<String>,
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub created_at: Option<PrimitiveDateTime>,
#[serde(with = "common_utils::custom_serde::iso8601::option")]

View File

@ -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<Foreign<storage::Refund>> for Foreign<api::RefundResponse> {
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),
}

View File

@ -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),

View File

@ -25,6 +25,7 @@ pub struct Refund {
pub refund_status: storage_enums::RefundStatus,
pub sent_to_gateway: bool,
pub refund_error_message: Option<String>,
pub refund_error_code: Option<String>,
pub metadata: Option<serde_json::Value>,
pub refund_arn: Option<String>,
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<String>,
pub metadata: Option<serde_json::Value>,
pub refund_arn: Option<String>,
pub created_at: Option<PrimitiveDateTime>,
@ -93,6 +93,7 @@ pub enum RefundUpdate {
ErrorUpdate {
refund_status: Option<storage_enums::RefundStatus>,
refund_error_message: Option<String>,
refund_error_code: Option<String>,
},
}
@ -103,6 +104,7 @@ pub struct RefundUpdateInternal {
refund_status: Option<storage_enums::RefundStatus>,
sent_to_gateway: Option<bool>,
refund_error_message: Option<String>,
refund_error_code: Option<String>,
refund_arn: Option<String>,
metadata: Option<serde_json::Value>,
refund_reason: Option<String>,
@ -143,9 +145,11 @@ impl From<RefundUpdate> 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

View File

@ -322,6 +322,7 @@ diesel::table! {
refund_status -> RefundStatus,
sent_to_gateway -> Bool,
refund_error_message -> Nullable<Text>,
refund_error_code -> Nullable<Varchar>,
metadata -> Nullable<Json>,
refund_arn -> Nullable<Varchar>,
created_at -> Timestamp,

View File

@ -0,0 +1,2 @@
ALTER TABLE refund
DROP COLUMN IF EXISTS refund_error_code;

View File

@ -0,0 +1,2 @@
ALTER TABLE refund
ADD IF NOT EXISTS refund_error_code TEXT DEFAULT NULL;