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 on_behalf_of support for Stripe Connect split payments (#11782)

awasthi21bff4eadd9c52
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index fd4143e8c5..95bfd54057 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -40467,6 +40467,12 @@
"transfer_account_id": {
"type": "string",
"description": "Identifier for the reseller's account where the funds were transferred"
+ },
+ "on_behalf_of": {
+ "type": "string",
+ "description": "The Stripe account ID that these funds are intended for",
+ "example": "acct_1234567890",
+ "nullable": true
}
},
"additionalProperties": false
@@ -40499,6 +40505,12 @@
"transfer_account_id": {
"type": "string",
"description": "Identifier for the reseller's account where the funds were transferred"
+ },
+ "on_behalf_of": {
+ "type": "string",
+ "description": "The Stripe account ID that these funds are intended for",
+ "example": "acct_1234567890",
+ "nullable": true
}
},
"additionalProperties": false
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index fce4061bf1..e2ec18274b 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -30126,6 +30126,12 @@
"transfer_account_id": {
"type": "string",
"description": "Identifier for the reseller's account where the funds were transferred"
+ },
+ "on_behalf_of": {
+ "type": "string",
+ "description": "The Stripe account ID that these funds are intended for",
+ "example": "acct_1234567890",
+ "nullable": true
}
},
"additionalProperties": false
@@ -30158,6 +30164,12 @@
"transfer_account_id": {
"type": "string",
"description": "Identifier for the reseller's account where the funds were transferred"
+ },
+ "on_behalf_of": {
+ "type": "string",
+ "description": "The Stripe account ID that these funds are intended for",
+ "example": "acct_1234567890",
+ "nullable": true
}
},
"additionalProperties": false
diff --git a/crates/common_types/src/payments.rs b/crates/common_types/src/payments.rs
index 938a1ea89d..bbbe59038e 100644
--- a/crates/common_types/src/payments.rs
+++ b/crates/common_types/src/payments.rs
@@ -92,6 +92,11 @@ pub struct StripeSplitPaymentRequest {
/// Identifier for the reseller's account where the funds were transferred
#[smithy(value_type = "String")]
pub transfer_account_id: String,
+
+ /// The Stripe account ID that these funds are intended for
+ #[schema(value_type = Option<String>, example = "acct_1234567890")]
+ #[smithy(value_type = "Option<String>")]
+ pub on_behalf_of: Option<String>,
}
impl_to_sql_from_sql_json!(StripeSplitPaymentRequest);
@@ -371,6 +376,11 @@ pub struct StripeChargeResponseData {
/// Identifier for the reseller's account where the funds were transferred
#[smithy(value_type = "String")]
pub transfer_account_id: String,
+
+ /// The Stripe account ID that these funds are intended for
+ #[schema(value_type = Option<String>, example = "acct_1234567890")]
+ #[smithy(value_type = "Option<String>")]
+ pub on_behalf_of: Option<String>,
}
impl_to_sql_from_sql_json!(StripeChargeResponseData);
diff --git a/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs b/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs
index a5b7d40ba3..af00f2414a 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs
@@ -226,6 +226,9 @@ pub struct PaymentIntentRequest {
pub charges: Option<IntentCharges>,
#[serde(rename = "payment_method_options[card][moto]")]
pub moto: Option<bool>,
+ /// The Stripe account ID that these funds are intended for
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub on_behalf_of: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Serialize, Clone)]
@@ -273,6 +276,9 @@ pub struct SetupIntentRequest {
pub browser_info: Option<StripeBrowserInformation>,
#[serde(rename = "payment_method_options[card][moto]")]
pub moto: Option<bool>,
+ /// The Stripe account ID that these funds are intended for
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub on_behalf_of: Option<String>,
}
#[derive(Debug, Eq, PartialEq, Serialize)]
@@ -1986,7 +1992,7 @@ impl TryFrom<(&PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntentRequest
_ => None,
});
- let (transfer_account_id, charge_type) = if let Some(secret_value) =
+ let (transfer_account_id, charge_type, mandate_on_behalf_of) = if let Some(secret_value) =
mandate_metadata.as_ref().and_then(|s| s.as_ref())
{
let json_value = secret_value.clone().expose();
@@ -1994,11 +2000,15 @@ impl TryFrom<(&PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntentRequest
let parsed: Result<StripeSplitPaymentRequest, _> = serde_json::from_value(json_value);
match parsed {
- Ok(data) => (data.transfer_account_id, data.charge_type),
- Err(_) => (None, None),
+ Ok(data) => (
+ data.transfer_account_id,
+ data.charge_type,
+ data.on_behalf_of,
+ ),
+ Err(_) => (None, None, None),
}
} else {
- (None, None)
+ (None, None, None)
};
let payment_method_token = match (
@@ -2359,6 +2369,24 @@ impl TryFrom<(&PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntentRequest
},
};
+ // on_behalf_of is only supported for destination charges, not direct charges
+ let on_behalf_of = match &item.request.split_payments {
+ Some(SplitPaymentsRequest::StripeSplitPayment(stripe_split_payment)) => {
+ match &stripe_split_payment.charge_type {
+ PaymentChargeType::Stripe(StripeChargeType::Destination) => {
+ stripe_split_payment.on_behalf_of.clone()
+ }
+ _ => None,
+ }
+ }
+ _ => match charge_type {
+ Some(PaymentChargeType::Stripe(StripeChargeType::Destination)) => {
+ mandate_on_behalf_of
+ }
+ _ => None,
+ },
+ };
+
let pm = match (payment_method, payment_method_token.clone()) {
(Some(method), _) => Some(Secret::new(method)),
(None, Some(token)) => Some(token),
@@ -2423,6 +2451,7 @@ impl TryFrom<(&PaymentsAuthorizeRouterData, MinorUnit)> for PaymentIntentRequest
browser_info,
charges,
moto: is_moto,
+ on_behalf_of,
})
}
}
@@ -2513,6 +2542,18 @@ impl TryFrom<&SetupMandateRouterData> for SetupIntentRequest {
_ => item.request.setup_future_usage,
};
+ let on_behalf_of = match &item.request.split_payments {
+ Some(SplitPaymentsRequest::StripeSplitPayment(stripe_split_payment)) => {
+ match &stripe_split_payment.charge_type {
+ PaymentChargeType::Stripe(StripeChargeType::Destination) => {
+ stripe_split_payment.on_behalf_of.clone()
+ }
+ _ => None,
+ }
+ }
+ _ => None,
+ };
+
Ok(Self {
confirm: true,
payment_data,
@@ -2526,6 +2567,7 @@ impl TryFrom<&SetupMandateRouterData> for SetupIntentRequest {
expand: Some(ExpandableObjects::LatestAttempt),
browser_info,
moto: is_moto,
+ on_behalf_of,
})
}
}
@@ -2597,6 +2639,7 @@ pub struct StripeSplitPaymentRequest {
pub charge_type: Option<PaymentChargeType>,
pub application_fees: Option<MinorUnit>,
pub transfer_account_id: Option<String>,
+ pub on_behalf_of: Option<String>,
}
pub fn get_stripe_compatible_connect_account_header(
@@ -2638,8 +2681,9 @@ pub fn get_stripe_compatible_connect_account_header(
if cit_metadata.charge_type != Some(split_payment_object.charge_type.clone())
|| cit_metadata.transfer_account_id
!= Some(split_payment_object.transfer_account_id.clone())
+ || cit_metadata.on_behalf_of != split_payment_object.on_behalf_of.clone()
{
- let mismatched_fields = ["transfer_account_id", "charge_type"];
+ let mismatched_fields = ["transfer_account_id", "charge_type", "on_behalf_of"];
let field_str = mismatched_fields.join(", ");
return Err(error_stack::Report::from(
@@ -3223,6 +3267,7 @@ where
"transfer_account_id": stripe_split_data.transfer_account_id,
"charge_type": stripe_split_data.charge_type,
"application_fees": stripe_split_data.application_fees,
+ "on_behalf_of": stripe_split_data.on_behalf_of,
})))
}
_ => None,
@@ -3659,6 +3704,7 @@ where
"transfer_account_id": stripe_split_data.transfer_account_id,
"charge_type": stripe_split_data.charge_type,
"application_fees": stripe_split_data.application_fees,
+ "on_behalf_of": stripe_split_data.on_behalf_of,
})))
}
_ => None,
@@ -5100,6 +5146,7 @@ where
charge_type: stripe_split_payment.charge_type,
application_fees: stripe_split_payment.application_fees,
transfer_account_id: stripe_split_payment.transfer_account_id,
+ on_behalf_of: stripe_split_payment.on_behalf_of,
};
Some(
common_types::payments::ConnectorChargeResponseData::StripeSplitPayment(