mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
refactor(settings): make the function to deserialize hashsets more generic (#3104)
This commit is contained in:
@ -391,12 +391,15 @@ pub enum Currency {
|
||||
ALL,
|
||||
AMD,
|
||||
ANG,
|
||||
AOA,
|
||||
ARS,
|
||||
AUD,
|
||||
AWG,
|
||||
AZN,
|
||||
BAM,
|
||||
BBD,
|
||||
BDT,
|
||||
BGN,
|
||||
BHD,
|
||||
BIF,
|
||||
BMD,
|
||||
@ -405,6 +408,7 @@ pub enum Currency {
|
||||
BRL,
|
||||
BSD,
|
||||
BWP,
|
||||
BYN,
|
||||
BZD,
|
||||
CAD,
|
||||
CHF,
|
||||
@ -413,6 +417,7 @@ pub enum Currency {
|
||||
COP,
|
||||
CRC,
|
||||
CUP,
|
||||
CVE,
|
||||
CZK,
|
||||
DJF,
|
||||
DKK,
|
||||
@ -422,7 +427,9 @@ pub enum Currency {
|
||||
ETB,
|
||||
EUR,
|
||||
FJD,
|
||||
FKP,
|
||||
GBP,
|
||||
GEL,
|
||||
GHS,
|
||||
GIP,
|
||||
GMD,
|
||||
@ -437,6 +444,7 @@ pub enum Currency {
|
||||
IDR,
|
||||
ILS,
|
||||
INR,
|
||||
IQD,
|
||||
JMD,
|
||||
JOD,
|
||||
JPY,
|
||||
@ -453,6 +461,7 @@ pub enum Currency {
|
||||
LKR,
|
||||
LRD,
|
||||
LSL,
|
||||
LYD,
|
||||
MAD,
|
||||
MDL,
|
||||
MGA,
|
||||
@ -460,11 +469,13 @@ pub enum Currency {
|
||||
MMK,
|
||||
MNT,
|
||||
MOP,
|
||||
MRU,
|
||||
MUR,
|
||||
MVR,
|
||||
MWK,
|
||||
MXN,
|
||||
MYR,
|
||||
MZN,
|
||||
NAD,
|
||||
NGN,
|
||||
NIO,
|
||||
@ -472,6 +483,7 @@ pub enum Currency {
|
||||
NPR,
|
||||
NZD,
|
||||
OMR,
|
||||
PAB,
|
||||
PEN,
|
||||
PGK,
|
||||
PHP,
|
||||
@ -480,34 +492,47 @@ pub enum Currency {
|
||||
PYG,
|
||||
QAR,
|
||||
RON,
|
||||
RSD,
|
||||
RUB,
|
||||
RWF,
|
||||
SAR,
|
||||
SBD,
|
||||
SCR,
|
||||
SEK,
|
||||
SGD,
|
||||
SHP,
|
||||
SLE,
|
||||
SLL,
|
||||
SOS,
|
||||
SRD,
|
||||
SSP,
|
||||
STN,
|
||||
SVC,
|
||||
SZL,
|
||||
THB,
|
||||
TND,
|
||||
TOP,
|
||||
TRY,
|
||||
TTD,
|
||||
TWD,
|
||||
TZS,
|
||||
UAH,
|
||||
UGX,
|
||||
#[default]
|
||||
USD,
|
||||
UYU,
|
||||
UZS,
|
||||
VES,
|
||||
VND,
|
||||
VUV,
|
||||
WST,
|
||||
XAF,
|
||||
XCD,
|
||||
XOF,
|
||||
XPF,
|
||||
YER,
|
||||
ZAR,
|
||||
ZMW,
|
||||
}
|
||||
|
||||
impl Currency {
|
||||
@ -564,12 +589,15 @@ impl Currency {
|
||||
Self::ALL => "008",
|
||||
Self::AMD => "051",
|
||||
Self::ANG => "532",
|
||||
Self::AOA => "973",
|
||||
Self::ARS => "032",
|
||||
Self::AUD => "036",
|
||||
Self::AWG => "533",
|
||||
Self::AZN => "944",
|
||||
Self::BAM => "977",
|
||||
Self::BBD => "052",
|
||||
Self::BDT => "050",
|
||||
Self::BGN => "975",
|
||||
Self::BHD => "048",
|
||||
Self::BIF => "108",
|
||||
Self::BMD => "060",
|
||||
@ -578,6 +606,7 @@ impl Currency {
|
||||
Self::BRL => "986",
|
||||
Self::BSD => "044",
|
||||
Self::BWP => "072",
|
||||
Self::BYN => "933",
|
||||
Self::BZD => "084",
|
||||
Self::CAD => "124",
|
||||
Self::CHF => "756",
|
||||
@ -585,6 +614,7 @@ impl Currency {
|
||||
Self::COP => "170",
|
||||
Self::CRC => "188",
|
||||
Self::CUP => "192",
|
||||
Self::CVE => "132",
|
||||
Self::CZK => "203",
|
||||
Self::DJF => "262",
|
||||
Self::DKK => "208",
|
||||
@ -594,7 +624,9 @@ impl Currency {
|
||||
Self::ETB => "230",
|
||||
Self::EUR => "978",
|
||||
Self::FJD => "242",
|
||||
Self::FKP => "238",
|
||||
Self::GBP => "826",
|
||||
Self::GEL => "981",
|
||||
Self::GHS => "936",
|
||||
Self::GIP => "292",
|
||||
Self::GMD => "270",
|
||||
@ -609,6 +641,7 @@ impl Currency {
|
||||
Self::IDR => "360",
|
||||
Self::ILS => "376",
|
||||
Self::INR => "356",
|
||||
Self::IQD => "368",
|
||||
Self::JMD => "388",
|
||||
Self::JOD => "400",
|
||||
Self::JPY => "392",
|
||||
@ -625,6 +658,7 @@ impl Currency {
|
||||
Self::LKR => "144",
|
||||
Self::LRD => "430",
|
||||
Self::LSL => "426",
|
||||
Self::LYD => "434",
|
||||
Self::MAD => "504",
|
||||
Self::MDL => "498",
|
||||
Self::MGA => "969",
|
||||
@ -632,11 +666,13 @@ impl Currency {
|
||||
Self::MMK => "104",
|
||||
Self::MNT => "496",
|
||||
Self::MOP => "446",
|
||||
Self::MRU => "929",
|
||||
Self::MUR => "480",
|
||||
Self::MVR => "462",
|
||||
Self::MWK => "454",
|
||||
Self::MXN => "484",
|
||||
Self::MYR => "458",
|
||||
Self::MZN => "943",
|
||||
Self::NAD => "516",
|
||||
Self::NGN => "566",
|
||||
Self::NIO => "558",
|
||||
@ -644,6 +680,7 @@ impl Currency {
|
||||
Self::NPR => "524",
|
||||
Self::NZD => "554",
|
||||
Self::OMR => "512",
|
||||
Self::PAB => "590",
|
||||
Self::PEN => "604",
|
||||
Self::PGK => "598",
|
||||
Self::PHP => "608",
|
||||
@ -653,33 +690,46 @@ impl Currency {
|
||||
Self::QAR => "634",
|
||||
Self::RON => "946",
|
||||
Self::CNY => "156",
|
||||
Self::RSD => "941",
|
||||
Self::RUB => "643",
|
||||
Self::RWF => "646",
|
||||
Self::SAR => "682",
|
||||
Self::SBD => "090",
|
||||
Self::SCR => "690",
|
||||
Self::SEK => "752",
|
||||
Self::SGD => "702",
|
||||
Self::SHP => "654",
|
||||
Self::SLE => "925",
|
||||
Self::SLL => "694",
|
||||
Self::SOS => "706",
|
||||
Self::SRD => "968",
|
||||
Self::SSP => "728",
|
||||
Self::STN => "930",
|
||||
Self::SVC => "222",
|
||||
Self::SZL => "748",
|
||||
Self::THB => "764",
|
||||
Self::TND => "788",
|
||||
Self::TOP => "776",
|
||||
Self::TRY => "949",
|
||||
Self::TTD => "780",
|
||||
Self::TWD => "901",
|
||||
Self::TZS => "834",
|
||||
Self::UAH => "980",
|
||||
Self::UGX => "800",
|
||||
Self::USD => "840",
|
||||
Self::UYU => "858",
|
||||
Self::UZS => "860",
|
||||
Self::VES => "928",
|
||||
Self::VND => "704",
|
||||
Self::VUV => "548",
|
||||
Self::WST => "882",
|
||||
Self::XAF => "950",
|
||||
Self::XCD => "951",
|
||||
Self::XOF => "952",
|
||||
Self::XPF => "953",
|
||||
Self::YER => "886",
|
||||
Self::ZAR => "710",
|
||||
Self::ZMW => "967",
|
||||
}
|
||||
}
|
||||
|
||||
@ -705,12 +755,15 @@ impl Currency {
|
||||
| Self::ALL
|
||||
| Self::AMD
|
||||
| Self::ANG
|
||||
| Self::AOA
|
||||
| Self::ARS
|
||||
| Self::AUD
|
||||
| Self::AWG
|
||||
| Self::AZN
|
||||
| Self::BAM
|
||||
| Self::BBD
|
||||
| Self::BDT
|
||||
| Self::BGN
|
||||
| Self::BHD
|
||||
| Self::BMD
|
||||
| Self::BND
|
||||
@ -718,6 +771,7 @@ impl Currency {
|
||||
| Self::BRL
|
||||
| Self::BSD
|
||||
| Self::BWP
|
||||
| Self::BYN
|
||||
| Self::BZD
|
||||
| Self::CAD
|
||||
| Self::CHF
|
||||
@ -725,6 +779,7 @@ impl Currency {
|
||||
| Self::COP
|
||||
| Self::CRC
|
||||
| Self::CUP
|
||||
| Self::CVE
|
||||
| Self::CZK
|
||||
| Self::DKK
|
||||
| Self::DOP
|
||||
@ -733,7 +788,9 @@ impl Currency {
|
||||
| Self::ETB
|
||||
| Self::EUR
|
||||
| Self::FJD
|
||||
| Self::FKP
|
||||
| Self::GBP
|
||||
| Self::GEL
|
||||
| Self::GHS
|
||||
| Self::GIP
|
||||
| Self::GMD
|
||||
@ -747,6 +804,7 @@ impl Currency {
|
||||
| Self::IDR
|
||||
| Self::ILS
|
||||
| Self::INR
|
||||
| Self::IQD
|
||||
| Self::JMD
|
||||
| Self::JOD
|
||||
| Self::KES
|
||||
@ -760,17 +818,20 @@ impl Currency {
|
||||
| Self::LKR
|
||||
| Self::LRD
|
||||
| Self::LSL
|
||||
| Self::LYD
|
||||
| Self::MAD
|
||||
| Self::MDL
|
||||
| Self::MKD
|
||||
| Self::MMK
|
||||
| Self::MNT
|
||||
| Self::MOP
|
||||
| Self::MRU
|
||||
| Self::MUR
|
||||
| Self::MVR
|
||||
| Self::MWK
|
||||
| Self::MXN
|
||||
| Self::MYR
|
||||
| Self::MZN
|
||||
| Self::NAD
|
||||
| Self::NGN
|
||||
| Self::NIO
|
||||
@ -778,6 +839,7 @@ impl Currency {
|
||||
| Self::NPR
|
||||
| Self::NZD
|
||||
| Self::OMR
|
||||
| Self::PAB
|
||||
| Self::PEN
|
||||
| Self::PGK
|
||||
| Self::PHP
|
||||
@ -785,42 +847,60 @@ impl Currency {
|
||||
| Self::PLN
|
||||
| Self::QAR
|
||||
| Self::RON
|
||||
| Self::RSD
|
||||
| Self::RUB
|
||||
| Self::SAR
|
||||
| Self::SBD
|
||||
| Self::SCR
|
||||
| Self::SEK
|
||||
| Self::SGD
|
||||
| Self::SHP
|
||||
| Self::SLE
|
||||
| Self::SLL
|
||||
| Self::SOS
|
||||
| Self::SRD
|
||||
| Self::SSP
|
||||
| Self::STN
|
||||
| Self::SVC
|
||||
| Self::SZL
|
||||
| Self::THB
|
||||
| Self::TND
|
||||
| Self::TOP
|
||||
| Self::TRY
|
||||
| Self::TTD
|
||||
| Self::TWD
|
||||
| Self::TZS
|
||||
| Self::UAH
|
||||
| Self::USD
|
||||
| Self::UYU
|
||||
| Self::UZS
|
||||
| Self::VES
|
||||
| Self::WST
|
||||
| Self::XCD
|
||||
| Self::YER
|
||||
| Self::ZAR => false,
|
||||
| Self::ZAR
|
||||
| Self::ZMW => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_three_decimal_currency(self) -> bool {
|
||||
match self {
|
||||
Self::BHD | Self::JOD | Self::KWD | Self::OMR => true,
|
||||
Self::BHD | Self::IQD | Self::JOD | Self::KWD | Self::LYD | Self::OMR | Self::TND => {
|
||||
true
|
||||
}
|
||||
Self::AED
|
||||
| Self::ALL
|
||||
| Self::AMD
|
||||
| Self::AOA
|
||||
| Self::ANG
|
||||
| Self::ARS
|
||||
| Self::AUD
|
||||
| Self::AWG
|
||||
| Self::AZN
|
||||
| Self::BAM
|
||||
| Self::BBD
|
||||
| Self::BDT
|
||||
| Self::BGN
|
||||
| Self::BIF
|
||||
| Self::BMD
|
||||
| Self::BND
|
||||
@ -828,6 +908,7 @@ impl Currency {
|
||||
| Self::BRL
|
||||
| Self::BSD
|
||||
| Self::BWP
|
||||
| Self::BYN
|
||||
| Self::BZD
|
||||
| Self::CAD
|
||||
| Self::CHF
|
||||
@ -836,6 +917,7 @@ impl Currency {
|
||||
| Self::COP
|
||||
| Self::CRC
|
||||
| Self::CUP
|
||||
| Self::CVE
|
||||
| Self::CZK
|
||||
| Self::DJF
|
||||
| Self::DKK
|
||||
@ -845,7 +927,9 @@ impl Currency {
|
||||
| Self::ETB
|
||||
| Self::EUR
|
||||
| Self::FJD
|
||||
| Self::FKP
|
||||
| Self::GBP
|
||||
| Self::GEL
|
||||
| Self::GHS
|
||||
| Self::GIP
|
||||
| Self::GMD
|
||||
@ -881,17 +965,20 @@ impl Currency {
|
||||
| Self::MMK
|
||||
| Self::MNT
|
||||
| Self::MOP
|
||||
| Self::MRU
|
||||
| Self::MUR
|
||||
| Self::MVR
|
||||
| Self::MWK
|
||||
| Self::MXN
|
||||
| Self::MYR
|
||||
| Self::MZN
|
||||
| Self::NAD
|
||||
| Self::NGN
|
||||
| Self::NIO
|
||||
| Self::NOK
|
||||
| Self::NPR
|
||||
| Self::NZD
|
||||
| Self::PAB
|
||||
| Self::PEN
|
||||
| Self::PGK
|
||||
| Self::PHP
|
||||
@ -900,33 +987,45 @@ impl Currency {
|
||||
| Self::PYG
|
||||
| Self::QAR
|
||||
| Self::RON
|
||||
| Self::RSD
|
||||
| Self::RUB
|
||||
| Self::RWF
|
||||
| Self::SAR
|
||||
| Self::SBD
|
||||
| Self::SCR
|
||||
| Self::SEK
|
||||
| Self::SGD
|
||||
| Self::SHP
|
||||
| Self::SLE
|
||||
| Self::SLL
|
||||
| Self::SOS
|
||||
| Self::SRD
|
||||
| Self::SSP
|
||||
| Self::STN
|
||||
| Self::SVC
|
||||
| Self::SZL
|
||||
| Self::THB
|
||||
| Self::TOP
|
||||
| Self::TRY
|
||||
| Self::TTD
|
||||
| Self::TWD
|
||||
| Self::TZS
|
||||
| Self::UAH
|
||||
| Self::UGX
|
||||
| Self::USD
|
||||
| Self::UYU
|
||||
| Self::UZS
|
||||
| Self::VES
|
||||
| Self::VND
|
||||
| Self::VUV
|
||||
| Self::WST
|
||||
| Self::XAF
|
||||
| Self::XCD
|
||||
| Self::XPF
|
||||
| Self::XOF
|
||||
| Self::YER
|
||||
| Self::ZAR => false,
|
||||
| Self::ZAR
|
||||
| Self::ZMW => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,6 @@ common_enums = { version = "0.1.0", path = "../common_enums", package = "common_
|
||||
|
||||
# Third party crates
|
||||
rust_decimal = "1.29"
|
||||
rusty-money = { version = "0.4.0", features = ["iso", "crypto"] }
|
||||
rusty-money = { git = "https://github.com/varunsrin/rusty_money", rev = "bbc0150742a0fff905225ff11ee09388e9babdcc", features = ["iso", "crypto"] }
|
||||
serde = { version = "1.0.193", features = ["derive"] }
|
||||
thiserror = "1.0.43"
|
||||
|
||||
@ -81,12 +81,15 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::ALL => iso::ALL,
|
||||
Currency::AMD => iso::AMD,
|
||||
Currency::ANG => iso::ANG,
|
||||
Currency::AOA => iso::AOA,
|
||||
Currency::ARS => iso::ARS,
|
||||
Currency::AUD => iso::AUD,
|
||||
Currency::AWG => iso::AWG,
|
||||
Currency::AZN => iso::AZN,
|
||||
Currency::BAM => iso::BAM,
|
||||
Currency::BBD => iso::BBD,
|
||||
Currency::BDT => iso::BDT,
|
||||
Currency::BGN => iso::BGN,
|
||||
Currency::BHD => iso::BHD,
|
||||
Currency::BIF => iso::BIF,
|
||||
Currency::BMD => iso::BMD,
|
||||
@ -95,6 +98,7 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::BRL => iso::BRL,
|
||||
Currency::BSD => iso::BSD,
|
||||
Currency::BWP => iso::BWP,
|
||||
Currency::BYN => iso::BYN,
|
||||
Currency::BZD => iso::BZD,
|
||||
Currency::CAD => iso::CAD,
|
||||
Currency::CHF => iso::CHF,
|
||||
@ -103,6 +107,7 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::COP => iso::COP,
|
||||
Currency::CRC => iso::CRC,
|
||||
Currency::CUP => iso::CUP,
|
||||
Currency::CVE => iso::CVE,
|
||||
Currency::CZK => iso::CZK,
|
||||
Currency::DJF => iso::DJF,
|
||||
Currency::DKK => iso::DKK,
|
||||
@ -112,7 +117,9 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::ETB => iso::ETB,
|
||||
Currency::EUR => iso::EUR,
|
||||
Currency::FJD => iso::FJD,
|
||||
Currency::FKP => iso::FKP,
|
||||
Currency::GBP => iso::GBP,
|
||||
Currency::GEL => iso::GEL,
|
||||
Currency::GHS => iso::GHS,
|
||||
Currency::GIP => iso::GIP,
|
||||
Currency::GMD => iso::GMD,
|
||||
@ -127,6 +134,7 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::IDR => iso::IDR,
|
||||
Currency::ILS => iso::ILS,
|
||||
Currency::INR => iso::INR,
|
||||
Currency::IQD => iso::IQD,
|
||||
Currency::JMD => iso::JMD,
|
||||
Currency::JOD => iso::JOD,
|
||||
Currency::JPY => iso::JPY,
|
||||
@ -143,6 +151,7 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::LKR => iso::LKR,
|
||||
Currency::LRD => iso::LRD,
|
||||
Currency::LSL => iso::LSL,
|
||||
Currency::LYD => iso::LYD,
|
||||
Currency::MAD => iso::MAD,
|
||||
Currency::MDL => iso::MDL,
|
||||
Currency::MGA => iso::MGA,
|
||||
@ -150,11 +159,13 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::MMK => iso::MMK,
|
||||
Currency::MNT => iso::MNT,
|
||||
Currency::MOP => iso::MOP,
|
||||
Currency::MRU => iso::MRU,
|
||||
Currency::MUR => iso::MUR,
|
||||
Currency::MVR => iso::MVR,
|
||||
Currency::MWK => iso::MWK,
|
||||
Currency::MXN => iso::MXN,
|
||||
Currency::MYR => iso::MYR,
|
||||
Currency::MZN => iso::MZN,
|
||||
Currency::NAD => iso::NAD,
|
||||
Currency::NGN => iso::NGN,
|
||||
Currency::NIO => iso::NIO,
|
||||
@ -162,6 +173,7 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::NPR => iso::NPR,
|
||||
Currency::NZD => iso::NZD,
|
||||
Currency::OMR => iso::OMR,
|
||||
Currency::PAB => iso::PAB,
|
||||
Currency::PEN => iso::PEN,
|
||||
Currency::PGK => iso::PGK,
|
||||
Currency::PHP => iso::PHP,
|
||||
@ -170,32 +182,45 @@ pub fn currency_match(currency: Currency) -> &'static iso::Currency {
|
||||
Currency::PYG => iso::PYG,
|
||||
Currency::QAR => iso::QAR,
|
||||
Currency::RON => iso::RON,
|
||||
Currency::RSD => iso::RSD,
|
||||
Currency::RUB => iso::RUB,
|
||||
Currency::RWF => iso::RWF,
|
||||
Currency::SAR => iso::SAR,
|
||||
Currency::SBD => iso::SBD,
|
||||
Currency::SCR => iso::SCR,
|
||||
Currency::SEK => iso::SEK,
|
||||
Currency::SGD => iso::SGD,
|
||||
Currency::SHP => iso::SHP,
|
||||
Currency::SLE => iso::SLE,
|
||||
Currency::SLL => iso::SLL,
|
||||
Currency::SOS => iso::SOS,
|
||||
Currency::SRD => iso::SRD,
|
||||
Currency::SSP => iso::SSP,
|
||||
Currency::STN => iso::STN,
|
||||
Currency::SVC => iso::SVC,
|
||||
Currency::SZL => iso::SZL,
|
||||
Currency::THB => iso::THB,
|
||||
Currency::TND => iso::TND,
|
||||
Currency::TOP => iso::TOP,
|
||||
Currency::TTD => iso::TTD,
|
||||
Currency::TRY => iso::TRY,
|
||||
Currency::TWD => iso::TWD,
|
||||
Currency::TZS => iso::TZS,
|
||||
Currency::UAH => iso::UAH,
|
||||
Currency::UGX => iso::UGX,
|
||||
Currency::USD => iso::USD,
|
||||
Currency::UYU => iso::UYU,
|
||||
Currency::UZS => iso::UZS,
|
||||
Currency::VES => iso::VES,
|
||||
Currency::VND => iso::VND,
|
||||
Currency::VUV => iso::VUV,
|
||||
Currency::WST => iso::WST,
|
||||
Currency::XAF => iso::XAF,
|
||||
Currency::XCD => iso::XCD,
|
||||
Currency::XOF => iso::XOF,
|
||||
Currency::XPF => iso::XPF,
|
||||
Currency::YER => iso::YER,
|
||||
Currency::ZAR => iso::ZAR,
|
||||
Currency::ZMW => iso::ZMW,
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,12 +312,15 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::ALL => Ok(dirval!(PaymentCurrency = ALL)),
|
||||
Self::AMD => Ok(dirval!(PaymentCurrency = AMD)),
|
||||
Self::ANG => Ok(dirval!(PaymentCurrency = ANG)),
|
||||
Self::AOA => Ok(dirval!(PaymentCurrency = AOA)),
|
||||
Self::ARS => Ok(dirval!(PaymentCurrency = ARS)),
|
||||
Self::AUD => Ok(dirval!(PaymentCurrency = AUD)),
|
||||
Self::AWG => Ok(dirval!(PaymentCurrency = AWG)),
|
||||
Self::AZN => Ok(dirval!(PaymentCurrency = AZN)),
|
||||
Self::BAM => Ok(dirval!(PaymentCurrency = BAM)),
|
||||
Self::BBD => Ok(dirval!(PaymentCurrency = BBD)),
|
||||
Self::BDT => Ok(dirval!(PaymentCurrency = BDT)),
|
||||
Self::BGN => Ok(dirval!(PaymentCurrency = BGN)),
|
||||
Self::BHD => Ok(dirval!(PaymentCurrency = BHD)),
|
||||
Self::BIF => Ok(dirval!(PaymentCurrency = BIF)),
|
||||
Self::BMD => Ok(dirval!(PaymentCurrency = BMD)),
|
||||
@ -326,6 +329,7 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::BRL => Ok(dirval!(PaymentCurrency = BRL)),
|
||||
Self::BSD => Ok(dirval!(PaymentCurrency = BSD)),
|
||||
Self::BWP => Ok(dirval!(PaymentCurrency = BWP)),
|
||||
Self::BYN => Ok(dirval!(PaymentCurrency = BYN)),
|
||||
Self::BZD => Ok(dirval!(PaymentCurrency = BZD)),
|
||||
Self::CAD => Ok(dirval!(PaymentCurrency = CAD)),
|
||||
Self::CHF => Ok(dirval!(PaymentCurrency = CHF)),
|
||||
@ -334,6 +338,7 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::COP => Ok(dirval!(PaymentCurrency = COP)),
|
||||
Self::CRC => Ok(dirval!(PaymentCurrency = CRC)),
|
||||
Self::CUP => Ok(dirval!(PaymentCurrency = CUP)),
|
||||
Self::CVE => Ok(dirval!(PaymentCurrency = CVE)),
|
||||
Self::CZK => Ok(dirval!(PaymentCurrency = CZK)),
|
||||
Self::DJF => Ok(dirval!(PaymentCurrency = DJF)),
|
||||
Self::DKK => Ok(dirval!(PaymentCurrency = DKK)),
|
||||
@ -343,7 +348,9 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::ETB => Ok(dirval!(PaymentCurrency = ETB)),
|
||||
Self::EUR => Ok(dirval!(PaymentCurrency = EUR)),
|
||||
Self::FJD => Ok(dirval!(PaymentCurrency = FJD)),
|
||||
Self::FKP => Ok(dirval!(PaymentCurrency = FKP)),
|
||||
Self::GBP => Ok(dirval!(PaymentCurrency = GBP)),
|
||||
Self::GEL => Ok(dirval!(PaymentCurrency = GEL)),
|
||||
Self::GHS => Ok(dirval!(PaymentCurrency = GHS)),
|
||||
Self::GIP => Ok(dirval!(PaymentCurrency = GIP)),
|
||||
Self::GMD => Ok(dirval!(PaymentCurrency = GMD)),
|
||||
@ -358,6 +365,7 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::IDR => Ok(dirval!(PaymentCurrency = IDR)),
|
||||
Self::ILS => Ok(dirval!(PaymentCurrency = ILS)),
|
||||
Self::INR => Ok(dirval!(PaymentCurrency = INR)),
|
||||
Self::IQD => Ok(dirval!(PaymentCurrency = IQD)),
|
||||
Self::JMD => Ok(dirval!(PaymentCurrency = JMD)),
|
||||
Self::JOD => Ok(dirval!(PaymentCurrency = JOD)),
|
||||
Self::JPY => Ok(dirval!(PaymentCurrency = JPY)),
|
||||
@ -374,6 +382,7 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::LKR => Ok(dirval!(PaymentCurrency = LKR)),
|
||||
Self::LRD => Ok(dirval!(PaymentCurrency = LRD)),
|
||||
Self::LSL => Ok(dirval!(PaymentCurrency = LSL)),
|
||||
Self::LYD => Ok(dirval!(PaymentCurrency = LYD)),
|
||||
Self::MAD => Ok(dirval!(PaymentCurrency = MAD)),
|
||||
Self::MDL => Ok(dirval!(PaymentCurrency = MDL)),
|
||||
Self::MGA => Ok(dirval!(PaymentCurrency = MGA)),
|
||||
@ -381,11 +390,13 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::MMK => Ok(dirval!(PaymentCurrency = MMK)),
|
||||
Self::MNT => Ok(dirval!(PaymentCurrency = MNT)),
|
||||
Self::MOP => Ok(dirval!(PaymentCurrency = MOP)),
|
||||
Self::MRU => Ok(dirval!(PaymentCurrency = MRU)),
|
||||
Self::MUR => Ok(dirval!(PaymentCurrency = MUR)),
|
||||
Self::MVR => Ok(dirval!(PaymentCurrency = MVR)),
|
||||
Self::MWK => Ok(dirval!(PaymentCurrency = MWK)),
|
||||
Self::MXN => Ok(dirval!(PaymentCurrency = MXN)),
|
||||
Self::MYR => Ok(dirval!(PaymentCurrency = MYR)),
|
||||
Self::MZN => Ok(dirval!(PaymentCurrency = MZN)),
|
||||
Self::NAD => Ok(dirval!(PaymentCurrency = NAD)),
|
||||
Self::NGN => Ok(dirval!(PaymentCurrency = NGN)),
|
||||
Self::NIO => Ok(dirval!(PaymentCurrency = NIO)),
|
||||
@ -393,6 +404,7 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::NPR => Ok(dirval!(PaymentCurrency = NPR)),
|
||||
Self::NZD => Ok(dirval!(PaymentCurrency = NZD)),
|
||||
Self::OMR => Ok(dirval!(PaymentCurrency = OMR)),
|
||||
Self::PAB => Ok(dirval!(PaymentCurrency = PAB)),
|
||||
Self::PEN => Ok(dirval!(PaymentCurrency = PEN)),
|
||||
Self::PGK => Ok(dirval!(PaymentCurrency = PGK)),
|
||||
Self::PHP => Ok(dirval!(PaymentCurrency = PHP)),
|
||||
@ -401,33 +413,46 @@ impl IntoDirValue for api_enums::Currency {
|
||||
Self::PYG => Ok(dirval!(PaymentCurrency = PYG)),
|
||||
Self::QAR => Ok(dirval!(PaymentCurrency = QAR)),
|
||||
Self::RON => Ok(dirval!(PaymentCurrency = RON)),
|
||||
Self::RSD => Ok(dirval!(PaymentCurrency = RSD)),
|
||||
Self::RUB => Ok(dirval!(PaymentCurrency = RUB)),
|
||||
Self::RWF => Ok(dirval!(PaymentCurrency = RWF)),
|
||||
Self::SAR => Ok(dirval!(PaymentCurrency = SAR)),
|
||||
Self::SBD => Ok(dirval!(PaymentCurrency = SBD)),
|
||||
Self::SCR => Ok(dirval!(PaymentCurrency = SCR)),
|
||||
Self::SEK => Ok(dirval!(PaymentCurrency = SEK)),
|
||||
Self::SGD => Ok(dirval!(PaymentCurrency = SGD)),
|
||||
Self::SHP => Ok(dirval!(PaymentCurrency = SHP)),
|
||||
Self::SLE => Ok(dirval!(PaymentCurrency = SLE)),
|
||||
Self::SLL => Ok(dirval!(PaymentCurrency = SLL)),
|
||||
Self::SOS => Ok(dirval!(PaymentCurrency = SOS)),
|
||||
Self::SRD => Ok(dirval!(PaymentCurrency = SRD)),
|
||||
Self::SSP => Ok(dirval!(PaymentCurrency = SSP)),
|
||||
Self::STN => Ok(dirval!(PaymentCurrency = STN)),
|
||||
Self::SVC => Ok(dirval!(PaymentCurrency = SVC)),
|
||||
Self::SZL => Ok(dirval!(PaymentCurrency = SZL)),
|
||||
Self::THB => Ok(dirval!(PaymentCurrency = THB)),
|
||||
Self::TND => Ok(dirval!(PaymentCurrency = TND)),
|
||||
Self::TOP => Ok(dirval!(PaymentCurrency = TOP)),
|
||||
Self::TRY => Ok(dirval!(PaymentCurrency = TRY)),
|
||||
Self::TTD => Ok(dirval!(PaymentCurrency = TTD)),
|
||||
Self::TWD => Ok(dirval!(PaymentCurrency = TWD)),
|
||||
Self::TZS => Ok(dirval!(PaymentCurrency = TZS)),
|
||||
Self::UAH => Ok(dirval!(PaymentCurrency = UAH)),
|
||||
Self::UGX => Ok(dirval!(PaymentCurrency = UGX)),
|
||||
Self::USD => Ok(dirval!(PaymentCurrency = USD)),
|
||||
Self::UYU => Ok(dirval!(PaymentCurrency = UYU)),
|
||||
Self::UZS => Ok(dirval!(PaymentCurrency = UZS)),
|
||||
Self::VES => Ok(dirval!(PaymentCurrency = VES)),
|
||||
Self::VND => Ok(dirval!(PaymentCurrency = VND)),
|
||||
Self::VUV => Ok(dirval!(PaymentCurrency = VUV)),
|
||||
Self::WST => Ok(dirval!(PaymentCurrency = WST)),
|
||||
Self::XAF => Ok(dirval!(PaymentCurrency = XAF)),
|
||||
Self::XCD => Ok(dirval!(PaymentCurrency = XCD)),
|
||||
Self::XOF => Ok(dirval!(PaymentCurrency = XOF)),
|
||||
Self::XPF => Ok(dirval!(PaymentCurrency = XPF)),
|
||||
Self::YER => Ok(dirval!(PaymentCurrency = YER)),
|
||||
Self::ZAR => Ok(dirval!(PaymentCurrency = ZAR)),
|
||||
Self::ZMW => Ok(dirval!(PaymentCurrency = ZMW)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
@ -20,7 +19,7 @@ use redis_interface::RedisSettings;
|
||||
pub use router_env::config::{Log, LogConsole, LogFile, LogTelemetry};
|
||||
use rust_decimal::Decimal;
|
||||
use scheduler::SchedulerSettings;
|
||||
use serde::{de::Error, Deserialize, Deserializer};
|
||||
use serde::Deserialize;
|
||||
use storage_impl::config::QueueStrategy;
|
||||
|
||||
#[cfg(feature = "olap")]
|
||||
@ -191,7 +190,7 @@ pub struct ApplepayMerchantConfigs {
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct MultipleApiVersionSupportedConnectors {
|
||||
#[serde(deserialize_with = "connector_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub supported_connectors: HashSet<api_models::enums::Connector>,
|
||||
}
|
||||
|
||||
@ -205,42 +204,13 @@ pub struct TempLockerEnableConfig(pub HashMap<String, TempLockerEnablePaymentMet
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct ConnectorCustomer {
|
||||
#[serde(deserialize_with = "connector_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub connector_list: HashSet<api_models::enums::Connector>,
|
||||
#[cfg(feature = "payouts")]
|
||||
#[serde(deserialize_with = "payout_connector_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub payout_connector_list: HashSet<api_models::enums::PayoutConnectors>,
|
||||
}
|
||||
|
||||
fn connector_deser<'a, D>(
|
||||
deserializer: D,
|
||||
) -> Result<HashSet<api_models::enums::Connector>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <String>::deserialize(deserializer)?;
|
||||
Ok(value
|
||||
.trim()
|
||||
.split(',')
|
||||
.flat_map(api_models::enums::Connector::from_str)
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[cfg(feature = "payouts")]
|
||||
fn payout_connector_deser<'a, D>(
|
||||
deserializer: D,
|
||||
) -> Result<HashSet<api_models::enums::PayoutConnectors>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <String>::deserialize(deserializer)?;
|
||||
Ok(value
|
||||
.trim()
|
||||
.split(',')
|
||||
.flat_map(api_models::enums::PayoutConnectors::from_str)
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[cfg(feature = "dummy_connector")]
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct DummyConnector {
|
||||
@ -281,13 +251,13 @@ pub struct SupportedPaymentMethodTypesForMandate(
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct SupportedConnectorsForMandate {
|
||||
#[serde(deserialize_with = "connector_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub connector_list: HashSet<api_models::enums::Connector>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct PaymentMethodTokenFilter {
|
||||
#[serde(deserialize_with = "pm_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub payment_method: HashSet<diesel_models::enums::PaymentMethod>,
|
||||
pub payment_method_type: Option<PaymentMethodTypeTokenFilter>,
|
||||
pub long_lived_token: bool,
|
||||
@ -304,7 +274,7 @@ pub enum ApplePayPreDecryptFlow {
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct TempLockerEnablePaymentMethodFilter {
|
||||
#[serde(deserialize_with = "pm_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub payment_method: HashSet<diesel_models::enums::PaymentMethod>,
|
||||
}
|
||||
|
||||
@ -316,44 +286,14 @@ pub struct TempLockerEnablePaymentMethodFilter {
|
||||
rename_all = "snake_case"
|
||||
)]
|
||||
pub enum PaymentMethodTypeTokenFilter {
|
||||
#[serde(deserialize_with = "pm_type_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
EnableOnly(HashSet<diesel_models::enums::PaymentMethodType>),
|
||||
#[serde(deserialize_with = "pm_type_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
DisableOnly(HashSet<diesel_models::enums::PaymentMethodType>),
|
||||
#[default]
|
||||
AllAccepted,
|
||||
}
|
||||
|
||||
fn pm_deser<'a, D>(
|
||||
deserializer: D,
|
||||
) -> Result<HashSet<diesel_models::enums::PaymentMethod>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <String>::deserialize(deserializer)?;
|
||||
value
|
||||
.trim()
|
||||
.split(',')
|
||||
.map(diesel_models::enums::PaymentMethod::from_str)
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(D::Error::custom)
|
||||
}
|
||||
|
||||
fn pm_type_deser<'a, D>(
|
||||
deserializer: D,
|
||||
) -> Result<HashSet<diesel_models::enums::PaymentMethodType>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <String>::deserialize(deserializer)?;
|
||||
value
|
||||
.trim()
|
||||
.split(',')
|
||||
.map(diesel_models::enums::PaymentMethodType::from_str)
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(D::Error::custom)
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct BankRedirectConfig(
|
||||
pub HashMap<api_models::enums::PaymentMethodType, ConnectorBankNames>,
|
||||
@ -363,7 +303,7 @@ pub struct ConnectorBankNames(pub HashMap<String, BanksVector>);
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct BanksVector {
|
||||
#[serde(deserialize_with = "bank_vec_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub banks: HashSet<api_models::enums::BankNames>,
|
||||
}
|
||||
|
||||
@ -385,9 +325,9 @@ pub enum PaymentMethodFilterKey {
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
#[serde(default)]
|
||||
pub struct CurrencyCountryFlowFilter {
|
||||
#[serde(deserialize_with = "currency_set_deser")]
|
||||
#[serde(deserialize_with = "deserialize_optional_hashset")]
|
||||
pub currency: Option<HashSet<api_models::enums::Currency>>,
|
||||
#[serde(deserialize_with = "string_set_deser")]
|
||||
#[serde(deserialize_with = "deserialize_optional_hashset")]
|
||||
pub country: Option<HashSet<api_models::enums::CountryAlpha2>>,
|
||||
pub not_available_flows: Option<NotAvailableFlows>,
|
||||
}
|
||||
@ -416,58 +356,6 @@ pub struct RequiredFieldFinal {
|
||||
pub common: HashMap<String, RequiredFieldInfo>,
|
||||
}
|
||||
|
||||
fn string_set_deser<'a, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<HashSet<api_models::enums::CountryAlpha2>>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <Option<String>>::deserialize(deserializer)?;
|
||||
Ok(value.and_then(|inner| {
|
||||
let list = inner
|
||||
.trim()
|
||||
.split(',')
|
||||
.flat_map(api_models::enums::CountryAlpha2::from_str)
|
||||
.collect::<HashSet<_>>();
|
||||
match list.len() {
|
||||
0 => None,
|
||||
_ => Some(list),
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
fn currency_set_deser<'a, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<HashSet<api_models::enums::Currency>>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <Option<String>>::deserialize(deserializer)?;
|
||||
Ok(value.and_then(|inner| {
|
||||
let list = inner
|
||||
.trim()
|
||||
.split(',')
|
||||
.flat_map(api_models::enums::Currency::from_str)
|
||||
.collect::<HashSet<_>>();
|
||||
match list.len() {
|
||||
0 => None,
|
||||
_ => Some(list),
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
fn bank_vec_deser<'a, D>(deserializer: D) -> Result<HashSet<api_models::enums::BankNames>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <String>::deserialize(deserializer)?;
|
||||
Ok(value
|
||||
.trim()
|
||||
.split(',')
|
||||
.flat_map(api_models::enums::BankNames::from_str)
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Clone)]
|
||||
#[serde(default)]
|
||||
pub struct Secrets {
|
||||
@ -723,13 +611,13 @@ pub struct ApiKeys {
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct DelayedSessionConfig {
|
||||
#[serde(deserialize_with = "deser_to_get_connectors")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub connectors_with_delayed_session_response: HashSet<api_models::enums::Connector>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct WebhookSourceVerificationCall {
|
||||
#[serde(deserialize_with = "connector_deser")]
|
||||
#[serde(deserialize_with = "deserialize_hashset")]
|
||||
pub connectors_with_webhook_source_verification_call: HashSet<api_models::enums::Connector>,
|
||||
}
|
||||
|
||||
@ -746,21 +634,6 @@ pub struct ConnectorRequestReferenceIdConfig {
|
||||
pub merchant_ids_send_payment_id_as_connector_request_id: HashSet<String>,
|
||||
}
|
||||
|
||||
fn deser_to_get_connectors<'a, D>(
|
||||
deserializer: D,
|
||||
) -> Result<HashSet<api_models::enums::Connector>, D::Error>
|
||||
where
|
||||
D: Deserializer<'a>,
|
||||
{
|
||||
let value = <String>::deserialize(deserializer)?;
|
||||
value
|
||||
.trim()
|
||||
.split(',')
|
||||
.map(api_models::enums::Connector::from_str)
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(D::Error::custom)
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn new() -> ApplicationResult<Self> {
|
||||
Self::with_config_path(None)
|
||||
@ -854,24 +727,6 @@ impl Settings {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod payment_method_deserialization_test {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use serde::de::{
|
||||
value::{Error as ValueError, StrDeserializer},
|
||||
IntoDeserializer,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_pm_deserializer() {
|
||||
let deserializer: StrDeserializer<'_, ValueError> = "wallet,card".into_deserializer();
|
||||
let test_pm = pm_deser(deserializer);
|
||||
assert!(test_pm.is_ok())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "payouts")]
|
||||
#[derive(Debug, Deserialize, Clone, Default)]
|
||||
pub struct Payouts {
|
||||
@ -886,7 +741,7 @@ pub struct LockSettings {
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for LockSettings {
|
||||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Inner {
|
||||
@ -921,3 +776,124 @@ pub struct PayPalOnboarding {
|
||||
pub partner_id: masking::Secret<String>,
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
fn deserialize_hashset_inner<T>(value: impl AsRef<str>) -> Result<HashSet<T>, String>
|
||||
where
|
||||
T: Eq + std::str::FromStr + std::hash::Hash,
|
||||
<T as std::str::FromStr>::Err: std::fmt::Display,
|
||||
{
|
||||
let (values, errors) = value
|
||||
.as_ref()
|
||||
.trim()
|
||||
.split(',')
|
||||
.map(|s| {
|
||||
T::from_str(s.trim()).map_err(|error| {
|
||||
format!(
|
||||
"Unable to deserialize `{}` as `{}`: {error}",
|
||||
s.trim(),
|
||||
std::any::type_name::<T>()
|
||||
)
|
||||
})
|
||||
})
|
||||
.fold(
|
||||
(HashSet::new(), Vec::new()),
|
||||
|(mut values, mut errors), result| match result {
|
||||
Ok(t) => {
|
||||
values.insert(t);
|
||||
(values, errors)
|
||||
}
|
||||
Err(error) => {
|
||||
errors.push(error);
|
||||
(values, errors)
|
||||
}
|
||||
},
|
||||
);
|
||||
if !errors.is_empty() {
|
||||
Err(format!("Some errors occurred:\n{}", errors.join("\n")))
|
||||
} else {
|
||||
Ok(values)
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_hashset<'a, D, T>(deserializer: D) -> Result<HashSet<T>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'a>,
|
||||
T: Eq + std::str::FromStr + std::hash::Hash,
|
||||
<T as std::str::FromStr>::Err: std::fmt::Display,
|
||||
{
|
||||
use serde::de::Error;
|
||||
|
||||
deserialize_hashset_inner(<String>::deserialize(deserializer)?).map_err(D::Error::custom)
|
||||
}
|
||||
|
||||
fn deserialize_optional_hashset<'a, D, T>(deserializer: D) -> Result<Option<HashSet<T>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'a>,
|
||||
T: Eq + std::str::FromStr + std::hash::Hash,
|
||||
<T as std::str::FromStr>::Err: std::fmt::Display,
|
||||
{
|
||||
use serde::de::Error;
|
||||
|
||||
<Option<String>>::deserialize(deserializer).map(|value| {
|
||||
value.map_or(Ok(None), |inner: String| {
|
||||
let list = deserialize_hashset_inner(inner).map_err(D::Error::custom)?;
|
||||
match list.len() {
|
||||
0 => Ok(None),
|
||||
_ => Ok(Some(list)),
|
||||
}
|
||||
})
|
||||
})?
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod hashset_deserialization_test {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use std::collections::HashSet;
|
||||
|
||||
use serde::de::{
|
||||
value::{Error as ValueError, StrDeserializer},
|
||||
IntoDeserializer,
|
||||
};
|
||||
|
||||
use super::deserialize_hashset;
|
||||
|
||||
#[test]
|
||||
fn test_payment_method_hashset_deserializer() {
|
||||
use diesel_models::enums::PaymentMethod;
|
||||
|
||||
let deserializer: StrDeserializer<'_, ValueError> = "wallet,card".into_deserializer();
|
||||
let payment_methods = deserialize_hashset::<'_, _, PaymentMethod>(deserializer);
|
||||
let expected_payment_methods = HashSet::from([PaymentMethod::Wallet, PaymentMethod::Card]);
|
||||
|
||||
assert!(payment_methods.is_ok());
|
||||
assert_eq!(payment_methods.unwrap(), expected_payment_methods);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_payment_method_hashset_deserializer_with_spaces() {
|
||||
use diesel_models::enums::PaymentMethod;
|
||||
|
||||
let deserializer: StrDeserializer<'_, ValueError> =
|
||||
"wallet, card, bank_debit".into_deserializer();
|
||||
let payment_methods = deserialize_hashset::<'_, _, PaymentMethod>(deserializer);
|
||||
let expected_payment_methods = HashSet::from([
|
||||
PaymentMethod::Wallet,
|
||||
PaymentMethod::Card,
|
||||
PaymentMethod::BankDebit,
|
||||
]);
|
||||
|
||||
assert!(payment_methods.is_ok());
|
||||
assert_eq!(payment_methods.unwrap(), expected_payment_methods);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_payment_method_hashset_deserializer_error() {
|
||||
use diesel_models::enums::PaymentMethod;
|
||||
|
||||
let deserializer: StrDeserializer<'_, ValueError> =
|
||||
"wallet, card, unknown".into_deserializer();
|
||||
let payment_methods = deserialize_hashset::<'_, _, PaymentMethod>(deserializer);
|
||||
|
||||
assert!(payment_methods.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user