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

feat(platform): add processor_merchant_id and created_by to refund and dispute (#11351)

Sandeep Kumar8f8847aa0b95
diff --git a/crates/diesel_models/src/dispute.rs b/crates/diesel_models/src/dispute.rs
index 322c9808f1..fa4824170f 100644
--- a/crates/diesel_models/src/dispute.rs
+++ b/crates/diesel_models/src/dispute.rs
@@ -35,6 +35,8 @@ pub struct DisputeNew {
pub dispute_amount: MinorUnit,
pub organization_id: common_utils::id_type::OrganizationId,
pub dispute_currency: Option<storage_enums::Currency>,
+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
+ pub created_by: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Identifiable, Queryable, Selectable)]
@@ -66,6 +68,8 @@ pub struct Dispute {
pub dispute_amount: MinorUnit,
pub organization_id: common_utils::id_type::OrganizationId,
pub dispute_currency: Option<storage_enums::Currency>,
+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,
+ pub created_by: Option<String>,
}
impl Dispute {
diff --git a/crates/diesel_models/src/refund.rs b/crates/diesel_models/src/refund.rs
index 7f5e08d027..47717a3065 100644
--- a/crates/diesel_models/src/refund.rs
+++ b/crates/diesel_models/src/refund.rs
@@ -67,6 +67,8 @@ pub struct Refund {
pub processor_transaction_data: Option<String>,
pub issuer_error_code: Option<String>,
pub issuer_error_message: Option<String>,
+ pub processor_merchant_id: Option<id_type::MerchantId>,
+ pub created_by: Option<String>,
}
#[cfg(feature = "v2")]
@@ -115,6 +117,8 @@ pub struct Refund {
pub unified_message: Option<String>,
pub processor_refund_data: Option<String>,
pub processor_transaction_data: Option<String>,
+ pub processor_merchant_id: Option<id_type::MerchantId>,
+ pub created_by: Option<String>,
pub id: id_type::GlobalRefundId,
#[diesel(deserialize_as = RequiredFromNullable<id_type::RefundReferenceId>)]
pub merchant_reference_id: id_type::RefundReferenceId,
@@ -166,6 +170,8 @@ pub struct RefundNew {
pub split_refunds: Option<common_types::refunds::SplitRefund>,
pub processor_refund_data: Option<String>,
pub processor_transaction_data: Option<String>,
+ pub processor_merchant_id: Option<id_type::MerchantId>,
+ pub created_by: Option<String>,
}
#[cfg(feature = "v2")]
@@ -213,6 +219,8 @@ pub struct RefundNew {
pub split_refunds: Option<common_types::refunds::SplitRefund>,
pub processor_refund_data: Option<String>,
pub processor_transaction_data: Option<String>,
+ pub processor_merchant_id: Option<id_type::MerchantId>,
+ pub created_by: Option<String>,
}
#[cfg(feature = "v1")]
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 450d39eb2d..2b420ec230 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -489,6 +489,10 @@ diesel::table! {
#[max_length = 32]
organization_id -> Varchar,
dispute_currency -> Nullable<Currency>,
+ #[max_length = 64]
+ processor_merchant_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ created_by -> Nullable<Varchar>,
}
}
@@ -1545,6 +1549,10 @@ diesel::table! {
#[max_length = 64]
issuer_error_code -> Nullable<Varchar>,
issuer_error_message -> Nullable<Text>,
+ #[max_length = 64]
+ processor_merchant_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ created_by -> Nullable<Varchar>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index 736290cd84..2ff50ef64c 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -503,6 +503,10 @@ diesel::table! {
#[max_length = 32]
organization_id -> Varchar,
dispute_currency -> Nullable<Currency>,
+ #[max_length = 64]
+ processor_merchant_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ created_by -> Nullable<Varchar>,
}
}
@@ -1478,6 +1482,10 @@ diesel::table! {
processor_refund_data -> Nullable<Text>,
processor_transaction_data -> Nullable<Text>,
#[max_length = 64]
+ processor_merchant_id -> Nullable<Varchar>,
+ #[max_length = 255]
+ created_by -> Nullable<Varchar>,
+ #[max_length = 64]
id -> Varchar,
#[max_length = 64]
merchant_reference_id -> Nullable<Varchar>,
diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rs
index 1c754aab47..b9f1ffc330 100644
--- a/crates/router/src/core/disputes.rs
+++ b/crates/router/src/core/disputes.rs
@@ -923,6 +923,7 @@ pub async fn update_dispute_data(
dispute_data,
platform.get_processor().get_account().get_id(),
&platform.get_processor().get_account().organization_id,
+ platform.get_initiator(),
&payment_attempt,
dispute_details.dispute_status,
&business_profile,
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index b8c4f2ec43..3e1bd7c146 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -1404,6 +1404,11 @@ pub async fn validate_and_create_refund(
.clone(),
processor_transaction_data,
processor_refund_data: None,
+ processor_merchant_id: Some(platform.get_processor().get_account().get_id().clone()),
+ created_by: platform
+ .get_initiator()
+ .and_then(|initiator| initiator.to_created_by())
+ .map(|created_by| created_by.to_string()),
};
let (refund, raw_connector_response) = match db
diff --git a/crates/router/src/core/refunds_v2.rs b/crates/router/src/core/refunds_v2.rs
index b506d20d85..d1d7870ef6 100644
--- a/crates/router/src/core/refunds_v2.rs
+++ b/crates/router/src/core/refunds_v2.rs
@@ -1245,6 +1245,11 @@ pub async fn validate_and_create_refund(
.clone(),
processor_transaction_data,
processor_refund_data: None,
+ processor_merchant_id: Some(platform.get_processor().get_account().get_id().clone()),
+ created_by: platform
+ .get_initiator()
+ .and_then(|initiator| initiator.to_created_by())
+ .map(|created_by| created_by.to_string()),
};
let (refund, raw_connector_response) = match db
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index 0055622e63..7d36cd425e 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -2286,6 +2286,7 @@ pub async fn get_or_update_dispute_object(
dispute_details: api::disputes::DisputePayload,
merchant_id: &common_utils::id_type::MerchantId,
organization_id: &common_utils::id_type::OrganizationId,
+ initiator: Option<&domain::Initiator>,
payment_attempt: &PaymentAttempt,
dispute_status: common_enums::enums::DisputeStatus,
business_profile: &domain::Profile,
@@ -2328,6 +2329,10 @@ pub async fn get_or_update_dispute_object(
)?,
organization_id: organization_id.clone(),
dispute_currency: Some(dispute_details.currency),
+ processor_merchant_id: Some(payment_attempt.processor_merchant_id.clone()),
+ created_by: initiator
+ .and_then(|initiator| initiator.to_created_by())
+ .map(|created_by| created_by.to_string()),
};
state
.store
@@ -2813,6 +2818,7 @@ async fn disputes_incoming_webhook_flow(
dispute_details,
platform.get_processor().get_account().get_id(),
&platform.get_processor().get_account().organization_id,
+ platform.get_initiator(),
&payment_attempt,
dispute_status,
&business_profile,
diff --git a/crates/router/src/db/dispute.rs b/crates/router/src/db/dispute.rs
index 14b609df79..448eec9dba 100644
--- a/crates/router/src/db/dispute.rs
+++ b/crates/router/src/db/dispute.rs
@@ -200,6 +200,8 @@ impl DisputeInterface for MockDb {
dispute_amount: dispute.dispute_amount,
organization_id: dispute.organization_id,
dispute_currency: dispute.dispute_currency,
+ processor_merchant_id: dispute.processor_merchant_id,
+ created_by: dispute.created_by,
};
locked_disputes.push(new_dispute.clone());
@@ -493,7 +495,7 @@ mod tests {
dispute_status: DisputeStatus::DisputeOpened,
payment_id: dispute_ids.payment_id,
attempt_id: dispute_ids.attempt_id,
- merchant_id: dispute_ids.merchant_id,
+ merchant_id: dispute_ids.merchant_id.clone(),
connector_status: "connector_status".into(),
connector_dispute_id: dispute_ids.connector_dispute_id,
connector_reason: Some("connector_reason".into()),
@@ -508,6 +510,8 @@ mod tests {
dispute_amount: MinorUnit::new(1040),
organization_id: common_utils::id_type::OrganizationId::default(),
dispute_currency: Some(Currency::default()),
+ processor_merchant_id: Some(dispute_ids.merchant_id),
+ created_by: None,
}
}
diff --git a/crates/router/src/db/refund.rs b/crates/router/src/db/refund.rs
index 6f181ba201..5d1db3ac72 100644
--- a/crates/router/src/db/refund.rs
+++ b/crates/router/src/db/refund.rs
@@ -545,6 +545,8 @@ mod storage {
processor_transaction_data: new.processor_transaction_data.clone(),
issuer_error_code: None,
issuer_error_message: None,
+ processor_merchant_id: new.processor_merchant_id.clone(),
+ created_by: new.created_by.clone(),
// Below fields are deprecated. Please add any new fields above this line.
connector_refund_data: None,
connector_transaction_data: None,
@@ -1152,6 +1154,8 @@ impl RefundInterface for MockDb {
processor_transaction_data: new.processor_transaction_data.clone(),
issuer_error_code: None,
issuer_error_message: None,
+ processor_merchant_id: new.processor_merchant_id.clone(),
+ created_by: new.created_by.clone(),
// Below fields are deprecated. Please add any new fields above this line.
connector_refund_data: None,
connector_transaction_data: None,
@@ -1203,6 +1207,8 @@ impl RefundInterface for MockDb {
unified_message: None,
processor_refund_data: new.processor_refund_data.clone(),
processor_transaction_data: new.processor_transaction_data.clone(),
+ processor_merchant_id: new.processor_merchant_id.clone(),
+ created_by: new.created_by.clone(),
};
refunds.push(refund.clone());
Ok(refund)
diff --git a/crates/router/src/services/kafka/dispute.rs b/crates/router/src/services/kafka/dispute.rs
index b0478b6a57..b308611047 100644
--- a/crates/router/src/services/kafka/dispute.rs
+++ b/crates/router/src/services/kafka/dispute.rs
@@ -38,6 +38,8 @@ pub struct KafkaDispute<'a> {
pub profile_id: Option<&'a id_type::ProfileId>,
pub merchant_connector_id: Option<&'a id_type::MerchantConnectorAccountId>,
pub organization_id: &'a id_type::OrganizationId,
+ pub processor_merchant_id: Option<&'a id_type::MerchantId>,
+ pub created_by: Option<&'a String>,
}
impl<'a> KafkaDispute<'a> {
@@ -80,6 +82,8 @@ impl<'a> KafkaDispute<'a> {
profile_id: dispute.profile_id.as_ref(),
merchant_connector_id: dispute.merchant_connector_id.as_ref(),
organization_id: &dispute.organization_id,
+ processor_merchant_id: dispute.processor_merchant_id.as_ref(),
+ created_by: dispute.created_by.as_ref(),
}
}
}
diff --git a/crates/router/src/services/kafka/refund.rs b/crates/router/src/services/kafka/refund.rs
index 4e10ac4ee3..76ddc7c39c 100644
--- a/crates/router/src/services/kafka/refund.rs
+++ b/crates/router/src/services/kafka/refund.rs
@@ -40,6 +40,8 @@ pub struct KafkaRefund<'a> {
pub refund_error_code: Option<&'a String>,
pub profile_id: Option<&'a id_type::ProfileId>,
pub organization_id: &'a id_type::OrganizationId,
+ pub processor_merchant_id: Option<&'a id_type::MerchantId>,
+ pub created_by: Option<&'a String>,
}
#[cfg(feature = "v1")]
@@ -70,6 +72,8 @@ impl<'a> KafkaRefund<'a> {
refund_error_code: refund.refund_error_code.as_ref(),
profile_id: refund.profile_id.as_ref(),
organization_id: &refund.organization_id,
+ processor_merchant_id: refund.processor_merchant_id.as_ref(),
+ created_by: refund.created_by.as_ref(),
}
}
}
@@ -115,6 +119,8 @@ pub struct KafkaRefund<'a> {
pub unified_message: Option<&'a String>,
pub processor_refund_data: Option<&'a String>,
pub processor_transaction_data: Option<&'a String>,
+ pub processor_merchant_id: Option<&'a id_type::MerchantId>,
+ pub created_by: Option<&'a String>,
}
#[cfg(feature = "v2")]
@@ -154,6 +160,8 @@ impl<'a> KafkaRefund<'a> {
id,
merchant_reference_id,
connector_id,
+ processor_merchant_id,
+ created_by,
} = refund;
Self {
@@ -192,6 +200,8 @@ impl<'a> KafkaRefund<'a> {
unified_message: unified_message.as_ref(),
processor_refund_data: processor_refund_data.as_ref(),
processor_transaction_data: processor_transaction_data.as_ref(),
+ processor_merchant_id: processor_merchant_id.as_ref(),
+ created_by: created_by.as_ref(),
}
}
}
diff --git a/crates/router/src/services/kafka/refund_event.rs b/crates/router/src/services/kafka/refund_event.rs
index fed6ee52af..5051bf899b 100644
--- a/crates/router/src/services/kafka/refund_event.rs
+++ b/crates/router/src/services/kafka/refund_event.rs
@@ -156,6 +156,8 @@ impl<'a> KafkaRefundEvent<'a> {
id,
merchant_reference_id,
connector_id,
+ processor_merchant_id,
+ created_by,
} = refund;
Self {
diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs
index 9bb00a8e33..b0241005dc 100644
--- a/crates/router/src/utils/user/sample_data.rs
+++ b/crates/router/src/utils/user/sample_data.rs
@@ -442,6 +442,8 @@ pub async fn generate_sample_data(
organization_id: org_id.clone(),
processor_refund_data: None,
processor_transaction_data,
+ processor_merchant_id: None,
+ created_by: None,
})
} else {
None
@@ -484,6 +486,8 @@ pub async fn generate_sample_data(
dispute_amount: MinorUnit::new(amount * 100),
organization_id: org_id.clone(),
dispute_currency: Some(payment_intent.currency.unwrap_or_default()),
+ processor_merchant_id: None,
+ created_by: None,
})
} else {
None
diff --git a/migrations/2026-02-22-130934_add_col_processor_merchant_id_and_created_by_for_refund/down.sql b/migrations/2026-02-22-130934_add_col_processor_merchant_id_and_created_by_for_refund/down.sql
new file mode 100644
index 0000000000..e907c40983
--- /dev/null
+++ b/migrations/2026-02-22-130934_add_col_processor_merchant_id_and_created_by_for_refund/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE refund DROP COLUMN IF EXISTS processor_merchant_id;
+ALTER TABLE refund DROP COLUMN IF EXISTS created_by;
diff --git a/migrations/2026-02-22-130934_add_col_processor_merchant_id_and_created_by_for_refund/up.sql b/migrations/2026-02-22-130934_add_col_processor_merchant_id_and_created_by_for_refund/up.sql
new file mode 100644
index 0000000000..56b929f3f4
--- /dev/null
+++ b/migrations/2026-02-22-130934_add_col_processor_merchant_id_and_created_by_for_refund/up.sql
@@ -0,0 +1,5 @@
+-- Your SQL goes here
+ALTER TABLE refund ADD COLUMN IF NOT EXISTS processor_merchant_id VARCHAR(64);
+ALTER TABLE refund ADD COLUMN IF NOT EXISTS created_by VARCHAR(255);
+-- This backfill should be executed after deployment is complete.
+UPDATE refund SET processor_merchant_id = merchant_id WHERE processor_merchant_id IS NULL;
diff --git a/migrations/2026-02-22-130936_add_col_processor_merchant_id_and_created_by_for_dispute/down.sql b/migrations/2026-02-22-130936_add_col_processor_merchant_id_and_created_by_for_dispute/down.sql
new file mode 100644
index 0000000000..db6db039c4
--- /dev/null
+++ b/migrations/2026-02-22-130936_add_col_processor_merchant_id_and_created_by_for_dispute/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE dispute DROP COLUMN IF EXISTS processor_merchant_id;
+ALTER TABLE dispute DROP COLUMN IF EXISTS created_by;
diff --git a/migrations/2026-02-22-130936_add_col_processor_merchant_id_and_created_by_for_dispute/up.sql b/migrations/2026-02-22-130936_add_col_processor_merchant_id_and_created_by_for_dispute/up.sql
new file mode 100644
index 0000000000..7fb4fe663c
--- /dev/null
+++ b/migrations/2026-02-22-130936_add_col_processor_merchant_id_and_created_by_for_dispute/up.sql
@@ -0,0 +1,5 @@
+-- Your SQL goes here
+ALTER TABLE dispute ADD COLUMN IF NOT EXISTS processor_merchant_id VARCHAR(64);
+ALTER TABLE dispute ADD COLUMN IF NOT EXISTS created_by VARCHAR(255);
+-- This backfill should be executed after deployment is complete.
+UPDATE dispute SET processor_merchant_id = merchant_id WHERE processor_merchant_id IS NULL;