mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
feat(payment_methods): pass required_billing_contact_fields field in /session call based on dynamic fields (#4601)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -396,13 +396,11 @@ pub struct UnresolvedResponseReason {
|
||||
Clone,
|
||||
Debug,
|
||||
Eq,
|
||||
PartialEq,
|
||||
serde::Deserialize,
|
||||
serde::Serialize,
|
||||
strum::Display,
|
||||
strum::EnumString,
|
||||
ToSchema,
|
||||
Hash,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
@ -430,6 +428,89 @@ pub enum FieldType {
|
||||
DropDown { options: Vec<String> },
|
||||
}
|
||||
|
||||
impl FieldType {
|
||||
pub fn get_billing_variants() -> Vec<Self> {
|
||||
vec![
|
||||
Self::UserBillingName,
|
||||
Self::UserAddressLine1,
|
||||
Self::UserAddressLine2,
|
||||
Self::UserAddressCity,
|
||||
Self::UserAddressPincode,
|
||||
Self::UserAddressState,
|
||||
Self::UserAddressCountry { options: vec![] },
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// This implementatiobn is to ignore the inner value of UserAddressCountry enum while comparing
|
||||
impl PartialEq for FieldType {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::UserCardNumber, Self::UserCardNumber) => true,
|
||||
(Self::UserCardExpiryMonth, Self::UserCardExpiryMonth) => true,
|
||||
(Self::UserCardExpiryYear, Self::UserCardExpiryYear) => true,
|
||||
(Self::UserCardCvc, Self::UserCardCvc) => true,
|
||||
(Self::UserFullName, Self::UserFullName) => true,
|
||||
(Self::UserEmailAddress, Self::UserEmailAddress) => true,
|
||||
(Self::UserPhoneNumber, Self::UserPhoneNumber) => true,
|
||||
(Self::UserCountryCode, Self::UserCountryCode) => true,
|
||||
(
|
||||
Self::UserCountry {
|
||||
options: options_self,
|
||||
},
|
||||
Self::UserCountry {
|
||||
options: options_other,
|
||||
},
|
||||
) => options_self.eq(options_other),
|
||||
(
|
||||
Self::UserCurrency {
|
||||
options: options_self,
|
||||
},
|
||||
Self::UserCurrency {
|
||||
options: options_other,
|
||||
},
|
||||
) => options_self.eq(options_other),
|
||||
(Self::UserBillingName, Self::UserBillingName) => true,
|
||||
(Self::UserAddressLine1, Self::UserAddressLine1) => true,
|
||||
(Self::UserAddressLine2, Self::UserAddressLine2) => true,
|
||||
(Self::UserAddressCity, Self::UserAddressCity) => true,
|
||||
(Self::UserAddressPincode, Self::UserAddressPincode) => true,
|
||||
(Self::UserAddressState, Self::UserAddressState) => true,
|
||||
(Self::UserAddressCountry { .. }, Self::UserAddressCountry { .. }) => true,
|
||||
(Self::UserBlikCode, Self::UserBlikCode) => true,
|
||||
(Self::UserBank, Self::UserBank) => true,
|
||||
(Self::Text, Self::Text) => true,
|
||||
(
|
||||
Self::DropDown {
|
||||
options: options_self,
|
||||
},
|
||||
Self::DropDown {
|
||||
options: options_other,
|
||||
},
|
||||
) => options_self.eq(options_other),
|
||||
_unused => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_partialeq_for_field_type() {
|
||||
let user_address_country_is_us = FieldType::UserAddressCountry {
|
||||
options: vec!["US".to_string()],
|
||||
};
|
||||
|
||||
let user_address_country_is_all = FieldType::UserAddressCountry {
|
||||
options: vec!["ALL".to_string()],
|
||||
};
|
||||
|
||||
assert!(user_address_country_is_us.eq(&user_address_country_is_all))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
serde::Deserialize,
|
||||
|
||||
Reference in New Issue
Block a user