Skip to content

Commit

Permalink
dispute currency type change to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSagnik007 committed Oct 28, 2024
1 parent cd62658 commit 661110c
Show file tree
Hide file tree
Showing 23 changed files with 190 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/api_models/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct DisputeResponse {
/// The dispute amount
pub amount: String,
/// The three-letter ISO currency code
pub currency: String,
pub currency: common_enums::Currency,
/// Stage of the dispute
pub dispute_stage: DisputeStage,
/// Status of the dispute
Expand Down
4 changes: 2 additions & 2 deletions crates/diesel_models/src/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{enums as storage_enums, schema::dispute};
pub struct DisputeNew {
pub dispute_id: String,
pub amount: String,
pub currency: String,
pub currency: storage_enums::Currency,
pub dispute_stage: storage_enums::DisputeStage,
pub dispute_status: storage_enums::DisputeStatus,
pub payment_id: common_utils::id_type::PaymentId,
Expand All @@ -38,7 +38,7 @@ pub struct DisputeNew {
pub struct Dispute {
pub dispute_id: String,
pub amount: String,
pub currency: String,
pub currency: storage_enums::Currency,
pub dispute_stage: storage_enums::DisputeStage,
pub dispute_status: storage_enums::DisputeStatus,
pub payment_id: common_utils::id_type::PaymentId,
Expand Down
3 changes: 1 addition & 2 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ diesel::table! {
dispute_id -> Varchar,
#[max_length = 255]
amount -> Varchar,
#[max_length = 255]
currency -> Varchar,
currency -> Currency,
dispute_stage -> DisputeStage,
dispute_status -> DisputeStatus,
#[max_length = 64]
Expand Down
3 changes: 1 addition & 2 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ diesel::table! {
dispute_id -> Varchar,
#[max_length = 255]
amount -> Varchar,
#[max_length = 255]
currency -> Varchar,
currency -> Currency,
dispute_stage -> DisputeStage,
dispute_status -> DisputeStatus,
#[max_length = 64]
Expand Down
2 changes: 1 addition & 1 deletion crates/hyperswitch_interfaces/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct DisputePayload {
/// amount
pub amount: String,
/// currency
pub currency: String,
pub currency: common_enums::enums::Currency,
/// dispute_stage
pub dispute_stage: common_enums::enums::DisputeStage,
/// connector_status
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/compatibility/stripe/webhooks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "payouts")]
use api_models::payouts as payout_models;
use api_models::{
enums::{DisputeStatus, MandateStatus},
enums::{DisputeStatus, MandateStatus, Currency},
webhooks::{self as api},
};
#[cfg(feature = "payouts")]
Expand Down Expand Up @@ -93,7 +93,7 @@ pub enum StripeWebhookObject {
pub struct StripeDisputeResponse {
pub id: String,
pub amount: String,
pub currency: String,
pub currency: Currency,
pub payment_intent: common_utils::id_type::PaymentId,
pub reason: Option<String>,
pub status: StripeDisputeStatus,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/adyen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ impl api::IncomingWebhook for Adyen {
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
Ok(api::disputes::DisputePayload {
amount: notif.amount.value.to_string(),
currency: notif.amount.currency.to_string(),
currency: notif.amount.currency,
dispute_stage: api_models::enums::DisputeStage::from(notif.event_code.clone()),
connector_dispute_id: notif.psp_reference,
connector_reason: notif.reason,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/airwallex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ impl api::IncomingWebhook for Airwallex {
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
Ok(api::disputes::DisputePayload {
amount: dispute_details.dispute_amount.to_string(),
currency: dispute_details.dispute_currency,
currency: connector_utils::string_to_currency(dispute_details.dispute_currency),
dispute_stage: api_models::enums::DisputeStage::from(dispute_details.stage.clone()),
connector_dispute_id: dispute_details.dispute_id,
connector_reason: dispute_details.dispute_reason_type,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/bluesnap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ impl api::IncomingWebhook for Bluesnap {
dispute_details.invoice_charge_amount.abs().to_string(),
dispute_details.currency,
)?,
currency: dispute_details.currency.to_string(),
currency: dispute_details.currency,
dispute_stage: api_models::enums::DisputeStage::Dispute,
connector_dispute_id: dispute_details.reversal_ref_num,
connector_reason: dispute_details.reversal_reason,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/braintree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ impl api::IncomingWebhook for Braintree {
dispute_data.amount_disputed.to_string(),
currency,
)?,
currency: dispute_data.currency_iso_code,
currency: connector_utils::string_to_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,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ impl api::IncomingWebhook for Checkout {
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;
Ok(api::disputes::DisputePayload {
amount: dispute_details.data.amount.to_string(),
currency: dispute_details.data.currency,
currency: connector_utils::string_to_currency(dispute_details.data.currency),
dispute_stage: api_models::enums::DisputeStage::from(
dispute_details.transaction_type.clone(),
),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/payme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ impl api::IncomingWebhook for Payme {

Ok(api::disputes::DisputePayload {
amount: webhook_object.price.to_string(),
currency: webhook_object.currency.to_string(),
currency: webhook_object.currency,
dispute_stage: api_models::enums::DisputeStage::Dispute,
connector_dispute_id: webhook_object.payme_transaction_id,
connector_reason: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/paypal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1988,7 +1988,7 @@ impl api::IncomingWebhook for Paypal {
payload.dispute_amount.value.get_amount_as_string(),
payload.dispute_amount.currency_code,
)?,
currency: payload.dispute_amount.currency_code.to_string(),
currency: payload.dispute_amount.currency_code,
dispute_stage: api_models::enums::DisputeStage::from(
payload.dispute_life_cycle_stage.clone(),
),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/rapyd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ impl api::IncomingWebhook for Rapyd {
}?;
Ok(api::disputes::DisputePayload {
amount: webhook_dispute_data.amount.to_string(),
currency: webhook_dispute_data.currency.to_string(),
currency: webhook_dispute_data.currency,
dispute_stage: api_models::enums::DisputeStage::Dispute,
connector_dispute_id: webhook_dispute_data.token,
connector_reason: Some(webhook_dispute_data.dispute_reason_description),
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/stripe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2432,7 +2432,7 @@ impl api::IncomingWebhook for Stripe {
field_name: "amount",
})?
.to_string(),
currency: details.event_data.event_object.currency,
currency: connector_utils::string_to_currency(details.event_data.event_object.currency),
dispute_stage: api_models::enums::DisputeStage::Dispute,
connector_dispute_id: details.event_data.event_object.id,
connector_reason: details.event_data.event_object.reason,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/trustpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl api::IncomingWebhook for Trustpay {
.ok_or(errors::ConnectorError::WebhookReferenceIdNotFound)?;
Ok(api::disputes::DisputePayload {
amount: payment_info.amount.amount.to_string(),
currency: payment_info.amount.currency,
currency: connector_utils::string_to_currency(payment_info.amount.currency),
dispute_stage: api_models::enums::DisputeStage::Dispute,
connector_dispute_id,
connector_reason: reason.reason.reject_reason,
Expand Down
163 changes: 163 additions & 0 deletions crates/router/src/connector/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3109,3 +3109,166 @@ impl NetworkTokenData for domain::NetworkTokenData {
Secret::new(year)
}
}

pub fn string_to_currency(currency: String) -> enums::Currency {
match currency.to_lowercase().as_str() {
"aed" => enums::Currency::AED,
"afn" => enums::Currency::AFN,
"all" => enums::Currency::ALL,
"amd" => enums::Currency::AMD,
"ang" => enums::Currency::ANG,
"aoa" => enums::Currency::AOA,
"ars" => enums::Currency::ARS,
"aud" => enums::Currency::AUD,
"awg" => enums::Currency::AWG,
"azn" => enums::Currency::AZN,
"bam" => enums::Currency::BAM,
"bbd" => enums::Currency::BBD,
"bdt" => enums::Currency::BDT,
"bgn" => enums::Currency::BGN,
"bhd" => enums::Currency::BHD,
"bif" => enums::Currency::BIF,
"bmd" => enums::Currency::BMD,
"bnd" => enums::Currency::BND,
"bob" => enums::Currency::BOB,
"brl" => enums::Currency::BRL,
"bsd" => enums::Currency::BSD,
"btn" => enums::Currency::BTN,
"bwp" => enums::Currency::BWP,
"byn" => enums::Currency::BYN,
"bzd" => enums::Currency::BZD,
"cad" => enums::Currency::CAD,
"cdf" => enums::Currency::CDF,
"chf" => enums::Currency::CHF,
"clp" => enums::Currency::CLP,
"cny" => enums::Currency::CNY,
"cop" => enums::Currency::COP,
"crc" => enums::Currency::CRC,
"cup" => enums::Currency::CUP,
"cve" => enums::Currency::CVE,
"czk" => enums::Currency::CZK,
"djf" => enums::Currency::DJF,
"dkk" => enums::Currency::DKK,
"dop" => enums::Currency::DOP,
"dzd" => enums::Currency::DZD,
"egp" => enums::Currency::EGP,
"ern" => enums::Currency::ERN,
"etb" => enums::Currency::ETB,
"eur" => enums::Currency::EUR,
"fjd" => enums::Currency::FJD,
"fkp" => enums::Currency::FKP,
"gbp" => enums::Currency::GBP,
"gel" => enums::Currency::GEL,
"ghs" => enums::Currency::GHS,
"gip" => enums::Currency::GIP,
"gmd" => enums::Currency::GMD,
"gnf" => enums::Currency::GNF,
"gtq" => enums::Currency::GTQ,
"gyd" => enums::Currency::GYD,
"hkd" => enums::Currency::HKD,
"hnl" => enums::Currency::HNL,
"hrk" => enums::Currency::HRK,
"htg" => enums::Currency::HTG,
"huf" => enums::Currency::HUF,
"idr" => enums::Currency::IDR,
"ils" => enums::Currency::ILS,
"inr" => enums::Currency::INR,
"iqd" => enums::Currency::IQD,
"irr" => enums::Currency::IRR,
"isk" => enums::Currency::ISK,
"jmd" => enums::Currency::JMD,
"jod" => enums::Currency::JOD,

Check warning on line 3180 in crates/router/src/connector/utils.rs

View workflow job for this annotation

GitHub Actions / Spell check

"jod" should be "job".
"jpy" => enums::Currency::JPY,
"kes" => enums::Currency::KES,
"kgs" => enums::Currency::KGS,
"KHR" => enums::Currency::KHR,
"kmf" => enums::Currency::KMF,
"kpw" => enums::Currency::KPW,
"krw" => enums::Currency::KRW,
"kwd" => enums::Currency::KWD,
"kyd" => enums::Currency::KYD,
"kzt" => enums::Currency::KZT,
"lak" => enums::Currency::LAK,
"lbp" => enums::Currency::LBP,
"lkr" => enums::Currency::LKR,
"lrd" => enums::Currency::LRD,
"lsl" => enums::Currency::LSL,
"lyd" => enums::Currency::LYD,
"mad" => enums::Currency::MAD,
"mdl" => enums::Currency::MDL,
"mga" => enums::Currency::MGA,
"mkd" => enums::Currency::MKD,
"mmk" => enums::Currency::MMK,
"mnt" => enums::Currency::MNT,
"mop" => enums::Currency::MOP,
"mru" => enums::Currency::MRU,
"mur" => enums::Currency::MUR,
"mvr" => enums::Currency::MVR,
"mwk" => enums::Currency::MWK,
"mxn" => enums::Currency::MXN,
"myr" => enums::Currency::MYR,
"mzn" => enums::Currency::MZN,
"nad" => enums::Currency::NAD,
"ngn" => enums::Currency::NGN,
"nio" => enums::Currency::NIO,
"nok" => enums::Currency::NOK,
"npr" => enums::Currency::NPR,
"nzd" => enums::Currency::NZD,
"omr" => enums::Currency::OMR,
"pab" => enums::Currency::PAB,
"pen" => enums::Currency::PEN,
"pgk" => enums::Currency::PGK,
"php" => enums::Currency::PHP,
"pkr" => enums::Currency::PKR,
"pln" => enums::Currency::PLN,
"pyg" => enums::Currency::PYG,
"qar" => enums::Currency::QAR,
"ron" => enums::Currency::RON,
"rsd" => enums::Currency::RSD,
"rub" => enums::Currency::RUB,
"rwf" => enums::Currency::RWF,
"sar" => enums::Currency::SAR,
"sbd" => enums::Currency::SBD,
"scr" => enums::Currency::SCR,
"sdg" => enums::Currency::SDG,
"sek" => enums::Currency::SEK,
"sgd" => enums::Currency::SGD,
"shp" => enums::Currency::SHP,
"sle" => enums::Currency::SLE,
"sll" => enums::Currency::SLL,
"sos" => enums::Currency::SOS,
"srd" => enums::Currency::SRD,
"ssp" => enums::Currency::SSP,
"stn" => enums::Currency::STN,
"svc" => enums::Currency::SVC,
"syp" => enums::Currency::SYP,
"szl" => enums::Currency::SZL,
"thb" => enums::Currency::THB,
"tjs" => enums::Currency::TJS,
"tmt" => enums::Currency::TMT,
"tnd" => enums::Currency::TND,
"top" => enums::Currency::TOP,
"try" => enums::Currency::TRY,
"ttd" => enums::Currency::TTD,
"twd" => enums::Currency::TWD,
"tzs" => enums::Currency::TZS,
"uah" => enums::Currency::UAH,
"ugx" => enums::Currency::UGX,
"usd" => enums::Currency::USD,
"uyu" => enums::Currency::UYU,
"uzs" => enums::Currency::UZS,
"ves" => enums::Currency::VES,
"vnd" => enums::Currency::VND,
"vuv" => enums::Currency::VUV,
"wst" => enums::Currency::WST,
"xaf" => enums::Currency::XAF,
"xcd" => enums::Currency::XCD,
"xof" => enums::Currency::XOF,
"xpf" => enums::Currency::XPF,
"yer" => enums::Currency::YER,
"zar" => enums::Currency::ZAR,
"zmw" => enums::Currency::ZMW,
"zwl" => enums::Currency::ZWL,
_ => enums::Currency::USD,
}
}
4 changes: 2 additions & 2 deletions crates/router/src/db/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl DisputeInterface for MockDb {
.map_or(true, |currencies| {
currencies
.iter()
.any(|currency| dispute.currency.as_str() == currency.to_string())
.any(|currency| &dispute.currency == currency)
})
&& dispute_constraints
.time_range
Expand Down Expand Up @@ -483,7 +483,7 @@ mod tests {
DisputeNew {
dispute_id: dispute_ids.dispute_id,
amount: "amount".into(),
currency: "currency".into(),
currency: common_enums::Currency::USD,
dispute_stage: DisputeStage::Dispute,
dispute_status: DisputeStatus::DisputeOpened,
payment_id: dispute_ids.payment_id,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/services/kafka/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 String,
pub currency: &'a storage_enums::Currency,
pub dispute_stage: &'a storage_enums::DisputeStage,
pub dispute_status: &'a storage_enums::DisputeStatus,
pub payment_id: &'a id_type::PaymentId,
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/services/kafka/dispute_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::types::storage::dispute::Dispute;
pub struct KafkaDisputeEvent<'a> {
pub dispute_id: &'a String,
pub dispute_amount: i64,
pub currency: &'a String,
pub currency: &'a 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,
Expand Down
8 changes: 1 addition & 7 deletions crates/router/src/types/storage/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,8 @@ impl DisputeDbExt for Dispute {
if let Some(dispute_status) = &dispute_list_constraints.dispute_status {
filter = filter.filter(dsl::dispute_status.eq_any(dispute_status.clone()));
}

if let Some(currency_list) = &dispute_list_constraints.currency {
let currency: Vec<String> = currency_list
.iter()
.map(|currency| currency.to_string())
.collect();

filter = filter.filter(dsl::currency.eq_any(currency));
filter = filter.filter(dsl::currency.eq_any(currency_list.clone()));
}
if let Some(merchant_connector_id) = &dispute_list_constraints.merchant_connector_id {
filter = filter.filter(dsl::merchant_connector_id.eq(merchant_connector_id.clone()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE dispute ALTER COLUMN currency TYPE VARCHAR(255) USING currency::VARCHAR(255);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE dispute ALTER COLUMN currency TYPE "Currency" USING currency::"Currency";

0 comments on commit 661110c

Please sign in to comment.