mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	fix(refund): add error code in refund table (#427)
This commit is contained in:
		| @ -76,6 +76,7 @@ pub struct RefundResponse { | |||||||
|     #[schema(value_type = Option<Object>)] |     #[schema(value_type = Option<Object>)] | ||||||
|     pub metadata: Option<serde_json::Value>, |     pub metadata: Option<serde_json::Value>, | ||||||
|     pub error_message: Option<String>, |     pub error_message: Option<String>, | ||||||
|  |     pub error_code: Option<String>, | ||||||
|     #[serde(with = "common_utils::custom_serde::iso8601::option")] |     #[serde(with = "common_utils::custom_serde::iso8601::option")] | ||||||
|     pub created_at: Option<PrimitiveDateTime>, |     pub created_at: Option<PrimitiveDateTime>, | ||||||
|     #[serde(with = "common_utils::custom_serde::iso8601::option")] |     #[serde(with = "common_utils::custom_serde::iso8601::option")] | ||||||
|  | |||||||
| @ -145,6 +145,7 @@ pub async fn trigger_refund_to_gateway( | |||||||
|         Err(err) => storage::RefundUpdate::ErrorUpdate { |         Err(err) => storage::RefundUpdate::ErrorUpdate { | ||||||
|             refund_status: Some(enums::RefundStatus::Failure), |             refund_status: Some(enums::RefundStatus::Failure), | ||||||
|             refund_error_message: Some(err.message), |             refund_error_message: Some(err.message), | ||||||
|  |             refund_error_code: Some(err.code), | ||||||
|         }, |         }, | ||||||
|         Ok(response) => storage::RefundUpdate::Update { |         Ok(response) => storage::RefundUpdate::Update { | ||||||
|             connector_refund_id: response.connector_refund_id, |             connector_refund_id: response.connector_refund_id, | ||||||
| @ -292,6 +293,7 @@ pub async fn sync_refund_with_gateway( | |||||||
|         Err(error_message) => storage::RefundUpdate::ErrorUpdate { |         Err(error_message) => storage::RefundUpdate::ErrorUpdate { | ||||||
|             refund_status: None, |             refund_status: None, | ||||||
|             refund_error_message: Some(error_message.message), |             refund_error_message: Some(error_message.message), | ||||||
|  |             refund_error_code: Some(error_message.code), | ||||||
|         }, |         }, | ||||||
|         Ok(response) => storage::RefundUpdate::Update { |         Ok(response) => storage::RefundUpdate::Update { | ||||||
|             connector_refund_id: response.connector_refund_id, |             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(), |             status: refund.refund_status.foreign_into(), | ||||||
|             metadata: refund.metadata, |             metadata: refund.metadata, | ||||||
|             error_message: refund.refund_error_message, |             error_message: refund.refund_error_message, | ||||||
|  |             error_code: refund.refund_error_code, | ||||||
|             created_at: Some(refund.created_at), |             created_at: Some(refund.created_at), | ||||||
|             updated_at: Some(refund.updated_at), |             updated_at: Some(refund.updated_at), | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -286,7 +286,8 @@ mod storage { | |||||||
|                         refund_amount: new.refund_amount, |                         refund_amount: new.refund_amount, | ||||||
|                         refund_status: new.refund_status, |                         refund_status: new.refund_status, | ||||||
|                         sent_to_gateway: new.sent_to_gateway, |                         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(), |                         metadata: new.metadata.clone(), | ||||||
|                         refund_arn: new.refund_arn.clone(), |                         refund_arn: new.refund_arn.clone(), | ||||||
|                         created_at: new.created_at.unwrap_or_else(date_time::now), |                         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_amount: new.refund_amount, | ||||||
|             refund_status: new.refund_status, |             refund_status: new.refund_status, | ||||||
|             sent_to_gateway: new.sent_to_gateway, |             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, |             metadata: new.metadata, | ||||||
|             refund_arn: new.refund_arn.clone(), |             refund_arn: new.refund_arn.clone(), | ||||||
|             created_at: new.created_at.unwrap_or(current_time), |             created_at: new.created_at.unwrap_or(current_time), | ||||||
|  | |||||||
| @ -25,6 +25,7 @@ pub struct Refund { | |||||||
|     pub refund_status: storage_enums::RefundStatus, |     pub refund_status: storage_enums::RefundStatus, | ||||||
|     pub sent_to_gateway: bool, |     pub sent_to_gateway: bool, | ||||||
|     pub refund_error_message: Option<String>, |     pub refund_error_message: Option<String>, | ||||||
|  |     pub refund_error_code: Option<String>, | ||||||
|     pub metadata: Option<serde_json::Value>, |     pub metadata: Option<serde_json::Value>, | ||||||
|     pub refund_arn: Option<String>, |     pub refund_arn: Option<String>, | ||||||
|     pub created_at: PrimitiveDateTime, |     pub created_at: PrimitiveDateTime, | ||||||
| @ -62,7 +63,6 @@ pub struct RefundNew { | |||||||
|     pub refund_amount: i64, |     pub refund_amount: i64, | ||||||
|     pub refund_status: storage_enums::RefundStatus, |     pub refund_status: storage_enums::RefundStatus, | ||||||
|     pub sent_to_gateway: bool, |     pub sent_to_gateway: bool, | ||||||
|     pub refund_error_message: Option<String>, |  | ||||||
|     pub metadata: Option<serde_json::Value>, |     pub metadata: Option<serde_json::Value>, | ||||||
|     pub refund_arn: Option<String>, |     pub refund_arn: Option<String>, | ||||||
|     pub created_at: Option<PrimitiveDateTime>, |     pub created_at: Option<PrimitiveDateTime>, | ||||||
| @ -93,6 +93,7 @@ pub enum RefundUpdate { | |||||||
|     ErrorUpdate { |     ErrorUpdate { | ||||||
|         refund_status: Option<storage_enums::RefundStatus>, |         refund_status: Option<storage_enums::RefundStatus>, | ||||||
|         refund_error_message: Option<String>, |         refund_error_message: Option<String>, | ||||||
|  |         refund_error_code: Option<String>, | ||||||
|     }, |     }, | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -103,6 +104,7 @@ pub struct RefundUpdateInternal { | |||||||
|     refund_status: Option<storage_enums::RefundStatus>, |     refund_status: Option<storage_enums::RefundStatus>, | ||||||
|     sent_to_gateway: Option<bool>, |     sent_to_gateway: Option<bool>, | ||||||
|     refund_error_message: Option<String>, |     refund_error_message: Option<String>, | ||||||
|  |     refund_error_code: Option<String>, | ||||||
|     refund_arn: Option<String>, |     refund_arn: Option<String>, | ||||||
|     metadata: Option<serde_json::Value>, |     metadata: Option<serde_json::Value>, | ||||||
|     refund_reason: Option<String>, |     refund_reason: Option<String>, | ||||||
| @ -143,9 +145,11 @@ impl From<RefundUpdate> for RefundUpdateInternal { | |||||||
|             RefundUpdate::ErrorUpdate { |             RefundUpdate::ErrorUpdate { | ||||||
|                 refund_status, |                 refund_status, | ||||||
|                 refund_error_message, |                 refund_error_message, | ||||||
|  |                 refund_error_code, | ||||||
|             } => Self { |             } => Self { | ||||||
|                 refund_status, |                 refund_status, | ||||||
|                 refund_error_message, |                 refund_error_message, | ||||||
|  |                 refund_error_code, | ||||||
|                 ..Default::default() |                 ..Default::default() | ||||||
|             }, |             }, | ||||||
|         } |         } | ||||||
| @ -160,6 +164,7 @@ impl RefundUpdate { | |||||||
|             refund_status: pa_update.refund_status.unwrap_or(source.refund_status), |             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), |             sent_to_gateway: pa_update.sent_to_gateway.unwrap_or(source.sent_to_gateway), | ||||||
|             refund_error_message: pa_update.refund_error_message, |             refund_error_message: pa_update.refund_error_message, | ||||||
|  |             refund_error_code: pa_update.refund_error_code, | ||||||
|             refund_arn: pa_update.refund_arn, |             refund_arn: pa_update.refund_arn, | ||||||
|             metadata: pa_update.metadata, |             metadata: pa_update.metadata, | ||||||
|             ..source |             ..source | ||||||
|  | |||||||
| @ -322,6 +322,7 @@ diesel::table! { | |||||||
|         refund_status -> RefundStatus, |         refund_status -> RefundStatus, | ||||||
|         sent_to_gateway -> Bool, |         sent_to_gateway -> Bool, | ||||||
|         refund_error_message -> Nullable<Text>, |         refund_error_message -> Nullable<Text>, | ||||||
|  |         refund_error_code -> Nullable<Varchar>, | ||||||
|         metadata -> Nullable<Json>, |         metadata -> Nullable<Json>, | ||||||
|         refund_arn -> Nullable<Varchar>, |         refund_arn -> Nullable<Varchar>, | ||||||
|         created_at -> Timestamp, |         created_at -> Timestamp, | ||||||
|  | |||||||
| @ -0,0 +1,2 @@ | |||||||
|  | ALTER TABLE refund | ||||||
|  | DROP COLUMN IF EXISTS refund_error_code; | ||||||
| @ -0,0 +1,2 @@ | |||||||
|  | ALTER TABLE refund | ||||||
|  | ADD IF NOT EXISTS refund_error_code TEXT DEFAULT NULL; | ||||||
		Reference in New Issue
	
	Block a user
	 Kartikeya Hegde
					Kartikeya Hegde