mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	refactor(payout): Handle saving wallet in temp locker (#4230)
This commit is contained in:
		| @ -2,6 +2,7 @@ use common_utils::{ | |||||||
|     crypto::{DecodeMessage, EncodeMessage, GcmAes256}, |     crypto::{DecodeMessage, EncodeMessage, GcmAes256}, | ||||||
|     ext_traits::{BytesExt, Encode}, |     ext_traits::{BytesExt, Encode}, | ||||||
|     generate_id_with_default_len, |     generate_id_with_default_len, | ||||||
|  |     pii::Email, | ||||||
| }; | }; | ||||||
| use error_stack::{report, ResultExt}; | use error_stack::{report, ResultExt}; | ||||||
| use masking::PeekInterface; | use masking::PeekInterface; | ||||||
| @ -415,55 +416,57 @@ impl Vaultable for api::CardPayout { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[derive(Debug, serde::Serialize, serde::Deserialize)] | ||||||
|  | pub struct TokenizedWalletSensitiveValues { | ||||||
|  |     pub email: Option<Email>, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Debug, serde::Serialize, serde::Deserialize)] | ||||||
|  | pub struct TokenizedWalletInsensitiveValues { | ||||||
|  |     pub customer_id: Option<String>, | ||||||
|  | } | ||||||
|  |  | ||||||
| #[cfg(feature = "payouts")] | #[cfg(feature = "payouts")] | ||||||
| impl Vaultable for api::WalletPayout { | impl Vaultable for api::WalletPayout { | ||||||
|     fn get_value1(&self, _customer_id: Option<String>) -> CustomResult<String, errors::VaultError> { |     fn get_value1(&self, _customer_id: Option<String>) -> CustomResult<String, errors::VaultError> { | ||||||
|         let value1 = match self { |         let value1 = match self { | ||||||
|             Self::Paypal(paypal_data) => api::TokenizedWalletValue1 { |             Self::Paypal(paypal_data) => TokenizedWalletSensitiveValues { | ||||||
|                 data: api::WalletData::PaypalRedirect(api_models::payments::PaypalRedirection { |  | ||||||
|                 email: paypal_data.email.clone(), |                 email: paypal_data.email.clone(), | ||||||
|                 }), |  | ||||||
|             }, |             }, | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         value1 |         value1 | ||||||
|             .encode_to_string_of_json() |             .encode_to_string_of_json() | ||||||
|             .change_context(errors::VaultError::RequestEncodingFailed) |             .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<String>) -> CustomResult<String, errors::VaultError> { |     fn get_value2(&self, customer_id: Option<String>) -> CustomResult<String, errors::VaultError> { | ||||||
|         let value2 = api::TokenizedWalletValue2 { customer_id }; |         let value2 = TokenizedWalletInsensitiveValues { customer_id }; | ||||||
|  |  | ||||||
|         value2 |         value2 | ||||||
|             .encode_to_string_of_json() |             .encode_to_string_of_json() | ||||||
|             .change_context(errors::VaultError::RequestEncodingFailed) |             .change_context(errors::VaultError::RequestEncodingFailed) | ||||||
|             .attach_printable("Failed to encode wallet value2") |             .attach_printable("Failed to encode data - TokenizedWalletInsensitiveValues") | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn from_values( |     fn from_values( | ||||||
|         value1: String, |         value1: String, | ||||||
|         value2: String, |         value2: String, | ||||||
|     ) -> CustomResult<(Self, SupplementaryVaultData), errors::VaultError> { |     ) -> CustomResult<(Self, SupplementaryVaultData), errors::VaultError> { | ||||||
|         let value1: api::TokenizedWalletValue1 = value1 |         let value1: TokenizedWalletSensitiveValues = value1 | ||||||
|             .parse_struct("TokenizedWalletValue1") |             .parse_struct("TokenizedWalletSensitiveValues") | ||||||
|             .change_context(errors::VaultError::ResponseDeserializationFailed) |             .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 |         let value2: TokenizedWalletInsensitiveValues = value2 | ||||||
|             .parse_struct("TokenizedWalletValue2") |             .parse_struct("TokenizedWalletInsensitiveValues") | ||||||
|             .change_context(errors::VaultError::ResponseDeserializationFailed) |             .change_context(errors::VaultError::ResponseDeserializationFailed) | ||||||
|             .attach_printable("Could not deserialize into wallet value2")?; |             .attach_printable("Could not deserialize into wallet data wallet_insensitive_data")?; | ||||||
|  |  | ||||||
|         let wallet = match value1.data { |  | ||||||
|             api::WalletData::PaypalRedirect(paypal_data) => { |  | ||||||
|                 Self::Paypal(api_models::payouts::Paypal { |  | ||||||
|                     email: paypal_data.email, |  | ||||||
|                 }) |  | ||||||
|             } |  | ||||||
|             _ => Err(errors::VaultError::ResponseDeserializationFailed)?, |  | ||||||
|         }; |  | ||||||
|  |  | ||||||
|  |         let wallet = Self::Paypal(api_models::payouts::Paypal { | ||||||
|  |             email: value1.email, | ||||||
|  |         }); | ||||||
|         let supp_data = SupplementaryVaultData { |         let supp_data = SupplementaryVaultData { | ||||||
|             customer_id: value2.customer_id, |             customer_id: value2.customer_id, | ||||||
|             payment_method_id: None, |             payment_method_id: None, | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Sakil Mostak
					Sakil Mostak