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(core): Added profileId to payments client secret (#12234)
Sahkal Poddar93b919fab5ef
diff --git a/crates/common_utils/src/id_type/payment.rs b/crates/common_utils/src/id_type/payment.rsindex 33cd41102c..35db95a37f 100644--- a/crates/common_utils/src/id_type/payment.rs+++ b/crates/common_utils/src/id_type/payment.rs@@ -1,6 +1,6 @@use crate::{errors::{CustomResult, ValidationError},- generate_id_with_default_len,+ generate_id_with_default_len, generate_id_with_default_len_with_profile_id,id_type::{AlphaNumericId, LengthId},};@@ -40,8 +40,11 @@ impl PaymentId {}/// Generate a client id for the payment id- pub fn generate_client_secret(&self) -> String {- generate_id_with_default_len(&format!("{}_secret", self.get_string_repr()))+ pub fn generate_client_secret(&self, profile_id: &str) -> String {+ generate_id_with_default_len_with_profile_id(+ &format!("{}_secret", self.get_string_repr()),+ profile_id,+ )}/// Generate a key for pm_authdiff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rsindex f8cc44c4b3..7e6417a72b 100644--- a/crates/common_utils/src/lib.rs+++ b/crates/common_utils/src/lib.rs@@ -283,6 +283,18 @@ pub fn generate_id_with_default_len(prefix: &str) -> String {format!("{}_{}", prefix, nanoid::nanoid!(len, &consts::ALPHABETS))}+/// Generate a nanoid with the given prefix and a default length with profileId+#[inline]+pub fn generate_id_with_default_len_with_profile_id(prefix: &str, profile_id: &str) -> String {+ let len: usize = consts::ID_LENGTH;+ format!(+ "{}_{},profile={}",+ prefix,+ nanoid::nanoid!(len, &consts::ALPHABETS),+ profile_id+ )+}+/// Generate a time-ordered (time-sortable) unique identifier using the current time#[inline]pub fn generate_time_ordered_id(prefix: &str) -> String {diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex d162a13f8c..9769a89dfd 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -1739,7 +1739,7 @@ impl PaymentCreate {}),request.confirm,);- let client_secret = payment_id.generate_client_secret();+ let client_secret = payment_id.generate_client_secret(profile_id.get_string_repr());let (amount, currency) = (money.0, Some(money.1));let order_details = requestdiff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rsindex b0241005dc..56b8ce4f4d 100644--- a/crates/router/src/utils/user/sample_data.rs+++ b/crates/router/src/utils/user/sample_data.rs@@ -198,7 +198,7 @@ pub async fn generate_sample_data(for num in 1..=sample_data_size {let payment_id = id_type::PaymentId::generate_test_payment_id_for_sample_data();let attempt_id = payment_id.get_attempt_id(1);- let client_secret = payment_id.generate_client_secret();+ let client_secret = payment_id.generate_client_secret(profile_id.get_string_repr());let amount = thread_rng().gen_range(min_amount..=max_amount);let created_at @ modified_at @ last_synced =