@@ -114,6 +114,14 @@ pub enum ExpandableObjects {
114
114
LatestAttempt ,
115
115
}
116
116
117
+ #[ derive( Debug , Eq , PartialEq , Serialize ) ]
118
+ pub struct StripeBrowserInformation {
119
+ #[ serde( rename = "payment_method_data[ip]" ) ]
120
+ pub ip_address : Option < Secret < String , pii:: IpAddress > > ,
121
+ #[ serde( rename = "payment_method_data[user_agent]" ) ]
122
+ pub user_agent : Option < String > ,
123
+ }
124
+
117
125
#[ derive( Debug , Eq , PartialEq , Serialize ) ]
118
126
pub struct PaymentIntentRequest {
119
127
pub amount : i64 , //amount in cents, hence passed as integer
@@ -144,6 +152,8 @@ pub struct PaymentIntentRequest {
144
152
pub payment_method_types : Option < StripePaymentMethodType > ,
145
153
#[ serde( rename = "expand[0]" ) ]
146
154
pub expand : Option < ExpandableObjects > ,
155
+ #[ serde( flatten) ]
156
+ pub browser_info : Option < StripeBrowserInformation > ,
147
157
}
148
158
149
159
// Field rename is required only in case of serialization as it is passed in the request to the connector.
@@ -177,6 +187,8 @@ pub struct SetupIntentRequest {
177
187
pub payment_method_types : Option < StripePaymentMethodType > ,
178
188
#[ serde( rename = "expand[0]" ) ]
179
189
pub expand : Option < ExpandableObjects > ,
190
+ #[ serde( flatten) ]
191
+ pub browser_info : Option < StripeBrowserInformation > ,
180
192
}
181
193
182
194
#[ derive( Debug , Eq , PartialEq , Serialize ) ]
@@ -1982,6 +1994,17 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
1982
1994
1983
1995
let meta_data = get_transaction_metadata ( item. request . metadata . clone ( ) , order_id) ;
1984
1996
1997
+ // We pass browser_info only when payment_data exists.
1998
+ // Hence, we're pass Null during recurring payments as payment_method_data[type] is not passed
1999
+ let browser_info = if payment_data. is_some ( ) {
2000
+ item. request
2001
+ . browser_info
2002
+ . clone ( )
2003
+ . map ( StripeBrowserInformation :: from)
2004
+ } else {
2005
+ None
2006
+ } ;
2007
+
1985
2008
Ok ( Self {
1986
2009
amount : item. request . amount , //hopefully we don't loose some cents here
1987
2010
currency : item. request . currency . to_string ( ) , //we need to copy the value and not transfer ownership
@@ -2007,6 +2030,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
2007
2030
setup_future_usage : item. request . setup_future_usage ,
2008
2031
payment_method_types,
2009
2032
expand : Some ( ExpandableObjects :: LatestCharge ) ,
2033
+ browser_info,
2010
2034
} )
2011
2035
}
2012
2036
}
@@ -2044,6 +2068,15 @@ fn get_payment_method_type_for_saved_payment_method_payment(
2044
2068
}
2045
2069
}
2046
2070
2071
+ impl From < types:: BrowserInformation > for StripeBrowserInformation {
2072
+ fn from ( item : types:: BrowserInformation ) -> Self {
2073
+ Self {
2074
+ ip_address : item. ip_address . map ( |ip| Secret :: new ( ip. to_string ( ) ) ) ,
2075
+ user_agent : item. user_agent ,
2076
+ }
2077
+ }
2078
+ }
2079
+
2047
2080
impl TryFrom < & types:: SetupMandateRouterData > for SetupIntentRequest {
2048
2081
type Error = error_stack:: Report < errors:: ConnectorError > ;
2049
2082
fn try_from ( item : & types:: SetupMandateRouterData ) -> Result < Self , Self :: Error > {
@@ -2060,6 +2093,12 @@ impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
2060
2093
item. connector_request_reference_id . clone ( ) ,
2061
2094
) ) ;
2062
2095
2096
+ let browser_info = item
2097
+ . request
2098
+ . browser_info
2099
+ . clone ( )
2100
+ . map ( StripeBrowserInformation :: from) ;
2101
+
2063
2102
Ok ( Self {
2064
2103
confirm : true ,
2065
2104
payment_data,
@@ -2071,6 +2110,7 @@ impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
2071
2110
meta_data,
2072
2111
payment_method_types : Some ( pm_type) ,
2073
2112
expand : Some ( ExpandableObjects :: LatestAttempt ) ,
2113
+ browser_info,
2074
2114
} )
2075
2115
}
2076
2116
}
0 commit comments