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(connector): Add support for processing_account_id via metadata across Payload flows (#10904)

awasthi219df0b71018a8
diff --git a/crates/connector_configs/src/connector.rs b/crates/connector_configs/src/connector.rs
index e9b526d6c3..85987596d1 100644
--- a/crates/connector_configs/src/connector.rs
+++ b/crates/connector_configs/src/connector.rs
@@ -15,7 +15,7 @@ use crate::common_config::{CardProvider, InputData, Provider, ZenApplePay};
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct PayloadCurrencyAuthKeyType {
pub api_key: String,
- pub processing_account_id: String,
+ pub processing_account_id: Option<String>,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
diff --git a/crates/hyperswitch_connectors/src/connectors/payload/requests.rs b/crates/hyperswitch_connectors/src/connectors/payload/requests.rs
index 546be98c7b..0926a1a190 100644
--- a/crates/hyperswitch_connectors/src/connectors/payload/requests.rs
+++ b/crates/hyperswitch_connectors/src/connectors/payload/requests.rs
@@ -64,6 +64,7 @@ pub struct CustomerRequest {
pub keep_active: bool,
pub email: Email,
pub name: Secret<String>,
+ pub primary_processing_id: Option<Secret<String>>,
}
#[derive(Debug, Clone, Serialize, PartialEq)]
diff --git a/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs b/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs
index 22bd4b1f3d..6097155927 100644
--- a/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/payload/transformers.rs
@@ -25,7 +25,7 @@ use hyperswitch_interfaces::{
consts::{NO_ERROR_CODE, NO_ERROR_MESSAGE},
errors,
};
-use masking::{ExposeOptionInterface, Secret};
+use masking::{ExposeOptionInterface, PeekInterface, Secret};
use serde::Deserialize;
use super::{requests, responses};
@@ -40,6 +40,15 @@ use crate::{
type Error = error_stack::Report<errors::ConnectorError>;
+fn get_processing_account_id_from_metadata(
+ metadata: Option<&serde_json::Value>,
+) -> Option<Secret<String>> {
+ metadata
+ .and_then(|m| m.get("processing_account_id"))
+ .and_then(|v| v.as_str())
+ .map(|s| Secret::new(s.to_string()))
+}
+
#[allow(clippy::too_many_arguments)]
fn build_payload_payment_request_data(
payment_method_data: &PaymentMethodData,
@@ -51,6 +60,7 @@ fn build_payload_payment_request_data(
is_mandate: bool,
customer_id: Option<String>,
is_three_ds: bool,
+ metadata: Option<&serde_json::Value>,
) -> Result<requests::PayloadPaymentRequestData, Error> {
let payment_method: Result<requests::PayloadPaymentMethods, Error> = match payment_method_data {
PaymentMethodData::Card(req_card) => {
@@ -131,13 +141,15 @@ fn build_payload_payment_request_data(
};
let payload_auth = PayloadAuth::try_from((connector_auth_type, currency))?;
+ // Metadata processing_account_id takes precedence over connector auth config
Ok(requests::PayloadPaymentRequestData {
amount,
payment_method: payment_method?,
transaction_types: requests::TransactionTypes::Payment,
status,
billing_address,
- processing_id: payload_auth.processing_account_id,
+ processing_id: get_processing_account_id_from_metadata(metadata)
+ .or(payload_auth.processing_account_id),
keep_active: is_mandate,
customer_id,
})
@@ -159,10 +171,22 @@ impl<T> From<(StringMajorUnit, T)> for PayloadRouterData<T> {
impl TryFrom<&ConnectorCustomerRouterData> for requests::CustomerRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &ConnectorCustomerRouterData) -> Result<Self, Self::Error> {
+ let currency =
+ item.request
+ .currency
+ .ok_or(errors::ConnectorError::MissingRequiredField {
+ field_name: "currency",
+ })?;
+ let payload_auth = PayloadAuth::try_from((&item.connector_auth_type, currency))?;
+ let primary_processing_id = get_processing_account_id_from_metadata(
+ item.request.metadata.as_ref().map(|m| m.peek()),
+ )
+ .or(payload_auth.processing_account_id);
Ok(Self {
keep_active: item.request.is_mandate_payment(),
email: item.request.get_email()?,
name: item.request.get_name()?,
+ primary_processing_id,
})
}
}
@@ -264,6 +288,7 @@ impl TryFrom<&SetupMandateRouterData> for requests::PayloadPaymentRequestData {
is_mandate,
item.get_connector_customer_id()?.into(),
item.is_three_ds(),
+ item.request.metadata.as_ref().map(|m| m.peek()),
)
}
}
@@ -292,6 +317,7 @@ impl TryFrom<&PayloadRouterData<&PaymentsAuthorizeRouterData>>
is_mandate,
item.router_data.connector_customer.clone(),
item.router_data.is_three_ds(),
+ item.router_data.request.metadata.as_ref(),
)?;
Ok(Self::PaymentRequest(Box::new(payment_request)))
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index 81a8539019..dc8b7a5256 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -195,6 +195,8 @@ impl
customer_acceptance: data.request.customer_acceptance.clone(),
customer_id: None,
billing_address: None,
+ metadata: None,
+ currency: Some(data.request.currency),
})
}
}
@@ -303,6 +305,8 @@ pub struct ConnectorCustomerData {
pub customer_acceptance: Option<common_payments_types::CustomerAcceptance>,
pub customer_id: Option<id_type::CustomerId>,
pub billing_address: Option<AddressDetails>,
+ pub metadata: Option<Secret<serde_json::Value>>,
+ pub currency: Option<storage_enums::Currency>,
}
impl TryFrom<SetupMandateRequestData> for ConnectorCustomerData {
@@ -320,6 +324,8 @@ impl TryFrom<SetupMandateRequestData> for ConnectorCustomerData {
customer_acceptance: data.customer_acceptance,
customer_id: None,
billing_address: None,
+ metadata: data.metadata,
+ currency: Some(data.currency),
})
}
}
@@ -382,6 +388,8 @@ impl
customer_acceptance: data.request.customer_acceptance.clone(),
customer_id: None,
billing_address: None,
+ metadata: data.request.metadata.clone().map(Secret::new),
+ currency: Some(data.request.currency),
})
}
}
@@ -410,6 +418,8 @@ impl TryFrom<&RouterData<flows::Session, PaymentsSessionData, response_types::Pa
customer_acceptance: None,
customer_id: None,
billing_address: None,
+ metadata: None,
+ currency: Some(data.request.currency),
})
}
}
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index 2d72f41285..8c3fd246b8 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -1133,6 +1133,8 @@ impl Default for CustomerType {
setup_future_usage: None,
customer_id: None,
billing_address: None,
+ currency: None,
+ metadata: None,
};
Self(data)
}
diff --git a/crates/subscriptions/src/core/billing_processor_handler.rs b/crates/subscriptions/src/core/billing_processor_handler.rs
index 25705181e9..0f85971848 100644
--- a/crates/subscriptions/src/core/billing_processor_handler.rs
+++ b/crates/subscriptions/src/core/billing_processor_handler.rs
@@ -119,6 +119,7 @@ impl BillingHandler {
description: None,
phone: None,
name: None,
+ metadata: None,
preprocessing_id: None,
split_payments: None,
setup_future_usage: None,
@@ -128,6 +129,7 @@ impl BillingHandler {
.as_ref()
.and_then(|add| add.address.clone())
.and_then(|addr| addr.into()),
+ currency: None,
};
let router_data = self.build_router_data(
state,