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,
|
||||
|
||||
@ -537,7 +537,7 @@ impl From<Percentage<SURCHARGE_PERCENTAGE_PRECISION_LENGTH>> for SurchargePercen
|
||||
}
|
||||
}
|
||||
/// Required fields info used while listing the payment_method_data
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq, ToSchema, Hash)]
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq, ToSchema)]
|
||||
pub struct RequiredFieldInfo {
|
||||
/// Required field for a payment_method through a payment_method_type
|
||||
pub required_field: String,
|
||||
|
||||
@ -3869,6 +3869,24 @@ pub struct GpayAllowedMethodsParameters {
|
||||
pub allowed_auth_methods: Vec<String>,
|
||||
/// The list of allowed card networks (ex: AMEX,JCB etc)
|
||||
pub allowed_card_networks: Vec<String>,
|
||||
/// Is billing address required
|
||||
pub billing_address_required: Option<bool>,
|
||||
/// Billing address parameters
|
||||
pub billing_address_parameters: Option<GpayBillingAddressParameters>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub struct GpayBillingAddressParameters {
|
||||
/// Is billing phone number required
|
||||
pub phone_number_required: bool,
|
||||
/// Billing address format
|
||||
pub format: GpayBillingAddressFormat,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
pub enum GpayBillingAddressFormat {
|
||||
FULL,
|
||||
MIN,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, serde::Deserialize, ToSchema)]
|
||||
@ -4215,6 +4233,8 @@ pub struct ApplePayPaymentRequest {
|
||||
/// The list of supported networks
|
||||
pub supported_networks: Option<Vec<String>>,
|
||||
pub merchant_identifier: Option<String>,
|
||||
/// The required billing contact fields for connector
|
||||
pub required_billing_contact_fields: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Serialize, ToSchema, serde::Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user