From ae37b059e09d9e6b597914536359fbdd5dd777d2 Mon Sep 17 00:00:00 2001 From: Sakil Mostak <73734619+Sakilmostak@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:55:14 +0530 Subject: [PATCH] refactor(payout): Handle saving wallet in temp locker (#4230) --- .../router/src/core/payment_methods/vault.rs | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs index aeb1ea102b..1bfa483029 100644 --- a/crates/router/src/core/payment_methods/vault.rs +++ b/crates/router/src/core/payment_methods/vault.rs @@ -2,6 +2,7 @@ use common_utils::{ crypto::{DecodeMessage, EncodeMessage, GcmAes256}, ext_traits::{BytesExt, Encode}, generate_id_with_default_len, + pii::Email, }; use error_stack::{report, ResultExt}; use masking::PeekInterface; @@ -415,55 +416,57 @@ impl Vaultable for api::CardPayout { } } +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct TokenizedWalletSensitiveValues { + pub email: Option, +} + +#[derive(Debug, serde::Serialize, serde::Deserialize)] +pub struct TokenizedWalletInsensitiveValues { + pub customer_id: Option, +} + #[cfg(feature = "payouts")] impl Vaultable for api::WalletPayout { fn get_value1(&self, _customer_id: Option) -> CustomResult { let value1 = match self { - Self::Paypal(paypal_data) => api::TokenizedWalletValue1 { - data: api::WalletData::PaypalRedirect(api_models::payments::PaypalRedirection { - email: paypal_data.email.clone(), - }), + Self::Paypal(paypal_data) => TokenizedWalletSensitiveValues { + email: paypal_data.email.clone(), }, }; value1 .encode_to_string_of_json() .change_context(errors::VaultError::RequestEncodingFailed) - .attach_printable("Failed to encode wallet value1") + .attach_printable("Failed to encode wallet data - TokenizedWalletSensitiveValues") } fn get_value2(&self, customer_id: Option) -> CustomResult { - let value2 = api::TokenizedWalletValue2 { customer_id }; + let value2 = TokenizedWalletInsensitiveValues { customer_id }; value2 .encode_to_string_of_json() .change_context(errors::VaultError::RequestEncodingFailed) - .attach_printable("Failed to encode wallet value2") + .attach_printable("Failed to encode data - TokenizedWalletInsensitiveValues") } fn from_values( value1: String, value2: String, ) -> CustomResult<(Self, SupplementaryVaultData), errors::VaultError> { - let value1: api::TokenizedWalletValue1 = value1 - .parse_struct("TokenizedWalletValue1") + let value1: TokenizedWalletSensitiveValues = value1 + .parse_struct("TokenizedWalletSensitiveValues") .change_context(errors::VaultError::ResponseDeserializationFailed) - .attach_printable("Could not deserialize into wallet value1")?; + .attach_printable("Could not deserialize into wallet data wallet_sensitive_data")?; - let value2: api::TokenizedWalletValue2 = value2 - .parse_struct("TokenizedWalletValue2") + let value2: TokenizedWalletInsensitiveValues = value2 + .parse_struct("TokenizedWalletInsensitiveValues") .change_context(errors::VaultError::ResponseDeserializationFailed) - .attach_printable("Could not deserialize into wallet value2")?; - - let wallet = match value1.data { - api::WalletData::PaypalRedirect(paypal_data) => { - Self::Paypal(api_models::payouts::Paypal { - email: paypal_data.email, - }) - } - _ => Err(errors::VaultError::ResponseDeserializationFailed)?, - }; + .attach_printable("Could not deserialize into wallet data wallet_insensitive_data")?; + let wallet = Self::Paypal(api_models::payouts::Paypal { + email: value1.email, + }); let supp_data = SupplementaryVaultData { customer_id: value2.customer_id, payment_method_id: None,