Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

chore(dispute): adding disputeamount as int type (#3886)

harsh-sharma-juspay7db499d8a938
diff --git a/crates/diesel_models/src/dispute.rs b/crates/diesel_models/src/dispute.rs
index 9bdac33229..eae8281a99 100644
--- a/crates/diesel_models/src/dispute.rs
+++ b/crates/diesel_models/src/dispute.rs
@@ -29,6 +29,7 @@ pub struct DisputeNew {
pub evidence: Option<Secret<serde_json::Value>>,
pub profile_id: Option<String>,
pub merchant_connector_id: Option<String>,
+ pub dispute_amount: i64,
}
#[derive(Clone, Debug, PartialEq, Serialize, Identifiable, Queryable)]
@@ -59,6 +60,7 @@ pub struct Dispute {
pub evidence: Secret<serde_json::Value>,
pub profile_id: Option<String>,
pub merchant_connector_id: Option<String>,
+ pub dispute_amount: i64,
}
#[derive(Debug)]
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 9e72d8dc21..9db9f8c2d4 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -295,6 +295,7 @@ diesel::table! {
profile_id -> Nullable<Varchar>,
#[max_length = 32]
merchant_connector_id -> Nullable<Varchar>,
+ dispute_amount -> Int8,
}
}
diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs
index ef313b6222..9ec8de21f9 100644
--- a/crates/router/src/core/webhooks.rs
+++ b/crates/router/src/core/webhooks.rs
@@ -352,7 +352,7 @@ pub async fn get_or_update_dispute_object(
let dispute_id = generate_id(consts::ID_LENGTH, "dp");
let new_dispute = diesel_models::dispute::DisputeNew {
dispute_id,
- amount: dispute_details.amount,
+ amount: dispute_details.amount.clone(),
currency: dispute_details.currency,
dispute_stage: dispute_details.dispute_stage,
dispute_status: event_type
@@ -374,6 +374,7 @@ pub async fn get_or_update_dispute_object(
profile_id: Some(business_profile.profile_id.clone()),
evidence: None,
merchant_connector_id: payment_attempt.merchant_connector_id.clone(),
+ dispute_amount: dispute_details.amount.parse::<i64>().unwrap_or(0),
};
state
.store
diff --git a/crates/router/src/db/dispute.rs b/crates/router/src/db/dispute.rs
index 0c34123b6f..b0d0594c01 100644
--- a/crates/router/src/db/dispute.rs
+++ b/crates/router/src/db/dispute.rs
@@ -180,6 +180,7 @@ impl DisputeInterface for MockDb {
profile_id: dispute.profile_id,
evidence,
merchant_connector_id: dispute.merchant_connector_id,
+ dispute_amount: dispute.dispute_amount,
};
locked_disputes.push(new_dispute.clone());
@@ -414,6 +415,7 @@ mod tests {
evidence: Some(Secret::from(Value::String("evidence".into()))),
profile_id: None,
merchant_connector_id: None,
+ dispute_amount: 1040,
}
}
diff --git a/migrations/2024-02-28-103308_add_dispute_amount_to_dispute/down.sql b/migrations/2024-02-28-103308_add_dispute_amount_to_dispute/down.sql
new file mode 100644
index 0000000000..e89bb9a356
--- /dev/null
+++ b/migrations/2024-02-28-103308_add_dispute_amount_to_dispute/down.sql
@@ -0,0 +1,17 @@
+-- This file should undo anything in `up.sql`
+-- Drop the new column
+ALTER TABLE dispute
+DROP COLUMN IF EXISTS dispute_amount;
+
+-- Optionally, if you want to revert the UPDATE statement as well (assuming you have a backup)
+-- You can restore the original data from the backup or use the old values to update the table
+
+-- For example, if you have a backup and want to revert the changes made by the UPDATE statement
+-- You can replace the data with the backup data or the original values
+-- For demonstration purposes, we're assuming you have a backup table named dispute_backup
+
+-- Restore the original values from the backup or any other source
+-- UPDATE dispute
+-- SET dispute_amount = backup.dispute_amount
+-- FROM dispute_backup AS backup
+-- WHERE dispute.id = backup.id;
diff --git a/migrations/2024-02-28-103308_add_dispute_amount_to_dispute/up.sql b/migrations/2024-02-28-103308_add_dispute_amount_to_dispute/up.sql
new file mode 100644
index 0000000000..b56ffc4fe9
--- /dev/null
+++ b/migrations/2024-02-28-103308_add_dispute_amount_to_dispute/up.sql
@@ -0,0 +1,8 @@
+-- Your SQL goes here
+-- Add the new column with a default value
+ALTER TABLE dispute
+ADD COLUMN dispute_amount BIGINT NOT NULL DEFAULT 0;
+
+-- Update existing rows to set the default value based on the integer equivalent of the amount column
+UPDATE dispute
+SET dispute_amount = CAST(amount AS BIGINT);