Skip to content

Commit

Permalink
refactor: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
swangi-kumari committed May 14, 2024
1 parent c268e74 commit a615396
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 118 deletions.
4 changes: 2 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,10 +1814,10 @@ pub enum BankRedirectData {
},
Interac {
/// The country for bank payment
#[schema(value_type = CountryAlpha2, example = "US")]
#[schema(value_type = Option<CountryAlpha2>, example = "US")]
country: Option<api_enums::CountryAlpha2>,

#[schema(value_type = String, example = "[email protected]")]
#[schema(value_type = Option<String>, example = "[email protected]")]
email: Option<Email>,
},
OnlineBankingCzechRepublic {
Expand Down
62 changes: 9 additions & 53 deletions crates/router/src/connector/aci/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,7 @@ impl
domain::BankRedirectData::Eps { .. } => {
Self::BankRedirect(Box::new(BankRedirectionPMData {
payment_brand: PaymentBrand::Eps,
bank_account_country: Some(
item.router_data.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "eps.country",
},
)?,
),
bank_account_country: Some(item.router_data.get_billing_country()?),
bank_account_bank_name: None,
bank_account_bic: None,
bank_account_iban: None,
Expand All @@ -188,11 +182,7 @@ impl
..
} => Self::BankRedirect(Box::new(BankRedirectionPMData {
payment_brand: PaymentBrand::Giropay,
bank_account_country: Some(item.router_data.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "giropay.country",
},
)?),
bank_account_country: Some(item.router_data.get_billing_country()?),
bank_account_bank_name: None,
bank_account_bic: bank_account_bic.clone(),
bank_account_iban: bank_account_iban.clone(),
Expand All @@ -204,13 +194,7 @@ impl
domain::BankRedirectData::Ideal { bank_name, .. } => {
Self::BankRedirect(Box::new(BankRedirectionPMData {
payment_brand: PaymentBrand::Ideal,
bank_account_country: Some(
item.router_data.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?,
),
bank_account_country: Some(item.router_data.get_billing_country()?),
bank_account_bank_name: Some(bank_name.ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "ideal.bank_name",
Expand All @@ -227,24 +211,14 @@ impl
domain::BankRedirectData::Sofort { .. } => {
Self::BankRedirect(Box::new(BankRedirectionPMData {
payment_brand: PaymentBrand::Sofortueberweisung,
bank_account_country: Some(
item.router_data.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?,
),
bank_account_country: Some(item.router_data.get_billing_country()?),
bank_account_bank_name: None,
bank_account_bic: None,
bank_account_iban: None,
billing_country: None,
merchant_customer_id: None,
merchant_transaction_id: None,
customer_email: Some(item.router_data.get_optional_billing_email().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.email",
},
)?),
customer_email: Some(item.router_data.get_billing_email()?),
}))
}
domain::BankRedirectData::Przelewy24 { .. } => {
Expand All @@ -257,34 +231,20 @@ impl
billing_country: None,
merchant_customer_id: None,
merchant_transaction_id: None,
customer_email: Some(item.router_data.get_optional_billing_email().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.email",
},
)?),
customer_email: Some(item.router_data.get_billing_email()?),
}))
}
domain::BankRedirectData::Interac {} => {
Self::BankRedirect(Box::new(BankRedirectionPMData {
payment_brand: PaymentBrand::InteracOnline,
bank_account_country: Some(
item.router_data.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?,
),
bank_account_country: Some(item.router_data.get_billing_country()?),
bank_account_bank_name: None,
bank_account_bic: None,
bank_account_iban: None,
billing_country: None,
merchant_customer_id: None,
merchant_transaction_id: None,
customer_email: Some(item.router_data.get_optional_billing_email().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.email",
},
)?),
customer_email: Some(item.router_data.get_billing_email()?),
}))
}
domain::BankRedirectData::Trustly {} => {
Expand All @@ -294,11 +254,7 @@ impl
bank_account_bank_name: None,
bank_account_bic: None,
bank_account_iban: None,
billing_country: Some(item.router_data.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?),
billing_country: Some(item.router_data.get_billing_country()?),
merchant_customer_id: Some(Secret::new(item.router_data.get_customer_id()?)),
merchant_transaction_id: Some(Secret::new(
item.router_data.connector_request_reference_id.clone(),
Expand Down
21 changes: 5 additions & 16 deletions crates/router/src/connector/adyen/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2285,11 +2285,7 @@ impl<'a>
field_name: "bancontact_card.card_exp_year",
})?
.clone(),
holder_name: item.get_optional_billing_full_name().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.card_holder_name",
},
)?,
holder_name: item.get_billing_full_name()?,
},
))),
domain::BankRedirectData::Bizum { .. } => {
Expand Down Expand Up @@ -2954,25 +2950,18 @@ impl<'a>

fn get_redirect_extra_details(
item: &types::PaymentsAuthorizeRouterData,
) -> Result<(Option<String>, Option<api_enums::CountryAlpha2>), errors::ConnectorError> {
) -> errors::CustomResult<(Option<String>, Option<api_enums::CountryAlpha2>), errors::ConnectorError>
{
match item.request.payment_method_data {
domain::PaymentMethodData::BankRedirect(ref redirect_data) => match redirect_data {
domain::BankRedirectData::Sofort {
preferred_language, ..
} => {
let country = item.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "country",
},
)?;
let country = item.get_billing_country()?;
Ok((preferred_language.clone(), Some(country)))
}
domain::BankRedirectData::OpenBankingUk { .. } => {
let country = item.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "country",
},
)?;
let country = item.get_billing_country()?;
Ok((None, Some(country)))
}
_ => Ok((None, None)),
Expand Down
48 changes: 8 additions & 40 deletions crates/router/src/connector/paypal/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,8 @@ fn get_payment_source(
match bank_redirection_data {
domain::BankRedirectData::Eps { bank_name: _ } => {
Ok(PaymentSourceItem::Eps(RedirectRequest {
name: item.get_optional_billing_full_name().clone().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.name",
},
)?,
country_code: item.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?,
name: item.get_billing_full_name()?,
country_code: item.get_billing_country()?,
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
Expand All @@ -306,16 +298,8 @@ fn get_payment_source(
}
domain::BankRedirectData::Giropay { .. } => {
Ok(PaymentSourceItem::Giropay(RedirectRequest {
name: item.get_optional_billing_full_name().clone().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.name",
},
)?,
country_code: item.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?,
name: item.get_billing_full_name()?,
country_code: item.get_billing_country()?,
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
Expand All @@ -330,16 +314,8 @@ fn get_payment_source(
}
domain::BankRedirectData::Ideal { bank_name: _, .. } => {
Ok(PaymentSourceItem::IDeal(RedirectRequest {
name: item.get_optional_billing_full_name().clone().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.name",
},
)?,
country_code: item.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?,
name: item.get_billing_full_name()?,
country_code: item.get_billing_country()?,
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
Expand All @@ -355,16 +331,8 @@ fn get_payment_source(
domain::BankRedirectData::Sofort {
preferred_language: _,
} => Ok(PaymentSourceItem::Sofort(RedirectRequest {
name: item.get_optional_billing_full_name().clone().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.name",
},
)?,
country_code: item.get_optional_billing_country().ok_or(
errors::ConnectorError::MissingRequiredField {
field_name: "billing.country",
},
)?,
name: item.get_billing_full_name()?,
country_code: item.get_billing_country()?,
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
Expand Down
8 changes: 1 addition & 7 deletions crates/router/src/connector/worldline/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,7 @@ fn make_bank_redirect_request(
{
PaymentMethodSpecificData::PaymentProduct816SpecificInput(Box::new(Giropay {
bank_account_iban: BankAccountIban {
account_holder_name: req
.get_optional_billing_full_name()
.as_ref()
.ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "billing_details.billing_name",
})?
.to_owned(),
account_holder_name: req.get_billing_full_name()?.to_owned(),
iban: bank_account_iban.clone(),
},
}))
Expand Down

0 comments on commit a615396

Please sign in to comment.