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

refactor(merchant_account): make `organization_id` as mandatory (#2458)

Narayan Bhat53b4816d27fe
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rs
index a1b13c5ff3..6162ceffcb 100644
--- a/crates/api_models/src/admin.rs
+++ b/crates/api_models/src/admin.rs
@@ -265,7 +265,7 @@ pub struct MerchantAccountResponse {
pub intent_fulfillment_time: Option<i64>,
/// The organization id merchant is associated with
- pub organization_id: Option<String>,
+ pub organization_id: String,
/// A boolean value to indicate if the merchant has recon service is enabled or not, by default value is false
pub is_recon_enabled: bool,
diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs
index 2b63d4bf9b..dd68f3755f 100644
--- a/crates/diesel_models/src/merchant_account.rs
+++ b/crates/diesel_models/src/merchant_account.rs
@@ -36,7 +36,7 @@ pub struct MerchantAccount {
pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
- pub organization_id: Option<String>,
+ pub organization_id: String,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
@@ -65,7 +65,7 @@ pub struct MerchantAccountNew {
pub modified_at: time::PrimitiveDateTime,
pub frm_routing_algorithm: Option<serde_json::Value>,
pub payout_routing_algorithm: Option<serde_json::Value>,
- pub organization_id: Option<String>,
+ pub organization_id: String,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: storage_enums::ReconStatus,
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index d8a888046b..0da819f2a7 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -437,7 +437,7 @@ diesel::table! {
frm_routing_algorithm -> Nullable<Jsonb>,
payout_routing_algorithm -> Nullable<Jsonb>,
#[max_length = 32]
- organization_id -> Nullable<Varchar>,
+ organization_id -> Varchar,
is_recon_enabled -> Bool,
#[max_length = 64]
default_profile -> Nullable<Varchar>,
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index c7009bf4cc..ec229bd8a5 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -31,6 +31,8 @@ use crate::{
utils::{self, OptionExt},
};
+const DEFAULT_ORG_ID: &str = "org_abcdefghijklmn";
+
#[inline]
pub fn create_merchant_publishable_key() -> String {
format!(
@@ -164,7 +166,7 @@ pub async fn create_merchant_account(
intent_fulfillment_time: req.intent_fulfillment_time.map(i64::from),
payout_routing_algorithm: req.payout_routing_algorithm,
id: None,
- organization_id: req.organization_id,
+ organization_id: req.organization_id.unwrap_or(DEFAULT_ORG_ID.to_string()),
is_recon_enabled: false,
default_profile: None,
recon_status: diesel_models::enums::ReconStatus::NotRequested,
diff --git a/crates/router/src/types/domain/merchant_account.rs b/crates/router/src/types/domain/merchant_account.rs
index 30950f8c9c..c32942a847 100644
--- a/crates/router/src/types/domain/merchant_account.rs
+++ b/crates/router/src/types/domain/merchant_account.rs
@@ -40,7 +40,7 @@ pub struct MerchantAccount {
pub modified_at: time::PrimitiveDateTime,
pub intent_fulfillment_time: Option<i64>,
pub payout_routing_algorithm: Option<serde_json::Value>,
- pub organization_id: Option<String>,
+ pub organization_id: String,
pub is_recon_enabled: bool,
pub default_profile: Option<String>,
pub recon_status: diesel_models::enums::ReconStatus,
diff --git a/migrations/2023-10-05-085859_make_org_id_mandatory_in_ma/down.sql b/migrations/2023-10-05-085859_make_org_id_mandatory_in_ma/down.sql
new file mode 100644
index 0000000000..eb6a02e3da
--- /dev/null
+++ b/migrations/2023-10-05-085859_make_org_id_mandatory_in_ma/down.sql
@@ -0,0 +1,3 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE merchant_account
+ALTER COLUMN organization_id DROP NOT NULL;
diff --git a/migrations/2023-10-05-085859_make_org_id_mandatory_in_ma/up.sql b/migrations/2023-10-05-085859_make_org_id_mandatory_in_ma/up.sql
new file mode 100644
index 0000000000..eb6b24e16a
--- /dev/null
+++ b/migrations/2023-10-05-085859_make_org_id_mandatory_in_ma/up.sql
@@ -0,0 +1,8 @@
+-- Your SQL goes here
+UPDATE merchant_account
+SET organization_id = 'org_abcdefghijklmn'
+WHERE organization_id IS NULL;
+
+ALTER TABLE merchant_account
+ALTER COLUMN organization_id
+SET NOT NULL;
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index 13ddad32af..56632a68c3 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -6113,6 +6113,7 @@
"enable_payment_response_hash",
"redirect_to_merchant_with_http_post",
"primary_business_details",
+ "organization_id",
"is_recon_enabled",
"recon_status"
],
@@ -6241,8 +6242,7 @@
},
"organization_id": {
"type": "string",
- "description": "The organization id merchant is associated with",
- "nullable": true
+ "description": "The organization id merchant is associated with"
},
"is_recon_enabled": {
"type": "boolean",