mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 01:57:45 +08:00 
			
		
		
		
	feat(compatibility): add receipt_ipaddress and user_agent in stripe compatibility (#1417)
This commit is contained in:
		 Abhishek Marrivagu
					Abhishek Marrivagu
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							4a8de7741d
						
					
				
				
					commit
					de2a6e86d7
				
			| @ -1,3 +1,5 @@ | ||||
| use std::str::FromStr; | ||||
|  | ||||
| use api_models::payments; | ||||
| use common_utils::{crypto::Encryptable, date_time, ext_traits::StringExt, pii as secret}; | ||||
| use error_stack::{IntoReport, ResultExt}; | ||||
| @ -146,6 +148,8 @@ pub struct StripePaymentIntentRequest { | ||||
|     pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>, | ||||
|     pub mandate_id: Option<String>, | ||||
|     pub off_session: Option<bool>, | ||||
|     pub receipt_ipaddress: Option<String>, | ||||
|     pub user_agent: Option<String>, | ||||
| } | ||||
|  | ||||
| impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest { | ||||
| @ -182,6 +186,16 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest { | ||||
|                     .attach_printable("converting to routing failed") | ||||
|             }) | ||||
|             .transpose()?; | ||||
|  | ||||
|         let ip_address = item | ||||
|             .receipt_ipaddress | ||||
|             .map(|ip| std::net::IpAddr::from_str(ip.as_str())) | ||||
|             .transpose() | ||||
|             .into_report() | ||||
|             .change_context(errors::ApiErrorResponse::InvalidDataFormat { | ||||
|                 field_name: "receipt_ipaddress".to_string(), | ||||
|                 expected_format: "127.0.0.1".to_string(), | ||||
|             })?; | ||||
|         let request = Ok(Self { | ||||
|             payment_id: item.id.map(payments::PaymentIdType::PaymentIntentId), | ||||
|             amount: item.amount.map(|amount| amount.into()), | ||||
| @ -228,6 +242,16 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest { | ||||
|             mandate_id: item.mandate_id, | ||||
|             off_session: item.off_session, | ||||
|             routing, | ||||
|             browser_info: Some( | ||||
|                 serde_json::to_value(crate::types::BrowserInformation { | ||||
|                     ip_address, | ||||
|                     user_agent: item.user_agent, | ||||
|                     ..Default::default() | ||||
|                 }) | ||||
|                 .into_report() | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("convert to browser info failed")?, | ||||
|             ), | ||||
|             ..Self::default() | ||||
|         }); | ||||
|         request | ||||
|  | ||||
| @ -1,6 +1,8 @@ | ||||
| use std::str::FromStr; | ||||
|  | ||||
| use api_models::payments; | ||||
| use common_utils::{date_time, ext_traits::StringExt}; | ||||
| use error_stack::ResultExt; | ||||
| use error_stack::{IntoReport, ResultExt}; | ||||
| use router_env::logger; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use serde_json::Value; | ||||
| @ -138,6 +140,8 @@ pub struct StripeSetupIntentRequest { | ||||
|     pub payment_method_options: Option<payment_intent::StripePaymentMethodOptions>, | ||||
|     pub payment_method: Option<String>, | ||||
|     pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>, | ||||
|     pub receipt_ipaddress: Option<String>, | ||||
|     pub user_agent: Option<String>, | ||||
| } | ||||
|  | ||||
| impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest { | ||||
| @ -161,6 +165,15 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest { | ||||
|             } | ||||
|             None => (None, None), | ||||
|         }; | ||||
|         let ip_address = item | ||||
|             .receipt_ipaddress | ||||
|             .map(|ip| std::net::IpAddr::from_str(ip.as_str())) | ||||
|             .transpose() | ||||
|             .into_report() | ||||
|             .change_context(errors::ApiErrorResponse::InvalidDataFormat { | ||||
|                 field_name: "receipt_ipaddress".to_string(), | ||||
|                 expected_format: "127.0.0.1".to_string(), | ||||
|             })?; | ||||
|         let request = Ok(Self { | ||||
|             amount: Some(api_types::Amount::Zero), | ||||
|             capture_method: None, | ||||
| @ -208,6 +221,17 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest { | ||||
|             merchant_connector_details: item.merchant_connector_details, | ||||
|             authentication_type, | ||||
|             mandate_data: mandate_options, | ||||
|             browser_info: Some( | ||||
|                 serde_json::to_value(crate::types::BrowserInformation { | ||||
|                     ip_address, | ||||
|                     user_agent: item.user_agent, | ||||
|                     ..Default::default() | ||||
|                 }) | ||||
|                 .into_report() | ||||
|                 .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|                 .attach_printable("convert to browser info failed")?, | ||||
|             ), | ||||
|  | ||||
|             ..Default::default() | ||||
|         }); | ||||
|         request | ||||
|  | ||||
		Reference in New Issue
	
	Block a user