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
refactor(platform): refactor payment, dispute, and webhook functions to accept Processor instead of Platform (#11349)
Sandeep Kumar7f33f2e36512
diff --git a/crates/router/src/core/disputes.rs b/crates/router/src/core/disputes.rsindex a9e3f57ab7..1c754aab47 100644--- a/crates/router/src/core/disputes.rs+++ b/crates/router/src/core/disputes.rs@@ -804,10 +804,9 @@ pub async fn fetch_disputes_from_connector(req: FetchDisputesRequestData,) -> RouterResponse<FetchDisputesResponse> {let db = &*state.store;- let merchant_id = platform.get_processor().get_account().get_id();let merchant_connector_account = db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(- merchant_id,+ platform.get_processor().get_account().get_id(),&merchant_connector_id,platform.get_processor().get_key_store(),)@@ -859,7 +858,7 @@ pub async fn fetch_disputes_from_connector(let payment_attempt = webhooks::incoming::get_payment_attempt_from_object_reference_id(&state,dispute.object_reference_id.clone(),- &platform,+ platform.get_processor(),).await;@@ -867,7 +866,7 @@ pub async fn fetch_disputes_from_connector(let schedule_time = process_dispute::get_sync_process_schedule_time(&*state.store,&connector_name,- merchant_id,+ platform.get_processor().get_account().get_id(),0,).await@@ -878,7 +877,7 @@ pub async fn fetch_disputes_from_connector(db,&connector_name,dispute,- merchant_id.clone(),+ platform.get_processor().get_account().get_id().clone(),schedule_time,state.conf.application_source,)diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex bfc9bd9746..01b04e57ed 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -854,12 +854,9 @@ whereshould_continue_capture,);- let is_eligible_for_uas = helpers::is_merchant_eligible_authentication_service(- platform.get_processor().get_account().get_id(),- platform.get_processor().get_account().get_org_id(),- state,- )- .await?;+ let is_eligible_for_uas =+ helpers::is_merchant_eligible_authentication_service(platform.get_processor(), state)+ .await?;if <Req as Authenticate>::is_external_three_ds_data_passed_by_merchant(&req) {let maybe_connector_enum = match &connector_details {@@ -919,7 +916,7 @@ where&mut payment_data,&connector_details,&business_profile,- platform,+ platform.get_processor(),).await?;@@ -1104,7 +1101,7 @@ whereif is_eligible_for_uas {complete_confirmation_for_click_to_pay_if_required(state,- platform,+ platform.get_processor(),&payment_data,).await?;@@ -1312,7 +1309,7 @@ whereif is_eligible_for_uas {complete_confirmation_for_click_to_pay_if_required(state,- platform,+ platform.get_processor(),&payment_data,).await?;@@ -1325,7 +1322,7 @@ wherelet session_surcharge_details =call_surcharge_decision_management_for_session_flow(state,- platform,+ platform.get_processor(),&business_profile,payment_data.get_payment_attempt(),payment_data.get_payment_intent(),@@ -2345,7 +2342,7 @@ fn get_connector_data_with_routing_decision(#[instrument(skip_all)]pub async fn call_surcharge_decision_management_for_session_flow(_state: &SessionState,- _platform: &domain::Platform,+ _processor: &domain::Processor,_payment_attempt: &storage::PaymentAttempt,_payment_intent: &storage::PaymentIntent,_billing_address: Option<hyperswitch_domain_models::address::Address>,@@ -2358,7 +2355,7 @@ pub async fn call_surcharge_decision_management_for_session_flow(#[instrument(skip_all)]pub async fn call_surcharge_decision_management_for_session_flow(state: &SessionState,- platform: &domain::Platform,+ processor: &domain::Processor,_business_profile: &domain::Profile,payment_attempt: &storage::PaymentAttempt,payment_intent: &storage::PaymentIntent,@@ -2385,8 +2382,7 @@ pub async fn call_surcharge_decision_management_for_session_flow(.collect();#[cfg(feature = "v1")]- let algorithm_ref: api::routing::RoutingAlgorithmRef = platform- .get_processor()+ let algorithm_ref: api::routing::RoutingAlgorithmRef = processor.get_account().routing_algorithm.clone()@@ -7395,7 +7391,7 @@ where#[cfg(feature = "v1")]async fn complete_confirmation_for_click_to_pay_if_required<F, D>(state: &SessionState,- platform: &domain::Platform,+ processor: &domain::Processor,payment_data: &D,) -> RouterResult<()>where@@ -7422,8 +7418,8 @@ where.attach_printable("Failed to get authentication connector id from authentication table",)?;- let key_store = platform.get_processor().get_key_store();- let merchant_id = platform.get_processor().get_account().get_id();+ let key_store = processor.get_key_store();+ let merchant_id = processor.get_account().get_id();let connector_mca = state.store@@ -11086,100 +11082,97 @@ pub async fn payment_external_authentication<F: Clone + Sync>(.get_required_value("authentication_connector_details").attach_printable("authentication_connector_details not configured by the merchant")?;- let authentication_response = if helpers::is_merchant_eligible_authentication_service(- platform.get_processor().get_account().get_id(),- platform.get_processor().get_account().get_org_id(),- &state,- )- .await?- {- let routing_region = uas_utils::fetch_routing_region_for_uas(- &state,- processor_merchant_id.clone(),- platform- .get_processor()- .get_account()- .organization_id- .clone(),- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed to fetch routing path")?;- let auth_response =- <ExternalAuthentication as UnifiedAuthenticationService>::authentication(+ let authentication_response =+ if helpers::is_merchant_eligible_authentication_service(platform.get_processor(), &state)+ .await?+ {+ let routing_region = uas_utils::fetch_routing_region_for_uas(&state,- &business_profile,- &payment_method_details.1,+ processor_merchant_id.clone(),+ platform+ .get_processor()+ .get_account()+ .organization_id+ .clone(),+ )+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to fetch routing path")?;+ let auth_response =+ <ExternalAuthentication as UnifiedAuthenticationService>::authentication(+ &state,+ &business_profile,+ &payment_method_details.1,+ browser_info,+ Some(amount),+ Some(currency),+ authentication::MessageCategory::Payment,+ req.device_channel,+ authentication.clone(),+ return_url,+ req.sdk_information.clone(),+ req.threeds_method_comp_ind,+ optional_customer.and_then(|customer| customer.email.map(pii::Email::from)),+ webhook_url,+ &merchant_connector_account,+ &authentication_connector,+ Some(payment_intent.payment_id),+ authentication.force_3ds_challenge,+ authentication.psd2_sca_exemption_type,+ Some(routing_region),+ )+ .await?;+ let authentication = Box::pin(external_authentication_update_trackers(+ &state,+ auth_response,+ authentication.clone(),+ None,+ platform.get_processor().get_key_store(),+ None,+ None,+ None,+ None,+ req.sdk_information+ .and_then(|sdk_information| sdk_information.device_details),+ None,+ None,+ ))+ .await?;+ authentication::AuthenticationResponse::try_from(authentication)?+ } else {+ Box::pin(authentication_core::perform_authentication(+ &state,+ business_profile.merchant_id,+ authentication_connector,+ payment_method_details.0,+ payment_method_details.1,+ billing_address+ .as_ref()+ .map(|address| address.into())+ .ok_or(errors::ApiErrorResponse::MissingRequiredField {+ field_name: "billing_address",+ })?,+ shipping_address.as_ref().map(|address| address.into()),browser_info,+ merchant_connector_account,Some(amount),Some(currency),authentication::MessageCategory::Payment,req.device_channel,- authentication.clone(),+ authentication,return_url,- req.sdk_information.clone(),+ req.sdk_information,req.threeds_method_comp_ind,optional_customer.and_then(|customer| customer.email.map(pii::Email::from)),webhook_url,- &merchant_connector_account,- &authentication_connector,- Some(payment_intent.payment_id),- authentication.force_3ds_challenge,- authentication.psd2_sca_exemption_type,- Some(routing_region),- )- .await?;- let authentication = Box::pin(external_authentication_update_trackers(- &state,- auth_response,- authentication.clone(),- None,- platform.get_processor().get_key_store(),- None,- None,- None,- None,- req.sdk_information- .and_then(|sdk_information| sdk_information.device_details),- None,- None,- ))- .await?;- authentication::AuthenticationResponse::try_from(authentication)?- } else {- Box::pin(authentication_core::perform_authentication(- &state,- business_profile.merchant_id,- authentication_connector,- payment_method_details.0,- payment_method_details.1,- billing_address- .as_ref()- .map(|address| address.into())- .ok_or(errors::ApiErrorResponse::MissingRequiredField {- field_name: "billing_address",- })?,- shipping_address.as_ref().map(|address| address.into()),- browser_info,- merchant_connector_account,- Some(amount),- Some(currency),- authentication::MessageCategory::Payment,- req.device_channel,- authentication,- return_url,- req.sdk_information,- req.threeds_method_comp_ind,- optional_customer.and_then(|customer| customer.email.map(pii::Email::from)),- webhook_url,- authentication_details.three_ds_requestor_url.clone(),- payment_intent.psd2_sca_exemption_type,- payment_intent.payment_id,- payment_intent.force_3ds_challenge_trigger.unwrap_or(false),- platform.get_processor().get_key_store(),- ))- .await?- };+ authentication_details.three_ds_requestor_url.clone(),+ payment_intent.psd2_sca_exemption_type,+ payment_intent.payment_id,+ payment_intent.force_3ds_challenge_trigger.unwrap_or(false),+ platform.get_processor().get_key_store(),+ ))+ .await?+ };Ok(services::ApplicationResponse::Json(api_models::payments::PaymentsExternalAuthenticationResponse {transaction_status: authentication_response.trans_status,diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 09b2c4e51b..f99844b1d6 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -8503,12 +8503,14 @@ pub fn validate_platform_request_for_marketplace(////// This ensures parent (org) rules take precedence over child (merchant) configurationspub async fn is_merchant_eligible_authentication_service(- merchant_id: &id_type::MerchantId,- org_id: &id_type::OrganizationId,+ processor: &domain::Processor,state: &SessionState,) -> RouterResult<bool> {let db = &*state.store;- let org_key = org_id.get_authentication_service_eligible_key();+ let org_key = processor+ .get_account()+ .get_org_id()+ .get_authentication_service_eligible_key();let org_eligible = db.find_config_by_key(&org_key).await@@ -8520,7 +8522,10 @@ pub async fn is_merchant_eligible_authentication_service(Ok(org_eligible.async_unwrap_or_else(|| async {- let merchant_key = merchant_id.get_authentication_service_eligible_key();+ let merchant_key = processor+ .get_account()+ .get_id()+ .get_authentication_service_eligible_key();db.find_config_by_key(&merchant_key).await.inspect_err(|error| {diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rsindex 763a6a4f0a..7155aebe2e 100644--- a/crates/router/src/core/payments/operations.rs+++ b/crates/router/src/core/payments/operations.rs@@ -434,7 +434,7 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {_payment_data: &mut D,_connector_call_type: &ConnectorCallType,_business_profile: &domain::Profile,- _platform: &domain::Platform,+ _processor: &domain::Processor,) -> CustomResult<(), errors::ApiErrorResponse> {Ok(())}diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex d05846a850..e5b7961495 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -742,7 +742,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forpayment_data: &mut PaymentData<F>,_connector_call_type: &ConnectorCallType,business_profile: &domain::Profile,- platform: &domain::Platform,+ processor: &domain::Processor,) -> CustomResult<(), errors::ApiErrorResponse> {let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled();let skip_external_tax_calculation = payment_data@@ -762,7 +762,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.find_by_merchant_connector_account_merchant_id_merchant_connector_id(&business_profile.merchant_id,merchant_connector_id,- platform.get_processor().get_key_store(),+ processor.get_key_store(),).await.to_not_found_response(@@ -786,7 +786,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forlet router_data = core_utils::construct_payments_dynamic_tax_calculation_router_data(state,- platform,+ processor,payment_data,&mca,)diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rsindex 48f3f511cc..d3a1f0650f 100644--- a/crates/router/src/core/payments/operations/payment_update.rs+++ b/crates/router/src/core/payments/operations/payment_update.rs@@ -643,7 +643,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forpayment_data: &mut PaymentData<F>,_connector_call_type: &ConnectorCallType,business_profile: &domain::Profile,- platform: &domain::Platform,+ processor: &domain::Processor,) -> CustomResult<(), errors::ApiErrorResponse> {let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled();let skip_external_tax_calculation = payment_data@@ -663,7 +663,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.find_by_merchant_connector_account_merchant_id_merchant_connector_id(&business_profile.merchant_id,merchant_connector_id,- platform.get_processor().get_key_store(),+ processor.get_key_store(),).await.to_not_found_response(@@ -687,7 +687,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> forlet router_data = core_utils::construct_payments_dynamic_tax_calculation_router_data(state,- platform,+ processor,payment_data,&mca,)diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rsindex 07c13c02aa..3cf43ed3fa 100644--- a/crates/router/src/core/payments/operations/tax_calculation.rs+++ b/crates/router/src/core/payments/operations/tax_calculation.rs@@ -240,7 +240,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsDynamicTaxCalculationRequestpayment_data: &mut PaymentData<F>,_connector_call_type: &ConnectorCallType,business_profile: &domain::Profile,- platform: &domain::Platform,+ processor: &domain::Processor,) -> errors::CustomResult<(), errors::ApiErrorResponse> {let is_tax_connector_enabled = business_profile.get_is_tax_connector_enabled();let skip_external_tax_calculation = payment_data@@ -260,7 +260,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsDynamicTaxCalculationRequest.find_by_merchant_connector_account_merchant_id_merchant_connector_id(&business_profile.merchant_id,merchant_connector_id,- platform.get_processor().get_key_store(),+ processor.get_key_store(),).await.to_not_found_response(@@ -284,7 +284,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsDynamicTaxCalculationRequestlet router_data = core_utils::construct_payments_dynamic_tax_calculation_router_data(state,- platform,+ processor,payment_data,&mca,)diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rsindex ef65179091..c3f6ea641d 100644--- a/crates/router/src/core/utils.rs+++ b/crates/router/src/core/utils.rs@@ -1506,7 +1506,7 @@ pub async fn construct_dispute_sync_router_data<'a>(#[cfg(feature = "v2")]pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>(state: &SessionState,- platform: &domain::Platform,+ processor: &domain::Processor,payment_data: &mut PaymentData<F>,merchant_connector_account: &MerchantConnectorAccount,) -> RouterResult<types::PaymentsTaxCalculationRouterData> {@@ -1516,7 +1516,7 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>(#[cfg(feature = "v1")]pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>(state: &SessionState,- platform: &domain::Platform,+ processor: &domain::Processor,payment_data: &mut PaymentData<F>,merchant_connector_account: &MerchantConnectorAccount,) -> RouterResult<types::PaymentsTaxCalculationRouterData> {@@ -1564,7 +1564,7 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>(let router_data = types::RouterData {flow: PhantomData,- merchant_id: platform.get_processor().get_account().get_id().to_owned(),+ merchant_id: processor.get_account().get_id().to_owned(),customer_id: None,connector_customer: None,connector: merchant_connector_account.connector_name.clone(),@@ -1599,7 +1599,7 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>(response: Err(ErrorResponse::default()),connector_request_reference_id: get_connector_request_reference_id(&state.conf,- platform.get_processor(),+ processor,payment_intent,payment_attempt,&merchant_connector_account.connector_name,diff --git a/crates/router/src/core/webhooks/incoming.rs b/crates/router/src/core/webhooks/incoming.rsindex 9557140c15..0055622e63 100644--- a/crates/router/src/core/webhooks/incoming.rs+++ b/crates/router/src/core/webhooks/incoming.rs@@ -504,8 +504,7 @@ async fn fetch_three_ds_execution_path(.attach_printable_lazy(|| format!("unable to parse connector name {connector_name:?}"))?;let is_merchant_eligible_for_uas =payments::helpers::is_merchant_eligible_authentication_service(- &platform.get_processor().get_account().get_id().clone(),- &platform.get_processor().get_account().get_org_id().clone(),+ platform.get_processor(),state,).await?;@@ -730,7 +729,7 @@ async fn process_non_ucs_webhook<'a>(let payment_attempt = get_payment_attempt_from_object_reference_id(state,webhooks::ObjectReferenceId::PaymentId(id.clone()),- platform,+ platform.get_processor(),).await?;Some(WebhookResourceData::Payment { payment_attempt })@@ -1447,7 +1446,7 @@ async fn payments_incoming_webhook_flow(get_payment_attempt_from_object_reference_id(&state,webhook_details.object_reference_id.clone(),- &platform,+ platform.get_processor(),).await?};@@ -2244,34 +2243,34 @@ async fn relay_incoming_webhook_flow(pub async fn get_payment_attempt_from_object_reference_id(state: &SessionState,object_reference_id: webhooks::ObjectReferenceId,- platform: &domain::Platform,+ processor: &domain::Processor,) -> CustomResult<PaymentAttempt, errors::ApiErrorResponse> {let db = &*state.store;match object_reference_id {api::ObjectReferenceId::PaymentId(api::PaymentIdType::ConnectorTransactionId(ref id)) => db.find_payment_attempt_by_processor_merchant_id_connector_txn_id(- platform.get_processor().get_account().get_id(),+ processor.get_account().get_id(),id,- platform.get_processor().get_account().storage_scheme,- platform.get_processor().get_key_store(),+ processor.get_account().storage_scheme,+ processor.get_key_store(),).await.to_not_found_response(errors::ApiErrorResponse::WebhookResourceNotFound),api::ObjectReferenceId::PaymentId(api::PaymentIdType::PaymentAttemptId(ref id)) => db.find_payment_attempt_by_attempt_id_processor_merchant_id(id,- platform.get_processor().get_account().get_id(),- platform.get_processor().get_account().storage_scheme,- platform.get_processor().get_key_store(),+ processor.get_account().get_id(),+ processor.get_account().storage_scheme,+ processor.get_key_store(),).await.to_not_found_response(errors::ApiErrorResponse::WebhookResourceNotFound),api::ObjectReferenceId::PaymentId(api::PaymentIdType::PreprocessingId(ref id)) => db.find_payment_attempt_by_preprocessing_id_processor_merchant_id(id,- platform.get_processor().get_account().get_id(),- platform.get_processor().get_account().storage_scheme,- platform.get_processor().get_key_store(),+ processor.get_account().get_id(),+ processor.get_account().storage_scheme,+ processor.get_key_store(),).await.to_not_found_response(errors::ApiErrorResponse::WebhookResourceNotFound),@@ -2659,8 +2658,12 @@ async fn frm_incoming_webhook_flow(business_profile: domain::Profile,) -> CustomResult<WebhookResponseTracker, errors::ApiErrorResponse> {if source_verified {- let payment_attempt =- get_payment_attempt_from_object_reference_id(&state, object_ref_id, &platform).await?;+ let payment_attempt = get_payment_attempt_from_object_reference_id(+ &state,+ object_ref_id,+ platform.get_processor(),+ )+ .await?;let payment_response = match event_type {webhooks::IncomingWebhookEvent::FrmApproved => {Box::pin(payments::payments_core::<@@ -2777,7 +2780,7 @@ async fn disputes_incoming_webhook_flow(get_payment_attempt_from_object_reference_id(&state,webhook_details.object_reference_id,- &platform,+ platform.get_processor(),).await?}@@ -2898,7 +2901,7 @@ async fn bank_transfer_webhook_flow(let payment_attempt = get_payment_attempt_from_object_reference_id(&state,webhook_details.object_reference_id,- &platform,+ platform.get_processor(),).await?;let payment_id = payment_attempt.payment_id;@@ -3206,8 +3209,12 @@ async fn update_connector_mandate_details(if webhook_connector_mandate_details.is_some()|| webhook_connector_network_transaction_id.is_some(){- let payment_attempt =- get_payment_attempt_from_object_reference_id(state, object_ref_id, platform).await?;+ let payment_attempt = get_payment_attempt_from_object_reference_id(+ state,+ object_ref_id,+ platform.get_processor(),+ )+ .await?;if let Some(ref payment_method_id) = payment_attempt.payment_method_id {let payment_method_info = state.storediff --git a/crates/router/src/workflows/process_dispute.rs b/crates/router/src/workflows/process_dispute.rsindex 748e727614..ffe48e4dd8 100644--- a/crates/router/src/workflows/process_dispute.rs+++ b/crates/router/src/workflows/process_dispute.rs@@ -64,7 +64,7 @@ impl ProcessTrackerWorkflow<SessionState> for ProcessDisputeWorkflow {let payment_attempt = get_payment_attempt_from_object_reference_id(state,tracking_data.dispute_payload.object_reference_id.clone(),- &platform,+ platform.get_processor(),).await?;