Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connector): [fiuu]fix mandates for fiuu #6487

Merged
merged 8 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1154,6 +1154,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 @@ -1315,6 +1318,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 @@ -288,24 +288,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 @@ -1419,8 +1401,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 @@ -1460,7 +1471,6 @@ impl Default for settings::RequiredFields {
)
]
),
common: HashMap::new(),
}
),
(
Expand Down Expand Up @@ -3385,24 +3395,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 @@ -4516,8 +4508,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 @@ -4557,7 +4578,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 @@ -2753,15 +2753,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 @@ -3269,16 +3272,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
Loading