Skip to content

Commit

Permalink
Merge branch 'main' into deprecate-v1-user-apis
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsMani committed Apr 25, 2024
2 parents 043d1a9 + 2848e0a commit e51c526
Show file tree
Hide file tree
Showing 23 changed files with 763 additions and 669 deletions.
4 changes: 4 additions & 0 deletions crates/data_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
updated_by: String,
},
PaymentMethodDetailsUpdate {
payment_method_id: Option<String>,
updated_by: String,
},
VoidUpdate {
status: storage_enums::AttemptStatus,
cancellation_reason: Option<String>,
Expand Down
12 changes: 12 additions & 0 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ pub enum PaymentAttemptUpdate {
cancellation_reason: Option<String>,
updated_by: String,
},
PaymentMethodDetailsUpdate {
payment_method_id: Option<String>,
updated_by: String,
},
BlocklistUpdate {
status: storage_enums::AttemptStatus,
error_code: Option<Option<String>>,
Expand Down Expand Up @@ -644,6 +648,14 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
merchant_connector_id: Some(None),
..Default::default()
},
PaymentAttemptUpdate::PaymentMethodDetailsUpdate {
payment_method_id,
updated_by,
} => Self {
payment_method_id,
updated_by,
..Default::default()
},
PaymentAttemptUpdate::ResponseUpdate {
status,
connector,
Expand Down
40 changes: 40 additions & 0 deletions crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ pub enum ExpandableObjects {
LatestAttempt,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
pub struct StripeBrowserInformation {
#[serde(rename = "payment_method_data[ip]")]
pub ip_address: Option<Secret<String, pii::IpAddress>>,
#[serde(rename = "payment_method_data[user_agent]")]
pub user_agent: Option<String>,
}

#[derive(Debug, Eq, PartialEq, Serialize)]
pub struct PaymentIntentRequest {
pub amount: i64, //amount in cents, hence passed as integer
Expand Down Expand Up @@ -144,6 +152,8 @@ pub struct PaymentIntentRequest {
pub payment_method_types: Option<StripePaymentMethodType>,
#[serde(rename = "expand[0]")]
pub expand: Option<ExpandableObjects>,
#[serde(flatten)]
pub browser_info: Option<StripeBrowserInformation>,
}

// Field rename is required only in case of serialization as it is passed in the request to the connector.
Expand Down Expand Up @@ -177,6 +187,8 @@ pub struct SetupIntentRequest {
pub payment_method_types: Option<StripePaymentMethodType>,
#[serde(rename = "expand[0]")]
pub expand: Option<ExpandableObjects>,
#[serde(flatten)]
pub browser_info: Option<StripeBrowserInformation>,
}

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

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

// We pass browser_info only when payment_data exists.
// Hence, we're pass Null during recurring payments as payment_method_data[type] is not passed
let browser_info = if payment_data.is_some() {
item.request
.browser_info
.clone()
.map(StripeBrowserInformation::from)
} else {
None
};

Ok(Self {
amount: item.request.amount, //hopefully we don't loose some cents here
currency: item.request.currency.to_string(), //we need to copy the value and not transfer ownership
Expand All @@ -2007,6 +2030,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
setup_future_usage: item.request.setup_future_usage,
payment_method_types,
expand: Some(ExpandableObjects::LatestCharge),
browser_info,
})
}
}
Expand Down Expand Up @@ -2044,6 +2068,15 @@ fn get_payment_method_type_for_saved_payment_method_payment(
}
}

impl From<types::BrowserInformation> for StripeBrowserInformation {
fn from(item: types::BrowserInformation) -> Self {
Self {
ip_address: item.ip_address.map(|ip| Secret::new(ip.to_string())),
user_agent: item.user_agent,
}
}
}

impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &types::SetupMandateRouterData) -> Result<Self, Self::Error> {
Expand All @@ -2060,6 +2093,12 @@ impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
item.connector_request_reference_id.clone(),
));

let browser_info = item
.request
.browser_info
.clone()
.map(StripeBrowserInformation::from);

Ok(Self {
confirm: true,
payment_data,
Expand All @@ -2071,6 +2110,7 @@ impl TryFrom<&types::SetupMandateRouterData> for SetupIntentRequest {
meta_data,
payment_method_types: Some(pm_type),
expand: Some(ExpandableObjects::LatestAttempt),
browser_info,
})
}
}
Expand Down
Loading

0 comments on commit e51c526

Please sign in to comment.