Skip to content

Commit

Permalink
refactor(connector): [Airwallex] add device_data in payment request (#…
Browse files Browse the repository at this point in the history
…6881)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
swangi-kumari and hyperswitch-bot[bot] authored Dec 22, 2024
1 parent 0f8b0b3 commit 573974b
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 2 deletions.
15 changes: 15 additions & 0 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5613,6 +5613,21 @@
"type": "string",
"description": "User-agent of the browser",
"nullable": true
},
"os_type": {
"type": "string",
"description": "The os type of the client device",
"nullable": true
},
"os_version": {
"type": "string",
"description": "The os version of the client device",
"nullable": true
},
"device_model": {
"type": "string",
"description": "The device model of the client",
"nullable": true
}
}
},
Expand Down
15 changes: 15 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8325,6 +8325,21 @@
"type": "string",
"description": "User-agent of the browser",
"nullable": true
},
"os_type": {
"type": "string",
"description": "The os type of the client device",
"nullable": true
},
"os_version": {
"type": "string",
"description": "The os version of the client device",
"nullable": true
},
"device_model": {
"type": "string",
"description": "The device model of the client",
"nullable": true
}
}
},
Expand Down
9 changes: 9 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,15 @@ pub struct BrowserInformation {

/// User-agent of the browser
pub user_agent: Option<String>,

/// The os type of the client device
pub os_type: Option<String>,

/// The os version of the client device
pub os_version: Option<String>,

/// The device model of the client
pub device_model: Option<String>,
}

impl RequestSurchargeDetails {
Expand Down
9 changes: 9 additions & 0 deletions crates/common_utils/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,15 @@ pub struct BrowserInformation {

/// User-agent of the browser
pub user_agent: Option<String>,

/// The os type of the client device
pub os_type: Option<String>,

/// The os version of the client device
pub os_version: Option<String>,

/// The device model of the client
pub device_model: Option<String>,
}

#[cfg(feature = "v2")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common_enums::enums;
use common_utils::{errors::ParsingError, request::Method};
use common_utils::{errors::ParsingError, pii::IpAddress, request::Method};
use error_stack::ResultExt;
use hyperswitch_domain_models::{
payment_method_data::{PaymentMethodData, WalletData},
Expand All @@ -21,7 +21,7 @@ use uuid::Uuid;

use crate::{
types::{RefundsResponseRouterData, ResponseRouterData},
utils::{self, CardData as _},
utils::{self, BrowserInformationData, CardData as _, PaymentsAuthorizeRequestData},
};

pub struct AirwallexAuthType {
Expand Down Expand Up @@ -124,6 +124,40 @@ pub struct AirwallexPaymentsRequest {
payment_method: AirwallexPaymentMethod,
payment_method_options: Option<AirwallexPaymentOptions>,
return_url: Option<String>,
device_data: DeviceData,
}

#[derive(Debug, Serialize)]
pub struct DeviceData {
accept_header: String,
browser: Browser,
ip_address: Secret<String, IpAddress>,
language: String,
mobile: Option<Mobile>,
screen_color_depth: u8,
screen_height: u32,
screen_width: u32,
timezone: String,
}

#[derive(Debug, Serialize)]
pub struct Browser {
java_enabled: bool,
javascript_enabled: bool,
user_agent: String,
}

#[derive(Debug, Serialize)]
pub struct Location {
lat: String,
lon: String,
}

#[derive(Debug, Serialize)]
pub struct Mobile {
device_model: Option<String>,
os_type: Option<String>,
os_version: Option<String>,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -242,16 +276,55 @@ impl TryFrom<&AirwallexRouterData<&types::PaymentsAuthorizeRouterData>>
))
}
}?;
let device_data = get_device_data(item.router_data)?;

Ok(Self {
request_id: Uuid::new_v4().to_string(),
payment_method,
payment_method_options,
return_url: request.complete_authorize_url.clone(),
device_data,
})
}
}

