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

feat: implement generic Locker api handler (#10242)

Ankit Kumar Gupta3c695d0adb10
diff --git a/config/config.example.toml b/config/config.example.toml
index df39904d6c..011277be06 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -141,7 +141,6 @@ jwt_secret = "secret" # JWT secret used for user authenticati
# like card details
[locker]
host = "" # Locker host
-host_rs = "" # Rust Locker host
mock_locker = true # Emulate a locker locally using Postgres
locker_signing_key_id = "1" # Key_id to sign basilisk hs locker
locker_enabled = true # Boolean to enable or disable saving cards in locker
@@ -155,7 +154,6 @@ connectors_with_webhook_source_verification_call = "paypal" # List of connectors
[jwekey] # 4 priv/pub key pair
vault_encryption_key = "" # public key in pem format, corresponding private key in basilisk-hs
-rust_locker_encryption_key = "" # public key in pem format, corresponding private key in rust locker
vault_private_key = "" # private key in pem format, corresponding public key in basilisk-hs
# Refund configuration
diff --git a/config/deployments/env_specific.toml b/config/deployments/env_specific.toml
index ea17197f7e..8450685277 100644
--- a/config/deployments/env_specific.toml
+++ b/config/deployments/env_specific.toml
@@ -123,7 +123,6 @@ redis_ttl_in_seconds = 172800 # Time to expire for forex data stored in Redi
[jwekey] # 3 priv/pub key pair
vault_encryption_key = "" # public key in pem format, corresponding private key in rust locker
-rust_locker_encryption_key = "" # public key in pem format, corresponding private key in rust locker
vault_private_key = "" # private key in pem format, corresponding public key in rust locker
# Locker settings contain details for accessing a card locker, a
@@ -131,7 +130,6 @@ vault_private_key = "" # private key in pem format, corresponding publi
# like card details
[locker]
host = "" # Locker host
-host_rs = "" # Rust Locker host
mock_locker = true # Emulate a locker locally using Postgres
locker_signing_key_id = "1" # Key_id to sign basilisk hs locker
locker_enabled = true # Boolean to enable or disable saving cards in locker
diff --git a/config/development.toml b/config/development.toml
index ba4569005b..753c888536 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -75,9 +75,7 @@ applepay_endpoint = "DOMAIN SPECIFIC ENDPOINT"
[locker]
host = "http://127.0.0.1:3000"
-host_rs = "http://127.0.0.1:3000"
mock_locker = true
-basilisk_host = ""
locker_enabled = true
ttl_for_storage_in_secs = 220752000
@@ -90,7 +88,6 @@ redis_ttl_in_seconds = 172800
[jwekey]
vault_encryption_key = ""
-rust_locker_encryption_key = ""
vault_private_key = ""
tunnel_private_key = ""
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index 27323a5a2c..9f4b99eaa1 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -77,15 +77,12 @@ redirect_uri = "" # Redirect URI registered for the OIDC client
[locker]
host = ""
-host_rs = ""
mock_locker = true
-basilisk_host = ""
locker_enabled = true
ttl_for_storage_in_secs = 220752000
[jwekey]
vault_encryption_key = ""
-rust_locker_encryption_key = ""
vault_private_key = ""
[redis]
diff --git a/crates/api_models/src/enums.rs b/crates/api_models/src/enums.rs
index 65591c82e5..0f20f43c0e 100644
--- a/crates/api_models/src/enums.rs
+++ b/crates/api_models/src/enums.rs
@@ -444,11 +444,6 @@ pub enum RetryAction {
Requeue,
}
-#[derive(Clone, Copy)]
-pub enum LockerChoice {
- HyperswitchCardVault,
-}
-
#[derive(
Clone,
Copy,
diff --git a/crates/payment_methods/src/controller.rs b/crates/payment_methods/src/controller.rs
index 47a91f8463..32e3c990f7 100644
--- a/crates/payment_methods/src/controller.rs
+++ b/crates/payment_methods/src/controller.rs
@@ -1,8 +1,8 @@
use std::fmt::Debug;
+use api_models::payment_methods as api;
#[cfg(feature = "payouts")]
use api_models::payouts;
-use api_models::{enums as api_enums, payment_methods as api};
#[cfg(feature = "v1")]
use common_enums::enums as common_enums;
#[cfg(feature = "v2")]
@@ -120,7 +120,6 @@ pub trait PaymentMethodsController {
req: api::PaymentMethodCreate,
card: &api::CardDetail,
customer_id: &id_type::CustomerId,
- locker_choice: api_enums::LockerChoice,
card_reference: Option<&str>,
) -> errors::VaultResult<(api::PaymentMethodResponse, Option<DataDuplicationCheck>)>;
diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs
index 703631da6d..654949f250 100644
--- a/crates/router/src/configs/defaults.rs
+++ b/crates/router/src/configs/defaults.rs
@@ -51,9 +51,7 @@ impl Default for super::settings::Locker {
fn default() -> Self {
Self {
host: "localhost".into(),
- host_rs: "localhost".into(),
mock_locker: true,
- basilisk_host: "localhost".into(),
locker_signing_key_id: "1".into(),
//true or false
locker_enabled: true,
diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rs
index 1619935c36..b1365eabdb 100644
--- a/crates/router/src/configs/secrets_transformers.rs
+++ b/crates/router/src/configs/secrets_transformers.rs
@@ -32,20 +32,13 @@ impl SecretsHandler for settings::Jwekey {
secret_management_client: &dyn SecretManagementInterface,
) -> CustomResult<SecretStateContainer<Self, RawSecret>, SecretsManagementError> {
let jwekey = value.get_inner();
- let (
- vault_encryption_key,
- rust_locker_encryption_key,
- vault_private_key,
- tunnel_private_key,
- ) = tokio::try_join!(
+ let (vault_encryption_key, vault_private_key, tunnel_private_key) = tokio::try_join!(
secret_management_client.get_secret(jwekey.vault_encryption_key.clone()),
- secret_management_client.get_secret(jwekey.rust_locker_encryption_key.clone()),
secret_management_client.get_secret(jwekey.vault_private_key.clone()),
secret_management_client.get_secret(jwekey.tunnel_private_key.clone())
)?;
Ok(value.transition_state(|_| Self {
vault_encryption_key,
- rust_locker_encryption_key,
vault_private_key,
tunnel_private_key,
}))
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 490c9c0ea3..8033db7429 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -740,15 +740,21 @@ impl OidcSettings {
#[serde(default)]
pub struct Locker {
pub host: String,
- pub host_rs: String,
pub mock_locker: bool,
- pub basilisk_host: String,
pub locker_signing_key_id: String,
pub locker_enabled: bool,
pub ttl_for_storage_in_secs: i64,
pub decryption_scheme: DecryptionScheme,
}
+impl Locker {
+ pub fn get_host(&self, endpoint_path: &str) -> String {
+ let mut url = self.host.clone();
+ url.push_str(endpoint_path);
+ url
+ }
+}
+
#[derive(Debug, Deserialize, Clone, Default)]
pub enum DecryptionScheme {
#[default]
@@ -775,7 +781,6 @@ pub struct EphemeralConfig {
#[serde(default)]
pub struct Jwekey {
pub vault_encryption_key: Secret<String>,
- pub rust_locker_encryption_key: Secret<String>,
pub vault_private_key: Secret<String>,
pub tunnel_private_key: Secret<String>,
}
diff --git a/crates/router/src/configs/validations.rs b/crates/router/src/configs/validations.rs
index 023b9ee5be..998b94013a 100644
--- a/crates/router/src/configs/validations.rs
+++ b/crates/router/src/configs/validations.rs
@@ -34,16 +34,7 @@ impl super::settings::Locker {
Err(ApplicationError::InvalidConfigurationValueError(
"locker host must not be empty when mock locker is disabled".into(),
))
- })?;
-
- when(
- !self.mock_locker && self.basilisk_host.is_default_or_empty(),
- || {
- Err(ApplicationError::InvalidConfigurationValueError(
- "basilisk host must not be empty when mock locker is disabled".into(),
- ))
- },
- )
+ })
}
}
diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rs
index 8850b8697a..22d35c4947 100644
--- a/crates/router/src/consts.rs
+++ b/crates/router/src/consts.rs
@@ -113,6 +113,9 @@ pub const MAX_INTENT_FULFILLMENT_EXPIRY: u32 = 1800;
pub const MIN_INTENT_FULFILLMENT_EXPIRY: u32 = 60;
pub const LOCKER_HEALTH_CALL_PATH: &str = "/health";
+pub const LOCKER_ADD_CARD_PATH: &str = "/cards/add";
+pub const LOCKER_RETRIEVE_CARD_PATH: &str = "/cards/retrieve";
+pub const LOCKER_DELETE_CARD_PATH: &str = "/cards/delete";
pub const AUTHENTICATION_ID_PREFIX: &str = "authn";
diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rs
index 2a11d02c84..61ac8b3fa6 100644
--- a/crates/router/src/core/admin.rs
+++ b/crates/router/src/core/admin.rs
@@ -4619,15 +4619,10 @@ async fn locker_recipient_create_call(
ttl: state.conf.locker.ttl_for_storage_in_secs,
});
- let store_resp = cards::add_card_to_hs_locker(
- state,
- &payload,
- &cust_id,
- api_enums::LockerChoice::HyperswitchCardVault,
- )
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Failed to encrypt merchant bank account data")?;
+ let store_resp = cards::add_card_to_vault(state, &payload, &cust_id)
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to encrypt merchant bank account data")?;
Ok(store_resp.card_reference)
}
diff --git a/crates/router/src/core/blocklist/transformers.rs b/crates/router/src/core/blocklist/transformers.rs
index fc459fea0f..f9262d2aeb 100644
--- a/crates/router/src/core/blocklist/transformers.rs
+++ b/crates/router/src/core/blocklist/transformers.rs
@@ -1,24 +1,15 @@
-use api_models::{blocklist, enums as api_enums};
-use common_utils::{
- ext_traits::{Encode, StringExt},
- id_type,
- request::RequestContent,
-};
+use api_models::blocklist;
use error_stack::ResultExt;
-use josekit::jwe;
-use masking::{PeekInterface, StrongSecret};
+use masking::StrongSecret;
use router_env::{instrument, tracing};
use crate::{
- configs::settings,
core::{
errors::{self, CustomResult},
payment_methods::transformers as payment_methods,
},
- headers, routes,
- services::{api as services, encryption, EncryptionAlgorithm},
+ routes,
types::{storage, transformers::ForeignFrom},
- utils::ConnectorResponseExt,
};
const LOCKER_FINGERPRINT_PATH: &str = "/cards/fingerprint";
@@ -33,191 +24,41 @@ impl ForeignFrom<storage::Blocklist> for blocklist::AddToBlocklistResponse {
}
}
-async fn generate_fingerprint_request(
- jwekey: &settings::Jwekey,
- locker: &settings::Locker,
- payload: &blocklist::GenerateFingerprintRequest,
- locker_choice: api_enums::LockerChoice,
- tenant_id: id_type::TenantId,
- request_id: Option<router_env::RequestId>,
-) -> CustomResult<services::Request, errors::VaultError> {
- let payload = payload
- .encode_to_vec()
- .change_context(errors::VaultError::RequestEncodingFailed)?;
-
- let private_key = jwekey.vault_private_key.peek().as_bytes();
-
- let jws = encryption::jws_sign_payload(&payload, &locker.locker_signing_key_id, private_key)
- .await
- .change_context(errors::VaultError::RequestEncodingFailed)?;
-
- let jwe_payload = generate_jwe_payload_for_request(jwekey, &jws, locker_choice).await?;
- let mut url = match locker_choice {
- api_enums::LockerChoice::HyperswitchCardVault => locker.host.to_owned(),
- };
- url.push_str(LOCKER_FINGERPRINT_PATH);
- let mut request = services::Request::new(services::Method::Post, &url);
- request.add_header(headers::CONTENT_TYPE, "application/json".into());
- request.add_header(
- headers::X_TENANT_ID,
- tenant_id.get_string_repr().to_owned().into(),
- );
- if let Some(req_id) = request_id {
- request.add_header(headers::X_REQUEST_ID, req_id.to_string().into());
- }
- request.set_body(RequestContent::Json(Box::new(jwe_payload)));
- Ok(request)
-}
-
-async fn generate_jwe_payload_for_request(
- jwekey: &settings::Jwekey,
- jws: &str,
- locker_choice: api_enums::LockerChoice,
-) -> CustomResult<encryption::JweBody, errors::VaultError> {
- let jws_payload: Vec<&str> = jws.split('.').collect();
-
- let generate_jws_body = |payload: Vec<&str>| -> Option<encryption::JwsBody> {
- Some(encryption::JwsBody {
- header: payload.first()?.to_string(),
- payload: payload.get(1)?.to_string(),
- signature: payload.get(2)?.to_string(),
- })
- };
-
- let jws_body =
- generate_jws_body(jws_payload).ok_or(errors::VaultError::GenerateFingerprintFailed)?;
-
- let payload = jws_body
- .encode_to_vec()
- .change_context(errors::VaultError::GenerateFingerprintFailed)?;
-
- let public_key = match locker_choice {
- api_enums::LockerChoice::HyperswitchCardVault => {
- jwekey.vault_encryption_key.peek().as_bytes()
- }
- };
-
- let jwe_encrypted =
- encryption::encrypt_jwe(&payload, public_key, EncryptionAlgorithm::A256GCM, None)
- .await
- .change_context(errors::VaultError::SaveCardFailed)
- .attach_printable("Error on jwe encrypt")?;
- let jwe_payload: Vec<&str> = jwe_encrypted.split('.').collect();
-
- let generate_jwe_body = |payload: Vec<&str>| -> Option<encryption::JweBody> {
- Some(encryption::JweBody {
- header: payload.first()?.to_string(),
- iv: payload.get(2)?.to_string(),
- encrypted_payload: payload.get(3)?.to_string(),
- tag: payload.get(4)?.to_string(),
- encrypted_key: payload.get(1)?.to_string(),
- })
- };
-
- let jwe_body =
- generate_jwe_body(jwe_payload).ok_or(errors::VaultError::GenerateFingerprintFailed)?;
-
- Ok(jwe_body)
-}
-
#[instrument(skip_all)]
pub async fn generate_fingerprint(
state: &routes::SessionState,
card_number: StrongSecret<String>,
hash_key: StrongSecret<String>,
- locker_choice: api_enums::LockerChoice,
) -> CustomResult<blocklist::GenerateFingerprintResponsePayload, errors::VaultError> {
let payload = blocklist::GenerateFingerprintRequest {
data: card_number,
key: hash_key,
};
- let generate_fingerprint_resp =
- call_to_locker_for_fingerprint(state, &payload, locker_choice).await?;
+ let generate_fingerprint_resp = call_to_vault_for_fingerprint(state, &payload).await?;
Ok(generate_fingerprint_resp)
}
#[instrument(skip_all)]
-async fn call_to_locker_for_fingerprint(
+async fn call_to_vault_for_fingerprint(
state: &routes::SessionState,
payload: &blocklist::GenerateFingerprintRequest,
- locker_choice: api_enums::LockerChoice,
) -> CustomResult<blocklist::GenerateFingerprintResponsePayload, errors::VaultError> {
let locker = &state.conf.locker;
let jwekey = state.conf.jwekey.get_inner();
-
- let request = generate_fingerprint_request(
- jwekey,
- locker,
- payload,
- locker_choice,
- state.tenant.tenant_id.clone(),
- state.request_id.clone(),
- )
- .await?;
- let response = services::call_connector_api(state, request, "call_locker_to_get_fingerprint")
+ let generate_fingerprint_response: blocklist::GenerateFingerprintResponsePayload =
+ payment_methods::call_vault_api(
+ state,
+ jwekey,
+ locker,
+ payload,
+ LOCKER_FINGERPRINT_PATH,
+ state.tenant.tenant_id.clone(),
+ state.request_id.clone(),
+ )
.await
- .change_context(errors::VaultError::GenerateFingerprintFailed);
- let jwe_body: encryption::JweBody = response
- .get_response_inner("JweBody")
.change_context(errors::VaultError::GenerateFingerprintFailed)?;
- let decrypted_payload = decrypt_generate_fingerprint_response_payload(
- jwekey,
- jwe_body,
- Some(locker_choice),
- locker.decryption_scheme.clone(),
- )
- .await
- .change_context(errors::VaultError::GenerateFingerprintFailed)
- .attach_printable("Error getting decrypted fingerprint response payload")?;
- let generate_fingerprint_response: blocklist::GenerateFingerprintResponsePayload =
- decrypted_payload
- .parse_struct("GenerateFingerprintResponse")
- .change_context(errors::VaultError::ResponseDeserializationFailed)?;
-
Ok(generate_fingerprint_response)
}
-
-async fn decrypt_generate_fingerprint_response_payload(
- jwekey: &settings::Jwekey,
- jwe_body: encryption::JweBody,
- locker_choice: Option<api_enums::LockerChoice>,
- decryption_scheme: settings::DecryptionScheme,
-) -> CustomResult<String, errors::VaultError> {
- let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::HyperswitchCardVault);
-
- let public_key = match target_locker {
- api_enums::LockerChoice::HyperswitchCardVault => {
- jwekey.vault_encryption_key.peek().as_bytes()
- }
- };
-
- let private_key = jwekey.vault_private_key.peek().as_bytes();
-
- let jwt = payment_methods::get_dotted_jwe(jwe_body);
- let alg = match decryption_scheme {
- settings::DecryptionScheme::RsaOaep => jwe::RSA_OAEP,
- settings::DecryptionScheme::RsaOaep256 => jwe::RSA_OAEP_256,
- };
-
- let jwe_decrypted = encryption::decrypt_jwe(
- &jwt,
- encryption::KeyIdCheck::SkipKeyIdCheck,
- private_key,
- alg,
- )
- .await
- .change_context(errors::VaultError::SaveCardFailed)
- .attach_printable("Jwe Decryption failed for JweBody for vault")?;
-
- let jws = jwe_decrypted
- .parse_struct("JwsBody")
- .change_context(errors::VaultError::ResponseDeserializationFailed)?;
- let jws_body = payment_methods::get_dotted_jws(jws);
-
- encryption::verify_sign(jws_body, public_key)
- .change_context(errors::VaultError::SaveCardFailed)
- .attach_printable("Jws Decryption failed for JwsBody for vault")
-}
diff --git a/crates/router/src/core/blocklist/utils.rs b/crates/router/src/core/blocklist/utils.rs
index 8721352555..4c3103895e 100644
--- a/crates/router/src/core/blocklist/utils.rs
+++ b/crates/router/src/core/blocklist/utils.rs
@@ -306,7 +306,6 @@ pub async fn should_payment_be_blocked(
state,
StrongSecret::new(card.card_number.get_card_no()),
StrongSecret::new(merchant_fingerprint_secret.clone()),
- api_models::enums::LockerChoice::HyperswitchCardVault,
)
.await
.attach_printable("error in pm fingerprint creation")
@@ -469,7 +468,6 @@ pub async fn generate_payment_fingerprint(
state,
StrongSecret::new(card.card_number.get_card_no()),
StrongSecret::new(merchant_fingerprint_secret),
- api_models::enums::LockerChoice::HyperswitchCardVault,
)
.await
.attach_printable("error in pm fingerprint creation")
diff --git a/crates/router/src/core/health_check.rs b/crates/router/src/core/health_check.rs
index 5df265ec4e..f1efca9184 100644
--- a/crates/router/src/core/health_check.rs
+++ b/crates/router/src/core/health_check.rs
@@ -89,7 +89,7 @@ impl HealthCheckInterface for app::SessionState {
) -> CustomResult<HealthState, errors::HealthCheckLockerError> {
let locker = &self.conf.locker;
if !locker.mock_locker {
- let mut url = locker.host_rs.to_owned();
+ let mut url = locker.host.to_owned();
url.push_str(consts::LOCKER_HEALTH_CALL_PATH);
let request = services::Request::new(services::Method::Get, &url);
services::call_connector_api(self, request, "health_check_for_locker")
diff --git a/crates/router/src/core/locker_migration.rs b/crates/router/src/core/locker_migration.rs
index 19572729e1..7c27fb509e 100644
--- a/crates/router/src/core/locker_migration.rs
+++ b/crates/router/src/core/locker_migration.rs
@@ -1,6 +1,4 @@
use ::payment_methods::controller::PaymentMethodsController;
-#[cfg(feature = "v1")]
-use api_models::enums as api_enums;
use api_models::locker_migration::MigrateCardResponse;
use common_utils::{errors::CustomResult, id_type};
#[cfg(feature = "v1")]
@@ -170,7 +168,6 @@ pub async fn call_to_locker(
pm_create,
&card_details,
customer_id,
- api_enums::LockerChoice::HyperswitchCardVault,
Some(pm.locker_id.as_ref().unwrap_or(&pm.payment_method_id)),
)
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 368292c26b..48b71714a9 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -111,6 +111,7 @@ use crate::{
core::payment_methods as pm_core, headers, types::payment_methods as pm_types,
utils::ConnectorResponseExt,
};
+
pub struct PmCards<'a> {
pub state: &'a routes::SessionState,
pub provider: &'a domain::Provider,
@@ -590,13 +591,7 @@ impl PaymentMethodsController for PmCards<'_> {
enc_data,
ttl: self.state.conf.locker.ttl_for_storage_in_secs,
});
- let store_resp = add_card_to_hs_locker(
- self.state,
- &payload,
- customer_id,
- api_enums::LockerChoice::HyperswitchCardVault,
- )
- .await?;
+ let store_resp = add_card_to_vault(self.state, &payload, customer_id).await?;
let payment_method_resp = payment_methods::mk_add_bank_response_hs(
bank.clone(),
store_resp.card_reference,
@@ -623,20 +618,17 @@ impl PaymentMethodsController for PmCards<'_> {
metrics::STORED_TO_LOCKER.add(1, &[]);
let add_card_to_hs_resp = Box::pin(common_utils::metrics::utils::record_operation_time(
async {
- self.add_card_hs(
- req.clone(),
- card,
- customer_id,
- api_enums::LockerChoice::HyperswitchCardVault,
- card_reference,
- )
- .await
- .inspect_err(|_| {
- metrics::CARD_LOCKER_FAILURES.add(
- 1,
- router_env::metric_attributes!(("locker", "rust"), ("operation", "add")),
- );
- })
+ self.add_card_hs(req.clone(), card, customer_id, card_reference)
+ .await
+ .inspect_err(|_| {
+ metrics::CARD_LOCKER_FAILURES.add(
+ 1,
+ router_env::metric_attributes!(
+ ("locker", "rust"),
+ ("operation", "add")
+ ),
+ );
+ })
},
&metrics::CARD_ADD_TIME,
router_env::metric_attributes!(("locker", "rust")),
@@ -657,7 +649,7 @@ impl PaymentMethodsController for PmCards<'_> {
common_utils::metrics::utils::record_operation_time(
async move {
- delete_card_from_hs_locker(self.state, customer_id, merchant_id, card_reference)
+ delete_card_from_vault(self.state, customer_id, merchant_id, card_reference)
.await
.inspect_err(|_| {
metrics::CARD_LOCKER_FAILURES.add(
@@ -683,7 +675,6 @@ impl PaymentMethodsController for PmCards<'_> {
req: api::PaymentMethodCreate,
card: &api::CardDetail,
customer_id: &id_type::CustomerId,
- locker_choice: api_enums::LockerChoice,
card_reference: Option<&str>,
) -> errors::CustomResult<
(
@@ -708,8 +699,7 @@ impl PaymentMethodsController for PmCards<'_> {
ttl: self.state.conf.locker.ttl_for_storage_in_secs,
});
- let store_card_payload =
- add_card_to_hs_locker(self.state, &payload, customer_id, locker_choice).await?;
+ let store_card_payload = add_card_to_vault(self.state, &payload, customer_id).await?;
let payment_method_resp = payment_methods::mk_add_card_response_hs(
card.clone(),
@@ -1171,7 +1161,6 @@ impl PaymentMethodsController for PmCards<'_> {
req.clone(),
&card,
&customer_id,
- api::enums::LockerChoice::HyperswitchCardVault,
Some(
existing_pm
.locker_id
@@ -1977,30 +1966,24 @@ pub async fn get_card_from_locker(
let get_card_from_rs_locker_resp = common_utils::metrics::utils::record_operation_time(
async {
- get_card_from_hs_locker(
- state,
- customer_id,
- merchant_id,
- card_reference,
- api_enums::LockerChoice::HyperswitchCardVault,
- )
- .await
- .map_err(|err| match err.current_context() {
- errors::VaultError::FetchCardFailed => {
- err.change_context(errors::ApiErrorResponse::GenericNotFoundError {
- message: "Card not found in vault".to_string(),
- })
- }
- _ => err
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error getting card from card vault"),
- })
- .inspect_err(|_| {
- metrics::CARD_LOCKER_FAILURES.add(
- 1,
- router_env::metric_attributes!(("locker", "rust"), ("operation", "get")),
- );
- })
+ get_card_from_vault(state, customer_id, merchant_id, card_reference)
+ .await
+ .map_err(|err| match err.current_context() {
+ errors::VaultError::FetchCardFailed => {
+ err.change_context(errors::ApiErrorResponse::GenericNotFoundError {
+ message: "Card not found in vault".to_string(),
+ })
+ }
+ _ => err
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Error getting card from card vault"),
+ })
+ .inspect_err(|_| {
+ metrics::CARD_LOCKER_FAILURES.add(
+ 1,
+ router_env::metric_attributes!(("locker", "rust"), ("operation", "get")),
+ );
+ })
},
&metrics::CARD_GET_TIME,
router_env::metric_attributes!(("locker", "rust")),
@@ -2050,25 +2033,29 @@ pub async fn decode_and_decrypt_locker_data(
}
#[instrument(skip_all)]
-pub async fn get_payment_method_from_hs_locker<'a>(
+pub async fn get_encrypted_data_from_vault<'a>(
state: &'a routes::SessionState,
key_store: &domain::MerchantKeyStore,
customer_id: &id_type::CustomerId,
merchant_id: &id_type::MerchantId,
payment_method_reference: &'a str,
- locker_choice: Option<api_enums::LockerChoice>,
) -> errors::CustomResult<Secret<String>, errors::VaultError> {
let locker = &state.conf.locker;
let jwekey = state.conf.jwekey.get_inner();
let payment_method_data = if !locker.mock_locker {
- let request = payment_methods::mk_get_card_request_hs(
+ let payload = payment_methods::CardReqBody {
+ merchant_id: merchant_id.to_owned(),
+ merchant_customer_id: customer_id.to_owned(),
+ card_reference: payment_method_reference.to_string(),
+ };
+
+ let get_card_resp: payment_methods::RetrieveCardResp = payment_methods::call_vault_api(
+ state,
jwekey,
locker,
- customer_id,
- merchant_id,
- payment_method_reference,
- locker_choice,
+ &payload,
+ router_consts::LOCKER_RETRIEVE_CARD_PATH,
state.tenant.tenant_id.clone(),
state.request_id.clone(),
)
@@ -2076,15 +2063,6 @@ pub async fn get_payment_method_from_hs_locker<'a>(
.change_context(errors::VaultError::FetchPaymentMethodFailed)
.attach_printable("Making get payment method request failed")?;
- let get_card_resp = call_locker_api::<payment_methods::RetrieveCardResp>(
- state,
- request,
- "get_pm_from_locker",
- locker_choice,
- )
- .await
- .change_context(errors::VaultError::FetchPaymentMethodFailed)?;
-
let retrieve_card_resp = get_card_resp
.payload
.get_required_value("RetrieveCardRespPayload")
@@ -2108,31 +2086,24 @@ pub async fn get_payment_method_from_hs_locker<'a>(
}
#[instrument(skip_all)]
-pub async fn add_card_to_hs_locker(
+pub async fn add_card_to_vault(
state: &routes::SessionState,
payload: &payment_methods::StoreLockerReq,
customer_id: &id_type::CustomerId,
- locker_choice: api_enums::LockerChoice,
) -> errors::CustomResult<payment_methods::StoreCardRespPayload, errors::VaultError> {
let locker = &state.conf.locker;
let jwekey = state.conf.jwekey.get_inner();
let db = &*state.store;
let stored_card_response = if !locker.mock_locker {
- let request = payment_methods::mk_add_locker_request_hs(
+ payment_methods::call_vault_api(
+ state,
jwekey,
locker,
payload,
- locker_choice,
+ router_consts::LOCKER_ADD_CARD_PATH,
state.tenant.tenant_id.clone(),
state.request_id.clone(),
)
- .await?;
- call_locker_api::<payment_methods::StoreCardResp>(
- state,
- request,
- "add_card_to_hs_locker",
- Some(locker_choice),
- )
.await
.change_context(errors::VaultError::SaveCardFailed)?
} else {
@@ -2148,11 +2119,10 @@ pub async fn add_card_to_hs_locker(
}
#[instrument(skip_all)]
-pub async fn call_locker_api<T>(
+pub async fn call_vault_service<T>(
state: &routes::SessionState,
request: Request,
flow_name: &str,
- locker_choice: Option<api_enums::LockerChoice>,
) -> errors::CustomResult<T, errors::VaultError>
where
T: serde::de::DeserializeOwned,
@@ -2177,7 +2147,6 @@ where
let decrypted_payload = payment_methods::get_decrypted_response_payload(
jwekey,
jwe_body,
- locker_choice,
locker.decryption_scheme.clone(),
)
.await
@@ -2289,38 +2258,34 @@ pub async fn update_payment_method_connector_mandate_details(
Ok(())
}
#[instrument(skip_all)]
-pub async fn get_card_from_hs_locker<'a>(
+pub async fn get_card_from_vault<'a>(
state: &'a routes::SessionState,
customer_id: &id_type::CustomerId,
merchant_id: &id_type::MerchantId,
card_reference: &'a str,
- locker_choice: api_enums::LockerChoice,
) -> errors::CustomResult<Card, errors::VaultError> {
let locker = &state.conf.locker;
let jwekey = &state.conf.jwekey.get_inner();
if !locker.mock_locker {
- let request = payment_methods::mk_get_card_request_hs(
+ let payload = payment_methods::CardReqBody {
+ merchant_id: merchant_id.to_owned(),
+ merchant_customer_id: customer_id.to_owned(),
+ card_reference: card_reference.to_string(),
+ };
+
+ let get_card_resp: payment_methods::RetrieveCardResp = payment_methods::call_vault_api(
+ state,
jwekey,
locker,
- customer_id,
- merchant_id,
- card_reference,
- Some(locker_choice),
+ &payload,
+ router_consts::LOCKER_RETRIEVE_CARD_PATH,
state.tenant.tenant_id.clone(),
state.request_id.clone(),
)
.await
.change_context(errors::VaultError::FetchCardFailed)
.attach_printable("Making get card request failed")?;
- let get_card_resp = call_locker_api::<payment_methods::RetrieveCardResp>(
- state,
- request,
- "get_card_from_locker",
- Some(locker_choice),
- )
- .await
- .change_context(errors::VaultError::FetchCardFailed)?;
let retrieve_card_resp = get_card_resp
.payload
@@ -2338,7 +2303,7 @@ pub async fn get_card_from_hs_locker<'a>(
}
#[instrument(skip_all)]
-pub async fn delete_card_from_hs_locker<'a>(
+pub async fn delete_card_from_vault<'a>(
state: &routes::SessionState,
customer_id: &id_type::CustomerId,
merchant_id: &id_type::MerchantId,
@@ -2347,28 +2312,25 @@ pub async fn delete_card_from_hs_locker<'a>(
let locker = &state.conf.locker;
let jwekey = &state.conf.jwekey.get_inner();
- let request = payment_methods::mk_delete_card_request_hs(
- jwekey,
- locker,
- customer_id,
- merchant_id,
- card_reference,
- state.tenant.tenant_id.clone(),
- state.request_id.clone(),
- )
- .await
- .change_context(errors::VaultError::DeleteCardFailed)
- .attach_printable("Making delete card request failed")?;
-
if !locker.mock_locker {
- call_locker_api::<payment_methods::DeleteCardResp>(
+ let payload = payment_methods::CardReqBody {
+ merchant_id: merchant_id.to_owned(),
+ merchant_customer_id: customer_id.to_owned(),
+ card_reference: card_reference.to_string(),
+ };
+
+ payment_methods::call_vault_api(
state,
- request,
- "delete_card_from_locker",
- Some(api_enums::LockerChoice::HyperswitchCardVault),
+ jwekey,
+ locker,
+ &payload,
+ router_consts::LOCKER_DELETE_CARD_PATH,
+ state.tenant.tenant_id.clone(),
+ state.request_id.clone(),
)
.await
.change_context(errors::VaultError::DeleteCardFailed)
+ .attach_printable("Making delete card request failed")
} else {
Ok(mock_delete_card_hs(&*state.store, card_reference)
.await
@@ -2376,18 +2338,6 @@ pub async fn delete_card_from_hs_locker<'a>(
}
}
-// Need to fix this function while completing v2
-#[cfg(feature = "v2")]
-#[instrument(skip_all)]
-pub async fn delete_card_from_hs_locker_by_global_id<'a>(
- state: &routes::SessionState,
- id: &str,
- merchant_id: &id_type::MerchantId,
- card_reference: &'a str,
-) -> errors::RouterResult<payment_methods::DeleteCardResp> {
- todo!()
-}
-
///Mock api for local testing
pub async fn mock_call_to_locker_hs(
db: &dyn db::StorageInterface,
@@ -4491,7 +4441,7 @@ pub async fn get_pm_list_context(
enums::PaymentMethod::BankTransfer => Some(PaymentMethodListContext {
card_details: None,
bank_transfer_details: Some(
- get_bank_from_hs_locker(
+ get_bank_from_vault(
state,
key_store,
parent_payment_method_token.as_ref(),
@@ -4885,7 +4835,7 @@ pub async fn update_last_used_at(
Ok(())
}
#[cfg(feature = "payouts")]
-pub async fn get_bank_from_hs_locker(
+pub async fn get_bank_from_vault(
state: &routes::SessionState,
key_store: &domain::MerchantKeyStore,
temp_token: Option<&String>,
@@ -4893,17 +4843,11 @@ pub async fn get_bank_from_hs_locker(
merchant_id: &id_type::MerchantId,
token_ref: &str,
) -> errors::RouterResult<api::BankPayout> {
- let payment_method = get_payment_method_from_hs_locker(
- state,
- key_store,
- customer_id,
- merchant_id,
- token_ref,
- None,
- )
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error getting payment method from locker")?;
+ let payment_method =
+ get_encrypted_data_from_vault(state, key_store, customer_id, merchant_id, token_ref)
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Error getting payment method from locker")?;
let pm_parsed: api::PayoutMethodData = payment_method
.peek()
.to_string()
diff --git a/crates/router/src/core/payment_methods/tokenize.rs b/crates/router/src/core/payment_methods/tokenize.rs
index 57b996c3ca..8b571a5f0e 100644
--- a/crates/router/src/core/payment_methods/tokenize.rs
+++ b/crates/router/src/core/payment_methods/tokenize.rs
@@ -13,7 +13,7 @@ use router_env::logger;
use crate::{
core::payment_methods::{
- cards::{add_card_to_hs_locker, create_encrypted_data, tokenize_card_flow},
+ cards::{add_card_to_vault, create_encrypted_data, tokenize_card_flow},
network_tokenization, transformers as pm_transformers,
},
errors::{self, RouterResult},
@@ -408,15 +408,10 @@ where
ttl: self.state.conf.locker.ttl_for_storage_in_secs,
});
- let stored_resp = add_card_to_hs_locker(
- self.state,
- &locker_req,
- customer_id,
- api_enums::LockerChoice::HyperswitchCardVault,
- )
- .await
- .inspect_err(|err| logger::info!("Error adding card in locker: {:?}", err))
- .change_context(errors::ApiErrorResponse::InternalServerError)?;
+ let stored_resp = add_card_to_vault(self.state, &locker_req, customer_id)
+ .await
+ .inspect_err(|err| logger::info!("Error adding card in locker: {:?}", err))
+ .change_context(errors::ApiErrorResponse::InternalServerError)?;
Ok(stored_resp)
}
diff --git a/crates/router/src/core/payment_methods/tokenize/card_executor.rs b/crates/router/src/core/payment_methods/tokenize/card_executor.rs
index 50d505f4fe..8879caba4a 100644
--- a/crates/router/src/core/payment_methods/tokenize/card_executor.rs
+++ b/crates/router/src/core/payment_methods/tokenize/card_executor.rs
@@ -21,7 +21,7 @@ use super::{
};
use crate::{
core::payment_methods::{
- cards::{add_card_to_hs_locker, PmCards},
+ cards::{add_card_to_vault, PmCards},
transformers as pm_transformers,
},
errors::{self, RouterResult},
@@ -508,15 +508,10 @@ impl CardNetworkTokenizeExecutor<'_, domain::TokenizeCardRequest> {
ttl: self.state.conf.locker.ttl_for_storage_in_secs,
});
- let stored_resp = add_card_to_hs_locker(
- self.state,
- &locker_req,
- customer_id,
- api_enums::LockerChoice::HyperswitchCardVault,
- )
- .await
- .inspect_err(|err| logger::info!("Error adding card in locker: {:?}", err))
- .change_context(errors::ApiErrorResponse::InternalServerError)?;
+ let stored_resp = add_card_to_vault(self.state, &locker_req, customer_id)
+ .await
+ .inspect_err(|err| logger::info!("Error adding card in locker: {:?}", err))
+ .change_context(errors::ApiErrorResponse::InternalServerError)?;
Ok(stored_resp)
}
diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs
index d7a6eeaf2c..e624b00a83 100644
--- a/crates/router/src/core/payment_methods/transformers.rs
+++ b/crates/router/src/core/payment_methods/transformers.rs
@@ -1,7 +1,7 @@
pub use ::payment_methods::controller::{DataDuplicationCheck, DeleteCardResp};
+use api_models::payment_methods::Card;
#[cfg(feature = "v2")]
-use api_models::payment_methods::PaymentMethodResponseItem;
-use api_models::{enums as api_enums, payment_methods::Card};
+use api_models::{enums as api_enums, payment_methods::PaymentMethodResponseItem};
use common_enums::CardNetwork;
use common_utils::{
ext_traits::{Encode, StringExt},
@@ -16,17 +16,24 @@ use josekit::jwe;
use router_env::RequestId;
use serde::{Deserialize, Serialize};
-#[cfg(feature = "v2")]
-use crate::types::{payment_methods as pm_types, transformers};
use crate::{
configs::settings,
- core::errors::{self, CustomResult},
+ core::{
+ errors::{self, CustomResult},
+ payment_methods::cards::call_vault_service,
+ },
headers,
pii::{prelude::*, Secret},
+ routes,
services::{api as services, encryption, EncryptionAlgorithm},
types::{api, domain},
utils::OptionExt,
};
+#[cfg(feature = "v2")]
+use crate::{
+ consts,
+ types::{payment_methods as pm_types, transformers},
+};
#[derive(Debug, Serialize)]
#[serde(untagged)]
@@ -201,16 +208,9 @@ pub fn get_dotted_jws(jws: encryption::JwsBody) -> String {
pub async fn get_decrypted_response_payload(
jwekey: &settings::Jwekey,
jwe_body: encryption::JweBody,
- locker_choice: Option<api_enums::LockerChoice>,
decryption_scheme: settings::DecryptionScheme,
) -> CustomResult<String, errors::VaultError> {
- let target_locker = locker_choice.unwrap_or(api_enums::LockerChoice::HyperswitchCardVault);
-
- let public_key = match target_locker {
- api_enums::LockerChoice::HyperswitchCardVault => {
- jwekey.vault_encryption_key.peek().as_bytes()
- }
- };
+ let public_key = jwekey.vault_encryption_key.peek().as_bytes();
let private_key = jwekey.vault_private_key.peek().as_bytes();
@@ -322,10 +322,9 @@ pub async fn create_jwe_body_for_vault(
Ok(jwe_body)
}
-pub async fn mk_basilisk_req(
+pub async fn mk_vault_req(
jwekey: &settings::Jwekey,
jws: &str,
- locker_choice: api_enums::LockerChoice,
) -> CustomResult<encryption::JweBody, errors::VaultError> {
let jws_payload: Vec<&str> = jws.split('.').collect();
@@ -343,11 +342,7 @@ pub async fn mk_basilisk_req(
.encode_to_vec()
.change_context(errors::VaultError::SaveCardFailed)?;
- let public_key = match locker_choice {
- api_enums::LockerChoice::HyperswitchCardVault => {
- jwekey.vault_encryption_key.peek().as_bytes()
- }
- };
+ let public_key = jwekey.vault_encryption_key.peek().as_bytes();
let jwe_encrypted =
encryption::encrypt_jwe(&payload, public_key, EncryptionAlgorithm::A256GCM, None)
@@ -371,40 +366,48 @@ pub async fn mk_basilisk_req(
Ok(jwe_body)
}
-pub async fn mk_add_locker_request_hs(
+pub async fn call_vault_api<'a, Req, Res>(
+ state: &routes::SessionState,
jwekey: &settings::Jwekey,
locker: &settings::Locker,
- payload: &StoreLockerReq,
- locker_choice: api_enums::LockerChoice,
+ payload: &'a Req,
+ endpoint_path: &str,
tenant_id: id_type::TenantId,
request_id: Option<RequestId>,
-) -> CustomResult<services::Request, errors::VaultError> {
- let payload = payload
+) -> CustomResult<Res, errors::VaultError>
+where
+ Req: Encode<'a> + Serialize,
+ Res: serde::de::DeserializeOwned,
+{
+ let encoded_payload = payload
.encode_to_vec()
.change_context(errors::VaultError::RequestEncodingFailed)?;
let private_key = jwekey.vault_private_key.peek().as_bytes();
+ let jws =
+ encryption::jws_sign_payload(&encoded_payload, &locker.locker_signing_key_id, private_key)
+ .await
+ .change_context(errors::VaultError::RequestEncodingFailed)?;
- let jws = encryption::jws_sign_payload(&payload, &locker.locker_signing_key_id, private_key)
- .await
- .change_context(errors::VaultError::RequestEncodingFailed)?;
+ let jwe_payload = mk_vault_req(jwekey, &jws).await?;
+
+ let url = locker.get_host(endpoint_path);
- let jwe_payload = mk_basilisk_req(jwekey, &jws, locker_choice).await?;
- let mut url = match locker_choice {
- api_enums::LockerChoice::HyperswitchCardVault => locker.host.to_owned(),
- };
- url.push_str("/cards/add");
let mut request = services::Request::new(services::Method::Post, &url);
request.add_header(headers::CONTENT_TYPE, "application/json".into());
- request.add_header(
- headers::X_TENANT_ID,
- tenant_id.get_string_repr().to_owned().into(),
- );
+ request.add_header(headers::X_TENANT_ID, tenant_id.get_string_repr().into());
+
if let Some(req_id) = request_id {
request.add_header(headers::X_REQUEST_ID, req_id.to_string().into());
}
+
request.set_body(RequestContent::Json(Box::new(jwe_payload)));
- Ok(request)
+
+ let response = call_vault_service::<Res>(state, request, endpoint_path)
+ .await
+ .change_context(errors::VaultError::VaultAPIError)?;
+
+ Ok(response)
}
#[cfg(all(feature = "v1", feature = "payouts"))]
@@ -599,54 +602,6 @@ pub fn generate_payment_method_response(
Ok(resp)
}
-#[allow(clippy::too_many_arguments)]
-pub async fn mk_get_card_request_hs(
- jwekey: &settings::Jwekey,
- locker: &settings::Locker,
- customer_id: &id_type::CustomerId,
- merchant_id: &id_type::MerchantId,
- card_reference: &str,
- locker_choice: Option<api_enums::LockerChoice>,
- tenant_id: id_type::TenantId,
- request_id: Option<RequestId>,
-) -> CustomResult<services::Request, errors::VaultError> {
- let merchant_customer_id = customer_id.to_owned();
- let card_req_body = CardReqBody {
- merchant_id: merchant_id.to_owned(),
- merchant_customer_id,
- card_reference: card_reference.to_owned(),
- };
- let payload = card_req_body
- .encode_to_vec()
- .change_context(errors::VaultError::RequestEncodingFailed)?;
-
- let private_key = jwekey.vault_private_key.peek().as_bytes();
-
- let jws = encryption::jws_sign_payload(&payload, &locker.locker_signing_key_id, private_key)
- .await
- .change_context(errors::VaultError::RequestEncodingFailed)?;
-
- 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::HyperswitchCardVault => locker.host.to_owned(),
- };
- url.push_str("/cards/retrieve");
- let mut request = services::Request::new(services::Method::Post, &url);
- request.add_header(headers::CONTENT_TYPE, "application/json".into());
- request.add_header(
- headers::X_TENANT_ID,
- tenant_id.get_string_repr().to_owned().into(),
- );
- if let Some(req_id) = request_id {
- request.add_header(headers::X_REQUEST_ID, req_id.to_string().into());
- }
-
- request.set_body(RequestContent::Json(Box::new(jwe_payload)));
- Ok(request)
-}
-
pub fn mk_get_card_request(
locker: &settings::Locker,
locker_id: &'static str,
@@ -682,53 +637,11 @@ pub fn mk_get_card_response(card: GetCardResponse) -> errors::RouterResult<Card>
})
}
-pub async fn mk_delete_card_request_hs(
- jwekey: &settings::Jwekey,
- locker: &settings::Locker,
- customer_id: &id_type::CustomerId,
- merchant_id: &id_type::MerchantId,
- card_reference: &str,
- tenant_id: id_type::TenantId,
- request_id: Option<RequestId>,
-) -> CustomResult<services::Request, errors::VaultError> {
- let merchant_customer_id = customer_id.to_owned();
- let card_req_body = CardReqBody {
- merchant_id: merchant_id.to_owned(),
- merchant_customer_id,
- card_reference: card_reference.to_owned(),
- };
- let payload = card_req_body
- .encode_to_vec()
- .change_context(errors::VaultError::RequestEncodingFailed)?;
-
- let private_key = jwekey.vault_private_key.peek().as_bytes();
-
- let jws = encryption::jws_sign_payload(&payload, &locker.locker_signing_key_id, private_key)
- .await
- .change_context(errors::VaultError::RequestEncodingFailed)?;
-
- 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");
- let mut request = services::Request::new(services::Method::Post, &url);
- request.add_header(headers::CONTENT_TYPE, "application/json".into());
- request.add_header(
- headers::X_TENANT_ID,
- tenant_id.get_string_repr().to_owned().into(),
- );
- if let Some(req_id) = request_id {
- request.add_header(headers::X_REQUEST_ID, req_id.to_string().into());
- }
-
- request.set_body(RequestContent::Json(Box::new(jwe_payload)));
- Ok(request)
-}
-
// Need to fix this once we start moving to v2 completion
#[cfg(feature = "v2")]
+#[allow(clippy::too_many_arguments)]
pub async fn mk_delete_card_request_hs_by_id(
+ state: &routes::SessionState,
jwekey: &settings::Jwekey,
locker: &settings::Locker,
id: &String,
@@ -736,40 +649,23 @@ pub async fn mk_delete_card_request_hs_by_id(
card_reference: &str,
tenant_id: id_type::TenantId,
request_id: Option<RequestId>,
-) -> CustomResult<services::Request, errors::VaultError> {
- let merchant_customer_id = id.to_owned();
+) -> CustomResult<DeleteCardResp, errors::VaultError> {
let card_req_body = CardReqBodyV2 {
merchant_id: merchant_id.to_owned(),
- merchant_customer_id,
+ merchant_customer_id: id.to_owned(),
card_reference: card_reference.to_owned(),
};
- let payload = card_req_body
- .encode_to_vec()
- .change_context(errors::VaultError::RequestEncodingFailed)?;
- let private_key = jwekey.vault_private_key.peek().as_bytes();
-
- let jws = encryption::jws_sign_payload(&payload, &locker.locker_signing_key_id, private_key)
- .await
- .change_context(errors::VaultError::RequestEncodingFailed)?;
-
- 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");
- let mut request = services::Request::new(services::Method::Post, &url);
- request.add_header(headers::CONTENT_TYPE, "application/json".into());
- request.add_header(
- headers::X_TENANT_ID,
- tenant_id.get_string_repr().to_owned().into(),
- );
- if let Some(req_id) = request_id {
- request.add_header(headers::X_REQUEST_ID, req_id.to_string().into());
- }
-
- request.set_body(RequestContent::Json(Box::new(jwe_payload)));
- Ok(request)
+ call_vault_api(
+ state,
+ jwekey,
+ locker,
+ &card_req_body,
+ consts::LOCKER_DELETE_CARD_PATH,
+ tenant_id,
+ request_id,
+ )
+ .await
}
pub fn mk_delete_card_response(
@@ -839,30 +735,6 @@ pub fn get_card_detail(
}
//------------------------------------------------TokenizeService------------------------------------------------
-pub fn mk_crud_locker_request(
- locker: &settings::Locker,
- path: &str,
- req: api::TokenizePayloadEncrypted,
- tenant_id: id_type::TenantId,
- request_id: Option<RequestId>,
-) -> CustomResult<services::Request, errors::VaultError> {
- let mut url = locker.basilisk_host.to_owned();
- url.push_str(path);
- let mut request = services::Request::new(services::Method::Post, &url);
- request.add_default_headers();
- request.add_header(headers::CONTENT_TYPE, "application/json".into());
- request.add_header(
- headers::X_TENANT_ID,
- tenant_id.get_string_repr().to_owned().into(),
- );
- if let Some(req_id) = request_id {
- request.add_header(headers::X_REQUEST_ID, req_id.to_string().into());
- }
-
- request.set_body(RequestContent::Json(Box::new(req)));
- Ok(request)
-}
-
#[allow(clippy::too_many_arguments)]
pub fn mk_card_value1(
card_number: cards::CardNumber,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 3e3a90d388..18a47505e9 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -6326,13 +6326,12 @@ pub async fn get_merchant_bank_data_for_open_banking_connectors(
let cust_id = id_type::CustomerId::try_from(std::borrow::Cow::from(merchant_id_str))
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to convert to CustomerId")?;
- let locker_resp = cards::get_payment_method_from_hs_locker(
+ let locker_resp = cards::get_encrypted_data_from_vault(
state,
platform.get_processor().get_key_store(),
&cust_id,
platform.get_processor().get_account().get_id(),
id.as_str(),
- Some(enums::LockerChoice::HyperswitchCardVault),
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs
index 119f1d95b8..b41df2f6a0 100644
--- a/crates/router/src/core/payments/tokenization.rs
+++ b/crates/router/src/core/payments/tokenization.rs
@@ -627,7 +627,6 @@ where
payment_method_create_request,
&card,
&customer_id,
- api::enums::LockerChoice::HyperswitchCardVault,
Some(
existing_pm
.locker_id
diff --git a/crates/router/src/core/payouts/helpers.rs b/crates/router/src/core/payouts/helpers.rs
index bd09c665ed..86a3dca794 100644
--- a/crates/router/src/core/payouts/helpers.rs
+++ b/crates/router/src/core/payouts/helpers.rs
@@ -388,14 +388,9 @@ pub async fn save_payout_data_to_locker(
};
// Store payout method in locker
- let stored_resp = cards::add_card_to_hs_locker(
- state,
- &locker_req,
- customer_id,
- api_enums::LockerChoice::HyperswitchCardVault,
- )
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)?;
+ let stored_resp = cards::add_card_to_vault(state, &locker_req, customer_id)
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)?;
let db = &*state.store;
@@ -664,7 +659,7 @@ pub async fn save_payout_data_to_locker(
.clone()
.unwrap_or(existing_pm.payment_method_id.clone());
// Delete from locker
- cards::delete_card_from_hs_locker(
+ cards::delete_card_from_vault(
state,
customer_id,
platform.get_processor().get_account().get_id(),
@@ -679,14 +674,9 @@ pub async fn save_payout_data_to_locker(
locker_req.update_requestor_card_reference(Some(card_reference.to_string()));
// Store in locker
- let stored_resp = cards::add_card_to_hs_locker(
- state,
- &locker_req,
- customer_id,
- api_enums::LockerChoice::HyperswitchCardVault,
- )
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError);
+ let stored_resp = cards::add_card_to_vault(state, &locker_req, customer_id)
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError);
// Check if locker operation was successful or not, if not, delete the entry from payment_methods table
if let Err(err) = stored_resp {
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 3215484804..d0068d9a24 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -53,9 +53,7 @@ redirect_uri = "" # Redirect URI registered for the OIDC client
[locker]
host = ""
-host_rs = ""
mock_locker = true
-basilisk_host = ""
locker_enabled = true
ttl_for_storage_in_secs = 220752000
@@ -75,7 +73,6 @@ max_age = 365
[jwekey]
vault_encryption_key = ""
-rust_locker_encryption_key = ""
vault_private_key = ""
[webhooks]