mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	refactor(router): add #[cfg(not(feature = "kms"))] feature flag to test the simplified apple pay flow locally (#2200)
				
					
				
			This commit is contained in:
		| @ -41,7 +41,6 @@ pub(crate) const APPLEPAY_VALIDATION_URL: &str = | |||||||
| pub(crate) const QR_IMAGE_DATA_SOURCE_STRING: &str = "data:image/png;base64"; | pub(crate) const QR_IMAGE_DATA_SOURCE_STRING: &str = "data:image/png;base64"; | ||||||
|  |  | ||||||
| // OID (Object Identifier) for the merchant ID field extension. | // OID (Object Identifier) for the merchant ID field extension. | ||||||
| #[cfg(feature = "kms")] |  | ||||||
| pub(crate) const MERCHANT_ID_FIELD_EXTENSION_ID: &str = "1.2.840.113635.100.6.32"; | pub(crate) const MERCHANT_ID_FIELD_EXTENSION_ID: &str = "1.2.840.113635.100.6.32"; | ||||||
|  |  | ||||||
| pub(crate) const METRICS_HOST_TAG_NAME: &str = "host"; | pub(crate) const METRICS_HOST_TAG_NAME: &str = "host"; | ||||||
|  | |||||||
| @ -15,7 +15,6 @@ use data_models::mandates::MandateData; | |||||||
| use diesel_models::{ephemeral_key, fraud_check::FraudCheck}; | use diesel_models::{ephemeral_key, fraud_check::FraudCheck}; | ||||||
| use error_stack::{IntoReport, ResultExt}; | use error_stack::{IntoReport, ResultExt}; | ||||||
| use futures::future::join_all; | use futures::future::join_all; | ||||||
| #[cfg(feature = "kms")] |  | ||||||
| use helpers::ApplePayData; | use helpers::ApplePayData; | ||||||
| use masking::Secret; | use masking::Secret; | ||||||
| use router_env::{instrument, tracing}; | use router_env::{instrument, tracing}; | ||||||
| @ -643,7 +642,6 @@ where | |||||||
|  |  | ||||||
|     // Tokenization Action will be DecryptApplePayToken, only when payment method type is Apple Pay |     // Tokenization Action will be DecryptApplePayToken, only when payment method type is Apple Pay | ||||||
|     // and the connector supports Apple Pay predecrypt |     // and the connector supports Apple Pay predecrypt | ||||||
|     #[cfg(feature = "kms")] |  | ||||||
|     if matches!( |     if matches!( | ||||||
|         tokenization_action, |         tokenization_action, | ||||||
|         TokenizationAction::DecryptApplePayToken |         TokenizationAction::DecryptApplePayToken | ||||||
|  | |||||||
| @ -16,26 +16,23 @@ use error_stack::{report, IntoReport, ResultExt}; | |||||||
| use external_services::kms; | use external_services::kms; | ||||||
| use josekit::jwe; | use josekit::jwe; | ||||||
| use masking::{ExposeInterface, PeekInterface}; | use masking::{ExposeInterface, PeekInterface}; | ||||||
| #[cfg(feature = "kms")] | use openssl::{ | ||||||
| use openssl::derive::Deriver; |     derive::Deriver, | ||||||
| #[cfg(feature = "kms")] |     pkey::PKey, | ||||||
| use openssl::pkey::PKey; |     symm::{decrypt_aead, Cipher}, | ||||||
| #[cfg(feature = "kms")] | }; | ||||||
| use openssl::symm::{decrypt_aead, Cipher}; |  | ||||||
| use router_env::{instrument, logger, tracing}; | use router_env::{instrument, logger, tracing}; | ||||||
| use time::Duration; | use time::Duration; | ||||||
| use uuid::Uuid; | use uuid::Uuid; | ||||||
| #[cfg(feature = "kms")] |  | ||||||
| use x509_parser::parse_x509_certificate; | use x509_parser::parse_x509_certificate; | ||||||
|  |  | ||||||
| use super::{ | use super::{ | ||||||
|     operations::{BoxedOperation, Operation, PaymentResponse}, |     operations::{BoxedOperation, Operation, PaymentResponse}, | ||||||
|     CustomerDetails, PaymentData, |     CustomerDetails, PaymentData, | ||||||
| }; | }; | ||||||
| #[cfg(feature = "kms")] |  | ||||||
| use crate::connector; |  | ||||||
| use crate::{ | use crate::{ | ||||||
|     configs::settings::{ConnectorRequestReferenceIdConfig, Server, TempLockerDisableConfig}, |     configs::settings::{ConnectorRequestReferenceIdConfig, Server, TempLockerDisableConfig}, | ||||||
|  |     connector, | ||||||
|     consts::{self, BASE64_ENGINE}, |     consts::{self, BASE64_ENGINE}, | ||||||
|     core::{ |     core::{ | ||||||
|         errors::{self, CustomResult, RouterResult, StorageErrorExt}, |         errors::{self, CustomResult, RouterResult, StorageErrorExt}, | ||||||
| @ -3213,7 +3210,6 @@ pub struct ApplePayHeader { | |||||||
|     transaction_id: masking::Secret<String>, |     transaction_id: masking::Secret<String>, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[cfg(feature = "kms")] |  | ||||||
| impl ApplePayData { | impl ApplePayData { | ||||||
|     pub fn token_json( |     pub fn token_json( | ||||||
|         wallet_data: api_models::payments::WalletData, |         wallet_data: api_models::payments::WalletData, | ||||||
| @ -3241,12 +3237,16 @@ impl ApplePayData { | |||||||
|         &self, |         &self, | ||||||
|         state: &AppState, |         state: &AppState, | ||||||
|     ) -> CustomResult<String, errors::ApplePayDecryptionError> { |     ) -> CustomResult<String, errors::ApplePayDecryptionError> { | ||||||
|  |         #[cfg(feature = "kms")] | ||||||
|         let cert_data = kms::get_kms_client(&state.conf.kms) |         let cert_data = kms::get_kms_client(&state.conf.kms) | ||||||
|             .await |             .await | ||||||
|             .decrypt(&state.conf.applepay_decrypt_keys.apple_pay_ppc) |             .decrypt(&state.conf.applepay_decrypt_keys.apple_pay_ppc) | ||||||
|             .await |             .await | ||||||
|             .change_context(errors::ApplePayDecryptionError::DecryptionFailed)?; |             .change_context(errors::ApplePayDecryptionError::DecryptionFailed)?; | ||||||
|  |  | ||||||
|  |         #[cfg(not(feature = "kms"))] | ||||||
|  |         let cert_data = &state.conf.applepay_decrypt_keys.apple_pay_ppc; | ||||||
|  |  | ||||||
|         let base64_decode_cert_data = BASE64_ENGINE |         let base64_decode_cert_data = BASE64_ENGINE | ||||||
|             .decode(cert_data) |             .decode(cert_data) | ||||||
|             .into_report() |             .into_report() | ||||||
| @ -3297,12 +3297,15 @@ impl ApplePayData { | |||||||
|             .change_context(errors::ApplePayDecryptionError::KeyDeserializationFailed) |             .change_context(errors::ApplePayDecryptionError::KeyDeserializationFailed) | ||||||
|             .attach_printable("Failed to deserialize the public key")?; |             .attach_printable("Failed to deserialize the public key")?; | ||||||
|  |  | ||||||
|  |         #[cfg(feature = "kms")] | ||||||
|         let decrypted_apple_pay_ppc_key = kms::get_kms_client(&state.conf.kms) |         let decrypted_apple_pay_ppc_key = kms::get_kms_client(&state.conf.kms) | ||||||
|             .await |             .await | ||||||
|             .decrypt(&state.conf.applepay_decrypt_keys.apple_pay_ppc_key) |             .decrypt(&state.conf.applepay_decrypt_keys.apple_pay_ppc_key) | ||||||
|             .await |             .await | ||||||
|             .change_context(errors::ApplePayDecryptionError::DecryptionFailed)?; |             .change_context(errors::ApplePayDecryptionError::DecryptionFailed)?; | ||||||
|  |  | ||||||
|  |         #[cfg(not(feature = "kms"))] | ||||||
|  |         let decrypted_apple_pay_ppc_key = &state.conf.applepay_decrypt_keys.apple_pay_ppc_key; | ||||||
|         // Create PKey objects from EcKey |         // Create PKey objects from EcKey | ||||||
|         let private_key = PKey::private_key_from_pem(decrypted_apple_pay_ppc_key.as_bytes()) |         let private_key = PKey::private_key_from_pem(decrypted_apple_pay_ppc_key.as_bytes()) | ||||||
|             .into_report() |             .into_report() | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Shankar Singh C
					Shankar Singh C