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(compatibility): add receipt_ipaddress and user_agent in stripe compatibility (#1417)
Abhishek Marrivagude2a6e86d767
diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rsindex b9496a8cb7..8f57ee6850 100644--- a/crates/router/src/compatibility/stripe/payment_intents/types.rs+++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs@@ -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()});requestdiff --git a/crates/router/src/compatibility/stripe/setup_intents/types.rs b/crates/router/src/compatibility/stripe/setup_intents/types.rsindex 9a90f044e2..b2eada9161 100644--- a/crates/router/src/compatibility/stripe/setup_intents/types.rs+++ b/crates/router/src/compatibility/stripe/setup_intents/types.rs@@ -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()});requestdiff --git a/crates/router/src/types.rs b/crates/router/src/types.rsindex 6cbe85f52f..150ff483a0 100644--- a/crates/router/src/types.rs+++ b/crates/router/src/types.rs@@ -442,7 +442,7 @@ pub struct RefundsData {pub connector_metadata: Option<serde_json::Value>,}-#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]+#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]pub struct BrowserInformation {pub color_depth: Option<u8>,pub java_enabled: Option<bool>,