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
feat(platform): enable profile_acquirer and relay for platform (#11973)
Ankit Kumar Gupta2348ebc8166d
diff --git a/crates/diesel_models/src/relay.rs b/crates/diesel_models/src/relay.rsindex 153e06ab17..0616e359a6 100644--- a/crates/diesel_models/src/relay.rs+++ b/crates/diesel_models/src/relay.rs@@ -33,6 +33,8 @@ pub struct Relay {#[serde(with = "common_utils::custom_serde::iso8601")]pub modified_at: PrimitiveDateTime,pub response_data: Option<pii::SecretSerdeValue>,+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,+ pub created_by: Option<String>,}#[derive(@@ -64,6 +66,8 @@ pub struct RelayNew {#[serde(with = "common_utils::custom_serde::iso8601")]pub modified_at: PrimitiveDateTime,pub response_data: Option<pii::SecretSerdeValue>,+ pub processor_merchant_id: Option<common_utils::id_type::MerchantId>,+ pub created_by: Option<String>,}#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rsindex f70e99322d..d1239ea990 100644--- a/crates/diesel_models/src/schema.rs+++ b/crates/diesel_models/src/schema.rs@@ -1673,6 +1673,10 @@ diesel::table! {created_at -> Timestamp,modified_at -> Timestamp,response_data -> Nullable<Jsonb>,+ #[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.rsindex 8ac0fd0428..451298730d 100644--- a/crates/diesel_models/src/schema_v2.rs+++ b/crates/diesel_models/src/schema_v2.rs@@ -1609,6 +1609,10 @@ diesel::table! {created_at -> Timestamp,modified_at -> Timestamp,response_data -> Nullable<Jsonb>,+ #[max_length = 64]+ processor_merchant_id -> Nullable<Varchar>,+ #[max_length = 255]+ created_by -> Nullable<Varchar>,}}diff --git a/crates/hyperswitch_domain_models/src/relay.rs b/crates/hyperswitch_domain_models/src/relay.rsindex 7b3bf40e4b..aa8c92c9e2 100644--- a/crates/hyperswitch_domain_models/src/relay.rs+++ b/crates/hyperswitch_domain_models/src/relay.rs@@ -5,7 +5,7 @@ use common_utils::{ext_traits::ValueExt,id_type::{self, GenerateId},pii,- types::{keymanager, MinorUnit},+ types::{keymanager, CreatedBy, MinorUnit},};use diesel_models::relay::RelayUpdateInternal;use error_stack::ResultExt;@@ -35,6 +35,8 @@ pub struct Relay {#[serde(with = "common_utils::custom_serde::iso8601")]pub modified_at: PrimitiveDateTime,pub response_data: Option<pii::SecretSerdeValue>,+ pub processor_merchant_id: Option<id_type::MerchantId>,+ pub created_by: Option<CreatedBy>,}impl Relay {@@ -42,6 +44,8 @@ impl Relay {relay_request: &api_models::relay::RelayRequest,merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,+ processor_merchant_id: Option<id_type::MerchantId>,+ created_by: Option<CreatedBy>,) -> Self {let relay_id = id_type::RelayId::generate();Self {@@ -59,6 +63,8 @@ impl Relay {created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),response_data: None,+ processor_merchant_id,+ created_by,}}}@@ -604,6 +610,8 @@ impl super::behaviour::Conversion for Relay {created_at: self.created_at,modified_at: self.modified_at,response_data: self.response_data,+ processor_merchant_id: self.processor_merchant_id,+ created_by: self.created_by.map(|created_by| created_by.to_string()),})}@@ -628,6 +636,10 @@ impl super::behaviour::Conversion for Relay {created_at: item.created_at,modified_at: item.modified_at,response_data: item.response_data,+ processor_merchant_id: item.processor_merchant_id,+ created_by: item+ .created_by+ .and_then(|created_by| created_by.parse::<CreatedBy>().ok()),})}@@ -655,6 +667,8 @@ impl super::behaviour::Conversion for Relay {created_at: self.created_at,modified_at: self.modified_at,response_data: self.response_data,+ processor_merchant_id: self.processor_merchant_id,+ created_by: self.created_by.map(|created_by| created_by.to_string()),})}}diff --git a/crates/router/src/core/profile_acquirer.rs b/crates/router/src/core/profile_acquirer.rsindex 2372f7e647..39e27f8703 100644--- a/crates/router/src/core/profile_acquirer.rs+++ b/crates/router/src/core/profile_acquirer.rs@@ -12,11 +12,11 @@ use crate::{pub async fn create_profile_acquirer(state: SessionState,request: profile_acquirer::ProfileAcquirerCreate,- platform: domain::Platform,+ processor: domain::Processor,) -> RouterResponse<profile_acquirer::ProfileAcquirerResponse> {let db = state.store.as_ref();let profile_acquirer_id = common_utils::generate_profile_acquirer_id_of_default_length();- let merchant_key_store = platform.get_processor().get_key_store();+ let merchant_key_store = processor.get_key_store();let mut business_profile = db.find_business_profile_by_profile_id(merchant_key_store, &request.profile_id)@@ -102,10 +102,10 @@ pub async fn update_profile_acquirer_config(profile_id: common_utils::id_type::ProfileId,profile_acquirer_id: common_utils::id_type::ProfileAcquirerId,request: profile_acquirer::ProfileAcquirerUpdate,- platform: domain::Platform,+ processor: domain::Processor,) -> RouterResponse<profile_acquirer::ProfileAcquirerResponse> {let db = state.store.as_ref();- let merchant_key_store = platform.get_processor().get_key_store();+ let merchant_key_store = processor.get_key_store();let mut business_profile = db.find_business_profile_by_profile_id(merchant_key_store, &profile_id)diff --git a/crates/router/src/core/relay.rs b/crates/router/src/core/relay.rsindex 87dd7649f8..2b95b217c3 100644--- a/crates/router/src/core/relay.rs+++ b/crates/router/src/core/relay.rs@@ -97,11 +97,13 @@ pub trait RelayInterface {relay_request: RelayRequestInner<Self>,merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,+ processor_merchant_id: Option<id_type::MerchantId>,+ created_by: Option<common_utils::types::CreatedBy>,) -> relay::Relay;async fn process_relay(state: &SessionState,- platform: domain::Platform,+ processor: domain::Processor,connector_account: domain::MerchantConnectorAccount,relay_record: &relay::Relay,) -> RouterResult<relay::RelayUpdate>;@@ -145,6 +147,8 @@ impl RelayInterface for RelayRefund {relay_request: RelayRequestInner<Self>,merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,+ processor_merchant_id: Option<id_type::MerchantId>,+ created_by: Option<common_utils::types::CreatedBy>,) -> relay::Relay {let relay_id = id_type::RelayId::generate();let relay_refund: relay::RelayRefundData = relay_request.data.into();@@ -163,18 +167,20 @@ impl RelayInterface for RelayRefund {created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),response_data: None,+ processor_merchant_id,+ created_by,}}async fn process_relay(state: &SessionState,- platform: domain::Platform,+ processor: domain::Processor,connector_account: domain::MerchantConnectorAccount,relay_record: &relay::Relay,) -> RouterResult<relay::RelayUpdate> {let connector_id = &relay_record.connector_id;- let merchant_id = platform.get_processor().get_account().get_id();+ let merchant_id = processor.get_account().get_id();let connector_name = &connector_account.get_connector_name_as_string();@@ -272,6 +278,8 @@ impl RelayInterface for RelayCapture {relay_request: RelayRequestInner<Self>,merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,+ processor_merchant_id: Option<id_type::MerchantId>,+ created_by: Option<common_utils::types::CreatedBy>,) -> relay::Relay {let relay_id = id_type::RelayId::generate();let relay_capture: relay::RelayCaptureData = relay_request.data.into();@@ -290,18 +298,20 @@ impl RelayInterface for RelayCapture {created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),response_data: None,+ processor_merchant_id,+ created_by,}}async fn process_relay(state: &SessionState,- platform: domain::Platform,+ processor: domain::Processor,connector_account: domain::MerchantConnectorAccount,relay_record: &relay::Relay,) -> RouterResult<relay::RelayUpdate> {let connector_id = &relay_record.connector_id;- let merchant_id = platform.get_processor().get_account().get_id();+ let merchant_id = processor.get_account().get_id();let connector_name = &connector_account.get_connector_name_as_string();@@ -402,6 +412,8 @@ impl RelayInterface for RelayIncrementalAuthorization {relay_request: RelayRequestInner<Self>,merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,+ processor_merchant_id: Option<id_type::MerchantId>,+ created_by: Option<common_utils::types::CreatedBy>,) -> relay::Relay {let relay_id = id_type::RelayId::generate();let relay_incremental_authorization: relay::RelayIncrementalAuthorizationData =@@ -423,18 +435,20 @@ impl RelayInterface for RelayIncrementalAuthorization {created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),response_data: None,+ processor_merchant_id,+ created_by,}}async fn process_relay(state: &SessionState,- platform: domain::Platform,+ processor: domain::Processor,connector_account: domain::MerchantConnectorAccount,relay_record: &relay::Relay,) -> RouterResult<relay::RelayUpdate> {let connector_id = &relay_record.connector_id;- let merchant_id = platform.get_processor().get_account().get_id();+ let merchant_id = processor.get_account().get_id();let connector_name = &connector_account.get_connector_name_as_string();@@ -533,6 +547,8 @@ impl RelayInterface for RelayVoid {relay_request: RelayRequestInner<Self>,merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,+ processor_merchant_id: Option<id_type::MerchantId>,+ created_by: Option<common_utils::types::CreatedBy>,) -> relay::Relay {let relay_id = id_type::RelayId::generate();let relay_void: relay::RelayVoidData = relay_request.data.into();@@ -551,18 +567,20 @@ impl RelayInterface for RelayVoid {created_at: common_utils::date_time::now(),modified_at: common_utils::date_time::now(),response_data: None,+ processor_merchant_id,+ created_by,}}async fn process_relay(state: &SessionState,- platform: domain::Platform,+ processor: domain::Processor,connector_account: domain::MerchantConnectorAccount,relay_record: &relay::Relay,) -> RouterResult<relay::RelayUpdate> {let connector_id = &relay_record.connector_id;- let merchant_id = platform.get_processor().get_account().get_id();+ let merchant_id = processor.get_account().get_id();let connector_name = &connector_account.get_connector_name_as_string();@@ -676,15 +694,20 @@ pub async fn relay<T: RelayInterface>(req: RelayRequestInner<T>,) -> RouterResponse<relay_api_models::RelayResponse> {let db = state.store.as_ref();- let merchant_id = platform.get_processor().get_account().get_id();+ let merchant_id = platform.get_provider().get_account().get_id();+ let processor_merchant_id = platform.get_processor().get_account().get_id();let connector_id = &req.connector_id;+ let created_by = platform+ .get_initiator()+ .and_then(|initiator| initiator.to_created_by());+let profile_id_from_auth_layer = profile_id_optional.get_required_value("ProfileId")?;let profile = db.find_business_profile_by_merchant_id_profile_id(platform.get_processor().get_key_store(),- merchant_id,+ processor_merchant_id,&profile_id_from_auth_layer,).await@@ -695,7 +718,7 @@ pub async fn relay<T: RelayInterface>(#[cfg(feature = "v1")]let connector_account = db.find_by_merchant_connector_account_merchant_id_merchant_connector_id(- merchant_id,+ processor_merchant_id,connector_id,platform.get_processor().get_key_store(),)@@ -717,7 +740,13 @@ pub async fn relay<T: RelayInterface>(T::validate_relay_request(&req.data)?;- let relay_domain = T::get_domain_models(req, merchant_id, profile.get_id());+ let relay_domain = T::get_domain_models(+ req,+ merchant_id,+ profile.get_id(),+ Some(processor_merchant_id.clone()),+ created_by,+ );let relay_record = db.insert_relay(platform.get_processor().get_key_store(), relay_domain)@@ -725,10 +754,14 @@ pub async fn relay<T: RelayInterface>(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to insert a relay record in db")?;- let relay_response =- T::process_relay(&state, platform.clone(), connector_account, &relay_record)- .await- .attach_printable("Failed to process relay")?;+ let relay_response = T::process_relay(+ &state,+ platform.get_processor().clone(),+ connector_account,+ &relay_record,+ )+ .await+ .attach_printable("Failed to process relay")?;let relay_update_record = db.update_relay(@@ -816,7 +849,7 @@ pub async fn relay_retrieve(if should_call_connector_for_relay_refund_status(&relay_record, req.force_sync) {let relay_response = sync_relay_refund_with_gateway(&state,- &platform,+ platform.get_processor(),&relay_record,connector_account,)@@ -838,7 +871,7 @@ pub async fn relay_retrieve(if should_call_connector_for_relay_capture_status(&relay_record, req.force_sync) {let relay_response = Box::pin(sync_relay_capture_with_gateway(&state,- &platform,+ platform.get_processor(),&relay_record,connector_account,))@@ -882,12 +915,11 @@ fn should_call_connector_for_relay_capture_status(relay: &relay::Relay, force_sypub async fn sync_relay_refund_with_gateway(state: &SessionState,- platform: &domain::Platform,+ processor: &domain::Processor,relay_record: &relay::Relay,connector_account: domain::MerchantConnectorAccount,) -> RouterResult<relay::RelayUpdate> {let connector_id = &relay_record.connector_id;- let merchant_id = platform.get_processor().get_account().get_id();let connector_name = &connector_account.get_connector_name_as_string();@@ -902,7 +934,7 @@ pub async fn sync_relay_refund_with_gateway(let router_data = utils::construct_relay_refund_router_data(state,- merchant_id,+ processor.get_account().get_id(),&connector_account,relay_record,)@@ -932,12 +964,12 @@ pub async fn sync_relay_refund_with_gateway(pub async fn sync_relay_capture_with_gateway(state: &SessionState,- platform: &domain::Platform,+ processor: &domain::Processor,relay_record: &relay::Relay,connector_account: domain::MerchantConnectorAccount,) -> RouterResult<relay::RelayUpdate> {let connector_id = &relay_record.connector_id;- let merchant_id = platform.get_processor().get_account().get_id();+ let merchant_id = processor.get_account().get_id();let connector_name = &connector_account.get_connector_name_as_string();diff --git a/crates/router/src/routes/profile_acquirer.rs b/crates/router/src/routes/profile_acquirer.rsindex c924038d85..23bebe5403 100644--- a/crates/router/src/routes/profile_acquirer.rs+++ b/crates/router/src/routes/profile_acquirer.rs@@ -24,16 +24,20 @@ pub async fn create_profile_acquirer(&req,payload,|state: super::SessionState, auth_data: auth::AuthenticationData, req, _| {- crate::core::profile_acquirer::create_profile_acquirer(state, req, auth_data.platform)+ crate::core::profile_acquirer::create_profile_acquirer(+ state,+ req,+ auth_data.platform.get_processor().clone(),+ )},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::ProfileAccountWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),@@ -69,17 +73,17 @@ pub async fn profile_acquirer_update(profile_id.clone(),profile_acquirer_id.clone(),req,- auth_data.platform,+ auth_data.platform.get_processor().clone(),)},auth::auth_type(&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),&auth::JWTAuth {permission: Permission::ProfileAccountWrite,- allow_connected: false,+ allow_connected: true,allow_platform: false,},req.headers(),diff --git a/crates/router/src/routes/relay.rs b/crates/router/src/routes/relay.rsindex 186258c47e..d0d544cd6f 100644--- a/crates/router/src/routes/relay.rs+++ b/crates/router/src/routes/relay.rs@@ -33,7 +33,7 @@ pub async fn relay()},&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),api_locking::LockAction::NotApplicable,@@ -71,7 +71,7 @@ pub async fn relay_retrieve()},&auth::HeaderAuth(auth::ApiKeyAuth {- allow_connected_scope_operation: false,+ allow_connected_scope_operation: true,allow_platform_self_operation: false,}),api_locking::LockAction::NotApplicable,diff --git a/migrations/2026-04-27-112659_add_processor_merchant_id_created_by_to_relay/down.sql b/migrations/2026-04-27-112659_add_processor_merchant_id_created_by_to_relay/down.sqlnew file mode 100644index 0000000000..855754cae8--- /dev/null+++ b/migrations/2026-04-27-112659_add_processor_merchant_id_created_by_to_relay/down.sql@@ -0,0 +1,3 @@+-- This file should undo anything in `up.sql`+ALTER TABLE relay DROP COLUMN IF EXISTS processor_merchant_id;+ALTER TABLE relay DROP COLUMN IF EXISTS created_by;diff --git a/migrations/2026-04-27-112659_add_processor_merchant_id_created_by_to_relay/up.sql b/migrations/2026-04-27-112659_add_processor_merchant_id_created_by_to_relay/up.sqlnew file mode 100644index 0000000000..a583976d55--- /dev/null+++ b/migrations/2026-04-27-112659_add_processor_merchant_id_created_by_to_relay/up.sql@@ -0,0 +1,6 @@+-- Your SQL goes here+ALTER TABLE relay ADD COLUMN IF NOT EXISTS processor_merchant_id VARCHAR(64);+ALTER TABLE relay ADD COLUMN IF NOT EXISTS created_by VARCHAR(255);++-- This backfill should be executed after deployment is complete.+UPDATE relay SET processor_merchant_id = merchant_id WHERE processor_merchant_id IS NULL;