mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
fix: [mollie] locale validation irrespective of auth type (#2814)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -9,8 +9,8 @@ use url::Url;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connector::utils::{
|
connector::utils::{
|
||||||
self, AddressDetailsData, BrowserInformationData, CardData, PaymentsAuthorizeRequestData,
|
self, AddressDetailsData, BrowserInformationData, CardData,
|
||||||
RouterData,
|
PaymentMethodTokenizationRequestData, PaymentsAuthorizeRequestData, RouterData,
|
||||||
},
|
},
|
||||||
core::errors,
|
core::errors,
|
||||||
services, types,
|
services, types,
|
||||||
@ -62,7 +62,7 @@ pub struct MolliePaymentsRequest {
|
|||||||
locale: Option<String>,
|
locale: Option<String>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
payment_method_data: PaymentMethodData,
|
payment_method_data: PaymentMethodData,
|
||||||
metadata: Option<serde_json::Value>,
|
metadata: Option<MollieMetadata>,
|
||||||
sequence_type: SequenceType,
|
sequence_type: SequenceType,
|
||||||
mandate_id: Option<String>,
|
mandate_id: Option<String>,
|
||||||
}
|
}
|
||||||
@ -148,8 +148,10 @@ pub struct Address {
|
|||||||
pub country: api_models::enums::CountryAlpha2,
|
pub country: api_models::enums::CountryAlpha2,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MollieBrowserInfo {
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
language: String,
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct MollieMetadata {
|
||||||
|
pub order_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MolliePaymentsRequest {
|
impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MolliePaymentsRequest {
|
||||||
@ -216,7 +218,9 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP
|
|||||||
webhook_url: "".to_string(),
|
webhook_url: "".to_string(),
|
||||||
locale: None,
|
locale: None,
|
||||||
payment_method_data,
|
payment_method_data,
|
||||||
metadata: None,
|
metadata: Some(MollieMetadata {
|
||||||
|
order_id: item.router_data.connector_request_reference_id.clone(),
|
||||||
|
}),
|
||||||
sequence_type: SequenceType::Oneoff,
|
sequence_type: SequenceType::Oneoff,
|
||||||
mandate_id: None,
|
mandate_id: None,
|
||||||
})
|
})
|
||||||
@ -287,12 +291,7 @@ impl TryFrom<&types::TokenizationRouterData> for MollieCardTokenRequest {
|
|||||||
let card_expiry_date =
|
let card_expiry_date =
|
||||||
ccard.get_card_expiry_month_year_2_digit_with_delimiter("/".to_owned());
|
ccard.get_card_expiry_month_year_2_digit_with_delimiter("/".to_owned());
|
||||||
let card_cvv = ccard.card_cvc;
|
let card_cvv = ccard.card_cvc;
|
||||||
let browser_info = get_browser_info(item)?;
|
let locale = item.request.get_browser_info()?.get_language()?;
|
||||||
let locale = browser_info
|
|
||||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
|
||||||
field_name: "browser_info.language",
|
|
||||||
})?
|
|
||||||
.language;
|
|
||||||
let testmode =
|
let testmode =
|
||||||
item.test_mode
|
item.test_mode
|
||||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||||
@ -386,24 +385,6 @@ fn get_address_details(
|
|||||||
Ok(address_details)
|
Ok(address_details)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_browser_info(
|
|
||||||
item: &types::TokenizationRouterData,
|
|
||||||
) -> Result<Option<MollieBrowserInfo>, error_stack::Report<errors::ConnectorError>> {
|
|
||||||
if matches!(item.auth_type, enums::AuthenticationType::ThreeDs) {
|
|
||||||
item.request
|
|
||||||
.browser_info
|
|
||||||
.as_ref()
|
|
||||||
.map(|info| {
|
|
||||||
Ok(MollieBrowserInfo {
|
|
||||||
language: info.get_language()?,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.transpose()
|
|
||||||
} else {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct MolliePaymentsResponse {
|
pub struct MolliePaymentsResponse {
|
||||||
@ -411,7 +392,7 @@ pub struct MolliePaymentsResponse {
|
|||||||
pub id: String,
|
pub id: String,
|
||||||
pub amount: Amount,
|
pub amount: Amount,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub metadata: Option<serde_json::Value>,
|
pub metadata: Option<MollieMetadata>,
|
||||||
pub status: MolliePaymentStatus,
|
pub status: MolliePaymentStatus,
|
||||||
pub is_cancelable: Option<bool>,
|
pub is_cancelable: Option<bool>,
|
||||||
pub sequence_type: SequenceType,
|
pub sequence_type: SequenceType,
|
||||||
@ -544,12 +525,12 @@ impl<F, T>
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
status: enums::AttemptStatus::from(item.response.status),
|
status: enums::AttemptStatus::from(item.response.status),
|
||||||
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
response: Ok(types::PaymentsResponseData::TransactionResponse {
|
||||||
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id),
|
resource_id: types::ResponseId::ConnectorTransactionId(item.response.id.clone()),
|
||||||
redirection_data: url,
|
redirection_data: url,
|
||||||
mandate_reference: None,
|
mandate_reference: None,
|
||||||
connector_metadata: None,
|
connector_metadata: None,
|
||||||
network_txn_id: None,
|
network_txn_id: None,
|
||||||
connector_response_reference_id: None,
|
connector_response_reference_id: Some(item.response.id),
|
||||||
}),
|
}),
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
@ -561,6 +542,7 @@ impl<F, T>
|
|||||||
pub struct MollieRefundRequest {
|
pub struct MollieRefundRequest {
|
||||||
amount: Amount,
|
amount: Amount,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
|
metadata: Option<MollieMetadata>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> TryFrom<&MollieRouterData<&types::RefundsRouterData<F>>> for MollieRefundRequest {
|
impl<F> TryFrom<&MollieRouterData<&types::RefundsRouterData<F>>> for MollieRefundRequest {
|
||||||
@ -575,6 +557,9 @@ impl<F> TryFrom<&MollieRouterData<&types::RefundsRouterData<F>>> for MollieRefun
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
amount,
|
amount,
|
||||||
description: item.router_data.request.reason.to_owned(),
|
description: item.router_data.request.reason.to_owned(),
|
||||||
|
metadata: Some(MollieMetadata {
|
||||||
|
order_id: item.router_data.request.refund_id.clone(),
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -589,7 +574,7 @@ pub struct RefundResponse {
|
|||||||
settlement_amount: Option<Amount>,
|
settlement_amount: Option<Amount>,
|
||||||
status: MollieRefundStatus,
|
status: MollieRefundStatus,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
metadata: serde_json::Value,
|
metadata: Option<MollieMetadata>,
|
||||||
payment_id: String,
|
payment_id: String,
|
||||||
#[serde(rename = "_links")]
|
#[serde(rename = "_links")]
|
||||||
links: Links,
|
links: Links,
|
||||||
@ -642,6 +627,4 @@ pub struct ErrorResponse {
|
|||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
pub detail: String,
|
pub detail: String,
|
||||||
pub field: Option<String>,
|
pub field: Option<String>,
|
||||||
#[serde(rename = "_links")]
|
|
||||||
pub links: Option<Links>,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -292,6 +292,18 @@ pub trait PaymentsAuthorizeRequestData {
|
|||||||
fn get_ip_address_as_optional(&self) -> Option<Secret<String, IpAddress>>;
|
fn get_ip_address_as_optional(&self) -> Option<Secret<String, IpAddress>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait PaymentMethodTokenizationRequestData {
|
||||||
|
fn get_browser_info(&self) -> Result<types::BrowserInformation, Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PaymentMethodTokenizationRequestData for types::PaymentMethodTokenizationData {
|
||||||
|
fn get_browser_info(&self) -> Result<types::BrowserInformation, Error> {
|
||||||
|
self.browser_info
|
||||||
|
.clone()
|
||||||
|
.ok_or_else(missing_field_err("browser_info"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData {
|
impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData {
|
||||||
fn is_auto_capture(&self) -> Result<bool, Error> {
|
fn is_auto_capture(&self) -> Result<bool, Error> {
|
||||||
match self.capture_method {
|
match self.capture_method {
|
||||||
|
|||||||
Reference in New Issue
Block a user