mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
feat(compatibility): add receipt_ipaddress and user_agent in stripe compatibility (#1417)
This commit is contained in:
committed by
GitHub
parent
4a8de7741d
commit
de2a6e86d7
@ -1,3 +1,5 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use api_models::payments;
|
use api_models::payments;
|
||||||
use common_utils::{crypto::Encryptable, date_time, ext_traits::StringExt, pii as secret};
|
use common_utils::{crypto::Encryptable, date_time, ext_traits::StringExt, pii as secret};
|
||||||
use error_stack::{IntoReport, ResultExt};
|
use error_stack::{IntoReport, ResultExt};
|
||||||
@ -146,6 +148,8 @@ pub struct StripePaymentIntentRequest {
|
|||||||
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
|
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
|
||||||
pub mandate_id: Option<String>,
|
pub mandate_id: Option<String>,
|
||||||
pub off_session: Option<bool>,
|
pub off_session: Option<bool>,
|
||||||
|
pub receipt_ipaddress: Option<String>,
|
||||||
|
pub user_agent: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
||||||
@ -182,6 +186,16 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
|||||||
.attach_printable("converting to routing failed")
|
.attach_printable("converting to routing failed")
|
||||||
})
|
})
|
||||||
.transpose()?;
|
.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 {
|
let request = Ok(Self {
|
||||||
payment_id: item.id.map(payments::PaymentIdType::PaymentIntentId),
|
payment_id: item.id.map(payments::PaymentIdType::PaymentIntentId),
|
||||||
amount: item.amount.map(|amount| amount.into()),
|
amount: item.amount.map(|amount| amount.into()),
|
||||||
@ -228,6 +242,16 @@ impl TryFrom<StripePaymentIntentRequest> for payments::PaymentsRequest {
|
|||||||
mandate_id: item.mandate_id,
|
mandate_id: item.mandate_id,
|
||||||
off_session: item.off_session,
|
off_session: item.off_session,
|
||||||
routing,
|
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()
|
..Self::default()
|
||||||
});
|
});
|
||||||
request
|
request
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use api_models::payments;
|
use api_models::payments;
|
||||||
use common_utils::{date_time, ext_traits::StringExt};
|
use common_utils::{date_time, ext_traits::StringExt};
|
||||||
use error_stack::ResultExt;
|
use error_stack::{IntoReport, ResultExt};
|
||||||
use router_env::logger;
|
use router_env::logger;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@ -138,6 +140,8 @@ pub struct StripeSetupIntentRequest {
|
|||||||
pub payment_method_options: Option<payment_intent::StripePaymentMethodOptions>,
|
pub payment_method_options: Option<payment_intent::StripePaymentMethodOptions>,
|
||||||
pub payment_method: Option<String>,
|
pub payment_method: Option<String>,
|
||||||
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
|
pub merchant_connector_details: Option<admin::MerchantConnectorDetailsWrap>,
|
||||||
|
pub receipt_ipaddress: Option<String>,
|
||||||
|
pub user_agent: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
||||||
@ -161,6 +165,15 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
|||||||
}
|
}
|
||||||
None => (None, None),
|
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 {
|
let request = Ok(Self {
|
||||||
amount: Some(api_types::Amount::Zero),
|
amount: Some(api_types::Amount::Zero),
|
||||||
capture_method: None,
|
capture_method: None,
|
||||||
@ -208,6 +221,17 @@ impl TryFrom<StripeSetupIntentRequest> for payments::PaymentsRequest {
|
|||||||
merchant_connector_details: item.merchant_connector_details,
|
merchant_connector_details: item.merchant_connector_details,
|
||||||
authentication_type,
|
authentication_type,
|
||||||
mandate_data: mandate_options,
|
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()
|
..Default::default()
|
||||||
});
|
});
|
||||||
request
|
request
|
||||||
|
|||||||
@ -442,7 +442,7 @@ pub struct RefundsData {
|
|||||||
pub connector_metadata: Option<serde_json::Value>,
|
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 struct BrowserInformation {
|
||||||
pub color_depth: Option<u8>,
|
pub color_depth: Option<u8>,
|
||||||
pub java_enabled: Option<bool>,
|
pub java_enabled: Option<bool>,
|
||||||
|
|||||||
Reference in New Issue
Block a user