mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +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::{ | ||||
|     connector::utils::{ | ||||
|         self, AddressDetailsData, BrowserInformationData, CardData, PaymentsAuthorizeRequestData, | ||||
|         RouterData, | ||||
|         self, AddressDetailsData, BrowserInformationData, CardData, | ||||
|         PaymentMethodTokenizationRequestData, PaymentsAuthorizeRequestData, RouterData, | ||||
|     }, | ||||
|     core::errors, | ||||
|     services, types, | ||||
| @ -62,7 +62,7 @@ pub struct MolliePaymentsRequest { | ||||
|     locale: Option<String>, | ||||
|     #[serde(flatten)] | ||||
|     payment_method_data: PaymentMethodData, | ||||
|     metadata: Option<serde_json::Value>, | ||||
|     metadata: Option<MollieMetadata>, | ||||
|     sequence_type: SequenceType, | ||||
|     mandate_id: Option<String>, | ||||
| } | ||||
| @ -148,8 +148,10 @@ pub struct Address { | ||||
|     pub country: api_models::enums::CountryAlpha2, | ||||
| } | ||||
|  | ||||
| pub struct MollieBrowserInfo { | ||||
|     language: String, | ||||
| #[derive(Debug, Serialize, Deserialize)] | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct MollieMetadata { | ||||
|     pub order_id: String, | ||||
| } | ||||
|  | ||||
| impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MolliePaymentsRequest { | ||||
| @ -216,7 +218,9 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP | ||||
|             webhook_url: "".to_string(), | ||||
|             locale: None, | ||||
|             payment_method_data, | ||||
|             metadata: None, | ||||
|             metadata: Some(MollieMetadata { | ||||
|                 order_id: item.router_data.connector_request_reference_id.clone(), | ||||
|             }), | ||||
|             sequence_type: SequenceType::Oneoff, | ||||
|             mandate_id: None, | ||||
|         }) | ||||
| @ -287,12 +291,7 @@ impl TryFrom<&types::TokenizationRouterData> for MollieCardTokenRequest { | ||||
|                 let card_expiry_date = | ||||
|                     ccard.get_card_expiry_month_year_2_digit_with_delimiter("/".to_owned()); | ||||
|                 let card_cvv = ccard.card_cvc; | ||||
|                 let browser_info = get_browser_info(item)?; | ||||
|                 let locale = browser_info | ||||
|                     .ok_or(errors::ConnectorError::MissingRequiredField { | ||||
|                         field_name: "browser_info.language", | ||||
|                     })? | ||||
|                     .language; | ||||
|                 let locale = item.request.get_browser_info()?.get_language()?; | ||||
|                 let testmode = | ||||
|                     item.test_mode | ||||
|                         .ok_or(errors::ConnectorError::MissingRequiredField { | ||||
| @ -386,24 +385,6 @@ fn get_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)] | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct MolliePaymentsResponse { | ||||
| @ -411,7 +392,7 @@ pub struct MolliePaymentsResponse { | ||||
|     pub id: String, | ||||
|     pub amount: Amount, | ||||
|     pub description: Option<String>, | ||||
|     pub metadata: Option<serde_json::Value>, | ||||
|     pub metadata: Option<MollieMetadata>, | ||||
|     pub status: MolliePaymentStatus, | ||||
|     pub is_cancelable: Option<bool>, | ||||
|     pub sequence_type: SequenceType, | ||||
| @ -544,12 +525,12 @@ impl<F, T> | ||||
|         Ok(Self { | ||||
|             status: enums::AttemptStatus::from(item.response.status), | ||||
|             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, | ||||
|                 mandate_reference: None, | ||||
|                 connector_metadata: None, | ||||
|                 network_txn_id: None, | ||||
|                 connector_response_reference_id: None, | ||||
|                 connector_response_reference_id: Some(item.response.id), | ||||
|             }), | ||||
|             ..item.data | ||||
|         }) | ||||
| @ -561,6 +542,7 @@ impl<F, T> | ||||
| pub struct MollieRefundRequest { | ||||
|     amount: Amount, | ||||
|     description: Option<String>, | ||||
|     metadata: Option<MollieMetadata>, | ||||
| } | ||||
|  | ||||
| impl<F> TryFrom<&MollieRouterData<&types::RefundsRouterData<F>>> for MollieRefundRequest { | ||||
| @ -575,6 +557,9 @@ impl<F> TryFrom<&MollieRouterData<&types::RefundsRouterData<F>>> for MollieRefun | ||||
|         Ok(Self { | ||||
|             amount, | ||||
|             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>, | ||||
|     status: MollieRefundStatus, | ||||
|     description: Option<String>, | ||||
|     metadata: serde_json::Value, | ||||
|     metadata: Option<MollieMetadata>, | ||||
|     payment_id: String, | ||||
|     #[serde(rename = "_links")] | ||||
|     links: Links, | ||||
| @ -642,6 +627,4 @@ pub struct ErrorResponse { | ||||
|     pub title: Option<String>, | ||||
|     pub detail: 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>>; | ||||
| } | ||||
|  | ||||
| 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 { | ||||
|     fn is_auto_capture(&self) -> Result<bool, Error> { | ||||
|         match self.capture_method { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Arjun Karthik
					Arjun Karthik