enhance(core): replace string with enum for country (#735)

This commit is contained in:
Narayan Bhat
2023-03-30 21:45:38 +05:30
committed by GitHub
parent 442bed0f6b
commit e18bfb2ae1
45 changed files with 734 additions and 649 deletions

View File

@ -59,7 +59,7 @@ pub struct ShopperName {
#[serde(rename_all = "camelCase")]
pub struct Address {
city: Option<String>,
country: Option<String>,
country: Option<api_enums::CountryCode>,
house_number_or_name: Option<Secret<String>>,
postal_code: Option<Secret<String>>,
state_or_province: Option<Secret<String>>,
@ -96,7 +96,7 @@ pub struct AdyenPaymentRequest<'a> {
telephone_number: Option<Secret<String>>,
billing_address: Option<Address>,
delivery_address: Option<Address>,
country_code: Option<String>,
country_code: Option<api_enums::CountryCode>,
line_items: Option<Vec<LineItem>>,
}
@ -496,7 +496,7 @@ fn get_address_info(address: Option<&api_models::payments::Address>) -> Option<A
address.and_then(|add| {
add.address.as_ref().map(|a| Address {
city: a.city.clone(),
country: a.country.clone(),
country: a.country,
house_number_or_name: a.line1.clone(),
postal_code: a.zip.clone(),
state_or_province: a.state.clone(),
@ -548,13 +548,11 @@ fn get_shopper_name(item: &types::PaymentsAuthorizeRouterData) -> Option<Shopper
})
}
fn get_country_code(item: &types::PaymentsAuthorizeRouterData) -> Option<String> {
let address = item
.address
fn get_country_code(item: &types::PaymentsAuthorizeRouterData) -> Option<api_enums::CountryCode> {
item.address
.billing
.as_ref()
.and_then(|billing| billing.address.as_ref());
address.and_then(|address| address.country.clone())
.and_then(|billing| billing.address.as_ref().and_then(|address| address.country))
}
fn get_payment_method_data<'a>(
@ -684,7 +682,7 @@ fn get_card_specific_payment_data<'a>(
fn get_sofort_extra_details(
item: &types::PaymentsAuthorizeRouterData,
) -> (Option<String>, Option<String>) {
) -> (Option<String>, Option<api_enums::CountryCode>) {
match item.request.payment_method_data {
api_models::payments::PaymentMethodData::BankRedirect(ref b) => {
if let api_models::payments::BankRedirectData::Sofort {
@ -694,7 +692,7 @@ fn get_sofort_extra_details(
{
(
Some(preferred_language.to_string()),
Some(country.to_string()),
Some(country.to_owned()),
)
} else {
(None, None)

View File

@ -64,7 +64,7 @@ pub struct SessionRequest {
#[serde(rename_all = "snake_case")]
pub struct PaymentRequest {
pub apple_pay_merchant_id: String,
pub country_code: String,
pub country_code: api_models::enums::CountryCode,
pub currency_code: String,
pub total: AmountInfo,
pub merchant_capabilities: Vec<String>,

View File

@ -8,7 +8,11 @@ use crate::{
consts,
core::errors,
pii::PeekInterface,
types::{self, api, storage::enums},
types::{
self,
api::{self, enums as api_enums},
storage::enums,
},
};
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
@ -76,7 +80,7 @@ pub struct BillTo {
locality: String,
administrative_area: Secret<String>,
postal_code: Secret<String>,
country: String,
country: api_enums::CountryCode,
email: Secret<String, pii::Email>,
phone_number: Secret<String>,
}

View File

@ -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: String,
pub country: api_models::enums::CountryCode,
/// The currency of the amount in ISO-4217(alpha-3)
pub currency: String,
pub currency_conversion: Option<CurrencyConversion>,

View File

@ -83,7 +83,7 @@ pub struct Address {
pub postal_code: Secret<String>,
pub city: String,
pub region: Option<Secret<String>>,
pub country: String,
pub country: api_models::enums::CountryCode,
}
impl TryFrom<&types::PaymentsAuthorizeRouterData> for MolliePaymentsRequest {

View File

@ -132,7 +132,7 @@ pub struct DeliveryObject {
house_number: Secret<String>,
zip_code: Secret<String>,
city: String,
country: String,
country: api_models::enums::CountryCode,
}
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]

View File

@ -129,7 +129,7 @@ pub enum AlternativePaymentMethodType {
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BillingAddress {
pub email: Secret<String, Email>,
pub country: String,
pub country: api_models::enums::CountryCode,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]

View File

@ -59,7 +59,7 @@ pub struct Address {
zip: Option<Secret<String>>,
state: Option<Secret<String>>,
city: Option<String>,
country: Option<String>,
country: Option<api_models::enums::CountryCode>,
}
#[derive(Default, Debug, Serialize, Eq, PartialEq)]
@ -172,7 +172,7 @@ fn get_address_details(address_details: Option<&payments::AddressDetails>) -> Op
zip: address.zip.clone(),
state: address.state.clone(),
city: address.city.clone(),
country: address.country.clone(),
country: address.country,
})
}

View File

@ -148,7 +148,7 @@ pub enum BankSpecificData {
#[serde(rename = "payment_method_options[sofort][preferred_language]")]
preferred_language: String,
#[serde(rename = "payment_method_data[sofort][country]")]
country: String,
country: api_enums::CountryCode,
},
}
@ -1080,7 +1080,7 @@ pub struct StripeShippingAddress {
#[serde(rename = "shipping[address][city]")]
pub city: Option<String>,
#[serde(rename = "shipping[address][country]")]
pub country: Option<String>,
pub country: Option<api_enums::CountryCode>,
#[serde(rename = "shipping[address][line1]")]
pub line1: Option<Secret<String>>,
#[serde(rename = "shipping[address][line2]")]
@ -1100,7 +1100,7 @@ pub struct StripeBillingAddress {
#[serde(rename = "payment_method_data[billing_details][email]")]
pub email: Option<Secret<String, Email>>,
#[serde(rename = "payment_method_data[billing_details][address][country]")]
pub country: Option<String>,
pub country: Option<api_enums::CountryCode>,
#[serde(rename = "payment_method_data[billing_details][name]")]
pub name: Option<Secret<String>>,
}

View File

@ -120,7 +120,7 @@ pub struct PaymentRequestCards {
#[serde(rename = "billing[city]")]
pub billing_city: String,
#[serde(rename = "billing[country]")]
pub billing_country: String,
pub billing_country: api_models::enums::CountryCode,
#[serde(rename = "billing[street1]")]
pub billing_street1: Secret<String>,
#[serde(rename = "billing[postcode]")]
@ -174,7 +174,7 @@ pub enum TrustpayPaymentsRequest {
#[derive(Debug, Serialize, Eq, PartialEq)]
pub struct TrustpayMandatoryParams {
pub billing_city: String,
pub billing_country: String,
pub billing_country: api_models::enums::CountryCode,
pub billing_street1: Secret<String>,
pub billing_postcode: Secret<String>,
}

View File

@ -47,7 +47,7 @@ impl AccessTokenRequestInfo for types::RefreshTokenRouterData {
pub trait RouterData {
fn get_billing(&self) -> Result<&api::Address, Error>;
fn get_billing_country(&self) -> Result<String, Error>;
fn get_billing_country(&self) -> Result<api_models::enums::CountryCode, Error>;
fn get_billing_phone(&self) -> Result<&api::PhoneDetails, Error>;
fn get_description(&self) -> Result<String, Error>;
fn get_billing_address(&self) -> Result<&api::AddressDetails, Error>;
@ -69,12 +69,12 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
.ok_or_else(missing_field_err("billing"))
}
fn get_billing_country(&self) -> Result<String, Error> {
fn get_billing_country(&self) -> Result<api_models::enums::CountryCode, Error> {
self.address
.billing
.as_ref()
.and_then(|a| a.address.as_ref())
.and_then(|ad| ad.country.clone())
.and_then(|ad| ad.country)
.ok_or_else(missing_field_err("billing.address.country"))
}
@ -314,7 +314,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<&String, Error>;
fn get_country(&self) -> Result<&api_models::enums::CountryCode, Error>;
fn get_combined_address_line(&self) -> Result<Secret<String>, Error>;
}
@ -355,7 +355,7 @@ impl AddressDetailsData for api::AddressDetails {
.ok_or_else(missing_field_err("address.zip"))
}
fn get_country(&self) -> Result<&String, Error> {
fn get_country(&self) -> Result<&api_models::enums::CountryCode, Error> {
self.country
.as_ref()
.ok_or_else(missing_field_err("address.country"))

View File

@ -49,7 +49,7 @@ pub struct Order {
#[serde(rename_all = "camelCase")]
pub struct BillingAddress {
pub city: Option<String>,
pub country_code: Option<String>,
pub country_code: Option<api_enums::CountryCode>,
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<String>,
pub country_code: Option<api_enums::CountryCode>,
pub house_number: Option<String>,
pub name: Option<Name>,
pub state: Option<Secret<String>>,