mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 11:06:50 +08:00
fix(router): [Trustpay] fix email & user-agent information as mandatory fields in trustpay card payment request (#1414)
This commit is contained in:
@ -9,7 +9,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connector::utils::{
|
connector::utils::{
|
||||||
self, AddressDetailsData, CardData, PaymentsAuthorizeRequestData, RouterData,
|
self, AddressDetailsData, BrowserInformationData, CardData, PaymentsAuthorizeRequestData,
|
||||||
|
RouterData,
|
||||||
},
|
},
|
||||||
consts,
|
consts,
|
||||||
core::errors,
|
core::errors,
|
||||||
@ -109,7 +110,7 @@ pub struct CallbackURLs {
|
|||||||
pub error: String,
|
pub error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, PartialEq)]
|
#[derive(Debug, Serialize, PartialEq)]
|
||||||
pub struct PaymentRequestCards {
|
pub struct PaymentRequestCards {
|
||||||
pub amount: String,
|
pub amount: String,
|
||||||
pub currency: String,
|
pub currency: String,
|
||||||
@ -130,9 +131,9 @@ pub struct PaymentRequestCards {
|
|||||||
#[serde(rename = "billing[postcode]")]
|
#[serde(rename = "billing[postcode]")]
|
||||||
pub billing_postcode: Secret<String>,
|
pub billing_postcode: Secret<String>,
|
||||||
#[serde(rename = "customer[email]")]
|
#[serde(rename = "customer[email]")]
|
||||||
pub customer_email: Option<Email>,
|
pub customer_email: Email,
|
||||||
#[serde(rename = "customer[ipAddress]")]
|
#[serde(rename = "customer[ipAddress]")]
|
||||||
pub customer_ip_address: Option<std::net::IpAddr>,
|
pub customer_ip_address: std::net::IpAddr,
|
||||||
#[serde(rename = "browser[acceptHeader]")]
|
#[serde(rename = "browser[acceptHeader]")]
|
||||||
pub browser_accept_header: String,
|
pub browser_accept_header: String,
|
||||||
#[serde(rename = "browser[language]")]
|
#[serde(rename = "browser[language]")]
|
||||||
@ -220,6 +221,8 @@ fn get_card_request_data(
|
|||||||
ccard: &api_models::payments::Card,
|
ccard: &api_models::payments::Card,
|
||||||
return_url: String,
|
return_url: String,
|
||||||
) -> Result<TrustpayPaymentsRequest, Error> {
|
) -> Result<TrustpayPaymentsRequest, Error> {
|
||||||
|
let email = item.request.get_email()?;
|
||||||
|
let customer_ip_address = browser_info.get_ip_address()?;
|
||||||
Ok(TrustpayPaymentsRequest::CardsPaymentRequest(Box::new(
|
Ok(TrustpayPaymentsRequest::CardsPaymentRequest(Box::new(
|
||||||
PaymentRequestCards {
|
PaymentRequestCards {
|
||||||
amount,
|
amount,
|
||||||
@ -234,8 +237,8 @@ fn get_card_request_data(
|
|||||||
billing_country: params.billing_country,
|
billing_country: params.billing_country,
|
||||||
billing_street1: params.billing_street1,
|
billing_street1: params.billing_street1,
|
||||||
billing_postcode: params.billing_postcode,
|
billing_postcode: params.billing_postcode,
|
||||||
customer_email: item.request.email.clone(),
|
customer_email: email,
|
||||||
customer_ip_address: browser_info.ip_address,
|
customer_ip_address,
|
||||||
browser_accept_header: browser_info
|
browser_accept_header: browser_info
|
||||||
.accept_header
|
.accept_header
|
||||||
.clone()
|
.clone()
|
||||||
@ -349,8 +352,16 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for TrustpayPaymentsRequest {
|
|||||||
screen_width: Some(1920),
|
screen_width: Some(1920),
|
||||||
time_zone: Some(3600),
|
time_zone: Some(3600),
|
||||||
accept_header: Some("*".to_string()),
|
accept_header: Some("*".to_string()),
|
||||||
user_agent: Some("none".to_string()),
|
user_agent: item
|
||||||
ip_address: None,
|
.request
|
||||||
|
.browser_info
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|info| info.user_agent.clone()),
|
||||||
|
ip_address: item
|
||||||
|
.request
|
||||||
|
.browser_info
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|info| info.ip_address),
|
||||||
};
|
};
|
||||||
let browser_info = item
|
let browser_info = item
|
||||||
.request
|
.request
|
||||||
|
|||||||
@ -262,7 +262,8 @@ pub trait BrowserInformationData {
|
|||||||
|
|
||||||
impl BrowserInformationData for types::BrowserInformation {
|
impl BrowserInformationData for types::BrowserInformation {
|
||||||
fn get_ip_address(&self) -> Result<std::net::IpAddr, Error> {
|
fn get_ip_address(&self) -> Result<std::net::IpAddr, Error> {
|
||||||
self.ip_address.ok_or_else(missing_field_err("ip_address"))
|
self.ip_address
|
||||||
|
.ok_or_else(missing_field_err("browser_info.ip_address"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user