fn get_device_data(
item: &types::PaymentsAuthorizeRouterData,
) -> Result<DeviceData, error_stack::Report<errors::ConnectorError>> {
let info = item.request.get_browser_info()?;
let browser = Browser {
java_enabled: info.get_java_enabled()?,
javascript_enabled: info.get_java_script_enabled()?,
user_agent: info.get_user_agent()?,
};
let mobile = {
let device_model = info.get_device_model().ok();
let os_type = info.get_os_type().ok();
let os_version = info.get_os_version().ok();

if device_model.is_some() || os_type.is_some() || os_version.is_some() {
Some(Mobile {
device_model,
os_type,
os_version,
})
} else {
None
}
};
Ok(DeviceData {
accept_header: info.get_accept_header()?,
browser,
ip_address: info.get_ip_address()?,
mobile,
screen_color_depth: info.get_color_depth()?,
screen_height: info.get_screen_height()?,
screen_width: info.get_screen_width()?,
timezone: info.get_time_zone()?.to_string(),
language: info.get_language()?,
})
}

fn get_wallet_details(
wallet_data: &WalletData,
) -> Result<AirwallexPaymentMethod, errors::ConnectorError> {
Expand Down
18 changes: 18 additions & 0 deletions crates/hyperswitch_connectors/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,9 @@ pub trait BrowserInformationData {
fn get_java_enabled(&self) -> Result<bool, Error>;
fn get_java_script_enabled(&self) -> Result<bool, Error>;
fn get_ip_address(&self) -> Result<Secret<String, IpAddress>, Error>;
fn get_os_type(&self) -> Result<String, Error>;
fn get_os_version(&self) -> Result<String, Error>;
fn get_device_model(&self) -> Result<String, Error>;
}

impl BrowserInformationData for BrowserInformation {
Expand Down Expand Up @@ -1807,6 +1810,21 @@ impl BrowserInformationData for BrowserInformation {
self.java_script_enabled
.ok_or_else(missing_field_err("browser_info.java_script_enabled"))
}
fn get_os_type(&self) -> Result<String, Error> {
self.os_type
.clone()
.ok_or_else(missing_field_err("browser_info.os_type"))
}
fn get_os_version(&self) -> Result<String, Error> {
self.os_version
.clone()
.ok_or_else(missing_field_err("browser_info.os_version"))
}
fn get_device_model(&self) -> Result<String, Error> {
self.device_model
.clone()
.ok_or_else(missing_field_err("browser_info.device_model"))
}
}

pub fn get_header_key_value<'a>(
Expand Down
3 changes: 3 additions & 0 deletions crates/hyperswitch_domain_models/src/router_request_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ pub struct BrowserInformation {
pub ip_address: Option<std::net::IpAddr>,
pub accept_header: Option<String>,
pub user_agent: Option<String>,
pub os_type: Option<String>,
pub os_version: Option<String>,
pub device_model: Option<String>,
}

#[derive(Debug, Clone, Default, Serialize)]
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/connector/trustpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ impl TryFrom<&TrustpayRouterData<&types::PaymentsAuthorizeRouterData>> for Trust
accept_header: Some(browser_info.accept_header.unwrap_or("*".to_string())),
user_agent: browser_info.user_agent,
ip_address: browser_info.ip_address,
os_type: None,
os_version: None,
device_model: None,
};
let params = get_mandatory_fields(item.router_data)?;
let amount = item.amount.to_owned();
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/routes/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub fn populate_ip_into_browser_info(
accept_header: None,
user_agent: None,
ip_address: None,
os_type: None,
os_version: None,
device_model: None,
});

let ip_address = req
Expand Down
3 changes: 3 additions & 0 deletions crates/router/tests/connectors/trustpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ fn get_default_browser_info() -> BrowserInformation {
accept_header: Some("*".to_string()),
user_agent: Some("none".to_string()),
ip_address: None,
os_type: None,
os_version: None,
device_model: None,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/router/tests/connectors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,9 @@ impl Default for BrowserInfoType {
java_enabled: Some(true),
java_script_enabled: Some(true),
ip_address: Some("127.0.0.1".parse().unwrap()),
device_model: Some("Apple IPHONE 7".to_string()),
os_type: Some("IOS or ANDROID".to_string()),
os_version: Some("IOS 14.5".to_string()),
};
Self(data)
}
Expand Down

0 comments on commit 573974b

Please sign in to comment.