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
refactor(router): remove fallback feature for `/add` and `/get` for locker (#3648)
Shankar Singh Cd0f529fa4b2d
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rsindex cc2052d18a..2d9801272c 100644--- a/crates/api_models/src/enums.rs+++ b/crates/api_models/src/enums.rs@@ -502,8 +502,7 @@ pub enum RetryAction {#[derive(Clone, Copy)]pub enum LockerChoice {- Basilisk,- Tartarus,+ HyperswitchCardVault,}#[derive(diff --git a/crates/router/src/core/locker_migration.rs b/crates/router/src/core/locker_migration.rsindex 48ddaf333b..2ebec569b3 100644--- a/crates/router/src/core/locker_migration.rs+++ b/crates/router/src/core/locker_migration.rs@@ -126,7 +126,7 @@ pub async fn call_to_locker(&card_details,customer_id.to_string(),merchant_account,- api_enums::LockerChoice::Tartarus,+ api_enums::LockerChoice::HyperswitchCardVault,Some(&pm.payment_method_id),).awaitdiff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rsindex 4f6d6b4c62..4b58404a5a 100644--- a/crates/router/src/core/payment_methods/cards.rs+++ b/crates/router/src/core/payment_methods/cards.rs@@ -225,7 +225,7 @@ pub async fn add_payment_method(&card,customer_id.clone(),merchant_account,- api::enums::LockerChoice::Tartarus,+ api::enums::LockerChoice::HyperswitchCardVault,Some(&resp.payment_method_id),).await;@@ -454,7 +454,7 @@ pub async fn add_bank_to_locker(state,&payload,customer_id,- api_enums::LockerChoice::Basilisk,+ api_enums::LockerChoice::HyperswitchCardVault,).await?;let payment_method_resp = payment_methods::mk_add_bank_response_hs(@@ -489,42 +489,10 @@ pub async fn add_card_to_locker(card,customer_id.to_string(),merchant_account,- api_enums::LockerChoice::Basilisk,+ api_enums::LockerChoice::HyperswitchCardVault,None,).await- .map_err(|error| {- metrics::CARD_LOCKER_FAILURES.add(- &metrics::CONTEXT,- 1,- &[- router_env::opentelemetry::KeyValue::new("locker", "basilisk"),- router_env::opentelemetry::KeyValue::new("operation", "add"),- ],- );- error- })- },- &metrics::CARD_ADD_TIME,- &[router_env::opentelemetry::KeyValue::new(- "locker", "basilisk",- )],- )- .await?;- logger::debug!("card added to basilisk locker");-- let add_card_to_rs_resp = request::record_operation_time(- async {- add_card_hs(- state,- req,- card,- customer_id.to_string(),- merchant_account,- api_enums::LockerChoice::Tartarus,- Some(&add_card_to_hs_resp.0.payment_method_id),- )- .await.map_err(|error| {metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT,@@ -540,34 +508,10 @@ pub async fn add_card_to_locker(&metrics::CARD_ADD_TIME,&[router_env::opentelemetry::KeyValue::new("locker", "rust")],)- .await;-- match add_card_to_rs_resp {- value @ Ok(_) => {- logger::debug!("card added to rust locker");- let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(- &metrics::CONTEXT,- 1,- &[- router_env::opentelemetry::KeyValue::new("locker", "rust"),- router_env::opentelemetry::KeyValue::new("operation", "add"),- ],- );- value- }- Err(err) => {- logger::debug!(error =? err,"failed to add card to rust locker");- let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(- &metrics::CONTEXT,- 1,- &[- router_env::opentelemetry::KeyValue::new("locker", "basilisk"),- router_env::opentelemetry::KeyValue::new("operation", "add"),- ],- );- Ok(add_card_to_hs_resp)- }- }+ .await?;++ logger::debug!("card added to hyperswitch-card-vault");+ Ok(add_card_to_hs_resp)}pub async fn get_card_from_locker(@@ -585,11 +529,11 @@ pub async fn get_card_from_locker(customer_id,merchant_id,card_reference,- api_enums::LockerChoice::Tartarus,+ api_enums::LockerChoice::HyperswitchCardVault,).await.change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed while getting card from basilisk_hs")+ .attach_printable("Failed while getting card from hyperswitch card vault").map_err(|error| {metrics::CARD_LOCKER_FAILURES.add(&metrics::CONTEXT,@@ -605,64 +549,10 @@ pub async fn get_card_from_locker(&metrics::CARD_GET_TIME,&[router_env::opentelemetry::KeyValue::new("locker", "rust")],)- .await;-- match get_card_from_rs_locker_resp {- Err(_) => request::record_operation_time(- async {- get_card_from_hs_locker(- state,- customer_id,- merchant_id,- card_reference,- api_enums::LockerChoice::Basilisk,- )- .await- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable("Failed while getting card from basilisk_hs")- .map_err(|error| {- metrics::CARD_LOCKER_FAILURES.add(- &metrics::CONTEXT,- 1,- &[- router_env::opentelemetry::KeyValue::new("locker", "basilisk"),- router_env::opentelemetry::KeyValue::new("operation", "get"),- ],- );- error- })- },- &metrics::CARD_GET_TIME,- &[router_env::opentelemetry::KeyValue::new(- "locker", "basilisk",- )],- )- .await- .map(|inner_card| {- logger::debug!("card retrieved from basilisk locker");- let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(- &metrics::CONTEXT,- 1,- &[- router_env::opentelemetry::KeyValue::new("locker", "basilisk"),- router_env::opentelemetry::KeyValue::new("operation", "get"),- ],- );- inner_card- }),- Ok(_) => {- logger::debug!("card retrieved from rust locker");- let _ = &metrics::CARD_LOCKER_SUCCESSFUL_RESPONSE.add(- &metrics::CONTEXT,- 1,- &[- router_env::opentelemetry::KeyValue::new("locker", "rust"),- router_env::opentelemetry::KeyValue::new("operation", "get"),- ],- );- get_card_from_rs_locker_resp- }- }+ .await?;++ logger::debug!("card retrieved from rust locker");+ Ok(get_card_from_rs_locker_resp)}pub async fn delete_card_from_locker(@@ -967,7 +857,7 @@ pub async fn delete_card_from_hs_locker<'a>(let decrypted_payload = payment_methods::get_decrypted_response_payload(jwekey,jwe_body,- Some(api_enums::LockerChoice::Basilisk),+ Some(api_enums::LockerChoice::HyperswitchCardVault),).await.change_context(errors::ApiErrorResponse::InternalServerError)diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rsindex 59b02d0193..f59e47c571 100644--- a/crates/router/src/core/payment_methods/transformers.rs+++ b/crates/router/src/core/payment_methods/transformers.rs@@ -198,13 +198,12 @@ pub async fn get_decrypted_response_payload(jwe_body: encryption::JweBody,locker_choice: Option<api_enums::LockerChoice>,) -> CustomResult<String, errors::VaultError> {- let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::Basilisk);+ let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::HyperswitchCardVault);#[cfg(feature = "aws_kms")]let public_key = match target_locker {- api_enums::LockerChoice::Basilisk => jwekey.jwekey.peek().vault_encryption_key.as_bytes(),- api_enums::LockerChoice::Tartarus => {- jwekey.jwekey.peek().rust_locker_encryption_key.as_bytes()+ api_enums::LockerChoice::HyperswitchCardVault => {+ jwekey.jwekey.peek().vault_encryption_key.as_bytes()}};@@ -213,8 +212,7 @@ pub async fn get_decrypted_response_payload(#[cfg(not(feature = "aws_kms"))]let public_key = match target_locker {- api_enums::LockerChoice::Basilisk => jwekey.vault_encryption_key.as_bytes(),- api_enums::LockerChoice::Tartarus => jwekey.rust_locker_encryption_key.as_bytes(),+ api_enums::LockerChoice::HyperswitchCardVault => jwekey.vault_encryption_key.as_bytes(),};#[cfg(not(feature = "aws_kms"))]@@ -266,16 +264,14 @@ pub async fn mk_basilisk_req(#[cfg(feature = "aws_kms")]let public_key = match locker_choice {- api_enums::LockerChoice::Basilisk => jwekey.jwekey.peek().vault_encryption_key.as_bytes(),- api_enums::LockerChoice::Tartarus => {- jwekey.jwekey.peek().rust_locker_encryption_key.as_bytes()+ api_enums::LockerChoice::HyperswitchCardVault => {+ jwekey.jwekey.peek().vault_encryption_key.as_bytes()}};#[cfg(not(feature = "aws_kms"))]let public_key = match locker_choice {- api_enums::LockerChoice::Basilisk => jwekey.vault_encryption_key.as_bytes(),- api_enums::LockerChoice::Tartarus => jwekey.rust_locker_encryption_key.as_bytes(),+ api_enums::LockerChoice::HyperswitchCardVault => jwekey.vault_encryption_key.as_bytes(),};let jwe_encrypted = encryption::encrypt_jwe(&payload, public_key)@@ -321,8 +317,7 @@ pub async fn mk_add_locker_request_hs<'a>(let jwe_payload = mk_basilisk_req(jwekey, &jws, locker_choice).await?;let mut url = match locker_choice {- api_enums::LockerChoice::Basilisk => locker.host.to_owned(),- api_enums::LockerChoice::Tartarus => locker.host_rs.to_owned(),+ api_enums::LockerChoice::HyperswitchCardVault => locker.host.to_owned(),};url.push_str("/cards/add");let mut request = services::Request::new(services::Method::Post, &url);@@ -497,12 +492,11 @@ pub async fn mk_get_card_request_hs(.await.change_context(errors::VaultError::RequestEncodingFailed)?;- let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::Basilisk);+ let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::HyperswitchCardVault);let jwe_payload = mk_basilisk_req(jwekey, &jws, target_locker).await?;let mut url = match target_locker {- api_enums::LockerChoice::Basilisk => locker.host.to_owned(),- api_enums::LockerChoice::Tartarus => locker.host_rs.to_owned(),+ api_enums::LockerChoice::HyperswitchCardVault => locker.host.to_owned(),};url.push_str("/cards/retrieve");let mut request = services::Request::new(services::Method::Post, &url);@@ -573,7 +567,8 @@ pub async fn mk_delete_card_request_hs(.await.change_context(errors::VaultError::RequestEncodingFailed)?;- let jwe_payload = mk_basilisk_req(jwekey, &jws, api_enums::LockerChoice::Basilisk).await?;+ let jwe_payload =+ mk_basilisk_req(jwekey, &jws, api_enums::LockerChoice::HyperswitchCardVault).await?;let mut url = locker.host.to_owned();url.push_str("/cards/delete");diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rsindex 7cff626334..2d7a09bdae 100644--- a/crates/router/src/core/payments/tokenization.rs+++ b/crates/router/src/core/payments/tokenization.rs@@ -179,7 +179,7 @@ where&card,customer.customer_id.clone(),merchant_account,- api::enums::LockerChoice::Tartarus,+ api::enums::LockerChoice::HyperswitchCardVault,Some(&locker_response.0.payment_method_id),).await;diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rsindex fe8f5c6297..7fb6fa3bde 100644--- a/crates/router/src/core/payouts/helpers.rs+++ b/crates/router/src/core/payouts/helpers.rs@@ -267,7 +267,7 @@ pub async fn save_payout_data_to_locker(state,&locker_req,&payout_attempt.customer_id,- api_enums::LockerChoice::Basilisk,+ api_enums::LockerChoice::HyperswitchCardVault,).await.change_context(errors::ApiErrorResponse::InternalServerError)?;diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rsindex 19bd28b8db..5b5bc414d2 100644--- a/crates/router/src/lib.rs+++ b/crates/router/src/lib.rs@@ -135,7 +135,6 @@ pub fn mk_app(.service(routes::Analytics::server(state.clone())).service(routes::Routing::server(state.clone())).service(routes::Blocklist::server(state.clone()))- .service(routes::LockerMigrate::server(state.clone())).service(routes::Gsm::server(state.clone())).service(routes::PaymentLink::server(state.clone())).service(routes::User::server(state.clone()))diff --git a/crates/router/src/routes.rs b/crates/router/src/routes.rsindex e058d4f1c1..51c938b097 100644--- a/crates/router/src/routes.rs+++ b/crates/router/src/routes.rs@@ -61,7 +61,7 @@ pub use self::app::Recon;pub use self::app::Verify;pub use self::app::{ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, ConnectorOnboarding, Customers,- Disputes, EphemeralKey, Files, Gsm, Health, LockerMigrate, Mandates, MerchantAccount,+ Disputes, EphemeralKey, Files, Gsm, Health, Mandates, MerchantAccount,MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Refunds, User, Webhooks,};#[cfg(feature = "stripe")]diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rsindex 1a8a2d696b..41881c60ff 100644--- a/crates/router/src/routes/app.rs+++ b/crates/router/src/routes/app.rs@@ -37,8 +37,8 @@ use super::routing as cloud_routing;use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains};#[cfg(feature = "olap")]use super::{- admin::*, api_keys::*, connector_onboarding::*, disputes::*, files::*, gsm::*,- locker_migration, payment_link::*, user::*, user_role::*,+ admin::*, api_keys::*, connector_onboarding::*, disputes::*, files::*, gsm::*, payment_link::*,+ user::*, user_role::*,};use super::{cache::*, health::*};#[cfg(any(feature = "olap", feature = "oltp"))]@@ -1064,19 +1064,6 @@ impl User {}}-pub struct LockerMigrate;--#[cfg(feature = "olap")]-impl LockerMigrate {- pub fn server(state: AppState) -> Scope {- web::scope("locker_migration/{merchant_id}")- .app_data(web::Data::new(state))- .service(- web::resource("").route(web::post().to(locker_migration::rust_locker_migration)),- )- }-}-pub struct ConnectorOnboarding;#[cfg(feature = "olap")]