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): refund workflows to use processor_merchant_id (#12223)

Ankit Kumar Gupta4a850f066008
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index def08b8eee..527f327947 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -1580,12 +1580,12 @@ pub async fn refund_retrieve_core_with_internal_reference_id(
force_sync: Option<bool>,
) -> RouterResult<diesel_refund::Refund> {
let db = &*state.store;
- let merchant_id = platform.get_processor().get_account().get_id();
+ let processor_merchant_id = platform.get_processor().get_account().get_id();
let refund = db
.find_refund_by_internal_reference_id_processor_merchant_id(
&refund_internal_request_id,
- merchant_id,
+ processor_merchant_id,
platform.get_processor().get_account().storage_scheme,
)
.await
@@ -1621,11 +1621,11 @@ pub async fn refund_retrieve_core_with_refund_id(
)> {
let refund_id = request.refund_id.clone();
let db = &*state.store;
- let merchant_id = platform.get_processor().get_account().get_id();
+ let processor_merchant_id = platform.get_processor().get_account().get_id();
let refund = db
.find_refund_by_processor_merchant_id_refund_id(
- merchant_id,
+ processor_merchant_id,
refund_id.as_str(),
platform.get_processor().get_account().storage_scheme,
)
@@ -2025,11 +2025,15 @@ pub async fn sync_refund_with_gateway_workflow(
.await?;
}
_ => {
+ let processor_merchant_id = response
+ .processor_merchant_id
+ .clone()
+ .unwrap_or(response.merchant_id);
_ = retry_refund_sync_task(
&*state.store,
state.superposition_service.as_ref(),
response.connector,
- response.merchant_id,
+ processor_merchant_id,
Some(refund_core.payment_id.clone()),
refund_tracker.to_owned(),
)
@@ -2047,7 +2051,7 @@ pub async fn retry_refund_sync_task(
db: &dyn db::StorageInterface,
superposition_client: &external_services::superposition::SuperpositionClient,
connector: String,
- merchant_id: common_utils::id_type::MerchantId,
+ processor_merchant_id: common_utils::id_type::MerchantId,
payment_id: Option<common_utils::id_type::PaymentId>,
pt: storage::ProcessTracker,
) -> Result<bool, sch_errors::ProcessTrackerError> {
@@ -2055,7 +2059,7 @@ pub async fn retry_refund_sync_task(
.parse::<common_enums::connector_enums::Connector>()
.map_err(|_| sch_errors::ProcessTrackerError::UnexpectedFlow)?;
let dimensions = crate::core::configs::dimension_state::Dimensions::new()
- .with_processor_merchant_id(merchant_id.into())
+ .with_processor_merchant_id(processor_merchant_id.into())
.with_connector(connector_enum);
let schedule_time = get_refund_sync_process_schedule_time(
db,
@@ -2116,25 +2120,26 @@ pub async fn trigger_refund_execute_workflow(
let processor_storage_scheme = platform.get_processor().get_account().storage_scheme;
+ let processor_merchant_id = refund_core
+ .processor_merchant_id
+ .as_ref()
+ .unwrap_or(&refund_core.merchant_id);
+
let refund = db
.find_refund_by_internal_reference_id_processor_merchant_id(
&refund_core.refund_internal_reference_id,
- &refund_core.merchant_id,
+ processor_merchant_id,
processor_storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)?;
- let refund_processor_merchant_id = refund
- .processor_merchant_id
- .clone()
- .unwrap_or_else(|| refund.merchant_id.clone());
match (&refund.sent_to_gateway, &refund.refund_status) {
(false, enums::RefundStatus::Pending) => {
let payment_attempt = db
.find_payment_attempt_by_connector_transaction_id_payment_id_processor_merchant_id(
&refund.connector_transaction_id,
&refund_core.payment_id,
- &refund_processor_merchant_id,
+ processor_merchant_id,
processor_storage_scheme,
platform.get_processor().get_key_store(),
)
@@ -2144,7 +2149,7 @@ pub async fn trigger_refund_execute_workflow(
let payment_intent = db
.find_payment_intent_by_payment_id_processor_merchant_id(
&payment_attempt.payment_id,
- &refund_processor_merchant_id,
+ processor_merchant_id,
platform.get_processor().get_key_store(),
processor_storage_scheme,
)
@@ -2231,8 +2236,12 @@ pub async fn add_refund_sync_task(
.parse::<common_enums::connector_enums::Connector>()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Invalid connector name in refund")?;
+ let processor_merchant_id = refund
+ .processor_merchant_id
+ .as_ref()
+ .unwrap_or(&refund.merchant_id);
let dimensions = crate::core::configs::dimension_state::Dimensions::new()
- .with_processor_merchant_id(refund.merchant_id.clone().into())
+ .with_processor_merchant_id(processor_merchant_id.clone().into())
.with_connector(connector_enum);
let schedule_time = get_refund_sync_process_schedule_time(
db,