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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(locker): create locker entity during merchant account creation (#13409)
Shankar Singh C1f90e0978d8f
diff --git a/config/config.example.toml b/config/config.example.tomlindex 9bf88fc1cc..278ce7c65a 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -233,6 +233,7 @@ mock_locker = true # Emulate a locker locally using Postgreslocker_signing_key_id = "1" # Key_id to sign basilisk hs lockerlocker_enabled = true # Boolean to enable or disable saving cards in lockerttl_for_storage_in_secs = 220752000 # Time to live for storage entries in locker+create_entity_on_merchant_create = false # Boolean to call the locker's entity-create API during merchant account creation, aborting creation on locker failure[delayed_session_response]connectors_with_delayed_session_response = "trustpay,payme" # List of connectors which has delayed session responsediff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.tomlindex f07477ab57..8f21cce125 100644--- a/config/deployments/env_specific.toml+++ b/config/deployments/env_specific.toml@@ -140,6 +140,7 @@ locker_signing_key_id = "1" # Key_id tlocker_enabled = true # Boolean to enable or disable saving cards in lockerredis_temp_locker_encryption_key = "redis_temp_locker_encryption_key" # Encryption key for redis temp lockerttl_for_storage_in_secs = 220752000 # Time to live for storage entries in locker+create_entity_on_merchant_create = false # Boolean to call the locker's entity-create API during merchant account creation, aborting creation on locker failurediff --git a/config/development.toml b/config/development.tomlindex 8ef3e4dc0b..0172effb12 100644--- a/config/development.toml+++ b/config/development.toml@@ -153,6 +153,7 @@ host = "http://127.0.0.1:3000"mock_locker = truelocker_enabled = truettl_for_storage_in_secs = 220752000+create_entity_on_merchant_create = false[forex_api]api_key = ""diff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex d68b0af823..cc3cd98dc2 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -150,6 +150,7 @@ host = ""mock_locker = truelocker_enabled = truettl_for_storage_in_secs = 220752000+create_entity_on_merchant_create = false[jwekey]vault_encryption_key = ""diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rsindex 3a3d5cc4e4..0322c8f4f8 100644--- a/crates/router/src/configs/defaults.rs+++ b/crates/router/src/configs/defaults.rs@@ -62,6 +62,7 @@ impl Default for super::settings::Locker {//Time to live for storage entries in lockerttl_for_storage_in_secs: 60 * 60 * 24 * 365 * 7,decryption_scheme: Default::default(),+ create_entity_on_merchant_create: false,}}}diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex 0377b30d55..828ad590c0 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -973,6 +973,7 @@ pub struct Locker {pub locker_enabled: bool,pub ttl_for_storage_in_secs: i64,pub decryption_scheme: DecryptionScheme,+ pub create_entity_on_merchant_create: bool,}impl Locker {diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rsindex 87419b5b77..53aea96cf9 100644--- a/crates/router/src/consts.rs+++ b/crates/router/src/consts.rs@@ -215,6 +215,12 @@ pub const V2_VAULT_DELETE_FLOW_TYPE: &str = "delete_from_vault";/// Vault Fingerprint fetch flow typepub const V2_VAULT_GET_FINGERPRINT_FLOW_TYPE: &str = "get_fingerprint_vault";+/// Locker entity create request url+pub const LOCKER_ENTITY_CREATE_REQUEST_URL: &str = "/entity";++/// Locker entity create flow type+pub const LOCKER_ENTITY_CREATE_FLOW_TYPE: &str = "create_entity";+/// Max volume split for Dynamic routingpub const DYNAMIC_ROUTING_MAX_VOLUME: u8 = 100;diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 28cef9605a..87f6d7a494 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -38,7 +38,7 @@ use crate::{disputes,encryption::transfer_encryption_key,errors::{self, RouterResponse, RouterResult, StorageErrorExt},- payment_methods::{cards, transformers},+ payment_methods::{cards, transformers, vault},payments::helpers::{self},pm_auth::helpers::PaymentAuthConnectorDataExt,routing, utils as core_utils,@@ -313,6 +313,14 @@ pub async fn create_merchant_account(let key_manager_state: &KeyManagerState = &(&state).into();let merchant_id = req.get_merchant_reference_id();++ if state.conf.locker.locker_enabled && state.conf.locker.create_entity_on_merchant_create {+ vault::create_entity_in_locker(&state, &merchant_id)+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to create entity in locker for merchant")?;+ }+let identifier = km_types::Identifier::Merchant(merchant_id.clone());keymanager::transfer_key_to_key_manager(key_manager_state,diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rsindex 0262ab55c0..fc64c66b55 100644--- a/crates/router/src/core/payment_methods/vault.rs+++ b/crates/router/src/core/payment_methods/vault.rs@@ -2026,6 +2026,27 @@ pub async fn call_to_vault<V: pm_types::VaultingInterface>(Ok(decrypted_payload)}+pub async fn create_entity_in_locker(+ state: &routes::SessionState,+ entity_id: &id_type::MerchantId,+) -> CustomResult<pm_types::EntityCreateResponse, errors::VaultError> {+ let payload = pm_types::EntityCreateRequest {+ entity_id: entity_id.clone(),+ }+ .encode_to_vec()+ .change_context(errors::VaultError::RequestEncodingFailed)?;++ let response = call_to_vault::<pm_types::EntityCreate>(state, payload, None, None)+ .await+ .change_context(errors::VaultError::VaultAPIError)+ .attach_printable("Call to vault failed while creating locker entity")?;++ response+ .parse_struct("EntityCreateResponse")+ .change_context(errors::VaultError::ResponseDeserializationFailed)+ .attach_printable("Failed to parse EntityCreateResponse")+}+#[cfg(feature = "v2")]pub async fn get_fingerprint_id_for_payment_method(state: &routes::SessionState,diff --git a/crates/router/src/types/payment_methods.rs b/crates/router/src/types/payment_methods.rsindex 45c59d3e8b..0f1eacf171 100644--- a/crates/router/src/types/payment_methods.rs+++ b/crates/router/src/types/payment_methods.rs@@ -167,6 +167,31 @@ impl VaultingInterface for VaultDelete {}}+#[derive(Debug)]+pub struct EntityCreate;++impl VaultingInterface for EntityCreate {+ fn get_vaulting_request_url() -> &'static str {+ consts::LOCKER_ENTITY_CREATE_REQUEST_URL+ }++ fn get_vaulting_flow_name() -> &'static str {+ consts::LOCKER_ENTITY_CREATE_FLOW_TYPE+ }+}++#[derive(Debug, serde::Serialize)]+pub struct EntityCreateRequest {+ pub entity_id: id_type::MerchantId,+}++#[derive(Debug, serde::Deserialize)]+pub struct EntityCreateResponse {+ pub entity_id: String,+ #[serde(with = "common_utils::custom_serde::iso8601")]+ pub created_at: time::PrimitiveDateTime,+}+#[cfg(feature = "v2")]pub struct SavedPMLPaymentsInfo {pub payment_intent: storage::PaymentIntent,diff --git a/loadtest/config/development.toml b/loadtest/config/development.tomlindex 87caada3ec..9611dcf201 100644--- a/loadtest/config/development.toml+++ b/loadtest/config/development.toml@@ -84,6 +84,7 @@ host = ""mock_locker = truelocker_enabled = truettl_for_storage_in_secs = 220752000+create_entity_on_merchant_create = false[forex_api]api_key = ""