From acd3a204c02b6aa0815acc687de793fb6d067d58 Mon Sep 17 00:00:00 2001 From: sumanmaji4 Date: Tue, 7 Jan 2025 23:32:00 +0530 Subject: [PATCH] nit fix --- crates/api_models/src/payment_methods.rs | 20 ++++++++++---------- crates/diesel_models/src/payment_method.rs | 18 +++++++----------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index 4da698d9dd7c..cfe72c506d52 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -306,17 +306,17 @@ pub struct PaymentsMandateReference( pub HashMap, ); -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub struct PayoutsMandateReference( pub HashMap, ); -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub struct PayoutsMandateReferenceRecord { pub transfer_method_id: Option, } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub struct PaymentsMandateReferenceRecord { pub connector_mandate_id: String, pub payment_method_type: Option, @@ -324,7 +324,7 @@ pub struct PaymentsMandateReferenceRecord { pub original_payment_authorized_currency: Option, } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub struct CommonMandateReference { pub payments: Option, pub payouts: Option, @@ -353,17 +353,17 @@ where { let value: Option = Option::::deserialize(deserializer)?; if let Some(connector_mandate_value) = value { - if let Ok(common_mandate) = - serde_json::from_value::(connector_mandate_value.clone()) - { - Ok(Some(common_mandate)) - } else if let Ok(payment_mandate_record) = - serde_json::from_value::(connector_mandate_value) + if let Ok(payment_mandate_record) = + serde_json::from_value::(connector_mandate_value.clone()) { Ok(Some(CommonMandateReference { payments: Some(payment_mandate_record), payouts: None, })) + } else if let Ok(common_mandate) = + serde_json::from_value::(connector_mandate_value) + { + Ok(Some(common_mandate)) } else { Err(de::Error::custom( "Failed to deserialize connector_mandate_details", diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs index e4ff5b3fe4c6..fb376a4c51e2 100644 --- a/crates/diesel_models/src/payment_method.rs +++ b/crates/diesel_models/src/payment_method.rs @@ -996,7 +996,7 @@ impl std::ops::DerefMut for PaymentsMandateReference { common_utils::impl_to_sql_from_sql_json!(PaymentsMandateReference); -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] pub struct PayoutsMandateReferenceRecord { pub transfer_method_id: Option, } @@ -1048,24 +1048,20 @@ where serde_json::Value: diesel::deserialize::FromSql, { fn from_sql(bytes: DB::RawValue<'_>) -> diesel::deserialize::Result { - // Deserialize into a generic serde_json::Value first let value = >::from_sql(bytes)?; - // Try to directly deserialize into CommonMandateReference - if let Ok(common_reference) = serde_json::from_value::(value.clone()) { - return Ok(common_reference); - } - - // If that fails, try deserializing into PaymentsMandateReference - if let Ok(payment_reference) = serde_json::from_value::(value) { - // Convert PaymentsMandateReference to CommonMandateReference + if let Ok(payment_reference) = + serde_json::from_value::(value.clone()) + { return Ok(Self::from(payment_reference)); } - // If neither succeeds, return an error + if let Ok(common_reference) = serde_json::from_value::(value) { + return Ok(common_reference); + } Err( report!(ParsingError::StructParseFailure("CommonMandateReference")).attach_printable( "Failed to parse JSON into CommonMandateReference or PaymentsMandateReference",