mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	refactor: use CountryAlpha2 instead of CountryCode for country codes (#904)
				
					
				
			This commit is contained in:
		| @ -127,12 +127,12 @@ pub struct CurrencyCountryFilter { | ||||
|     #[serde(deserialize_with = "currency_set_deser")] | ||||
|     pub currency: Option<HashSet<api_models::enums::Currency>>, | ||||
|     #[serde(deserialize_with = "string_set_deser")] | ||||
|     pub country: Option<HashSet<api_models::enums::CountryCode>>, | ||||
|     pub country: Option<HashSet<api_models::enums::CountryAlpha2>>, | ||||
| } | ||||
|  | ||||
| fn string_set_deser<'a, D>( | ||||
|     deserializer: D, | ||||
| ) -> Result<Option<HashSet<api_models::enums::CountryCode>>, D::Error> | ||||
| ) -> Result<Option<HashSet<api_models::enums::CountryAlpha2>>, D::Error> | ||||
| where | ||||
|     D: Deserializer<'a>, | ||||
| { | ||||
| @ -141,7 +141,7 @@ where | ||||
|         let list = inner | ||||
|             .trim() | ||||
|             .split(',') | ||||
|             .flat_map(api_models::enums::CountryCode::from_str) | ||||
|             .flat_map(api_models::enums::CountryAlpha2::from_str) | ||||
|             .collect::<HashSet<_>>(); | ||||
|         match list.len() { | ||||
|             0 => None, | ||||
|  | ||||
| @ -65,7 +65,7 @@ pub enum PaymentDetails { | ||||
| pub struct BankRedirectionPMData { | ||||
|     payment_brand: PaymentBrand, | ||||
|     #[serde(rename = "bankAccount.country")] | ||||
|     bank_account_country: Option<api_models::enums::CountryCode>, | ||||
|     bank_account_country: Option<api_models::enums::CountryAlpha2>, | ||||
|     #[serde(rename = "bankAccount.bankName")] | ||||
|     bank_account_bank_name: Option<String>, | ||||
|     #[serde(rename = "bankAccount.bic")] | ||||
| @ -140,7 +140,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest { | ||||
|                     api_models::payments::BankRedirectData::Eps { .. } => { | ||||
|                         PaymentDetails::BankRedirect(Box::new(BankRedirectionPMData { | ||||
|                             payment_brand: PaymentBrand::Eps, | ||||
|                             bank_account_country: Some(api_models::enums::CountryCode::AT), | ||||
|                             bank_account_country: Some(api_models::enums::CountryAlpha2::AT), | ||||
|                             bank_account_bank_name: None, | ||||
|                             bank_account_bic: None, | ||||
|                             bank_account_iban: None, | ||||
| @ -153,7 +153,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest { | ||||
|                         .. | ||||
|                     } => PaymentDetails::BankRedirect(Box::new(BankRedirectionPMData { | ||||
|                         payment_brand: PaymentBrand::Giropay, | ||||
|                         bank_account_country: Some(api_models::enums::CountryCode::DE), | ||||
|                         bank_account_country: Some(api_models::enums::CountryAlpha2::DE), | ||||
|                         bank_account_bank_name: None, | ||||
|                         bank_account_bic: bank_account_bic.clone(), | ||||
|                         bank_account_iban: bank_account_iban.clone(), | ||||
| @ -162,7 +162,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest { | ||||
|                     api_models::payments::BankRedirectData::Ideal { bank_name, .. } => { | ||||
|                         PaymentDetails::BankRedirect(Box::new(BankRedirectionPMData { | ||||
|                             payment_brand: PaymentBrand::Ideal, | ||||
|                             bank_account_country: Some(api_models::enums::CountryCode::NL), | ||||
|                             bank_account_country: Some(api_models::enums::CountryAlpha2::NL), | ||||
|                             bank_account_bank_name: Some(bank_name.to_string()), | ||||
|                             bank_account_bic: None, | ||||
|                             bank_account_iban: None, | ||||
|  | ||||
| @ -62,7 +62,7 @@ pub struct ShopperName { | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct Address { | ||||
|     city: Option<String>, | ||||
|     country: Option<api_enums::CountryCode>, | ||||
|     country: Option<api_enums::CountryAlpha2>, | ||||
|     house_number_or_name: Option<Secret<String>>, | ||||
|     postal_code: Option<Secret<String>>, | ||||
|     state_or_province: Option<Secret<String>>, | ||||
| @ -99,7 +99,7 @@ pub struct AdyenPaymentRequest<'a> { | ||||
|     telephone_number: Option<Secret<String>>, | ||||
|     billing_address: Option<Address>, | ||||
|     delivery_address: Option<Address>, | ||||
|     country_code: Option<api_enums::CountryCode>, | ||||
|     country_code: Option<api_enums::CountryAlpha2>, | ||||
|     line_items: Option<Vec<LineItem>>, | ||||
| } | ||||
|  | ||||
| @ -827,7 +827,7 @@ fn get_shopper_name(item: &types::PaymentsAuthorizeRouterData) -> Option<Shopper | ||||
|     }) | ||||
| } | ||||
|  | ||||
| fn get_country_code(item: &types::PaymentsAuthorizeRouterData) -> Option<api_enums::CountryCode> { | ||||
| fn get_country_code(item: &types::PaymentsAuthorizeRouterData) -> Option<api_enums::CountryAlpha2> { | ||||
|     item.address | ||||
|         .billing | ||||
|         .as_ref() | ||||
| @ -1107,7 +1107,7 @@ impl<'a> | ||||
|  | ||||
| fn get_sofort_extra_details( | ||||
|     item: &types::PaymentsAuthorizeRouterData, | ||||
| ) -> (Option<String>, Option<api_enums::CountryCode>) { | ||||
| ) -> (Option<String>, Option<api_enums::CountryAlpha2>) { | ||||
|     match item.request.payment_method_data { | ||||
|         api_models::payments::PaymentMethodData::BankRedirect(ref b) => { | ||||
|             if let api_models::payments::BankRedirectData::Sofort { | ||||
|  | ||||
| @ -80,7 +80,7 @@ pub struct BillTo { | ||||
|     locality: String, | ||||
|     administrative_area: Secret<String>, | ||||
|     postal_code: Secret<String>, | ||||
|     country: api_enums::CountryCode, | ||||
|     country: api_enums::CountryAlpha2, | ||||
|     email: Secret<String, pii::Email>, | ||||
|     phone_number: Secret<String>, | ||||
| } | ||||
|  | ||||
| @ -27,7 +27,7 @@ pub struct GlobalpayPaymentsRequest { | ||||
|     /// related currency. | ||||
|     pub convenience_amount: Option<String>, | ||||
|     /// The country in ISO-3166-1(alpha-2 code) format. | ||||
|     pub country: api_models::enums::CountryCode, | ||||
|     pub country: api_models::enums::CountryAlpha2, | ||||
|     /// The currency of the amount in ISO-4217(alpha-3) | ||||
|     pub currency: String, | ||||
|  | ||||
|  | ||||
| @ -83,7 +83,7 @@ pub struct Address { | ||||
|     pub postal_code: Secret<String>, | ||||
|     pub city: String, | ||||
|     pub region: Option<Secret<String>>, | ||||
|     pub country: api_models::enums::CountryCode, | ||||
|     pub country: api_models::enums::CountryAlpha2, | ||||
| } | ||||
|  | ||||
| impl TryFrom<&types::PaymentsAuthorizeRouterData> for MolliePaymentsRequest { | ||||
|  | ||||
| @ -132,7 +132,7 @@ pub struct DeliveryObject { | ||||
|     house_number: Secret<String>, | ||||
|     zip_code: Secret<String>, | ||||
|     city: String, | ||||
|     country: api_models::enums::CountryCode, | ||||
|     country: api_models::enums::CountryAlpha2, | ||||
| } | ||||
|  | ||||
| #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||||
|  | ||||
| @ -186,7 +186,7 @@ pub struct BillingAddress { | ||||
|     pub email: Option<Secret<String, Email>>, | ||||
|     pub first_name: Option<Secret<String>>, | ||||
|     pub last_name: Option<Secret<String>>, | ||||
|     pub country: api_models::enums::CountryCode, | ||||
|     pub country: api_models::enums::CountryAlpha2, | ||||
| } | ||||
|  | ||||
| #[serde_with::skip_serializing_none] | ||||
|  | ||||
| @ -36,7 +36,7 @@ pub struct PurchaseUnitRequest { | ||||
| pub struct Address { | ||||
|     address_line_1: Option<Secret<String>>, | ||||
|     postal_code: Option<Secret<String>>, | ||||
|     country_code: api_models::enums::CountryCode, | ||||
|     country_code: api_models::enums::CountryAlpha2, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Serialize)] | ||||
| @ -51,7 +51,7 @@ pub struct CardRequest { | ||||
| #[derive(Debug, Serialize)] | ||||
| pub struct RedirectRequest { | ||||
|     name: Secret<String>, | ||||
|     country_code: api_models::enums::CountryCode, | ||||
|     country_code: api_models::enums::CountryAlpha2, | ||||
|     experience_context: ContextStruct, | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -87,7 +87,7 @@ pub struct Address { | ||||
|     zip: Option<Secret<String>>, | ||||
|     state: Option<Secret<String>>, | ||||
|     city: Option<String>, | ||||
|     country: Option<api_models::enums::CountryCode>, | ||||
|     country: Option<api_models::enums::CountryAlpha2>, | ||||
| } | ||||
|  | ||||
| #[derive(Default, Debug, Serialize, Eq, PartialEq)] | ||||
|  | ||||
| @ -179,7 +179,7 @@ pub enum BankSpecificData { | ||||
|         #[serde(rename = "payment_method_options[sofort][preferred_language]")] | ||||
|         preferred_language: String, | ||||
|         #[serde(rename = "payment_method_data[sofort][country]")] | ||||
|         country: api_enums::CountryCode, | ||||
|         country: api_enums::CountryAlpha2, | ||||
|     }, | ||||
| } | ||||
|  | ||||
| @ -1425,7 +1425,7 @@ pub struct StripeShippingAddress { | ||||
|     #[serde(rename = "shipping[address][city]")] | ||||
|     pub city: Option<String>, | ||||
|     #[serde(rename = "shipping[address][country]")] | ||||
|     pub country: Option<api_enums::CountryCode>, | ||||
|     pub country: Option<api_enums::CountryAlpha2>, | ||||
|     #[serde(rename = "shipping[address][line1]")] | ||||
|     pub line1: Option<Secret<String>>, | ||||
|     #[serde(rename = "shipping[address][line2]")] | ||||
| @ -1445,7 +1445,7 @@ pub struct StripeBillingAddress { | ||||
|     #[serde(rename = "payment_method_data[billing_details][email]")] | ||||
|     pub email: Option<Secret<String, pii::Email>>, | ||||
|     #[serde(rename = "payment_method_data[billing_details][address][country]")] | ||||
|     pub country: Option<api_enums::CountryCode>, | ||||
|     pub country: Option<api_enums::CountryAlpha2>, | ||||
|     #[serde(rename = "payment_method_data[billing_details][name]")] | ||||
|     pub name: Option<Secret<String>>, | ||||
|     #[serde(rename = "payment_method_data[billing_details][address][city]")] | ||||
| @ -1896,7 +1896,7 @@ pub struct DisputeObj { | ||||
| #[cfg(test)] | ||||
| mod test_validate_shipping_address_against_payment_method { | ||||
|     #![allow(clippy::unwrap_used)] | ||||
|     use api_models::enums::CountryCode; | ||||
|     use api_models::enums::CountryAlpha2; | ||||
|     use masking::Secret; | ||||
|  | ||||
|     use crate::{ | ||||
| @ -1913,7 +1913,7 @@ mod test_validate_shipping_address_against_payment_method { | ||||
|         let stripe_shipping_address = create_stripe_shipping_address( | ||||
|             Some("name".to_string()), | ||||
|             Some("line1".to_string()), | ||||
|             Some(CountryCode::AD), | ||||
|             Some(CountryAlpha2::AD), | ||||
|             Some("zip".to_string()), | ||||
|         ); | ||||
|  | ||||
| @ -1935,7 +1935,7 @@ mod test_validate_shipping_address_against_payment_method { | ||||
|         let stripe_shipping_address = create_stripe_shipping_address( | ||||
|             None, | ||||
|             Some("line1".to_string()), | ||||
|             Some(CountryCode::AD), | ||||
|             Some(CountryAlpha2::AD), | ||||
|             Some("zip".to_string()), | ||||
|         ); | ||||
|  | ||||
| @ -1960,7 +1960,7 @@ mod test_validate_shipping_address_against_payment_method { | ||||
|         let stripe_shipping_address = create_stripe_shipping_address( | ||||
|             Some("name".to_string()), | ||||
|             None, | ||||
|             Some(CountryCode::AD), | ||||
|             Some(CountryAlpha2::AD), | ||||
|             Some("zip".to_string()), | ||||
|         ); | ||||
|  | ||||
| @ -2010,7 +2010,7 @@ mod test_validate_shipping_address_against_payment_method { | ||||
|         let stripe_shipping_address = create_stripe_shipping_address( | ||||
|             Some("name".to_string()), | ||||
|             Some("line1".to_string()), | ||||
|             Some(CountryCode::AD), | ||||
|             Some(CountryAlpha2::AD), | ||||
|             None, | ||||
|         ); | ||||
|         let payment_method = &StripePaymentMethodType::AfterpayClearpay; | ||||
| @ -2066,7 +2066,7 @@ mod test_validate_shipping_address_against_payment_method { | ||||
|     fn create_stripe_shipping_address( | ||||
|         name: Option<String>, | ||||
|         line1: Option<String>, | ||||
|         country: Option<CountryCode>, | ||||
|         country: Option<CountryAlpha2>, | ||||
|         zip: Option<String>, | ||||
|     ) -> StripeShippingAddress { | ||||
|         StripeShippingAddress { | ||||
|  | ||||
| @ -124,7 +124,7 @@ pub struct PaymentRequestCards { | ||||
|     #[serde(rename = "billing[city]")] | ||||
|     pub billing_city: String, | ||||
|     #[serde(rename = "billing[country]")] | ||||
|     pub billing_country: api_models::enums::CountryCode, | ||||
|     pub billing_country: api_models::enums::CountryAlpha2, | ||||
|     #[serde(rename = "billing[street1]")] | ||||
|     pub billing_street1: Secret<String>, | ||||
|     #[serde(rename = "billing[postcode]")] | ||||
| @ -178,7 +178,7 @@ pub enum TrustpayPaymentsRequest { | ||||
| #[derive(Debug, Serialize, Eq, PartialEq)] | ||||
| pub struct TrustpayMandatoryParams { | ||||
|     pub billing_city: String, | ||||
|     pub billing_country: api_models::enums::CountryCode, | ||||
|     pub billing_country: api_models::enums::CountryAlpha2, | ||||
|     pub billing_street1: Secret<String>, | ||||
|     pub billing_postcode: Secret<String>, | ||||
| } | ||||
|  | ||||
| @ -49,7 +49,7 @@ impl AccessTokenRequestInfo for types::RefreshTokenRouterData { | ||||
|  | ||||
| pub trait RouterData { | ||||
|     fn get_billing(&self) -> Result<&api::Address, Error>; | ||||
|     fn get_billing_country(&self) -> Result<api_models::enums::CountryCode, Error>; | ||||
|     fn get_billing_country(&self) -> Result<api_models::enums::CountryAlpha2, Error>; | ||||
|     fn get_billing_phone(&self) -> Result<&api::PhoneDetails, Error>; | ||||
|     fn get_description(&self) -> Result<String, Error>; | ||||
|     fn get_return_url(&self) -> Result<String, Error>; | ||||
| @ -72,7 +72,7 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re | ||||
|             .ok_or_else(missing_field_err("billing")) | ||||
|     } | ||||
|  | ||||
|     fn get_billing_country(&self) -> Result<api_models::enums::CountryCode, Error> { | ||||
|     fn get_billing_country(&self) -> Result<api_models::enums::CountryAlpha2, Error> { | ||||
|         self.address | ||||
|             .billing | ||||
|             .as_ref() | ||||
| @ -440,7 +440,7 @@ pub trait AddressDetailsData { | ||||
|     fn get_city(&self) -> Result<&String, Error>; | ||||
|     fn get_line2(&self) -> Result<&Secret<String>, Error>; | ||||
|     fn get_zip(&self) -> Result<&Secret<String>, Error>; | ||||
|     fn get_country(&self) -> Result<&api_models::enums::CountryCode, Error>; | ||||
|     fn get_country(&self) -> Result<&api_models::enums::CountryAlpha2, Error>; | ||||
|     fn get_combined_address_line(&self) -> Result<Secret<String>, Error>; | ||||
| } | ||||
|  | ||||
| @ -481,7 +481,7 @@ impl AddressDetailsData for api::AddressDetails { | ||||
|             .ok_or_else(missing_field_err("address.zip")) | ||||
|     } | ||||
|  | ||||
|     fn get_country(&self) -> Result<&api_models::enums::CountryCode, Error> { | ||||
|     fn get_country(&self) -> Result<&api_models::enums::CountryAlpha2, Error> { | ||||
|         self.country | ||||
|             .as_ref() | ||||
|             .ok_or_else(missing_field_err("address.country")) | ||||
|  | ||||
| @ -49,7 +49,7 @@ pub struct Order { | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct BillingAddress { | ||||
|     pub city: Option<String>, | ||||
|     pub country_code: Option<api_enums::CountryCode>, | ||||
|     pub country_code: Option<api_enums::CountryAlpha2>, | ||||
|     pub house_number: Option<String>, | ||||
|     pub state: Option<Secret<String>>, | ||||
|     pub state_code: Option<String>, | ||||
| @ -84,7 +84,7 @@ pub struct Name { | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct Shipping { | ||||
|     pub city: Option<String>, | ||||
|     pub country_code: Option<api_enums::CountryCode>, | ||||
|     pub country_code: Option<api_enums::CountryAlpha2>, | ||||
|     pub house_number: Option<String>, | ||||
|     pub name: Option<Name>, | ||||
|     pub state: Option<Secret<String>>, | ||||
|  | ||||
| @ -50,7 +50,7 @@ fn get_primary_business_details( | ||||
|             .to_owned() | ||||
|             .unwrap_or_else(|| { | ||||
|                 vec![PrimaryBusinessDetails { | ||||
|                     country: enums::CountryCode::US, | ||||
|                     country: enums::CountryAlpha2::US, | ||||
|                     business: "default".to_string(), | ||||
|                 }] | ||||
|             }) | ||||
| @ -328,7 +328,7 @@ async fn validate_merchant_id<S: Into<String>>( | ||||
| fn get_business_details_wrapper( | ||||
|     request: &api::MerchantConnectorCreate, | ||||
|     _merchant_account: &MerchantAccount, | ||||
| ) -> RouterResult<(enums::CountryCode, String)> { | ||||
| ) -> RouterResult<(enums::CountryAlpha2, String)> { | ||||
|     #[cfg(feature = "multiple_mca")] | ||||
|     { | ||||
|         // The fields are mandatory | ||||
|  | ||||
| @ -1163,7 +1163,7 @@ fn filter_pm_based_on_config<'a>( | ||||
|     connector: &'a str, | ||||
|     payment_method_type: &'a api_enums::PaymentMethodType, | ||||
|     card_network: &mut Option<Vec<api_enums::CardNetwork>>, | ||||
|     country: &Option<api_enums::CountryCode>, | ||||
|     country: &Option<api_enums::CountryAlpha2>, | ||||
|     currency: Option<api_enums::Currency>, | ||||
| ) -> bool { | ||||
|     config | ||||
| @ -1185,7 +1185,7 @@ fn filter_pm_based_on_config<'a>( | ||||
| } | ||||
|  | ||||
| fn card_network_filter( | ||||
|     country: &Option<api_enums::CountryCode>, | ||||
|     country: &Option<api_enums::CountryAlpha2>, | ||||
|     currency: Option<api_enums::Currency>, | ||||
|     card_network: &mut Option<Vec<api_enums::CardNetwork>>, | ||||
|     payment_method_filters: &settings::PaymentMethodFilters, | ||||
| @ -1209,7 +1209,7 @@ fn card_network_filter( | ||||
|  | ||||
| fn global_country_currency_filter( | ||||
|     item: &settings::CurrencyCountryFilter, | ||||
|     country: &Option<api_enums::CountryCode>, | ||||
|     country: &Option<api_enums::CountryAlpha2>, | ||||
|     currency: Option<api_enums::Currency>, | ||||
| ) -> bool { | ||||
|     let country_condition = item | ||||
| @ -1247,10 +1247,10 @@ fn filter_pm_card_network_based( | ||||
| } | ||||
| fn filter_pm_country_based( | ||||
|     accepted_countries: &Option<admin::AcceptedCountries>, | ||||
|     req_country_list: &Option<Vec<api_enums::CountryCode>>, | ||||
|     req_country_list: &Option<Vec<api_enums::CountryAlpha2>>, | ||||
| ) -> ( | ||||
|     Option<admin::AcceptedCountries>, | ||||
|     Option<Vec<api_enums::CountryCode>>, | ||||
|     Option<Vec<api_enums::CountryAlpha2>>, | ||||
|     bool, | ||||
| ) { | ||||
|     match (accepted_countries, req_country_list) { | ||||
|  | ||||
| @ -1273,7 +1273,7 @@ fn connector_needs_business_sub_label(connector_name: &str) -> bool { | ||||
| /// Create the connector label | ||||
| /// {connector_name}_{country}_{business_label} | ||||
| pub fn get_connector_label( | ||||
|     business_country: api_models::enums::CountryCode, | ||||
|     business_country: api_models::enums::CountryAlpha2, | ||||
|     business_label: &str, | ||||
|     business_sub_label: Option<&String>, | ||||
|     connector_name: &str, | ||||
| @ -1302,10 +1302,10 @@ pub fn get_connector_label( | ||||
| /// If there is more than one label or country configured in merchant account, then | ||||
| /// passing business details for payment is mandatory to avoid ambiguity | ||||
| pub fn get_business_details( | ||||
|     business_country: Option<api_enums::CountryCode>, | ||||
|     business_country: Option<api_enums::CountryAlpha2>, | ||||
|     business_label: Option<&String>, | ||||
|     merchant_account: &storage_models::merchant_account::MerchantAccount, | ||||
| ) -> RouterResult<(api_enums::CountryCode, String)> { | ||||
| ) -> RouterResult<(api_enums::CountryAlpha2, String)> { | ||||
|     let (business_country, business_label) = match business_country.zip(business_label) { | ||||
|         Some((business_country, business_label)) => { | ||||
|             (business_country.to_owned(), business_label.to_owned()) | ||||
|  | ||||
| @ -147,7 +147,7 @@ Never share your secret api keys. Keep them guarded and secure. | ||||
|         api_models::enums::CardNetwork, | ||||
|         api_models::enums::DisputeStage, | ||||
|         api_models::enums::DisputeStatus, | ||||
|         api_models::enums::CountryCode, | ||||
|         api_models::enums::CountryAlpha2, | ||||
|         api_models::admin::MerchantConnectorCreate, | ||||
|         api_models::admin::PaymentMethodsEnabled, | ||||
|         api_models::disputes::DisputeResponse, | ||||
|  | ||||
| @ -261,7 +261,7 @@ pub struct PaymentsCancelData { | ||||
| pub struct PaymentsSessionData { | ||||
|     pub amount: i64, | ||||
|     pub currency: storage_enums::Currency, | ||||
|     pub country: Option<api::enums::CountryCode>, | ||||
|     pub country: Option<api::enums::CountryAlpha2>, | ||||
|     pub order_details: Option<api_models::payments::OrderDetails>, | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Pa1NarK
					Pa1NarK