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): implement processor and provider context to refunds core (#11611)

Ankit Kumar Gupta5343a79ac926
diff --git a/crates/diesel_models/src/refund.rs b/crates/diesel_models/src/refund.rs
index 47717a3065..c930a0b355 100644
--- a/crates/diesel_models/src/refund.rs
+++ b/crates/diesel_models/src/refund.rs
@@ -792,6 +792,7 @@ pub struct RefundCoreWorkflow {
pub refund_internal_reference_id: String,
pub connector_transaction_id: ConnectorTransactionId,
pub merchant_id: id_type::MerchantId,
+ pub processor_merchant_id: Option<id_type::MerchantId>,
pub payment_id: id_type::PaymentId,
pub processor_transaction_data: Option<String>,
}
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index fc7fca4809..9525cdba39 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -14281,12 +14281,12 @@ impl PaymentIntentStateMetadataExt {
pub async fn update_intent_state_metadata_for_refund(
self,
state: &SessionState,
- platform: &domain::Platform,
+ processor: &domain::Processor,
payment_intent: payments::PaymentIntent,
) -> CustomResult<(), errors::ApiErrorResponse> {
let db = state.store.clone();
- let key_store = platform.get_processor().get_key_store().clone();
- let merchant_account = platform.get_processor().get_account().clone();
+ let key_store = processor.get_key_store().clone();
+ let merchant_account = processor.get_account().clone();
// Update payment_intent for the refund's payment_id
// Calculate total_refunded_amount based on all succeeded refunds for that payment_id
let all_refunds_for_payment = db
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 94c65ed9c4..1f13c86c33 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -213,7 +213,7 @@ pub async fn trigger_refund_to_gateway(
let mut router_data = core_utils::construct_refund_router_data(
state,
&routed_through,
- platform,
+ platform.get_processor(),
(payment_attempt.get_total_amount(), currency),
payment_intent,
payment_attempt,
@@ -898,7 +898,7 @@ pub async fn sync_refund_with_gateway(
let mut router_data = core_utils::construct_refund_router_data::<api::RSync>(
state,
&connector_id,
- platform,
+ platform.get_processor(),
(payment_attempt.get_total_amount(), currency),
payment_intent,
payment_attempt,
@@ -999,7 +999,7 @@ pub async fn sync_refund_with_gateway(
Box::pin(execute_refund_sync_via_direct_with_ucs_shadow(
&updated_state,
&connector,
- platform,
+ platform.get_processor(),
router_data,
merchant_connector_account,
))
@@ -1096,13 +1096,13 @@ pub async fn sync_refund_with_gateway(
// If the original refund status was not success and upon a force sync it is now success, in that case we update the state metadata of the payment intent
tokio::spawn({
let state = state.clone();
- let platform = platform.clone();
+ let processor = platform.get_processor().clone();
let payment_intent = payment_intent.clone();
let state_metadata = payment_intent.state_metadata.clone().unwrap_or_default();
async move {
if let Err(err) = PaymentIntentStateMetadataExt::from(state_metadata)
- .update_intent_state_metadata_for_refund(&state, &platform, payment_intent)
+ .update_intent_state_metadata_for_refund(&state, &processor, payment_intent)
.await
{
logger::error!(
@@ -1189,7 +1189,7 @@ async fn execute_refund_sync_via_direct(
async fn execute_refund_sync_via_direct_with_ucs_shadow(
state: &SessionState,
connector: &api::ConnectorData,
- platform: &domain::Platform,
+ processor: &domain::Processor,
router_data: types::RefundSyncRouterData,
merchant_connector_account: MerchantConnectorAccountType,
) -> RouterResult<types::RefundSyncRouterData> {
@@ -1204,7 +1204,7 @@ async fn execute_refund_sync_via_direct_with_ucs_shadow(
// Execute UCS in shadow mode for comparison
let state = state.clone();
- let platform = platform.clone();
+ let processor = processor.clone();
let merchant_connector_account = merchant_connector_account.clone();
let direct_router_data_for_comparison = direct_result.as_ref().ok().cloned();
@@ -1214,7 +1214,7 @@ async fn execute_refund_sync_via_direct_with_ucs_shadow(
let ucs_result =
unified_connector_service::call_unified_connector_service_for_refund_sync(
&state,
- platform.get_processor(),
+ &processor,
router_data,
ExecutionMode::Shadow,
merchant_connector_account
@@ -1410,7 +1410,7 @@ pub async fn validate_and_create_refund(
internal_reference_id: utils::generate_id(consts::ID_LENGTH, "refid"),
external_reference_id: Some(refund_id.clone()),
payment_id: req.payment_id,
- merchant_id: platform.get_processor().get_account().get_id().clone(),
+ merchant_id: platform.get_provider().get_account().get_id().clone(),
connector_transaction_id,
connector,
refund_type: req.refund_type.unwrap_or_default().foreign_into(),
@@ -1432,11 +1432,7 @@ pub async fn validate_and_create_refund(
sent_to_gateway: Default::default(),
refund_arn: None,
updated_by: Default::default(),
- organization_id: platform
- .get_processor()
- .get_account()
- .organization_id
- .clone(),
+ organization_id: platform.get_processor().get_account().get_org_id().clone(),
processor_transaction_data,
processor_refund_data: None,
processor_merchant_id: Some(platform.get_processor().get_account().get_id().clone()),
@@ -1471,7 +1467,7 @@ pub async fn validate_and_create_refund(
if updated_refund.refund_status.is_success() {
tokio::spawn({
let state = state.clone();
- let platform = platform.clone();
+ let processor = platform.get_processor().clone();
let payment_intent = payment_intent.clone();
let state_metadata = payment_intent.state_metadata.clone().unwrap_or_default();
@@ -1479,7 +1475,7 @@ pub async fn validate_and_create_refund(
if let Err(err) = PaymentIntentStateMetadataExt::from(state_metadata)
.update_intent_state_metadata_for_refund(
&state,
- &platform,
+ &processor,
payment_intent,
)
.await
@@ -1535,7 +1531,7 @@ pub async fn validate_and_create_refund(
#[cfg(feature = "olap")]
pub async fn refund_list(
state: SessionState,
- platform: domain::Platform,
+ processor: domain::Processor,
profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
req: api_models::refunds::RefundListRequest,
) -> RouterResponse<api_models::refunds::RefundListResponse> {
@@ -1545,9 +1541,9 @@ pub async fn refund_list(
let refund_list = db
.filter_refund_by_constraints(
- platform.get_processor().get_account().get_id(),
+ processor.get_account().get_id(),
&(req.clone(), profile_id_list.clone()).try_into()?,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
limit,
offset,
)
@@ -1561,9 +1557,9 @@ pub async fn refund_list(
let total_count = db
.get_total_count_of_refunds(
- platform.get_processor().get_account().get_id(),
+ processor.get_account().get_id(),
&(req, profile_id_list).try_into()?,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
@@ -1581,15 +1577,15 @@ pub async fn refund_list(
#[cfg(feature = "olap")]
pub async fn refund_filter_list(
state: SessionState,
- platform: domain::Platform,
+ processor: domain::Processor,
req: common_utils::types::TimeRange,
) -> RouterResponse<api_models::refunds::RefundListMetaData> {
let db = state.store;
let filter_list = db
.filter_refund_by_meta_constraints(
- platform.get_processor().get_account().get_id(),
+ processor.get_account().get_id(),
&req,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)?;
@@ -1732,16 +1728,11 @@ pub async fn refund_manual_update(
#[cfg(feature = "olap")]
pub async fn get_filters_for_refunds(
state: SessionState,
- platform: domain::Platform,
+ processor: domain::Processor,
profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
) -> RouterResponse<api_models::refunds::RefundListFilters> {
let merchant_connector_accounts = if let services::ApplicationResponse::Json(data) =
- super::admin::list_payment_connectors(
- state,
- platform.get_processor().clone(),
- profile_id_list,
- )
- .await?
+ super::admin::list_payment_connectors(state, processor, profile_id_list).await?
{
data
} else {
@@ -1780,17 +1771,17 @@ pub async fn get_filters_for_refunds(
#[cfg(feature = "olap")]
pub async fn get_aggregates_for_refunds(
state: SessionState,
- platform: domain::Platform,
+ processor: domain::Processor,
profile_id_list: Option<Vec<common_utils::id_type::ProfileId>>,
time_range: common_utils::types::TimeRange,
) -> RouterResponse<api_models::refunds::RefundAggregateResponse> {
let db = state.store.as_ref();
let refund_status_with_count = db
.get_refund_status_with_count(
- platform.get_processor().get_account().get_id(),
+ processor.get_account().get_id(),
profile_id_list,
&time_range,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
@@ -2027,25 +2018,8 @@ pub async fn sync_refund_with_gateway_workflow(
)
})?;
- let key_store = state
- .store
- .get_merchant_key_store_by_merchant_id(
- &refund_core.merchant_id,
- &state.store.get_master_key().to_vec().into(),
- )
- .await?;
+ let platform = core_utils::build_platform_from_refund_core(state, &refund_core).await?;
- let merchant_account = state
- .store
- .find_merchant_account_by_merchant_id(&refund_core.merchant_id, &key_store)
- .await?;
- let platform = domain::Platform::new(
- merchant_account.clone(),
- key_store.clone(),
- merchant_account.clone(),
- key_store.clone(),
- None,
- );
let response = Box::pin(refund_retrieve_core_with_internal_reference_id(
state.clone(),
platform,
@@ -2143,48 +2117,31 @@ pub async fn trigger_refund_execute_workflow(
refund_tracker.tracking_data
)
})?;
- let key_store = state
- .store
- .get_merchant_key_store_by_merchant_id(
- &refund_core.merchant_id,
- &state.store.get_master_key().to_vec().into(),
- )
- .await?;
+ let platform = core_utils::build_platform_from_refund_core(state, &refund_core).await?;
- let merchant_account = db
- .find_merchant_account_by_merchant_id(&refund_core.merchant_id, &key_store)
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+ let processor_storage_scheme = platform.get_processor().get_account().storage_scheme;
- let platform = domain::Platform::new(
- merchant_account.clone(),
- key_store.clone(),
- merchant_account.clone(),
- key_store.clone(),
- None,
- );
let refund = db
.find_refund_by_internal_reference_id_merchant_id(
&refund_core.refund_internal_reference_id,
&refund_core.merchant_id,
- merchant_account.storage_scheme,
+ 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 merchant_account = db
- .find_merchant_account_by_merchant_id(&refund.merchant_id, &key_store)
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
-
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.merchant_id,
- merchant_account.storage_scheme,
- &key_store,
+ &refund_processor_merchant_id,
+ processor_storage_scheme,
+ platform.get_processor().get_key_store(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
@@ -2192,9 +2149,9 @@ 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.merchant_id,
- &key_store,
- merchant_account.storage_scheme,
+ &refund_processor_merchant_id,
+ platform.get_processor().get_key_store(),
+ processor_storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
@@ -2256,6 +2213,7 @@ pub fn refund_to_refund_core_workflow_model(
refund_internal_reference_id: refund.internal_reference_id.clone(),
connector_transaction_id: refund.connector_transaction_id.clone(),
merchant_id: refund.merchant_id.clone(),
+ processor_merchant_id: refund.processor_merchant_id.clone(),
payment_id: refund.payment_id.clone(),
processor_transaction_data: refund.processor_transaction_data.clone(),
}
diff --git a/crates/router/src/core/refunds_v2.rs b/crates/router/src/core/refunds_v2.rs
index 87fc645e71..df1a03e08f 100644
--- a/crates/router/src/core/refunds_v2.rs
+++ b/crates/router/src/core/refunds_v2.rs
@@ -117,7 +117,7 @@ pub async fn refund_create_core(
pub async fn trigger_refund_to_gateway(
state: &SessionState,
refund: &diesel_refund::Refund,
- platform: &domain::Platform,
+ processor: &domain::Processor,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
return_raw_connector_response: Option<bool>,
@@ -129,10 +129,10 @@ pub async fn trigger_refund_to_gateway(
let mca_id = payment_attempt.get_attempt_merchant_connector_account_id()?;
- let storage_scheme = platform.get_processor().get_account().storage_scheme;
+ let storage_scheme = processor.get_account().storage_scheme;
let mca = db
- .find_merchant_connector_account_by_id(&mca_id, platform.get_processor().get_key_store())
+ .find_merchant_connector_account_by_id(&mca_id, processor.get_key_store())
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to fetch merchant connector account")?;
@@ -159,7 +159,7 @@ pub async fn trigger_refund_to_gateway(
let mut router_data = core_utils::construct_refund_router_data(
state,
connector_enum,
- platform,
+ processor,
payment_intent,
payment_attempt,
refund,
@@ -168,7 +168,7 @@ pub async fn trigger_refund_to_gateway(
.await?;
let profile_id = payment_intent.profile_id.clone();
let default_gateway_context = gateway_context::RouterGatewayContext::direct(
- platform.get_processor().clone(),
+ processor.clone(),
merchant_connector_account,
payment_intent.merchant_id.clone(),
profile_id,
@@ -206,7 +206,7 @@ pub async fn trigger_refund_to_gateway(
state,
&connector,
&storage_scheme,
- platform,
+ processor,
&connector_response,
)
.await;
@@ -217,7 +217,7 @@ pub async fn trigger_refund_to_gateway(
.update_refund(
refund.to_owned(),
refund_update,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
@@ -243,7 +243,7 @@ pub async fn trigger_refund_to_gateway(
pub async fn internal_trigger_refund_to_gateway(
state: &SessionState,
refund: &diesel_refund::Refund,
- platform: &domain::Platform,
+ processor: &domain::Processor,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
merchant_connector_details: common_types::domain::MerchantConnectorAuthDetails,
@@ -252,7 +252,7 @@ pub async fn internal_trigger_refund_to_gateway(
diesel_refund::Refund,
Option<hyperswitch_masking::Secret<String>>,
)> {
- let storage_scheme = platform.get_processor().get_account().storage_scheme;
+ let storage_scheme = processor.get_account().storage_scheme;
let routed_through = payment_attempt
.connector
@@ -284,7 +284,7 @@ pub async fn internal_trigger_refund_to_gateway(
let mut router_data = core_utils::construct_refund_router_data(
state,
connector_enum,
- platform,
+ processor,
payment_intent,
payment_attempt,
refund,
@@ -294,7 +294,7 @@ pub async fn internal_trigger_refund_to_gateway(
let profile_id = payment_intent.profile_id.clone();
let default_gateway_context = gateway_context::RouterGatewayContext::direct(
- platform.get_processor().clone(),
+ processor.clone(),
merchant_connector_account,
payment_intent.merchant_id.clone(),
profile_id,
@@ -330,7 +330,7 @@ pub async fn internal_trigger_refund_to_gateway(
state,
&connector,
&storage_scheme,
- platform,
+ processor,
&connector_response,
)
.await;
@@ -341,7 +341,7 @@ pub async fn internal_trigger_refund_to_gateway(
.update_refund(
refund.to_owned(),
refund_update,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)
@@ -405,7 +405,7 @@ async fn get_refund_update_object(
state: &SessionState,
connector: &api::ConnectorData,
storage_scheme: &enums::MerchantStorageScheme,
- platform: &domain::Platform,
+ processor: &domain::Processor,
router_data_response: &Result<
RouterData<api::Execute, types::RefundsData, types::RefundsResponseData>,
error_stack::Report<errors::ConnectorError>,
@@ -425,7 +425,7 @@ async fn get_refund_update_object(
connector,
refund_response_data,
storage_scheme,
- platform,
+ processor,
)),
}
}
@@ -508,7 +508,7 @@ pub fn get_refund_update_for_refund_response_data(
connector: &api::ConnectorData,
refund_response_data: types::RefundsResponseData,
storage_scheme: &enums::MerchantStorageScheme,
- platform: &domain::Platform,
+ processor: &domain::Processor,
) -> diesel_refund::RefundUpdate {
// match on connector integrity checks
match router_data.integrity_check.clone() {
@@ -521,10 +521,7 @@ pub fn get_refund_update_for_refund_response_data(
1,
router_env::metric_attributes!(
("connector", connector.connector_name.to_string()),
- (
- "merchant_id",
- platform.get_processor().get_account().get_id().clone()
- ),
+ ("merchant_id", processor.get_account().get_id().clone()),
),
);
@@ -679,7 +676,7 @@ pub async fn refund_metadata_update_core(
#[instrument(skip_all)]
pub async fn refund_retrieve_core_with_refund_id(
state: SessionState,
- platform: domain::Platform,
+ processor: domain::Processor,
profile: domain::Profile,
request: refunds::RefundsRetrieveRequest,
) -> errors::RouterResponse<refunds::RefundResponse> {
@@ -687,16 +684,13 @@ pub async fn refund_retrieve_core_with_refund_id(
let db = &*state.store;
let profile_id = profile.get_id().to_owned();
let refund = db
- .find_refund_by_id(
- &refund_id,
- platform.get_processor().get_account().storage_scheme,
- )
+ .find_refund_by_id(&refund_id, processor.get_account().storage_scheme)
.await
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)?;
let (response, raw_connector_response) = Box::pin(refund_retrieve_core(
state.clone(),
- platform,
+ processor,
Some(profile_id),
request,
refund,
@@ -709,7 +703,7 @@ pub async fn refund_retrieve_core_with_refund_id(
#[instrument(skip_all)]
pub async fn refund_retrieve_core(
state: SessionState,
- platform: domain::Platform,
+ processor: domain::Processor,
profile_id: Option<id_type::ProfileId>,
request: refunds::RefundsRetrieveRequest,
refund: diesel_refund::Refund,
@@ -724,8 +718,8 @@ pub async fn refund_retrieve_core(
let payment_intent = db
.find_payment_intent_by_id(
payment_id,
- platform.get_processor().get_key_store(),
- platform.get_processor().get_account().storage_scheme,
+ processor.get_key_store(),
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
@@ -738,9 +732,9 @@ pub async fn refund_retrieve_core(
let payment_attempt = db
.find_payment_attempt_by_id(
- platform.get_processor().get_key_store(),
+ processor.get_key_store(),
&active_attempt_id,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
@@ -781,7 +775,7 @@ pub async fn refund_retrieve_core(
};
Box::pin(internal_sync_refund_with_gateway(
&state,
- &platform,
+ &processor,
&payment_attempt,
&payment_intent,
&refund,
@@ -792,7 +786,7 @@ pub async fn refund_retrieve_core(
} else {
Box::pin(sync_refund_with_gateway(
&state,
- &platform,
+ &processor,
&payment_attempt,
&payment_intent,
&refund,
@@ -832,7 +826,7 @@ fn should_call_refund(
#[instrument(skip_all)]
pub async fn sync_refund_with_gateway(
state: &SessionState,
- platform: &domain::Platform,
+ processor: &domain::Processor,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
refund: &diesel_refund::Refund,
@@ -856,7 +850,7 @@ pub async fn sync_refund_with_gateway(
let mca_id = payment_attempt.get_attempt_merchant_connector_account_id()?;
let mca = db
- .find_merchant_connector_account_by_id(&mca_id, platform.get_processor().get_key_store())
+ .find_merchant_connector_account_by_id(&mca_id, processor.get_key_store())
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to fetch merchant connector account")?;
@@ -869,7 +863,7 @@ pub async fn sync_refund_with_gateway(
let mut router_data = core_utils::construct_refund_router_data::<api::RSync>(
state,
connector_enum,
- platform,
+ processor,
payment_intent,
payment_attempt,
refund,
@@ -878,7 +872,7 @@ pub async fn sync_refund_with_gateway(
.await?;
let profile_id = payment_intent.profile_id.clone();
let default_gateway_context = gateway_context::RouterGatewayContext::direct(
- platform.get_processor().clone(),
+ processor.clone(),
merchant_connector_account,
payment_intent.merchant_id.clone(),
profile_id,
@@ -916,14 +910,14 @@ pub async fn sync_refund_with_gateway(
let connector_response = perform_integrity_check(connector_response);
let refund_update =
- build_refund_update_for_rsync(&connector, platform, connector_response.clone());
+ build_refund_update_for_rsync(&connector, processor, connector_response.clone());
let response = state
.store
.update_refund(
refund.to_owned(),
refund_update,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)
@@ -942,7 +936,7 @@ pub async fn sync_refund_with_gateway(
#[instrument(skip_all)]
pub async fn internal_sync_refund_with_gateway(
state: &SessionState,
- platform: &domain::Platform,
+ processor: &domain::Processor,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
refund: &diesel_refund::Refund,
@@ -969,7 +963,7 @@ pub async fn internal_sync_refund_with_gateway(
let mut router_data = core_utils::construct_refund_router_data::<api::RSync>(
state,
connector_enum,
- platform,
+ processor,
payment_intent,
payment_attempt,
refund,
@@ -978,7 +972,7 @@ pub async fn internal_sync_refund_with_gateway(
.await?;
let profile_id = payment_intent.profile_id.clone();
let default_gateway_context = gateway_context::RouterGatewayContext::direct(
- platform.get_processor().clone(),
+ processor.clone(),
merchant_connector_account,
payment_intent.merchant_id.clone(),
profile_id,
@@ -1014,14 +1008,14 @@ pub async fn internal_sync_refund_with_gateway(
let connector_response = perform_integrity_check(connector_response);
let refund_update =
- build_refund_update_for_rsync(&connector, platform, connector_response.clone());
+ build_refund_update_for_rsync(&connector, processor, connector_response.clone());
let response = state
.store
.update_refund(
refund.to_owned(),
refund_update,
- platform.get_processor().get_account().storage_scheme,
+ processor.get_account().storage_scheme,
)
.await
.to_not_found_response(errors::ApiErrorResponse::RefundNotFound)
@@ -1038,11 +1032,11 @@ pub async fn internal_sync_refund_with_gateway(
pub fn build_refund_update_for_rsync(
connector: &api::ConnectorData,
- platform: &domain::Platform,
+ processor: &domain::Processor,
router_data_response: RouterData<api::RSync, types::RefundsData, types::RefundsResponseData>,
) -> diesel_refund::RefundUpdate {
- let merchant_account = platform.get_processor().get_account();
- let storage_scheme = &platform.get_processor().get_account().storage_scheme;
+ let merchant_account = processor.get_account();
+ let storage_scheme = &processor.get_account().storage_scheme;
match router_data_response.response {
Err(error_message) => {
@@ -1283,7 +1277,7 @@ pub async fn validate_and_create_refund(
state,
refund.clone(),
refund_type,
- platform,
+ platform.get_processor(),
payment_attempt,
payment_intent,
merchant_connector_details,
@@ -1379,7 +1373,7 @@ pub async fn schedule_refund_execution(
state: &SessionState,
refund: diesel_refund::Refund,
refund_type: api_models::refunds::RefundType,
- platform: &domain::Platform,
+ processor: &domain::Processor,
payment_attempt: &storage::PaymentAttempt,
payment_intent: &storage::PaymentIntent,
merchant_connector_details: Option<common_types::domain::MerchantConnectorAuthDetails>,
@@ -1430,7 +1424,7 @@ pub async fn schedule_refund_execution(
Box::pin(internal_trigger_refund_to_gateway(
state,
&refund,
- platform,
+ processor,
payment_attempt,
payment_intent,
merchant_connector_details,
@@ -1441,7 +1435,7 @@ pub async fn schedule_refund_execution(
Box::pin(trigger_refund_to_gateway(
state,
&refund,
- platform,
+ processor,
payment_attempt,
payment_intent,
return_raw_connector_response,
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index b64793ac62..d37d442041 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -298,7 +298,7 @@ pub async fn construct_payout_router_data<'a, F>(
pub async fn construct_refund_router_data<'a, F>(
state: &'a SessionState,
connector_enum: Connector,
- platform: &domain::Platform,
+ processor: &domain::Processor,
payment_intent: &'a storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
refund: &'a diesel_refund::Refund,
@@ -320,7 +320,7 @@ pub async fn construct_refund_router_data<'a, F>(
merchant_connector_account,
) => Some(helpers::create_webhook_url(
&state.base_url.clone(),
- platform.get_processor().get_account().get_id(),
+ processor.get_account().get_id(),
merchant_connector_account.get_id().get_string_repr(),
)),
// TODO: Implement for connectors that require a webhook URL to be included in the request payload.
@@ -377,7 +377,7 @@ pub async fn construct_refund_router_data<'a, F>(
let router_data = types::RouterData {
flow: PhantomData,
- merchant_id: platform.get_processor().get_account().get_id().clone(),
+ merchant_id: processor.get_account().get_id().clone(),
customer_id,
tenant_id: state.tenant.tenant_id.clone(),
connector: connector_enum.to_string(),
@@ -476,7 +476,7 @@ pub async fn construct_refund_router_data<'a, F>(
pub async fn construct_refund_router_data<'a, F>(
state: &'a SessionState,
connector_id: &str,
- platform: &domain::Platform,
+ processor: &domain::Processor,
money: (MinorUnit, enums::Currency),
payment_intent: &'a storage::PaymentIntent,
payment_attempt: &storage::PaymentAttempt,
@@ -506,7 +506,7 @@ pub async fn construct_refund_router_data<'a, F>(
let webhook_url = Some(helpers::create_webhook_url(
&state.base_url.clone(),
- platform.get_processor().get_account().get_id(),
+ processor.get_account().get_id(),
merchant_connector_account_id_or_connector_name,
));
let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on();
@@ -575,7 +575,7 @@ pub async fn construct_refund_router_data<'a, F>(
let router_data = types::RouterData {
flow: PhantomData,
- merchant_id: platform.get_processor().get_account().get_id().clone(),
+ merchant_id: processor.get_account().get_id().clone(),
customer_id: payment_intent.customer_id.to_owned(),
tenant_id: state.tenant.tenant_id.clone(),
connector: connector_id.to_string(),
@@ -696,6 +696,59 @@ pub fn validate_id(id: String, key: &str) -> Result<String, errors::ApiErrorResp
}
}
+#[cfg(feature = "v1")]
+pub async fn build_platform_from_refund_core(
+ state: &SessionState,
+ refund_core: &diesel_refund::RefundCoreWorkflow,
+) -> RouterResult<domain::Platform> {
+ let provider_key_store = state
+ .store
+ .get_merchant_key_store_by_merchant_id(
+ &refund_core.merchant_id,
+ &state.store.get_master_key().to_vec().into(),
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
+ .attach_printable("Error while fetching the key store for provider merchant")?;
+
+ let provider_account = state
+ .store
+ .find_merchant_account_by_merchant_id(&refund_core.merchant_id, &provider_key_store)
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
+ .attach_printable("Error while fetching the merchant account for provider")?;
+
+ let processor_merchant_id = refund_core
+ .processor_merchant_id
+ .as_ref()
+ .unwrap_or(&refund_core.merchant_id);
+
+ let processor_key_store = state
+ .store
+ .get_merchant_key_store_by_merchant_id(
+ processor_merchant_id,
+ &state.store.get_master_key().to_vec().into(),
+ )
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
+ .attach_printable("Error while fetching the key store for processor merchant")?;
+
+ let processor_account = state
+ .store
+ .find_merchant_account_by_merchant_id(processor_merchant_id, &processor_key_store)
+ .await
+ .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
+ .attach_printable("Error while fetching the merchant account for processor")?;
+
+ Ok(domain::Platform::new(
+ provider_account,
+ provider_key_store,
+ processor_account,
+ processor_key_store,
+ None,
+ ))
+}
+
#[cfg(feature = "v1")]
pub fn get_split_refunds(
split_refund_input: refunds_transformers::SplitRefundInput,
diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rs
index 3e5275d5ce..86eaa2af77 100644
--- a/crates/router/src/core/webhooks/incoming.rs
+++ b/crates/router/src/core/webhooks/incoming.rs
@@ -2164,7 +2164,7 @@ async fn refunds_incoming_webhook_flow(
)
})?;
let state_task = state.clone();
- let platform_task = platform.clone();
+ let processor_task = platform.get_processor().clone();
let payment_intent_task = payment_intent.clone();
tokio::spawn(async move {
if let Err(err) = PaymentIntentStateMetadataExt::from(
@@ -2173,7 +2173,7 @@ async fn refunds_incoming_webhook_flow(
.clone()
.unwrap_or_default(),
)
- .update_intent_state_metadata_for_refund(&state_task, &platform_task, payment_intent_task)
+ .update_intent_state_metadata_for_refund(&state_task, &processor_task, payment_intent_task)
.await
{
tracing::error!(?err, "Failed to update intent state metadata for refund");
diff --git a/crates/router/src/routes/refunds.rs b/crates/router/src/routes/refunds.rs
index 40bd361932..7643c243e1 100644
--- a/crates/router/src/routes/refunds.rs
+++ b/crates/router/src/routes/refunds.rs
@@ -217,7 +217,12 @@ pub async fn refunds_retrieve(
&req,
refund_request,
|state, auth: auth::AuthenticationData, refund_request, _| {
- refund_retrieve_core_with_refund_id(state, auth.platform, auth.profile, refund_request)
+ refund_retrieve_core_with_refund_id(
+ state,
+ auth.platform.get_processor().clone(),
+ auth.profile,
+ refund_request,
+ )
},
auth::auth_type(
&auth::V2ApiKeyAuth {
@@ -281,7 +286,12 @@ pub async fn refunds_retrieve_with_gateway_creds(
&req,
refund_request,
|state, auth: auth::AuthenticationData, refund_request, _| {
- refund_retrieve_core_with_refund_id(state, auth.platform, auth.profile, refund_request)
+ refund_retrieve_core_with_refund_id(
+ state,
+ auth.platform.get_processor().clone(),
+ auth.profile,
+ refund_request,
+ )
},
auth_type,
api_locking::LockAction::NotApplicable,
@@ -419,7 +429,7 @@ pub async fn refunds_list(
&req,
payload.into_inner(),
|state, auth: auth::AuthenticationData, req, _| {
- refund_list(state, auth.platform, None, req)
+ refund_list(state, auth.platform.get_processor().clone(), None, req)
},
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth {
@@ -495,7 +505,7 @@ pub async fn refunds_list_profile(
|state, auth: auth::AuthenticationData, req, _| {
refund_list(
state,
- auth.platform,
+ auth.platform.get_processor().clone(),
auth.profile.map(|profile| vec![profile.get_id().clone()]),
req,
)
@@ -534,7 +544,7 @@ pub async fn refunds_filter_list(
&req,
payload.into_inner(),
|state, auth: auth::AuthenticationData, req, _| {
- refund_filter_list(state, auth.platform, req)
+ refund_filter_list(state, auth.platform.get_processor().clone(), req)
},
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth {
@@ -566,7 +576,7 @@ pub async fn get_refunds_filters(state: web::Data<AppState>, req: HttpRequest) -
&req,
(),
|state, auth: auth::AuthenticationData, _, _| {
- get_filters_for_refunds(state, auth.platform, None)
+ get_filters_for_refunds(state, auth.platform.get_processor().clone(), None)
},
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth {
@@ -603,7 +613,7 @@ pub async fn get_refunds_filters_profile(
|state, auth: auth::AuthenticationData, _, _| {
get_filters_for_refunds(
state,
- auth.platform,
+ auth.platform.get_processor().clone(),
auth.profile.map(|profile| vec![profile.get_id().clone()]),
)
},
@@ -639,7 +649,7 @@ pub async fn get_refunds_aggregates(
&req,
query_params,
|state, auth: auth::AuthenticationData, req, _| {
- get_aggregates_for_refunds(state, auth.platform, None, req)
+ get_aggregates_for_refunds(state, auth.platform.get_processor().clone(), None, req)
},
auth::auth_type(
&auth::HeaderAuth(auth::ApiKeyAuth {
@@ -698,7 +708,7 @@ pub async fn get_refunds_aggregate_profile(
|state, auth: auth::AuthenticationData, req, _| {
get_aggregates_for_refunds(
state,
- auth.platform,
+ auth.platform.get_processor().clone(),
auth.profile.map(|profile| vec![profile.get_id().clone()]),
req,
)