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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(refunds): Enforce profile scoping (#15131)
Anurag Thakur9f47e0e004f5
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rsindex 9c9552fb3a..1407c2e03a 100644--- a/crates/router/src/core/refunds.rs+++ b/crates/router/src/core/refunds.rs@@ -403,7 +403,7 @@ async fn get_refund_payment_method_data(pub async fn refund_create_core(state: SessionState,platform: domain::Platform,- _profile_id: Option<common_utils::id_type::ProfileId>,+ profile_id: Option<common_utils::id_type::ProfileId>,req: refunds::RefundRequest,) -> RouterResponse<refunds::RefundResponse> {let db = &*state.store;@@ -421,6 +421,8 @@ pub async fn refund_create_core(.await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;+ core_utils::validate_profile_id_from_auth_layer(profile_id, &payment_intent)?;+utils::when(!(payment_intent.status == enums::IntentStatus::Succeeded|| payment_intent.status == enums::IntentStatus::PartiallyCaptured),diff --git a/crates/router/src/core/refunds_v2.rs b/crates/router/src/core/refunds_v2.rsindex a97ea03592..de6629cbe5 100644--- a/crates/router/src/core/refunds_v2.rs+++ b/crates/router/src/core/refunds_v2.rs@@ -44,6 +44,7 @@ use crate::{pub async fn refund_create_core(state: SessionState,platform: domain::Platform,+ profile: domain::Profile,req: refunds::RefundsCreateRequest,global_refund_id: id_type::GlobalRefundId,) -> errors::RouterResponse<refunds::RefundResponse> {@@ -59,6 +60,10 @@ pub async fn refund_create_core(.await.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;+ utils::when(payment_intent.profile_id != *profile.get_id(), || {+ Err(report!(errors::ApiErrorResponse::PaymentNotFound))+ })?;+utils::when(!(payment_intent.status == enums::IntentStatus::Succeeded|| payment_intent.status == enums::IntentStatus::PartiallyCaptured),diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rsindex f873c5ce0a..e44fdf871d 100644--- a/crates/router/src/routes/refunds.rs+++ b/crates/router/src/routes/refunds.rs@@ -168,7 +168,13 @@ pub async fn refunds_create(&req,internal_refund_create_payload,|state, auth: auth::AuthenticationData, req, _| {- refund_create_core(state, auth.platform, req.payload, global_refund_id.clone())+ refund_create_core(+ state,+ auth.platform,+ auth.profile,+ req.payload,+ global_refund_id.clone(),+ )},auth_type,locking_action,