diff --git a/crates/api_models/src/disputes.rs b/crates/api_models/src/disputes.rs index c5448b0dfc6d..5b0de11f2d05 100644 --- a/crates/api_models/src/disputes.rs +++ b/crates/api_models/src/disputes.rs @@ -6,7 +6,7 @@ use serde::de::Error; use time::PrimitiveDateTime; use utoipa::ToSchema; -use super::enums::{DisputeStage, DisputeStatus, Currency}; +use super::enums::{Currency, DisputeStage, DisputeStatus}; use crate::{admin::MerchantConnectorInfo, files}; #[derive(Clone, Debug, Serialize, ToSchema, Eq, PartialEq)] diff --git a/crates/diesel_models/src/dispute.rs b/crates/diesel_models/src/dispute.rs index 20544b9ac2fc..8e3bab20d89c 100644 --- a/crates/diesel_models/src/dispute.rs +++ b/crates/diesel_models/src/dispute.rs @@ -31,7 +31,7 @@ pub struct DisputeNew { pub merchant_connector_id: Option, pub dispute_amount: i64, pub organization_id: common_utils::id_type::OrganizationId, - pub dispute_currency: storage_enums::Currency, + pub dispute_currency: Option, } #[derive(Clone, Debug, PartialEq, Serialize, Identifiable, Queryable, Selectable)] @@ -62,7 +62,7 @@ pub struct Dispute { pub merchant_connector_id: Option, pub dispute_amount: i64, pub organization_id: common_utils::id_type::OrganizationId, - pub dispute_currency: storage_enums::Currency, + pub dispute_currency: Option, } #[derive(Debug)] diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index c2541c8fc815..2b815db390c0 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -351,6 +351,7 @@ diesel::table! { dispute_id -> Varchar, #[max_length = 255] amount -> Varchar, + #[max_length = 255] currency -> Varchar, dispute_stage -> DisputeStage, dispute_status -> DisputeStatus, @@ -383,7 +384,7 @@ diesel::table! { dispute_amount -> Int8, #[max_length = 32] organization_id -> Varchar, - dispute_currency -> Currency, + dispute_currency -> Nullable, } } diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs index 020a15cd65fb..aea22e3d7c68 100644 --- a/crates/diesel_models/src/schema_v2.rs +++ b/crates/diesel_models/src/schema_v2.rs @@ -396,7 +396,7 @@ diesel::table! { dispute_amount -> Int8, #[max_length = 32] organization_id -> Varchar, - dispute_currency -> Currency, + dispute_currency -> Nullable, } } diff --git a/crates/hyperswitch_connectors/src/connectors/novalnet.rs b/crates/hyperswitch_connectors/src/connectors/novalnet.rs index 8331e229acb9..fd7ff906d08a 100644 --- a/crates/hyperswitch_connectors/src/connectors/novalnet.rs +++ b/crates/hyperswitch_connectors/src/connectors/novalnet.rs @@ -906,7 +906,7 @@ impl webhooks::IncomingWebhook for Novalnet { novalnet::get_novalnet_dispute_status(notif.event.event_type).to_string(); Ok(disputes::DisputePayload { amount: novalnet::option_to_result(amount)?.to_string(), - currency: novalnet::option_to_result(currency)?.to_string(), + currency: novalnet::option_to_result(currency)?, dispute_stage: api_models::enums::DisputeStage::Dispute, connector_dispute_id: notif.event.tid.to_string(), connector_reason: reason, diff --git a/crates/router/src/compatibility/stripe/webhooks.rs b/crates/router/src/compatibility/stripe/webhooks.rs index 999f2418a860..2212a8953fc7 100644 --- a/crates/router/src/compatibility/stripe/webhooks.rs +++ b/crates/router/src/compatibility/stripe/webhooks.rs @@ -1,7 +1,7 @@ #[cfg(feature = "payouts")] use api_models::payouts as payout_models; use api_models::{ - enums::{DisputeStatus, MandateStatus, Currency}, + enums::{Currency, DisputeStatus, MandateStatus}, webhooks::{self as api}, }; #[cfg(feature = "payouts")] diff --git a/crates/router/src/connector/braintree.rs b/crates/router/src/connector/braintree.rs index 2451a7318854..dba261218801 100644 --- a/crates/router/src/connector/braintree.rs +++ b/crates/router/src/connector/braintree.rs @@ -997,23 +997,21 @@ impl api::IncomingWebhook for Braintree { let response = decode_webhook_payload(notif.bt_payload.replace('\n', "").as_bytes())?; match response.dispute { - Some(dispute_data) => { - Ok(api::disputes::DisputePayload { - amount: connector_utils::to_currency_lower_unit( - dispute_data.amount_disputed.to_string(), - dispute_data.currency_iso_code, - )?, - currency: dispute_data.currency_iso_code, - dispute_stage: transformers::get_dispute_stage(dispute_data.kind.as_str())?, - connector_dispute_id: dispute_data.id, - connector_reason: dispute_data.reason, - connector_reason_code: dispute_data.reason_code, - challenge_required_by: dispute_data.reply_by_date, - connector_status: dispute_data.status, - created_at: dispute_data.created_at, - updated_at: dispute_data.updated_at, - }) - } + Some(dispute_data) => Ok(api::disputes::DisputePayload { + amount: connector_utils::to_currency_lower_unit( + dispute_data.amount_disputed.to_string(), + dispute_data.currency_iso_code, + )?, + currency: dispute_data.currency_iso_code, + dispute_stage: transformers::get_dispute_stage(dispute_data.kind.as_str())?, + connector_dispute_id: dispute_data.id, + connector_reason: dispute_data.reason, + connector_reason_code: dispute_data.reason_code, + challenge_required_by: dispute_data.reply_by_date, + connector_status: dispute_data.status, + created_at: dispute_data.created_at, + updated_at: dispute_data.updated_at, + }), None => Err(errors::ConnectorError::WebhookResourceObjectNotFound)?, } } diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 6b6ee33f642c..ed4b97e2a996 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -28,7 +28,7 @@ use hyperswitch_domain_models::{ SyncIntegrityObject, }, }; -use masking::{ExposeInterface, Secret, Deserialize}; +use masking::{Deserialize, ExposeInterface, Secret}; use once_cell::sync::Lazy; use regex::Regex; use serde::Serializer; @@ -3153,4 +3153,4 @@ where use serde::de::Error; let output = <&str>::deserialize(v)?; output.to_uppercase().parse::().map_err(D::Error::custom) -} \ No newline at end of file +} diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs index 3f7830b78828..3532f1e3fd72 100644 --- a/crates/router/src/core/webhooks/incoming.rs +++ b/crates/router/src/core/webhooks/incoming.rs @@ -963,7 +963,7 @@ async fn get_or_update_dispute_object( merchant_connector_id: payment_attempt.merchant_connector_id.clone(), dispute_amount: dispute_details.amount.parse::().unwrap_or(0), organization_id: organization_id.clone(), - dispute_currency: dispute_details.currency, + dispute_currency: Some(dispute_details.currency), }; state .store diff --git a/crates/router/src/db/dispute.rs b/crates/router/src/db/dispute.rs index 519d06ddce83..054f949059d9 100644 --- a/crates/router/src/db/dispute.rs +++ b/crates/router/src/db/dispute.rs @@ -309,9 +309,12 @@ impl DisputeInterface for MockDb { .currency .as_ref() .map_or(true, |currencies| { - currencies - .iter() - .any(|currency| &dispute.dispute_currency == currency) + currencies.iter().any(|currency| { + dispute + .dispute_currency + .map(|dispute_currency| &dispute_currency == currency) + .unwrap_or(dispute.currency.as_str() == currency.to_string()) + }) }) && dispute_constraints .time_range @@ -503,7 +506,7 @@ mod tests { merchant_connector_id: None, dispute_amount: 1040, organization_id: common_utils::id_type::OrganizationId::default(), - dispute_currency: common_enums::Currency::default(), + dispute_currency: Some(common_enums::Currency::default()), } } diff --git a/crates/router/src/services/kafka/dispute.rs b/crates/router/src/services/kafka/dispute.rs index d45cea065568..cc3a538851ef 100644 --- a/crates/router/src/services/kafka/dispute.rs +++ b/crates/router/src/services/kafka/dispute.rs @@ -1,4 +1,4 @@ -use common_utils::id_type; +use common_utils::{ext_traits::StringExt, id_type}; use diesel_models::enums as storage_enums; use masking::Secret; use time::OffsetDateTime; @@ -9,7 +9,7 @@ use crate::types::storage::dispute::Dispute; pub struct KafkaDispute<'a> { pub dispute_id: &'a String, pub dispute_amount: i64, - pub currency: &'a storage_enums::Currency, + pub currency: storage_enums::Currency, pub dispute_stage: &'a storage_enums::DisputeStage, pub dispute_status: &'a storage_enums::DisputeStatus, pub payment_id: &'a id_type::PaymentId, @@ -41,7 +41,13 @@ impl<'a> KafkaDispute<'a> { Self { dispute_id: &dispute.dispute_id, dispute_amount: dispute.amount.parse::().unwrap_or_default(), - currency: &dispute.dispute_currency, + currency: dispute.dispute_currency.unwrap_or( + dispute + .currency + .to_uppercase() + .parse_enum("Currency") + .unwrap_or_default(), + ), dispute_stage: &dispute.dispute_stage, dispute_status: &dispute.dispute_status, payment_id: &dispute.payment_id, diff --git a/crates/router/src/services/kafka/dispute_event.rs b/crates/router/src/services/kafka/dispute_event.rs index 899175ee6b78..64d91e8acaa6 100644 --- a/crates/router/src/services/kafka/dispute_event.rs +++ b/crates/router/src/services/kafka/dispute_event.rs @@ -1,3 +1,4 @@ +use common_utils::ext_traits::StringExt; use diesel_models::enums as storage_enums; use masking::Secret; use time::OffsetDateTime; @@ -9,7 +10,7 @@ use crate::types::storage::dispute::Dispute; pub struct KafkaDisputeEvent<'a> { pub dispute_id: &'a String, pub dispute_amount: i64, - pub currency: &'a storage_enums::Currency, + pub currency: storage_enums::Currency, pub dispute_stage: &'a storage_enums::DisputeStage, pub dispute_status: &'a storage_enums::DisputeStatus, pub payment_id: &'a common_utils::id_type::PaymentId, @@ -41,7 +42,13 @@ impl<'a> KafkaDisputeEvent<'a> { Self { dispute_id: &dispute.dispute_id, dispute_amount: dispute.amount.parse::().unwrap_or_default(), - currency: &dispute.dispute_currency, + currency: dispute.dispute_currency.unwrap_or( + dispute + .currency + .to_uppercase() + .parse_enum("Currency") + .unwrap_or_default(), + ), dispute_stage: &dispute.dispute_stage, dispute_status: &dispute.dispute_status, payment_id: &dispute.payment_id, diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 23327b1f50b5..8fe910cd7b46 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -886,7 +886,13 @@ impl ForeignFrom for api_models::disputes::DisputeResponse { payment_id: dispute.payment_id, attempt_id: dispute.attempt_id, amount: dispute.amount, - currency: dispute.dispute_currency, + currency: dispute.dispute_currency.unwrap_or( + dispute + .currency + .to_uppercase() + .parse_enum("Currency") + .unwrap_or_default(), + ), dispute_stage: dispute.dispute_stage, dispute_status: dispute.dispute_status, connector: dispute.connector, diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs index 31dfeec22eab..8ffb0f2001fb 100644 --- a/crates/router/src/utils/user/sample_data.rs +++ b/crates/router/src/utils/user/sample_data.rs @@ -435,9 +435,7 @@ pub async fn generate_sample_data( merchant_connector_id: payment_attempt.merchant_connector_id.clone(), dispute_amount: amount * 100, organization_id: org_id.clone(), - dispute_currency: payment_intent - .currency - .unwrap_or_default(), + dispute_currency: Some(payment_intent.currency.unwrap_or_default()), }) } else { None diff --git a/migrations/2024-10-28-125949_change_currency_type_in_dispute/down.sql b/migrations/2024-10-28-125949_add_dispute_currency_column_in_dispute_table/down.sql similarity index 100% rename from migrations/2024-10-28-125949_change_currency_type_in_dispute/down.sql rename to migrations/2024-10-28-125949_add_dispute_currency_column_in_dispute_table/down.sql diff --git a/migrations/2024-10-28-125949_add_dispute_currency_column_in_dispute_table/up.sql b/migrations/2024-10-28-125949_add_dispute_currency_column_in_dispute_table/up.sql new file mode 100644 index 000000000000..732909adfea2 --- /dev/null +++ b/migrations/2024-10-28-125949_add_dispute_currency_column_in_dispute_table/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE dispute ADD COLUMN IF NOT EXISTS dispute_currency "Currency"; \ No newline at end of file diff --git a/migrations/2024-10-28-125949_change_currency_type_in_dispute/up.sql b/migrations/2024-10-28-125949_change_currency_type_in_dispute/up.sql deleted file mode 100644 index c73d7c550887..000000000000 --- a/migrations/2024-10-28-125949_change_currency_type_in_dispute/up.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Your SQL goes here -ALTER TABLE dispute ADD COLUMN IF NOT EXISTS dispute_currency TYPE "Currency" USING currency::"Currency"; -- Migration query to be run after deployment before running this query \ No newline at end of file