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
chore(payments): token generation and consumption changes in v2 (#10835)
Shivansh Mathur9f5da8feabfd
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rsindex 46c1ae7fb5..706cf4b7a6 100644--- a/crates/router/src/core/payment_methods.rs+++ b/crates/router/src/core/payment_methods.rs@@ -3153,10 +3153,9 @@ pub async fn list_customer_payment_methods_core(let token_data = get_pm_list_token_data(payment_method_type, &pm)?;if let Some(token_data) = token_data {- pm_routes::ParentPaymentMethodToken::create_key_for_token((+ pm_routes::ParentPaymentMethodToken::create_key_for_token(&parent_payment_method_token,- payment_method_type,- ))+ ).insert(intent_fulfillment_time, token_data, state).await?;@@ -3996,12 +3995,9 @@ pub async fn payment_methods_session_confirm(// insert the token data into redisif let Some(token_data) = token_data {- pm_routes::ParentPaymentMethodToken::create_key_for_token((- &parent_payment_method_token,- request.payment_method_type,- ))- .insert(intent_fulfillment_time, token_data, &state)- .await?;+ pm_routes::ParentPaymentMethodToken::create_key_for_token(&parent_payment_method_token)+ .insert(intent_fulfillment_time, token_data, &state)+ .await?;};let update_payment_method_session = hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum::UpdateAssociatedPaymentMethods {@@ -4157,7 +4153,7 @@ impl pm_types::SavedPMLPaymentsInfo {.get_order_fulfillment_time().unwrap_or(common_utils::consts::DEFAULT_INTENT_FULFILLMENT_TIME);- pm_routes::ParentPaymentMethodToken::create_key_for_token((token, pma.payment_method_type))+ pm_routes::ParentPaymentMethodToken::create_key_for_token(token).insert(intent_fulfillment_time, token_data, state).await?;diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rsindex 3f4f44e355..fee1ad11d9 100644--- a/crates/router/src/core/payment_methods/utils.rs+++ b/crates/router/src/core/payment_methods/utils.rs@@ -860,14 +860,7 @@ pub(super) async fn retrieve_payment_token_data(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to get redis connection")?;- let key = format!(- "pm_token_{}_{}_hyperswitch",- token,- payment_method- .get_required_value("payment_method")- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Payment method is required")?- );+ let key = format!("pm_token_{}_hyperswitch", token);let token_data_string = redis_conn.get_key::<Option<String>>(&key.into())diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rsindex 74a19366cb..14ff021fae 100644--- a/crates/router/src/core/payment_methods/vault.rs+++ b/crates/router/src/core/payment_methods/vault.rs@@ -1794,7 +1794,7 @@ pub async fn insert_cvc_using_payment_token(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to get redis connection")?;- let key = format!("pm_token_{payment_token}_{payment_method}_hyperswitch_cvc");+ let key = format!("pm_token_{payment_token}_hyperswitch_cvc");let payload_to_be_encrypted = TemporaryVaultCvc { card_cvc };@@ -1837,7 +1837,7 @@ pub async fn retrieve_and_delete_cvc_from_payment_token(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to get redis connection")?;- let key = format!("pm_token_{payment_token}_{payment_method}_hyperswitch_cvc",);+ let key = format!("pm_token_{payment_token}_hyperswitch_cvc");let data = redis_conn.get_key::<bytes::Bytes>(&key.clone().into())diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex e82bd44c2c..3592208b85 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -392,7 +392,7 @@ where.payment_token.as_ref().zip(Some(payment_data.get_payment_attempt().payment_method_type))- .map(ParentPaymentMethodToken::return_key_for_token)+ .map(|(token, _)| ParentPaymentMethodToken::return_key_for_token(token)).async_map(|key_for_token| async move {let _ = vault::delete_payment_token(state, &key_for_token, payment_intent_status).awaitdiff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rsindex 21adab0414..3ab679e1f5 100644--- a/crates/router/src/routes/payment_methods.rs+++ b/crates/router/src/routes/payment_methods.rs@@ -1131,6 +1131,7 @@ pub struct ParentPaymentMethodToken {}impl ParentPaymentMethodToken {+ #[cfg(feature = "v1")]pub fn create_key_for_token((parent_pm_token, payment_method): (&String, api_models::enums::PaymentMethod),) -> Self {@@ -1140,10 +1141,15 @@ impl ParentPaymentMethodToken {}#[cfg(feature = "v2")]- pub fn return_key_for_token(- (parent_pm_token, payment_method): (&String, api_models::enums::PaymentMethod),- ) -> String {- format!("pm_token_{parent_pm_token}_{payment_method}_hyperswitch")+ pub fn create_key_for_token(parent_pm_token: &String) -> Self {+ Self {+ key_for_token: format!("pm_token_{parent_pm_token}_hyperswitch"),+ }+ }++ #[cfg(feature = "v2")]+ pub fn return_key_for_token(parent_pm_token: &String) -> String {+ format!("pm_token_{parent_pm_token}_hyperswitch")}pub async fn insert(