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

@ -14,6 +14,7 @@ encrypter = "encrypter" # Used by the `ring` crate
nin = "nin" # National identification number, a field used by PayU connector
substituters = "substituters" # Present in `flake.nix`
FO = "FO" # Faroe Islands (the) country code
BA = "BA" # Bosnia and Herzegovina country code
[files]
extend-exclude = [

110
Cargo.lock generated
View File

@ -104,7 +104,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
dependencies = [
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -239,7 +239,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -250,7 +250,7 @@ checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -326,6 +326,7 @@ name = "api_models"
version = "0.1.0"
dependencies = [
"actix-web",
"common_enums",
"common_utils",
"error-stack",
"frunk",
@ -460,7 +461,7 @@ checksum = "e4655ae1a7b0cdf149156f780c5bf3f1352bc53cbd9e0a361a7ef7b22947e965"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -471,7 +472,7 @@ checksum = "b84f9ebcc6c1f5b8cb160f6990096a5c127f423fcb6e1ccc46c370cbdfb75dfc"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1117,7 +1118,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1139,6 +1140,17 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "common_enums"
version = "0.1.0"
dependencies = [
"diesel",
"router_derive",
"serde",
"strum",
"utoipa",
]
[[package]]
name = "common_utils"
version = "0.1.0"
@ -1331,7 +1343,7 @@ dependencies = [
"proc-macro2",
"quote",
"scratch",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1348,7 +1360,7 @@ checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1372,7 +1384,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1383,7 +1395,7 @@ checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
dependencies = [
"darling_core",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1426,7 +1438,7 @@ checksum = "dcdbcee2d9941369faba772587a565f4f534e42cb8d17e5295871de730163b2b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1439,7 +1451,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc_version",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1467,7 +1479,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1759,7 +1771,7 @@ checksum = "b83164912bb4c97cfe0772913c7af7387ee2e00cb6d4636fb65a35b3d0c8f173"
dependencies = [
"frunk_proc_macro_helpers",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1771,7 +1783,7 @@ dependencies = [
"frunk_core",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1795,7 +1807,7 @@ dependencies = [
"frunk_proc_macro_helpers",
"proc-macro-hack",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1869,7 +1881,7 @@ checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -2507,7 +2519,7 @@ dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -2732,7 +2744,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -2967,7 +2979,7 @@ dependencies = [
"pest_meta",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -2998,7 +3010,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -3069,7 +3081,7 @@ dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
"version_check",
]
@ -3140,7 +3152,7 @@ dependencies = [
"itertools",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -3184,9 +3196,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]]
name = "quote"
version = "1.0.24"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50686e0021c4136d1d453b2dfe059902278681512a34d4248435dc34b6b5c8ec"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
dependencies = [
"proc-macro2",
]
@ -3520,7 +3532,7 @@ dependencies = [
"serde",
"serde_json",
"strum",
"syn",
"syn 1.0.109",
]
[[package]]
@ -3569,7 +3581,7 @@ dependencies = [
"quote",
"rust-embed-utils",
"shellexpand",
"syn",
"syn 1.0.109",
"walkdir",
]
@ -3777,7 +3789,7 @@ checksum = "d071a94a3fac4aff69d023a7f411e33f40f3483f8c5190b1953822b6b76d7630"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -3869,7 +3881,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -3894,7 +3906,7 @@ checksum = "079a83df15f85d89a68d64ae1238f142f172b1fa915d0d76b26a7cba1b659a69"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -4045,6 +4057,7 @@ version = "0.1.0"
dependencies = [
"async-bb8-diesel",
"async-trait",
"common_enums",
"common_utils",
"diesel",
"error-stack",
@ -4086,7 +4099,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
"syn",
"syn 1.0.109",
]
[[package]]
@ -4106,6 +4119,17 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21e3787bb71465627110e7d87ed4faaa36c1f61042ee67badb9e2ef173accc40"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "0.1.2"
@ -4157,7 +4181,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -4250,7 +4274,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -4466,7 +4490,7 @@ checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -4637,9 +4661,9 @@ checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9"
[[package]]
name = "utoipa"
version = "3.1.0"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9376d225846fe53ab3425916eba3736936f19bdd5dbfe46604e9cc6a28ed411"
checksum = "6f6ec551be59b8d61831b9bde585b85fced81eb3771afa60ccd920d1c1cc8b6d"
dependencies = [
"indexmap",
"serde",
@ -4649,21 +4673,21 @@ dependencies = [
[[package]]
name = "utoipa-gen"
version = "3.1.0"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d050a2b5851b1d1aaa976854af782491298052e29fdfe47ca37872e2b3aa99"
checksum = "81d51d7de9f57fc943abe9a3ceeea62835341186b3c12a05617c155df1824e2b"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
"syn 2.0.11",
]
[[package]]
name = "utoipa-swagger-ui"
version = "3.1.0"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c745a5ecb9f3b1b30780e45cc4ad77b3bdd76501319570046e4db7318e3c4381"
checksum = "643f0dd2d71b127043054bcf097b92788bf6567168b39cbab803120439b45a9b"
dependencies = [
"actix-web",
"mime_guess",
@ -4797,7 +4821,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
"wasm-bindgen-shared",
]
@ -4831,7 +4855,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View File

@ -22,9 +22,10 @@ serde_json = "1.0.94"
strum = { version = "0.24.1", features = ["derive"] }
time = { version = "0.3.20", features = ["serde", "serde-well-known", "std"] }
url = { version = "2.3.1", features = ["serde"] }
utoipa = { version = "3.1.0", features = ["preserve_order"] }
utoipa = { version = "3.2.0", features = ["preserve_order"] }
# First party crates
common_utils = { version = "0.1.0", path = "../common_utils" }
masking = { version = "0.1.0", path = "../masking" }
router_derive = { version = "0.1.0", path = "../router_derive" }
common_enums = {path = "../common_enums"}

View File

@ -381,8 +381,8 @@ pub enum AcceptedCurrencies {
rename_all = "snake_case"
)]
pub enum AcceptedCountries {
EnableOnly(Vec<String>),
DisableOnly(Vec<String>),
EnableOnly(Vec<api_enums::CountryCode>),
DisableOnly(Vec<api_enums::CountryCode>),
AllAccepted,
}
@ -428,7 +428,7 @@ pub struct MerchantConnectorDetailsWrap {
},
"metadata": {
"user_defined_field_1": "sample_1",
"user_defined_field_2": "sample_2",
"user_defined_field_2": "sample_2",
},
}"#)]
pub encoded_data: Option<Secret<String>>,

View File

@ -1,3 +1,4 @@
pub use common_enums::*;
use utoipa::ToSchema;
#[derive(

View File

@ -283,8 +283,8 @@ pub struct PaymentMethodListRequest {
pub client_secret: Option<String>,
/// The two-letter ISO currency code
#[schema(example = json!(["US", "UK", "IN"]))]
pub accepted_countries: Option<Vec<String>>,
#[schema(value_type = Option<Vec<Country>>, example = json!(["US", "UK", "IN"]))]
pub accepted_countries: Option<Vec<api_enums::CountryCode>>,
/// The three-letter ISO currency code
#[schema(value_type = Option<Vec<Currency>>,example = json!(["USD", "EUR"]))]

View File

@ -413,7 +413,8 @@ pub enum PayLaterData {
#[schema(value_type = String)]
billing_email: Secret<String, pii::Email>,
// The billing country code
billing_country: String,
#[schema(value_type = Country)]
billing_country: api_enums::CountryCode,
},
/// For Klarna Sdk as PayLater Option
KlarnaSdk {
@ -506,8 +507,8 @@ pub enum BankRedirectData {
},
Sofort {
/// The country for bank payment
#[schema(example = "US")]
country: String,
#[schema(value_type = Country, example = "US")]
country: api_enums::CountryCode,
/// The preferred language
#[schema(example = "en")]
@ -675,8 +676,8 @@ pub struct AddressDetails {
pub city: Option<String>,
/// The two-letter ISO country code for the address
#[schema(max_length = 2, min_length = 2, example = "US")]
pub country: Option<String>,
#[schema(value_type = Option<Country>, max_length = 2, min_length = 2, example = "US")]
pub country: Option<api_enums::CountryCode>,
/// The first line of the address
#[schema(value_type = Option<String>, max_length = 200, example = "123, King Street")]
@ -1242,7 +1243,8 @@ pub struct GpayAllowedPaymentMethods {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct GpayTransactionInfo {
/// The country code
pub country_code: String,
#[schema(value_type = Country)]
pub country_code: api_enums::CountryCode,
/// The currency code
pub currency_code: String,
/// The total price status (ex: 'FINAL')
@ -1348,7 +1350,8 @@ pub struct ApplePaySessionResponse {
#[derive(Debug, Clone, serde::Serialize, ToSchema, serde::Deserialize)]
pub struct ApplePayPaymentRequest {
/// The code for country
pub country_code: String,
#[schema(value_type = Country)]
pub country_code: api_enums::CountryCode,
/// The code for currency
pub currency_code: String,
/// Represents the total for the payment.

View File

@ -0,0 +1,15 @@
[package]
name = "common_enums"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0.155", features = [ "derive" ] }
strum = { version = "0.24.1", features = [ "derive" ] }
utoipa = { version = "3.2.0", features = ["preserve_order"] }
diesel = { version = "2.0.3", features = ["postgres"] }
# First party crates
router_derive = { version = "0.1.0", path = "../router_derive" }

View File

@ -0,0 +1,39 @@
use router_derive;
#[derive(
Clone,
Debug,
Eq,
Default,
Hash,
PartialEq,
serde::Deserialize,
serde::Serialize,
strum::Display,
strum::EnumString,
utoipa::ToSchema,
Copy
)]
#[router_derive::diesel_enum(storage_type = "pg_enum")]
#[rustfmt::skip]
pub enum CountryCode {
AF, AX, AL, DZ, AS, AD, AO, AI, AQ, AG, AR, AM, AW, AU, AT,
AZ, BS, BH, BD, BB, BY, BE, BZ, BJ, BM, BT, BO, BQ, BA, BW,
BV, BR, IO, BN, BG, BF, BI, KH, CM, CA, CV, KY, CF, TD, CL,
CN, CX, CC, CO, KM, CG, CD, CK, CR, CI, HR, CU, CW, CY, CZ,
DK, DJ, DM, DO, EC, EG, SV, GQ, ER, EE, ET, FK, FO, FJ, FI,
FR, GF, PF, TF, GA, GM, GE, DE, GH, GI, GR, GL, GD, GP, GU,
GT, GG, GN, GW, GY, HT, HM, VA, HN, HK, HU, IS, IN, ID, IR,
IQ, IE, IM, IL, IT, JM, JP, JE, JO, KZ, KE, KI, KP, KR, KW,
KG, LA, LV, LB, LS, LR, LY, LI, LT, LU, MO, MK, MG, MW, MY,
MV, ML, MT, MH, MQ, MR, MU, YT, MX, FM, MD, MC, MN, ME, MS,
MA, MZ, MM, NA, NR, NP, NL, NC, NZ, NI, NE, NG, NU, NF, MP,
NO, OM, PK, PW, PS, PA, PG, PY, PE, PH, PN, PL, PT, PR, QA,
RE, RO, RU, RW, BL, SH, KN, LC, MF, PM, VC, WS, SM, ST, SA,
SN, RS, SC, SL, SG, SX, SK, SI, SB, SO, ZA, GS, SS, ES, LK,
SD, SR, SJ, SZ, SE, CH, SY, TW, TJ, TZ, TH, TL, TG, TK, TO,
TT, TN, TR, TM, TC, TV, UG, UA, AE, GB, UM, UY, UZ, VU,
VE, VN, VG, VI, WF, EH, YE, ZM, ZW,
#[default]
US
}

View File

@ -0,0 +1,2 @@
pub mod enums;
pub use enums::*;

View File

@ -74,8 +74,8 @@ thiserror = "1.0.39"
time = { version = "0.3.20", features = ["serde", "serde-well-known", "std"] }
tokio = { version = "1.26.0", features = ["macros", "rt-multi-thread"] }
url = { version = "2.3.1", features = ["serde"] }
utoipa = { version = "3.1.0", features = ["preserve_order", "time"] }
utoipa-swagger-ui = { version = "3.1.0", features = ["actix-web"] }
utoipa = { version = "3.2.0", features = ["preserve_order", "time"] }
utoipa-swagger-ui = { version = "3.1.1", features = ["actix-web"] }
uuid = { version = "1.3.0", features = ["serde", "v4"] }
# First party crates

View File

@ -27,7 +27,9 @@ impl From<StripeBillingDetails> for payments::Address {
Self {
phone: Some(payments::PhoneDetails {
number: details.phone,
country_code: details.address.as_ref().and_then(|a| a.country.clone()),
country_code: details.address.as_ref().and_then(|address| {
address.country.as_ref().map(|country| country.to_string())
}),
}),
address: details.address,
@ -109,7 +111,9 @@ impl From<Shipping> for payments::Address {
Self {
phone: Some(payments::PhoneDetails {
number: details.phone,
country_code: details.address.as_ref().and_then(|a| a.country.clone()),
country_code: details.address.as_ref().and_then(|address| {
address.country.as_ref().map(|country| country.to_string())
}),
}),
address: details.address,
}

View File

@ -98,10 +98,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<String>>,
pub country: Option<HashSet<api_models::enums::CountryCode>>,
}
fn string_set_deser<'a, D>(deserializer: D) -> Result<Option<HashSet<String>>, D::Error>
fn string_set_deser<'a, D>(
deserializer: D,
) -> Result<Option<HashSet<api_models::enums::CountryCode>>, D::Error>
where
D: Deserializer<'a>,
{
@ -110,7 +112,7 @@ where
let list = inner
.trim()
.split(',')
.map(|value| value.to_string())
.flat_map(api_models::enums::CountryCode::from_str)
.collect::<HashSet<_>>();
match list.len() {
0 => None,

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>>,

View File

@ -170,7 +170,7 @@ pub async fn delete_customer(
let update_address = storage::AddressUpdate::Update {
city: Some(REDACTED.to_string()),
country: Some(REDACTED.to_string()),
country: None,
line1: Some(REDACTED.to_string().into()),
line2: Some(REDACTED.to_string().into()),
line3: Some(REDACTED.to_string().into()),

View File

@ -1120,7 +1120,7 @@ async fn filter_payment_methods(
&connector,
&payment_method_object.payment_method_type,
&mut payment_method_object.card_networks,
&address.and_then(|inner| inner.country.clone()),
&address.and_then(|inner| inner.country),
payment_attempt
.and_then(|value| value.currency)
.map(|value| value.foreign_into()),
@ -1149,7 +1149,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<String>,
country: &Option<api_enums::CountryCode>,
currency: Option<api_enums::Currency>,
) -> bool {
config
@ -1171,7 +1171,7 @@ fn filter_pm_based_on_config<'a>(
}
fn card_network_filter(
country: &Option<String>,
country: &Option<api_enums::CountryCode>,
currency: Option<api_enums::Currency>,
card_network: &mut Option<Vec<api_enums::CardNetwork>>,
payment_method_filters: &settings::PaymentMethodFilters,
@ -1195,7 +1195,7 @@ fn card_network_filter(
fn global_country_currency_filter(
item: &settings::CurrencyCountryFilter,
country: &Option<String>,
country: &Option<api_enums::CountryCode>,
currency: Option<api_enums::Currency>,
) -> bool {
let country_condition = item
@ -1233,8 +1233,12 @@ fn filter_pm_card_network_based(
}
fn filter_pm_country_based(
accepted_countries: &Option<admin::AcceptedCountries>,
req_country_list: &Option<Vec<String>>,
) -> (Option<admin::AcceptedCountries>, Option<Vec<String>>, bool) {
req_country_list: &Option<Vec<api_enums::CountryCode>>,
) -> (
Option<admin::AcceptedCountries>,
Option<Vec<api_enums::CountryCode>>,
bool,
) {
match (accepted_countries, req_country_list) {
(None, None) => (None, None, true),
(None, Some(ref r)) => (

View File

@ -92,7 +92,7 @@ fn create_gpay_session_token(
let session_data = router_data.request.clone();
let transaction_info = payment_types::GpayTransactionInfo {
country_code: session_data.country.unwrap_or_else(|| "US".to_string()),
country_code: session_data.country.unwrap_or_default(),
currency_code: router_data.request.currency.to_string(),
total_price_status: "Final".to_string(),
total_price: router_data.request.amount,

View File

@ -561,11 +561,9 @@ impl<F: Clone> TryFrom<PaymentData<F>> for types::PaymentsSessionData {
Ok(Self {
amount: payment_data.amount.into(),
currency: payment_data.currency,
country: payment_data
.address
.billing
.and_then(|billing_address| billing_address.address.map(|address| address.country))
.flatten(),
country: payment_data.address.billing.and_then(|billing_address| {
billing_address.address.and_then(|address| address.country)
}),
order_details,
})
}

View File

@ -143,6 +143,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::enums::PaymentExperience,
api_models::enums::BankNames,
api_models::enums::CardNetwork,
api_models::enums::CountryCode,
api_models::admin::MerchantConnector,
api_models::admin::PaymentMethodsEnabled,
api_models::payments::AddressDetails,

View File

@ -205,7 +205,7 @@ pub struct PaymentsCancelData {
pub struct PaymentsSessionData {
pub amount: i64,
pub currency: storage_enums::Currency,
pub country: Option<String>,
pub country: Option<api::enums::CountryCode>,
pub order_details: Option<api_models::payments::OrderDetails>,
}

View File

@ -262,6 +262,7 @@ impl ForeignFrom<api_enums::Currency> for storage_enums::Currency {
frunk::labelled_convert_from(currency)
}
}
impl ForeignFrom<storage_enums::Currency> for api_enums::Currency {
fn foreign_from(currency: storage_enums::Currency) -> Self {
frunk::labelled_convert_from(currency)
@ -273,7 +274,7 @@ impl<'a> ForeignFrom<&'a api_types::Address> for storage::AddressUpdate {
let address = address;
Self::Update {
city: address.address.as_ref().and_then(|a| a.city.clone()),
country: address.address.as_ref().and_then(|a| a.country.clone()),
country: address.address.as_ref().and_then(|a| a.country),
line1: address.address.as_ref().and_then(|a| a.line1.clone()),
line2: address.address.as_ref().and_then(|a| a.line2.clone()),
line3: address.address.as_ref().and_then(|a| a.line3.clone()),
@ -312,7 +313,7 @@ impl<'a> ForeignFrom<&'a storage::Address> for api_types::Address {
Self {
address: Some(api_types::AddressDetails {
city: address.city.clone(),
country: address.country.clone(),
country: address.country,
line1: address.line1.clone(),
line2: address.line2.clone(),
line3: address.line3.clone(),

View File

@ -39,7 +39,7 @@ impl AdyenTest {
address: Some(PaymentAddress {
billing: Some(Address {
address: Some(AddressDetails {
country: Some("US".to_string()),
country: Some(api_models::enums::CountryCode::US),
..Default::default()
}),
phone: None,

View File

@ -42,7 +42,7 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
line2: Some(Secret::new("line2".to_string())),
city: Some("city".to_string()),
zip: Some(Secret::new("zip".to_string())),
country: Some("IN".to_string()),
country: Some(api_models::enums::CountryCode::IN),
..Default::default()
}),
phone: Some(api::PhoneDetails {

View File

@ -443,7 +443,7 @@ pub fn get_payment_info() -> PaymentInfo {
phone: None,
address: Some(api::AddressDetails {
city: None,
country: Some("PA".to_string()),
country: Some(api_models::enums::CountryCode::PA),
line1: None,
line2: None,
line3: None,

View File

@ -41,7 +41,7 @@ fn get_default_payment_info() -> Option<PaymentInfo> {
address: Some(types::PaymentAddress {
billing: Some(api::Address {
address: Some(api::AddressDetails {
country: Some("US".to_string()),
country: Some(api_models::enums::CountryCode::US),
..Default::default()
}),
phone: None,

View File

@ -71,7 +71,7 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
line2: Some(Secret::new("line2".to_string())),
city: Some("city".to_string()),
zip: Some(Secret::new("zip".to_string())),
country: Some("IN".to_string()),
country: Some(api_models::enums::CountryCode::IN),
..Default::default()
}),
phone: None,

View File

@ -42,7 +42,7 @@ impl WorldlineTest {
address: Some(PaymentAddress {
billing: Some(Address {
address: Some(AddressDetails {
country: Some("US".to_string()),
country: Some(api_models::enums::CountryCode::US),
..Default::default()
}),
phone: None,

View File

@ -25,6 +25,7 @@ time = { version = "0.3.20", features = ["serde", "serde-well-known", "std"] }
# First party crates
common_utils = { version = "0.1.0", path = "../common_utils" }
common_enums = {path = "../common_enums"}
masking = { version = "0.1.0", path = "../masking" }
router_derive = { version = "0.1.0", path = "../router_derive" }
router_env = { version = "0.1.0", path = "../router_env", features = ["log_extra_implicit_fields", "log_custom_entries_to_extra"] }

View File

@ -4,7 +4,7 @@ use masking::Secret;
use serde::{Deserialize, Serialize};
use time::{OffsetDateTime, PrimitiveDateTime};
use crate::schema::address;
use crate::{enums, schema::address};
#[derive(Clone, Debug, Deserialize, Serialize, Insertable, router_derive::DebugAsDisplay)]
#[diesel(table_name = address)]
@ -12,7 +12,7 @@ use crate::schema::address;
pub struct AddressNew {
pub address_id: String,
pub city: Option<String>,
pub country: Option<String>,
pub country: Option<enums::CountryCode>,
pub line1: Option<Secret<String>>,
pub line2: Option<Secret<String>>,
pub line3: Option<Secret<String>>,
@ -34,7 +34,7 @@ pub struct Address {
#[serde(skip_serializing)]
pub address_id: String,
pub city: Option<String>,
pub country: Option<String>,
pub country: Option<enums::CountryCode>,
pub line1: Option<Secret<String>>,
pub line2: Option<Secret<String>>,
pub line3: Option<Secret<String>>,
@ -58,7 +58,7 @@ pub struct Address {
pub enum AddressUpdate {
Update {
city: Option<String>,
country: Option<String>,
country: Option<enums::CountryCode>,
line1: Option<Secret<String>>,
line2: Option<Secret<String>>,
line3: Option<Secret<String>>,
@ -75,7 +75,7 @@ pub enum AddressUpdate {
#[diesel(table_name = address)]
pub struct AddressUpdateInternal {
city: Option<String>,
country: Option<String>,
country: Option<enums::CountryCode>,
line1: Option<Secret<String>>,
line2: Option<Secret<String>>,
line3: Option<Secret<String>>,

View File

@ -2,9 +2,10 @@
pub mod diesel_exports {
pub use super::{
DbAttemptStatus as AttemptStatus, DbAuthenticationType as AuthenticationType,
DbCaptureMethod as CaptureMethod, DbConnectorType as ConnectorType, DbCurrency as Currency,
DbDisputeStage as DisputeStage, DbDisputeStatus as DisputeStatus,
DbEventClass as EventClass, DbEventObjectType as EventObjectType, DbEventType as EventType,
DbCaptureMethod as CaptureMethod, DbConnectorType as ConnectorType,
DbCountryCode as CountryCode, DbCurrency as Currency, DbDisputeStage as DisputeStage,
DbDisputeStatus as DisputeStatus, DbEventClass as EventClass,
DbEventObjectType as EventObjectType, DbEventType as EventType,
DbFutureUsage as FutureUsage, DbIntentStatus as IntentStatus,
DbMandateStatus as MandateStatus, DbMandateType as MandateType,
DbMerchantStorageScheme as MerchantStorageScheme,
@ -14,6 +15,8 @@ pub mod diesel_exports {
};
}
pub use common_enums::*;
#[derive(
Clone,
Copy,

View File

@ -8,7 +8,7 @@ diesel::table! {
id -> Int4,
address_id -> Varchar,
city -> Nullable<Varchar>,
country -> Nullable<Varchar>,
country -> Nullable<CountryCode>,
line1 -> Nullable<Varchar>,
line2 -> Nullable<Varchar>,
line3 -> Nullable<Varchar>,

View File

@ -0,0 +1,4 @@
ALTER TABLE address
ALTER COLUMN country TYPE VARCHAR(255);
DROP TYPE IF EXISTS "CountryCode";

View File

@ -0,0 +1,254 @@
CREATE TYPE "CountryCode" AS ENUM (
'AF',
'AX',
'AL',
'DZ',
'AS',
'AD',
'AO',
'AI',
'AQ',
'AG',
'AR',
'AM',
'AW',
'AU',
'AT',
'AZ',
'BS',
'BH',
'BD',
'BB',
'BY',
'BE',
'BZ',
'BJ',
'BM',
'BT',
'BO',
'BQ',
'BA',
'BW',
'BV',
'BR',
'IO',
'BN',
'BG',
'BF',
'BI',
'KH',
'CM',
'CA',
'CV',
'KY',
'CF',
'TD',
'CL',
'CN',
'CX',
'CC',
'CO',
'KM',
'CG',
'CD',
'CK',
'CR',
'CI',
'HR',
'CU',
'CW',
'CY',
'CZ',
'DK',
'DJ',
'DM',
'DO',
'EC',
'EG',
'SV',
'GQ',
'ER',
'EE',
'ET',
'FK',
'FO',
'FJ',
'FI',
'FR',
'GF',
'PF',
'TF',
'GA',
'GM',
'GE',
'DE',
'GH',
'GI',
'GR',
'GL',
'GD',
'GP',
'GU',
'GT',
'GG',
'GN',
'GW',
'GY',
'HT',
'HM',
'VA',
'HN',
'HK',
'HU',
'IS',
'IN',
'ID',
'IR',
'IQ',
'IE',
'IM',
'IL',
'IT',
'JM',
'JP',
'JE',
'JO',
'KZ',
'KE',
'KI',
'KP',
'KR',
'KW',
'KG',
'LA',
'LV',
'LB',
'LS',
'LR',
'LY',
'LI',
'LT',
'LU',
'MO',
'MK',
'MG',
'MW',
'MY',
'MV',
'ML',
'MT',
'MH',
'MQ',
'MR',
'MU',
'YT',
'MX',
'FM',
'MD',
'MC',
'MN',
'ME',
'MS',
'MA',
'MZ',
'MM',
'NA',
'NR',
'NP',
'NL',
'NC',
'NZ',
'NI',
'NE',
'NG',
'NU',
'NF',
'MP',
'NO',
'OM',
'PK',
'PW',
'PS',
'PA',
'PG',
'PY',
'PE',
'PH',
'PN',
'PL',
'PT',
'PR',
'QA',
'RE',
'RO',
'RU',
'RW',
'BL',
'SH',
'KN',
'LC',
'MF',
'PM',
'VC',
'WS',
'SM',
'ST',
'SA',
'SN',
'RS',
'SC',
'SL',
'SG',
'SX',
'SK',
'SI',
'SB',
'SO',
'ZA',
'GS',
'SS',
'ES',
'LK',
'SD',
'SR',
'SJ',
'SZ',
'SE',
'CH',
'SY',
'TW',
'TJ',
'TZ',
'TH',
'TL',
'TG',
'TK',
'TO',
'TT',
'TN',
'TR',
'TM',
'TC',
'TV',
'UG',
'UA',
'AE',
'GB',
'US',
'UM',
'UY',
'UZ',
'VU',
'VE',
'VN',
'VG',
'VI',
'WF',
'EH',
'YE',
'ZM',
'ZW'
);
ALTER TABLE address
ALTER COLUMN country TYPE "CountryCode" USING country::"CountryCode";

File diff suppressed because it is too large Load Diff