Skip to content

Commit

Permalink
fix(connector): [fiuu]fix mandates for fiuu (#6487)
Browse files Browse the repository at this point in the history
Co-authored-by: Chikke Srujan <[email protected]>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent 378ec44 commit bc92a2e
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 73 deletions.
20 changes: 8 additions & 12 deletions crates/hyperswitch_connectors/src/connectors/fiuu/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ impl TryFrom<&FiuuRouterData<&PaymentsAuthorizeRouterData>> for FiuuMandateReque
let order_id = item.router_data.connector_request_reference_id.clone();
let currency = item.router_data.request.currency;
let amount = item.amount.clone();
let billing_name = item.router_data.get_billing_full_name()?;
let email = item.router_data.request.get_email()?;
let billing_name = item
.router_data
.request
.get_card_holder_name_from_additional_payment_method_data()?;
let email = item.router_data.get_billing_email()?;
let token = Secret::new(item.router_data.request.get_connector_mandate_id()?);
let verify_key = auth.verify_key;
let recurring_request = FiuuRecurringRequest {
Expand Down Expand Up @@ -313,8 +316,6 @@ pub struct FiuuCardData {
cc_year: Secret<String>,
#[serde(rename = "mpstokenstatus")]
mps_token_status: Option<i32>,
#[serde(rename = "CustName")]
customer_name: Option<Secret<String>>,
#[serde(rename = "CustEmail")]
customer_email: Option<Email>,
}
Expand Down Expand Up @@ -548,15 +549,11 @@ impl TryFrom<(&Card, &PaymentsAuthorizeRouterData)> for FiuuPaymentMethodData {
fn try_from(
(req_card, item): (&Card, &PaymentsAuthorizeRouterData),
) -> Result<Self, Self::Error> {
let (mps_token_status, customer_name, customer_email) =
let (mps_token_status, customer_email) =
if item.request.is_customer_initiated_mandate_payment() {
(
Some(1),
Some(item.request.get_customer_name()?),
Some(item.request.get_email()?),
)
(Some(1), Some(item.get_billing_email()?))
} else {
(None, None, None)
(None, None)
};
let non_3ds = match item.is_three_ds() {
false => 1,
Expand All @@ -570,7 +567,6 @@ impl TryFrom<(&Card, &PaymentsAuthorizeRouterData)> for FiuuPaymentMethodData {
cc_month: req_card.card_exp_month.clone(),
cc_year: req_card.card_exp_year.clone(),
mps_token_status,
customer_name,
customer_email,
})))
}
Expand Down
20 changes: 20 additions & 0 deletions crates/hyperswitch_connectors/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,9 @@ pub trait PaymentsAuthorizeRequestData {
fn get_metadata_as_object(&self) -> Option<pii::SecretSerdeValue>;
fn get_authentication_data(&self) -> Result<AuthenticationData, Error>;
fn get_customer_name(&self) -> Result<Secret<String>, Error>;
fn get_card_holder_name_from_additional_payment_method_data(
&self,
) -> Result<Secret<String>, Error>;
}

impl PaymentsAuthorizeRequestData for PaymentsAuthorizeData {
Expand Down Expand Up @@ -1316,6 +1319,23 @@ impl PaymentsAuthorizeRequestData for PaymentsAuthorizeData {
.clone()
.ok_or_else(missing_field_err("customer_name"))
}

fn get_card_holder_name_from_additional_payment_method_data(
&self,
) -> Result<Secret<String>, Error> {
match &self.additional_payment_method_data {
Some(payments::AdditionalPaymentData::Card(card_data)) => Ok(card_data
.card_holder_name
.clone()
.ok_or_else(|| errors::ConnectorError::MissingRequiredField {
field_name: "card_holder_name",
})?),
_ => Err(errors::ConnectorError::MissingRequiredFields {
field_names: vec!["card_holder_name"],
}
.into()),
}
}
}

pub trait PaymentsCaptureRequestData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,6 @@ impl Default for settings::RequiredFields {
common: HashMap::new(),
}
),
(
enums::Connector::Fiuu,
RequiredFieldFinal {
mandate: HashMap::from([
(
"billing.email".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.email".to_string(),
display_name: "email".to_string(),
field_type: enums::FieldType::UserEmailAddress,
value: None,
}
)
]),
non_mandate: HashMap::new(),
common: HashMap::new(),
}
),
(
enums::Connector::Authorizedotnet,
RequiredFieldFinal {
Expand Down Expand Up @@ -1423,8 +1405,37 @@ impl Default for settings::RequiredFields {
(
enums::Connector::Fiuu,
RequiredFieldFinal {
mandate: HashMap::new(),
non_mandate: HashMap::from(
mandate: HashMap::from([
(
"billing.email".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.email".to_string(),
display_name: "email".to_string(),
field_type: enums::FieldType::UserEmailAddress,
value: None,
}
),
(
"billing.address.first_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.first_name".to_string(),
display_name: "card_holder_name".to_string(),
field_type: enums::FieldType::UserFullName,
value: None,
}
),
(
"billing.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.last_name".to_string(),
display_name: "card_holder_name".to_string(),
field_type: enums::FieldType::UserFullName,
value: None,
}
),
]),
non_mandate: HashMap::new(),
common: HashMap::from(
[
(
"payment_method_data.card.card_number".to_string(),
Expand Down Expand Up @@ -1464,7 +1475,6 @@ impl Default for settings::RequiredFields {
)
]
),
common: HashMap::new(),
}
),
(
Expand Down Expand Up @@ -3402,24 +3412,6 @@ impl Default for settings::RequiredFields {
common: HashMap::new(),
}
),
(
enums::Connector::Fiuu,
RequiredFieldFinal {
mandate: HashMap::from([
(
"billing.email".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.email".to_string(),
display_name: "email".to_string(),
field_type: enums::FieldType::UserEmailAddress,
value: None,
}
)
]),
non_mandate: HashMap::new(),
common: HashMap::new(),
}
),
(
enums::Connector::Authorizedotnet,
RequiredFieldFinal {
Expand Down Expand Up @@ -4533,8 +4525,37 @@ impl Default for settings::RequiredFields {
(
enums::Connector::Fiuu,
RequiredFieldFinal {
mandate: HashMap::new(),
non_mandate: HashMap::from(
mandate: HashMap::from([
(
"billing.email".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.email".to_string(),
display_name: "email".to_string(),
field_type: enums::FieldType::UserEmailAddress,
value: None,
}
),
(
"billing.address.first_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.first_name".to_string(),
display_name: "card_holder_name".to_string(),
field_type: enums::FieldType::UserFullName,
value: None,
}
),
(
"billing.address.last_name".to_string(),
RequiredFieldInfo {
required_field: "payment_method_data.billing.address.last_name".to_string(),
display_name: "card_holder_name".to_string(),
field_type: enums::FieldType::UserFullName,
value: None,
}
),
]),
non_mandate: HashMap::new(),
common: HashMap::from(
[
(
"payment_method_data.card.card_number".to_string(),
Expand Down Expand Up @@ -4574,7 +4595,6 @@ impl Default for settings::RequiredFields {
)
]
),
common: HashMap::new(),
}
),
(
Expand Down
18 changes: 9 additions & 9 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3103,15 +3103,18 @@ pub async fn list_payment_methods(
.await
.transpose()?;
let setup_future_usage = payment_intent.as_ref().and_then(|pi| pi.setup_future_usage);
let is_cit_transaction = payment_attempt
.as_ref()
.map(|pa| pa.mandate_details.is_some())
.unwrap_or(false)
|| setup_future_usage
.map(|future_usage| future_usage == common_enums::FutureUsage::OffSession)
.unwrap_or(false);
let payment_type = payment_attempt.as_ref().map(|pa| {
let amount = api::Amount::from(pa.net_amount.get_order_amount());
let mandate_type = if pa.mandate_id.is_some() {
Some(api::MandateTransactionType::RecurringMandateTransaction)
} else if pa.mandate_details.is_some()
|| setup_future_usage
.map(|future_usage| future_usage == common_enums::enums::FutureUsage::OffSession)
.unwrap_or(false)
{
} else if is_cit_transaction {
Some(api::MandateTransactionType::NewMandateTransaction)
} else {
None
Expand Down Expand Up @@ -3619,16 +3622,13 @@ pub async fn list_payment_methods(
.get(&connector_variant)
.map(|required_fields_final| {
let mut required_fields_hs = required_fields_final.common.clone();
if let Some(pa) = payment_attempt.as_ref() {
if let Some(_mandate) = &pa.mandate_details {
if is_cit_transaction {
required_fields_hs
.extend(required_fields_final.mandate.clone());
} else {
required_fields_hs
.extend(required_fields_final.non_mandate.clone());
}
}

required_fields_hs = should_collect_shipping_or_billing_details_from_wallet_connector(
&payment_method,
element.payment_experience.as_ref(),
Expand Down
Loading

0 comments on commit bc92a2e

Please sign in to comment.