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(pm): opt in for plain fingerprint response (#14147)
Kashife0467e2f6dc1
diff --git a/config/config.example.toml b/config/config.example.tomlindex 9de425b292..943ccb9b05 100644--- a/config/config.example.toml+++ b/config/config.example.toml@@ -230,6 +230,7 @@ locker_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 lockercreate_entity_on_merchant_create = false # Boolean to call the locker's entity-create API during merchant account creation, aborting creation on locker failure+plain_fingerprint_response = true # Ask the vault for plain (unencrypted) fingerprint responses; honoured only if the vault has opted in (v2)[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 97969911a9..82c2214b10 100644--- a/config/deployments/env_specific.toml+++ b/config/deployments/env_specific.toml@@ -145,6 +145,7 @@ locker_enabled = true # Booleanredis_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 lockercreate_entity_on_merchant_create = false # Boolean to call the locker's entity-create API during merchant account creation, aborting creation on locker failure+plain_fingerprint_response = true # Ask the vault for plain (unencrypted) fingerprint responses; honoured only if the vault has opted in (v2)diff --git a/config/development.toml b/config/development.tomlindex c44423d42a..8fcfaecd4f 100644--- a/config/development.toml+++ b/config/development.toml@@ -150,6 +150,7 @@ mock_locker = truelocker_enabled = truettl_for_storage_in_secs = 220752000create_entity_on_merchant_create = false+plain_fingerprint_response = true[forex_api]api_key = ""diff --git a/config/docker_compose.toml b/config/docker_compose.tomlindex 5fec52506a..dc41ff7361 100644--- a/config/docker_compose.toml+++ b/config/docker_compose.toml@@ -147,6 +147,7 @@ mock_locker = truelocker_enabled = truettl_for_storage_in_secs = 220752000create_entity_on_merchant_create = false+plain_fingerprint_response = true[jwekey]vault_encryption_key = ""diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rsindex 0322c8f4f8..8de2f19b47 100644--- a/crates/router/src/configs/defaults.rs+++ b/crates/router/src/configs/defaults.rs@@ -63,6 +63,8 @@ impl Default for super::settings::Locker {ttl_for_storage_in_secs: 60 * 60 * 24 * 365 * 7,decryption_scheme: Default::default(),create_entity_on_merchant_create: false,+ #[cfg(feature = "v2")]+ plain_fingerprint_response: true,}}}diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rsindex eb872e22fc..41af2826b9 100644--- a/crates/router/src/configs/settings.rs+++ b/crates/router/src/configs/settings.rs@@ -1151,6 +1151,8 @@ pub struct Locker {pub ttl_for_storage_in_secs: i64,pub decryption_scheme: DecryptionScheme,pub create_entity_on_merchant_create: bool,+ #[cfg(feature = "v2")]+ pub plain_fingerprint_response: bool,}impl Locker {diff --git a/crates/router/src/consts.rs b/crates/router/src/consts.rsindex 8efaea035e..245e63c8de 100644--- a/crates/router/src/consts.rs+++ b/crates/router/src/consts.rs@@ -201,6 +201,13 @@ pub const V2_VAULT_DELETE_REQUEST_URL: &str = "/api/v2/vault/delete";/// Vault Header content typepub const V2_VAULT_HEADER_CONTENT_TYPE: &str = "application/json";+/// Header asking the vault for a plain (unencrypted) fingerprint response; the vault echoes it+/// when honoured+pub const V2_VAULT_FP_RESPONSE_ENCODING_HEADER: &str = "x-fp-response-encoding";++/// `x-fp-response-encoding` value for a plain JSON response+pub const V2_VAULT_FP_RESPONSE_ENCODING_PLAIN: &str = "plain";+/// Vault Add flow typepub const V2_VAULT_ADD_FLOW_TYPE: &str = "add_to_vault";diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rsindex fa00ad5ba6..32a8f3264f 100644--- a/crates/router/src/core/payment_methods/vault.rs+++ b/crates/router/src/core/payment_methods/vault.rs@@ -2241,21 +2241,50 @@ pub async fn call_to_vault<V: pm_types::VaultingInterface>(.add(1, router_env::metric_attributes!(("operation", flow_name)));});- let jwe_body: services::JweBody = response- .get_response_inner("JweBody")+ let response = response+ .get_response().change_context(errors::VaultError::ResponseDeserializationFailed)- .attach_printable("Failed to get JweBody from vault response")?;+ .attach_printable("Failed to get response from vault")?;- let decrypted_payload = pm_transforms::get_decrypted_vault_response_payload(- jwekey,- jwe_body,- locker.decryption_scheme.clone(),- )- .await- .change_context(errors::VaultError::ResponseDecryptionFailed)- .attach_printable("Error getting decrypted vault response payload")?;+ #[cfg(feature = "v2")]+ let is_plain_response = V::supports_plain_response() && is_plain_vault_response(&response);+ #[cfg(not(feature = "v2"))]+ let is_plain_response = false;- Ok(decrypted_payload)+ if is_plain_response {+ String::from_utf8(response.response.to_vec())+ .change_context(errors::VaultError::ResponseDeserializationFailed)+ .attach_printable("Plain vault response is not valid UTF-8")+ } else {+ let jwe_body: services::JweBody = response+ .response+ .parse_struct("JweBody")+ .change_context(errors::VaultError::ResponseDeserializationFailed)+ .attach_printable("Failed to get JweBody from vault response")?;++ let decrypted_payload = pm_transforms::get_decrypted_vault_response_payload(+ jwekey,+ jwe_body,+ locker.decryption_scheme.clone(),+ )+ .await+ .change_context(errors::VaultError::ResponseDecryptionFailed)+ .attach_printable("Error getting decrypted vault response payload")?;++ Ok(decrypted_payload)+ }+}++/// The vault marks a response it returned unencrypted (at the caller's request) with the same+/// header the caller sent; anything without it is a JWE envelope.+#[cfg(feature = "v2")]+fn is_plain_vault_response(response: &types::Response) -> bool {+ response+ .headers+ .as_ref()+ .and_then(|headers| headers.get(consts::V2_VAULT_FP_RESPONSE_ENCODING_HEADER))+ .and_then(|value| value.to_str().ok())+ .is_some_and(|value| value == consts::V2_VAULT_FP_RESPONSE_ENCODING_PLAIN)}pub async fn create_entity_in_locker(@@ -2320,10 +2349,18 @@ async fn get_fingerprint_id_from_vault<D: serde::Serialize>(.change_context(errors::VaultError::RequestEncodingFailed).attach_printable("Failed to encode VaultFingerprintRequestNew")?;- let resp = call_to_vault::<pm_types::GetVaultFingerprint>(state, payload, None, None)- .await- .change_context(errors::VaultError::VaultAPIError)- .attach_printable("Call to vault failed")?;+ let additional_headers = state.conf.locker.plain_fingerprint_response.then(|| {+ HashMap::from([(+ consts::V2_VAULT_FP_RESPONSE_ENCODING_HEADER.to_string(),+ consts::V2_VAULT_FP_RESPONSE_ENCODING_PLAIN.to_string(),+ )])+ });++ let resp =+ call_to_vault::<pm_types::GetVaultFingerprint>(state, payload, None, additional_headers)+ .await+ .change_context(errors::VaultError::VaultAPIError)+ .attach_printable("Call to vault failed")?;let fingerprint_resp: pm_types::VaultFingerprintResponse = resp.parse_struct("VaultFingerprintResponse")diff --git a/crates/router/src/types/payment_methods.rs b/crates/router/src/types/payment_methods.rsindex 6a50b1c744..6322db78c8 100644--- a/crates/router/src/types/payment_methods.rs+++ b/crates/router/src/types/payment_methods.rs@@ -24,6 +24,10 @@ pub trait VaultingInterface {fn get_vaulting_request_url() -> &'static str;fn get_vaulting_flow_name() -> &'static str;++ fn supports_plain_response() -> bool {+ false+ }}#[cfg(feature = "v1")]@@ -145,6 +149,11 @@ impl VaultingInterface for GetVaultFingerprint {fn get_vaulting_flow_name() -> &'static str {consts::V2_VAULT_GET_FINGERPRINT_FLOW_TYPE}++ // The response is only a fingerprint id.+ fn supports_plain_response() -> bool {+ true+ }}impl VaultingInterface for VaultRetrieve {