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

fix(platform): use organization platform_merchant_id to validate platform merchant creation (#15205)

Apoorv Dixit9dd14e139b36
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 6ec4456f3e..52ff35225a 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -544,17 +544,7 @@ impl MerchantAccountCreateBridge for api::MerchantAccountCreate {
},
OrganizationType::Platform => {
- let accounts = state
- .store
- .list_merchant_accounts_by_organization_id(&organization.get_organization_id())
- .await
- .to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
-
- let platform_account_exists = accounts
- .iter()
- .any(|account| account.merchant_account_type == MerchantAccountType::Platform);
-
- if accounts.is_empty() || !platform_account_exists {
+ if organization.platform_merchant_id.is_none() {
// First merchant in a Platform org must be Platform
MerchantAccountType::Platform
} else {
@@ -1452,6 +1442,12 @@ pub async fn merchant_account_delete(
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;
+ fp_utils::when(merchant_account.is_platform_account(), || {
+ Err(report!(errors::ApiErrorResponse::InvalidRequestData {
+ message: "Platform merchant account cannot be deleted".to_string(),
+ }))
+ })?;
+
let is_merchant_account_deleted = db
.delete_merchant_account_by_merchant_id(&merchant_id)
.await