mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-11 18:59:20 +08:00
refactor: use CountryAlpha2 instead of CountryCode for country codes (#904)
This commit is contained in:
@@ -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>>,
|
||||
|
||||
Reference in New Issue
Block a user