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): add processor_merchant_id and initiator fields to payments response (#10804)

Sandeep Kumara9f1280427fb
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 8fd2cbdbcc..6c2a6428f4 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -20259,6 +20259,14 @@
}
}
},
+ "Initiator": {
+ "type": "string",
+ "description": "Represents the initiator context in platform-connected setups\nUsed in payment/refund/dispute responses to indicate who initiated the operation\nNone indicates a standard merchant flow / JWT flow / Admin flow or insufficient information",
+ "enum": [
+ "platform",
+ "connected"
+ ]
+ },
"IntentStatus": {
"type": "string",
"description": "Represents the overall status of a payment intent.\nThe status transitions through various states depending on the payment method, confirmation, capture method, and any subsequent actions (like customer authentication or manual capture).",
@@ -27971,6 +27979,7 @@
"amount",
"net_amount",
"amount_capturable",
+ "processor_merchant_id",
"currency",
"payment_method",
"attempt_count"
@@ -28030,6 +28039,20 @@
"example": 6540,
"nullable": true
},
+ "processor_merchant_id": {
+ "type": "string",
+ "description": "The identifier for the processor merchant account. In platform-connected setups,\nthis is the connected merchant ID. For standard merchants, this is same as merchant_id.",
+ "example": "merchant_1689512302",
+ "maxLength": 255
+ },
+ "initiator": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/Initiator"
+ }
+ ],
+ "nullable": true
+ },
"connector": {
"type": "string",
"description": "The name of the payment connector (e.g., 'stripe', 'adyen') that processed or is processing this payment.",
@@ -29536,6 +29559,7 @@
"amount",
"net_amount",
"amount_capturable",
+ "processor_merchant_id",
"currency",
"payment_method",
"attempt_count"
@@ -29595,6 +29619,20 @@
"example": 6540,
"nullable": true
},
+ "processor_merchant_id": {
+ "type": "string",
+ "description": "The identifier for the processor merchant account. In platform-connected setups,\nthis is the connected merchant ID. For standard merchants, this is same as merchant_id.",
+ "example": "merchant_1689512302",
+ "maxLength": 255
+ },
+ "initiator": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/Initiator"
+ }
+ ],
+ "nullable": true
+ },
"connector": {
"type": "string",
"description": "The name of the payment connector (e.g., 'stripe', 'adyen') that processed or is processing this payment.",
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index c4dab932c9..e808c04fae 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -13916,6 +13916,14 @@
}
}
},
+ "Initiator": {
+ "type": "string",
+ "description": "Represents the initiator context in platform-connected setups\nUsed in payment/refund/dispute responses to indicate who initiated the operation\nNone indicates a standard merchant flow / JWT flow / Admin flow or insufficient information",
+ "enum": [
+ "platform",
+ "connected"
+ ]
+ },
"IntentStatus": {
"type": "string",
"description": "Represents the overall status of a payment intent.\nThe status transitions through various states depending on the payment method, confirmation, capture method, and any subsequent actions (like customer authentication or manual capture).",
@@ -21467,6 +21475,7 @@
"status",
"amount",
"customer_id",
+ "processor_merchant_id",
"created",
"modified_at"
],
@@ -21491,6 +21500,20 @@
"maxLength": 64,
"minLength": 32
},
+ "processor_merchant_id": {
+ "type": "string",
+ "description": "The identifier for the processor merchant account. In platform-connected setups,\nthis is the connected merchant ID. For standard merchants, this is same as merchant_id.",
+ "example": "merchant_1689512302",
+ "maxLength": 255
+ },
+ "initiator": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/Initiator"
+ }
+ ],
+ "nullable": true
+ },
"connector": {
"type": "string",
"description": "The connector used for the payment",
diff --git a/crates/api_models/src/lib.rs b/crates/api_models/src/lib.rs
index 50e08674d4..c5ab2d5e75 100644
--- a/crates/api_models/src/lib.rs
+++ b/crates/api_models/src/lib.rs
@@ -32,6 +32,7 @@ pub mod payment_methods;
pub mod payments;
#[cfg(feature = "payouts")]
pub mod payouts;
+pub mod platform;
pub mod pm_auth;
pub mod poll;
pub mod process_tracker;
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index d0a66e271e..fb5b54d0fb 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -82,6 +82,7 @@ use crate::{
CardTokenAdditionalData, GiftCardAdditionalData, UpiAdditionalData,
WalletAdditionalDataForCard,
},
+ platform,
};
#[cfg(feature = "v1")]
use crate::{disputes, refunds, ValidateFieldAndGet};
@@ -7069,6 +7070,20 @@ pub struct PaymentsResponse {
#[smithy(value_type = "Option<i64>")]
pub amount_received: Option<MinorUnit>,
+ /// The identifier for the processor merchant account. In platform-connected setups,
+ /// this is the connected merchant ID. For standard merchants, this is same as merchant_id.
+ #[schema(max_length = 255, example = "merchant_1689512302", value_type = String)]
+ #[smithy(value_type = "String")]
+ pub processor_merchant_id: id_type::MerchantId,
+
+ /// Indicates who initiated the payment in platform-connected setups.
+ /// - Some(Platform): Platform merchant initiated payment on behalf of connected merchant
+ /// - Some(Connected): Connected merchant initiated payment directly in a platform setup
+ /// - None: Standard merchant flow, JWT/Admin initiator, or insufficient information
+ #[schema(value_type = Option<Initiator>, example = "platform")]
+ #[smithy(value_type = "Option<Initiator>")]
+ pub initiator: Option<platform::Initiator>,
+
/// The name of the payment connector (e.g., 'stripe', 'adyen') that processed or is processing this payment.
#[schema(example = "stripe")]
#[smithy(value_type = "Option<String>")]
@@ -8254,6 +8269,18 @@ pub struct PaymentsResponse {
)]
pub customer_id: Option<id_type::GlobalCustomerId>,
+ /// The identifier for the processor merchant account. In platform-connected setups,
+ /// this is the connected merchant ID. For standard merchants, this is same as merchant_id.
+ #[schema(max_length = 255, example = "merchant_1689512302", value_type = String)]
+ pub processor_merchant_id: id_type::MerchantId,
+
+ /// Indicates who initiated the payment in platform-connected setups.
+ /// - Some(Platform): Platform merchant initiated payment on behalf of connected merchant
+ /// - Some(Connected): Connected merchant initiated payment directly in a platform setup
+ /// - None: Standard merchant flow, JWT/Admin initiator, or insufficient information
+ #[schema(value_type = Option<Initiator>, example = "platform")]
+ pub initiator: Option<platform::Initiator>,
+
/// The connector used for the payment
#[schema(example = "stripe")]
pub connector: Option<String>,
diff --git a/crates/api_models/src/platform.rs b/crates/api_models/src/platform.rs
new file mode 100644
index 0000000000..6e6f504dfa
--- /dev/null
+++ b/crates/api_models/src/platform.rs
@@ -0,0 +1,41 @@
+use common_enums::MerchantAccountType;
+use utoipa::ToSchema;
+
+/// Represents the initiator context in platform-connected setups
+/// Used in payment/refund/dispute responses to indicate who initiated the operation
+/// None indicates a standard merchant flow / JWT flow / Admin flow or insufficient information
+#[derive(
+ Clone,
+ Copy,
+ Debug,
+ Eq,
+ PartialEq,
+ serde::Deserialize,
+ serde::Serialize,
+ strum::Display,
+ strum::EnumString,
+ ToSchema,
+)]
+#[strum(serialize_all = "snake_case")]
+#[serde(rename_all = "snake_case")]
+pub enum Initiator {
+ /// Platform merchant initiated the operation on behalf of connected merchant
+ Platform,
+ /// Connected merchant initiated the operation directly in a platform setup
+ Connected,
+}
+
+impl Initiator {
+ /// Converts MerchantAccountType to Initiator
+ /// - Some(Platform) → Some(Initiator::Platform)
+ /// - Some(Connected) → Some(Initiator::Connected)
+ /// - Some(Standard) → None (standard flows don't need this context in responses)
+ /// - None → None
+ pub fn from_merchant_account_type(account_type: MerchantAccountType) -> Option<Self> {
+ match account_type {
+ MerchantAccountType::Platform => Some(Self::Platform),
+ MerchantAccountType::Connected => Some(Self::Connected),
+ MerchantAccountType::Standard => None,
+ }
+ }
+}
diff --git a/crates/hyperswitch_domain_models/src/platform.rs b/crates/hyperswitch_domain_models/src/platform.rs
index 15b0658f38..c67771b2bb 100644
--- a/crates/hyperswitch_domain_models/src/platform.rs
+++ b/crates/hyperswitch_domain_models/src/platform.rs
@@ -62,6 +62,45 @@ pub enum Initiator {
Admin,
}
+impl Initiator {
+ /// Converts the domain Initiator to CreatedBy for database storage.
+ ///
+ /// # Returns
+ /// - `Some(CreatedBy::Api)` for API initiators
+ /// - `Some(CreatedBy::Jwt)` for JWT initiators
+ /// - `None` for Admin initiators (CreatedBy doesn't have an Admin variant)
+ pub fn to_created_by(&self) -> Option<common_utils::types::CreatedBy> {
+ match self {
+ Self::Api { merchant_id, .. } => Some(common_utils::types::CreatedBy::Api {
+ merchant_id: merchant_id.get_string_repr().to_string(),
+ }),
+ Self::Jwt { user_id } => Some(common_utils::types::CreatedBy::Jwt {
+ user_id: user_id.clone(),
+ }),
+ Self::Admin => None,
+ }
+ }
+
+ /// Computes the initiator context for API responses.
+ ///
+ /// # Returns
+ /// - `Some(Platform)`: Platform merchant initiated the operation
+ /// - `Some(Connected)`: Connected merchant initiated the operation
+ /// - `None`: Standard merchant flow, JWT/Admin initiator, or no initiator
+ pub fn to_api_initiator(&self) -> Option<api_models::platform::Initiator> {
+ match self {
+ Self::Api {
+ merchant_account_type,
+ ..
+ } => {
+ // If this returns Option<Initiator>, just return it directly (NO extra Some)
+ api_models::platform::Initiator::from_merchant_account_type(*merchant_account_type)
+ }
+ Self::Jwt { .. } | Self::Admin => None,
+ }
+ }
+}
+
/// Platform holds both Provider and Processor together.
/// This struct makes it possible to distinguish the business owner for the org versus whose processor credentials are used for execution.
/// For a standard merchant flow, provider == processor.
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index e50fe7dc8b..4150341044 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -945,6 +945,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::open_router::PriorityLogicData,
api_models::user::PlatformAccountCreateRequest,
api_models::user::PlatformAccountCreateResponse,
+ api_models::platform::Initiator,
common_utils::id_type::CustomerId,
common_utils::id_type::SubscriptionId,
common_utils::id_type::MerchantId,
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index 7cd477ea13..e37cac17a4 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -684,6 +684,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payouts::Bank,
api_models::payouts::ApplePayDecrypt,
api_models::payouts::PayoutCreatePayoutLinkConfig,
+ api_models::platform::Initiator,
api_models::enums::PayoutEntityType,
api_models::enums::PayoutSendPriority,
api_models::enums::PayoutStatus,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 7b6166e825..c2d29ddd93 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -2209,6 +2209,7 @@ where
connector_http_status_code,
external_latency,
header_payload.x_hs_latency,
+ &platform,
)
}
@@ -2248,7 +2249,7 @@ where
proxy_for_payments_operation_core::<_, _, _, _, _>(
&state,
req_state,
- platform,
+ platform.clone(),
profile_id,
operation.clone(),
req,
@@ -2269,6 +2270,7 @@ where
connector_http_status_code,
external_latency,
header_payload.x_hs_latency,
+ &platform,
)
}
@@ -8261,11 +8263,15 @@ pub async fn list_payments(
.collect::<Result<Vec<(storage::PaymentIntent, storage::PaymentAttempt)>, _>>();
//Will collect responses in same order async, leading to sorted responses
+ let api_initiator = platform
+ .get_initiator()
+ .and_then(domain::Initiator::to_api_initiator);
+
//Converting Intent-Attempt array to Response if no error
let data: Vec<api::PaymentsResponse> = pi_pa_tuple_vec
.change_context(errors::ApiErrorResponse::InternalServerError)?
.into_iter()
- .map(ForeignFrom::foreign_from)
+ .map(|(pi, pa)| ForeignFrom::foreign_from((pi, pa, api_initiator)))
.collect();
Ok(services::ApplicationResponse::Json(
@@ -8516,8 +8522,15 @@ pub async fn apply_filters_on_payments(
)
.await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
- let data: Vec<api::PaymentsResponse> =
- list.into_iter().map(ForeignFrom::foreign_from).collect();
+ let api_initiator = platform
+ .get_initiator()
+ .and_then(domain::Initiator::to_api_initiator);
+ let data: Vec<api::PaymentsResponse> = list
+ .into_iter()
+ .map(|(payment_intent, payment_attempt)| {
+ ForeignFrom::foreign_from((payment_intent, payment_attempt, api_initiator))
+ })
+ .collect();
let active_attempt_ids = db
.get_filtered_active_attempt_ids_for_total_count(
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 40ea68bef2..2a76138367 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -2166,6 +2166,7 @@ where
connector_http_status_code: Option<u16>,
external_latency: Option<u128>,
is_latency_header_enabled: Option<bool>,
+ platform: &domain::Platform,
) -> RouterResponse<Self>;
#[cfg(feature = "v2")]
@@ -2399,6 +2400,7 @@ where
connector_http_status_code: Option<u16>,
external_latency: Option<u128>,
is_latency_header_enabled: Option<bool>,
+ platform: &domain::Platform,
) -> RouterResponse<Self> {
let captures = payment_data
.get_multiple_capture_data()
@@ -2427,6 +2429,7 @@ where
connector_http_status_code,
external_latency,
is_latency_header_enabled,
+ platform,
)
}
}
@@ -2449,6 +2452,7 @@ where
_connector_http_status_code: Option<u16>,
_external_latency: Option<u128>,
_is_latency_header_enabled: Option<bool>,
+ _platform: &domain::Platform,
) -> RouterResponse<Self> {
Ok(services::ApplicationResponse::JsonWithHeaders((
Self {
@@ -2514,6 +2518,7 @@ where
_connector_http_status_code: Option<u16>,
_external_latency: Option<u128>,
_is_latency_header_enabled: Option<bool>,
+ _platform: &domain::Platform,
) -> RouterResponse<Self> {
let mut amount = payment_data.get_payment_intent().amount;
let shipping_cost = payment_data.get_payment_intent().shipping_cost;
@@ -2796,6 +2801,10 @@ where
status: payment_intent.status,
amount,
customer_id: payment_intent.customer_id.clone(),
+ processor_merchant_id: platform.get_processor().get_account().get_id().clone(),
+ initiator: platform
+ .get_initiator()
+ .and_then(|initiator| initiator.to_api_initiator()),
connector: Some(connector),
created: payment_intent.created_at,
modified_at: payment_intent.modified_at,
@@ -2948,6 +2957,10 @@ impl GenerateResponse<api_models::payments::PaymentsResponse>
status: payment_intent.status,
amount,
customer_id: payment_intent.customer_id.clone(),
+ processor_merchant_id: platform.get_processor().get_account().get_id().clone(),
+ initiator: platform
+ .get_initiator()
+ .and_then(|initiator| initiator.to_api_initiator()),
connector: Some(connector),
created: payment_intent.created_at,
modified_at: payment_intent.modified_at,
@@ -3057,6 +3070,10 @@ where
status: payment_intent.status,
amount,
customer_id: payment_intent.customer_id.clone(),
+ processor_merchant_id: platform.get_processor().get_account().get_id().clone(),
+ initiator: platform
+ .get_initiator()
+ .and_then(|initiator| initiator.to_api_initiator()),
connector,
billing: self
.payment_address
@@ -3180,6 +3197,7 @@ where
_connector_http_status_code: Option<u16>,
_external_latency: Option<u128>,
_is_latency_header_enabled: Option<bool>,
+ _platform: &domain::Platform,
) -> RouterResponse<Self> {
let papal_sdk_next_action =
paypal_sdk_next_steps_check(payment_data.get_payment_attempt().clone())?;
@@ -3216,6 +3234,7 @@ where
_connector_http_status_code: Option<u16>,
_external_latency: Option<u128>,
_is_latency_header_enabled: Option<bool>,
+ _platform: &domain::Platform,
) -> RouterResponse<Self> {
Ok(services::ApplicationResponse::JsonWithHeaders((
Self {
@@ -3301,6 +3320,7 @@ where
_connector_http_status_code: Option<u16>,
_external_latency: Option<u128>,
_is_latency_header_enabled: Option<bool>,
+ _platform: &domain::Platform,
) -> RouterResponse<Self> {
todo!()
}
@@ -3317,6 +3337,7 @@ where
_connector_http_status_code: Option<u16>,
_external_latency: Option<u128>,
_is_latency_header_enabled: Option<bool>,
+ _platform: &domain::Platform,
) -> RouterResponse<Self> {
let additional_payment_method_data: Option<api_models::payments::AdditionalPaymentData> =
payment_data
@@ -3402,6 +3423,7 @@ pub fn payments_to_payments_response<Op, F: Clone, D>(
connector_http_status_code: Option<u16>,
external_latency: Option<u128>,
_is_latency_header_enabled: Option<bool>,
+ platform: &domain::Platform,
) -> RouterResponse<api::PaymentsResponse>
where
Op: Debug,
@@ -3892,6 +3914,10 @@ where
net_amount: payment_attempt.get_total_amount(),
amount_capturable: payment_attempt.amount_capturable,
amount_received: payment_intent.amount_captured,
+ processor_merchant_id: platform.get_processor().get_account().get_id().clone(),
+ initiator: platform
+ .get_initiator()
+ .and_then(|initiator| initiator.to_api_initiator()),
connector: routed_through,
client_secret: payment_intent.client_secret.map(Secret::new),
created: Some(payment_intent.created_at),
@@ -4174,8 +4200,20 @@ pub fn construct_connector_invoke_hidden_frame(
}
#[cfg(feature = "v1")]
-impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::PaymentsResponse {
- fn foreign_from((pi, pa): (storage::PaymentIntent, storage::PaymentAttempt)) -> Self {
+impl
+ ForeignFrom<(
+ storage::PaymentIntent,
+ storage::PaymentAttempt,
+ Option<api_models::platform::Initiator>,
+ )> for api::PaymentsResponse
+{
+ fn foreign_from(
+ (pi, pa, api_initiator): (
+ storage::PaymentIntent,
+ storage::PaymentAttempt,
+ Option<api_models::platform::Initiator>,
+ ),
+ ) -> Self {
let connector_transaction_id = pa.get_connector_payment_id().map(ToString::to_string);
Self {
payment_id: pi.payment_id,
@@ -4251,6 +4289,8 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay
// TODO: fill in details based on requirement
net_amount: pa.net_amount.get_total_amount(),
amount_received: None,
+ processor_merchant_id: pi.processor_merchant_id,
+ initiator: api_initiator,
refunds: None,
disputes: None,
attempts: None,
diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs
index 86b679279f..cbdf26601c 100644
--- a/crates/router/src/db/events.rs
+++ b/crates/router/src/db/events.rs
@@ -1434,8 +1434,10 @@ mod tests {
description: Some("Its my first payment request".to_string()),
refunds: None,
mandate_id: None,
- merchant_id,
+ merchant_id: merchant_id.clone(),
net_amount: MinorUnit::new(6540),
+ processor_merchant_id: merchant_id,
+ initiator: None,
connector: None,
customer: None,
disputes: None,
diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rs
index 4d192c19e7..34d9ce459c 100644
--- a/crates/router/src/utils.rs
+++ b/crates/router/src/utils.rs
@@ -1181,6 +1181,7 @@ where
None,
None,
None,
+ &platform,
)?;
let event_type = status.into();
diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs
index 9a95902e59..fb37ad5886 100644
--- a/crates/router/tests/payments.rs
+++ b/crates/router/tests/payments.rs
@@ -385,8 +385,10 @@ async fn payments_create_core() {
description: Some("Its my first payment request".to_string()),
refunds: None,
mandate_id: None,
- merchant_id,
+ merchant_id: merchant_id.clone(),
net_amount: MinorUnit::new(6540),
+ processor_merchant_id: merchant_id,
+ initiator: None,
connector: None,
customer: None,
disputes: None,
@@ -679,8 +681,10 @@ async fn payments_create_core_adyen_no_redirect() {
description: Some("Its my first payment request".to_string()),
refunds: None,
mandate_id: None,
- merchant_id,
+ merchant_id: merchant_id.clone(),
net_amount: MinorUnit::new(6540),
+ processor_merchant_id: merchant_id,
+ initiator: None,
connector: None,
customer: None,
disputes: None,
diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs
index f61ade3090..863e5c83ee 100644
--- a/crates/router/tests/payments2.rs
+++ b/crates/router/tests/payments2.rs
@@ -145,8 +145,10 @@ async fn payments_create_core() {
description: Some("Its my first payment request".to_string()),
refunds: None,
mandate_id: None,
- merchant_id,
+ merchant_id: merchant_id.clone(),
net_amount: MinorUnit::new(6540),
+ processor_merchant_id: merchant_id,
+ initiator: None,
connector: None,
customer: None,
disputes: None,
@@ -448,8 +450,10 @@ async fn payments_create_core_adyen_no_redirect() {
description: Some("Its my first payment request".to_string()),
refunds: None,
mandate_id: None,
- merchant_id,
+ merchant_id: merchant_id.clone(),
net_amount: MinorUnit::new(6540),
+ processor_merchant_id: merchant_id,
+ initiator: None,
connector: None,
customer: None,
disputes: None,