Skip to content

Commit 74ca7c9

Browse files
committed
Merge branch 'main' of github.com:juspay/hyperswitch into move-creds-to-env
* 'main' of github.com:juspay/hyperswitch: ci(postman): Fix Adyen postman collection (#4459) docs(cypress): Update Cypress README Documentation (#4380) Refactor(core): make save_payment_method as post_update_tracker trait function (#4307) refactor(connector): pass optional browser_info to stripe for increased trust (#4374)
2 parents 74a9e4d + 2848e0a commit 74ca7c9

File tree

23 files changed

+763
-669
lines changed

23 files changed

+763
-669
lines changed

crates/data_models/src/payments/payment_attempt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ pub enum PaymentAttemptUpdate {
338338
error_message: Option<Option<String>>,
339339
updated_by: String,
340340
},
341+
PaymentMethodDetailsUpdate {
342+
payment_method_id: Option<String>,
343+
updated_by: String,
344+
},
341345
VoidUpdate {
342346
status: storage_enums::AttemptStatus,
343347
cancellation_reason: Option<String>,

crates/diesel_models/src/payment_attempt.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ pub enum PaymentAttemptUpdate {
237237
cancellation_reason: Option<String>,
238238
updated_by: String,
239239
},
240+
PaymentMethodDetailsUpdate {
241+
payment_method_id: Option<String>,
242+
updated_by: String,
243+
},
240244
BlocklistUpdate {
241245
status: storage_enums::AttemptStatus,
242246
error_code: Option<Option<String>>,
@@ -644,6 +648,14 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
644648
merchant_connector_id: Some(None),
645649
..Default::default()
646650
},
651+
PaymentAttemptUpdate::PaymentMethodDetailsUpdate {
652+
payment_method_id,
653+
updated_by,
654+
} => Self {
655+
payment_method_id,
656+
updated_by,
657+
..Default::default()
658+
},
647659
PaymentAttemptUpdate::ResponseUpdate {
648660
status,
649661
connector,

crates/router/src/connector/stripe/transformers.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ pub enum ExpandableObjects {
114114
LatestAttempt,
115115
}
116116

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+
117125
#[derive(Debug, Eq, PartialEq, Serialize)]
118126
pub struct PaymentIntentRequest {
119127
pub amount: i64, //amount in cents, hence passed as integer
@@ -144,6 +152,8 @@ pub struct PaymentIntentRequest {
144152
pub payment_method_types: Option<StripePaymentMethodType>,
145153
#[serde(rename = "expand[0]")]
146154
pub expand: Option<ExpandableObjects>,
155+
#[serde(flatten)]
156+
pub browser_info: Option<StripeBrowserInformation>,
147157
}
148158

149159
// 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 {
177187
pub payment_method_types: Option<StripePaymentMethodType>,
178188
#[serde(rename = "expand[0]")]
179189
pub expand: Option<ExpandableObjects>,
190+
#[serde(flatten)]
191+
pub browser_info: Option<StripeBrowserInformation>,
180192
}
181193

182194
#[derive(Debug, Eq, PartialEq, Serialize)]
@@ -1982,6 +1994,17 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
19821994

19831995
let meta_data = get_transaction_metadata(item.request.metadata.clone(), order_id);
19841996

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+
19852008
Ok(Self {
19862009
amount: item.request.amount, //hopefully we don't loose some cents here
19872010
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 {
20072030
setup_future_usage: item.request.setup_future_usage,
20082031
payment_method_types,
20092032
expand: Some(ExpandableObjects::LatestCharge),
2033+
browser_info,
20102034
})
20112035
}
20122036
}
@@ -2044,6 +2068,15 @@ fn get_payment_method_type_for_saved_payment_method_payment(
20442068
}
20452069
}
20462070

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+
20472080
impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
20482081
type Error = error_stack::Report<errors::ConnectorError>;
20492082
fn try_from(item: &types::SetupMandateRouterData) -> Result<Self, Self::Error> {
@@ -2060,6 +2093,12 @@ impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
20602093
item.connector_request_reference_id.clone(),
20612094
));
20622095

2096+
let browser_info = item
2097+
.request
2098+
.browser_info
2099+
.clone()
2100+
.map(StripeBrowserInformation::from);
2101+
20632102
Ok(Self {
20642103
confirm: true,
20652104
payment_data,
@@ -2071,6 +2110,7 @@ impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
20712110
meta_data,
20722111
payment_method_types: Some(pm_type),
20732112
expand: Some(ExpandableObjects::LatestAttempt),
2113+
browser_info,
20742114
})
20752115
}
20762116
}

0 commit comments

Comments
 (0)