mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
refactor(bank-redirect): remove billing from bankredirect payment data (#4362)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -163,14 +163,10 @@ impl
|
||||
) -> Result<Self, Self::Error> {
|
||||
let (item, bank_redirect_data) = value;
|
||||
let payment_data = match bank_redirect_data {
|
||||
domain::BankRedirectData::Eps { country, .. } => {
|
||||
domain::BankRedirectData::Eps { .. } => {
|
||||
Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::Eps,
|
||||
bank_account_country: Some(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,
|
||||
@ -183,15 +179,10 @@ impl
|
||||
domain::BankRedirectData::Giropay {
|
||||
bank_account_bic,
|
||||
bank_account_iban,
|
||||
country,
|
||||
..
|
||||
} => Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::Giropay,
|
||||
bank_account_country: Some(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(),
|
||||
@ -200,35 +191,27 @@ impl
|
||||
merchant_transaction_id: None,
|
||||
customer_email: None,
|
||||
})),
|
||||
domain::BankRedirectData::Ideal {
|
||||
bank_name, country, ..
|
||||
} => Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::Ideal,
|
||||
bank_account_country: Some(country.ok_or(
|
||||
errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "ideal.country",
|
||||
},
|
||||
)?),
|
||||
bank_account_bank_name: Some(bank_name.ok_or(
|
||||
errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "ideal.bank_name",
|
||||
},
|
||||
)?),
|
||||
bank_account_bic: None,
|
||||
bank_account_iban: None,
|
||||
billing_country: None,
|
||||
merchant_customer_id: None,
|
||||
merchant_transaction_id: None,
|
||||
customer_email: None,
|
||||
})),
|
||||
domain::BankRedirectData::Sofort { country, .. } => {
|
||||
domain::BankRedirectData::Ideal { bank_name, .. } => {
|
||||
Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::Sofortueberweisung,
|
||||
bank_account_country: Some(country.to_owned().ok_or(
|
||||
payment_brand: PaymentBrand::Ideal,
|
||||
bank_account_country: Some(item.router_data.get_billing_country()?),
|
||||
bank_account_bank_name: Some(bank_name.ok_or(
|
||||
errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "sofort.country",
|
||||
field_name: "ideal.bank_name",
|
||||
},
|
||||
)?),
|
||||
bank_account_bic: None,
|
||||
bank_account_iban: None,
|
||||
billing_country: None,
|
||||
merchant_customer_id: None,
|
||||
merchant_transaction_id: None,
|
||||
customer_email: None,
|
||||
}))
|
||||
}
|
||||
domain::BankRedirectData::Sofort { .. } => {
|
||||
Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::Sofortueberweisung,
|
||||
bank_account_country: Some(item.router_data.get_billing_country()?),
|
||||
bank_account_bank_name: None,
|
||||
bank_account_bic: None,
|
||||
bank_account_iban: None,
|
||||
@ -238,40 +221,40 @@ impl
|
||||
customer_email: None,
|
||||
}))
|
||||
}
|
||||
domain::BankRedirectData::Przelewy24 {
|
||||
billing_details, ..
|
||||
} => Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::Przelewy,
|
||||
bank_account_country: None,
|
||||
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: billing_details.email.to_owned(),
|
||||
})),
|
||||
domain::BankRedirectData::Interac { email, country } => {
|
||||
domain::BankRedirectData::Przelewy24 { .. } => {
|
||||
Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::InteracOnline,
|
||||
bank_account_country: Some(country.to_owned()),
|
||||
payment_brand: PaymentBrand::Przelewy,
|
||||
bank_account_country: None,
|
||||
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(email.to_owned()),
|
||||
customer_email: Some(item.router_data.get_billing_email()?),
|
||||
}))
|
||||
}
|
||||
domain::BankRedirectData::Trustly { country } => {
|
||||
domain::BankRedirectData::Interac {} => {
|
||||
Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::InteracOnline,
|
||||
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_billing_email()?),
|
||||
}))
|
||||
}
|
||||
domain::BankRedirectData::Trustly {} => {
|
||||
Self::BankRedirect(Box::new(BankRedirectionPMData {
|
||||
payment_brand: PaymentBrand::Trustly,
|
||||
bank_account_country: None,
|
||||
bank_account_bank_name: None,
|
||||
bank_account_bic: None,
|
||||
bank_account_iban: None,
|
||||
billing_country: Some(country.to_owned()),
|
||||
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(),
|
||||
|
||||
@ -2242,17 +2242,26 @@ impl<'a>
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<(&domain::BankRedirectData, Option<bool>)> for AdyenPaymentMethod<'a> {
|
||||
impl<'a>
|
||||
TryFrom<(
|
||||
&domain::BankRedirectData,
|
||||
Option<bool>,
|
||||
&types::PaymentsAuthorizeRouterData,
|
||||
)> for AdyenPaymentMethod<'a>
|
||||
{
|
||||
type Error = Error;
|
||||
fn try_from(
|
||||
(bank_redirect_data, test_mode): (&domain::BankRedirectData, Option<bool>),
|
||||
(bank_redirect_data, test_mode, item): (
|
||||
&domain::BankRedirectData,
|
||||
Option<bool>,
|
||||
&types::PaymentsAuthorizeRouterData,
|
||||
),
|
||||
) -> Result<Self, Self::Error> {
|
||||
match bank_redirect_data {
|
||||
domain::BankRedirectData::BancontactCard {
|
||||
card_number,
|
||||
card_exp_month,
|
||||
card_exp_year,
|
||||
card_holder_name,
|
||||
..
|
||||
} => Ok(AdyenPaymentMethod::BancontactCard(Box::new(
|
||||
BancontactCardData {
|
||||
@ -2276,12 +2285,7 @@ impl<'a> TryFrom<(&domain::BankRedirectData, Option<bool>)> for AdyenPaymentMeth
|
||||
field_name: "bancontact_card.card_exp_year",
|
||||
})?
|
||||
.clone(),
|
||||
holder_name: card_holder_name
|
||||
.as_ref()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "bancontact_card.card_holder_name",
|
||||
})?
|
||||
.clone(),
|
||||
holder_name: item.get_billing_full_name()?,
|
||||
},
|
||||
))),
|
||||
domain::BankRedirectData::Bizum { .. } => {
|
||||
@ -2886,8 +2890,11 @@ impl<'a>
|
||||
let browser_info = get_browser_info(item.router_data)?;
|
||||
let additional_data = get_additional_data(item.router_data);
|
||||
let return_url = item.router_data.request.get_return_url()?;
|
||||
let payment_method =
|
||||
AdyenPaymentMethod::try_from((bank_redirect_data, item.router_data.test_mode))?;
|
||||
let payment_method = AdyenPaymentMethod::try_from((
|
||||
bank_redirect_data,
|
||||
item.router_data.test_mode,
|
||||
item.router_data,
|
||||
))?;
|
||||
let (shopper_locale, country) = get_redirect_extra_details(item.router_data)?;
|
||||
let line_items = Some(get_line_items(item));
|
||||
|
||||
@ -2922,18 +2929,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 {
|
||||
country,
|
||||
preferred_language,
|
||||
..
|
||||
} => Ok((preferred_language.clone(), *country)),
|
||||
domain::BankRedirectData::OpenBankingUk { country, .. } => {
|
||||
let country = country.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "country",
|
||||
})?;
|
||||
preferred_language, ..
|
||||
} => {
|
||||
let country = item.get_billing_country()?;
|
||||
Ok((preferred_language.clone(), Some(country)))
|
||||
}
|
||||
domain::BankRedirectData::OpenBankingUk { .. } => {
|
||||
let country = item.get_billing_country()?;
|
||||
Ok((None, Some(country)))
|
||||
}
|
||||
_ => Ok((None, None)),
|
||||
|
||||
@ -189,7 +189,7 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP
|
||||
)))
|
||||
}
|
||||
domain::PaymentMethodData::BankRedirect(ref redirect_data) => {
|
||||
PaymentMethodData::try_from(redirect_data)
|
||||
PaymentMethodData::try_from((item.router_data, redirect_data))
|
||||
}
|
||||
domain::PaymentMethodData::Wallet(ref wallet_data) => {
|
||||
get_payment_method_for_wallet(item.router_data, wallet_data)
|
||||
@ -230,9 +230,19 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&domain::BankRedirectData> for PaymentMethodData {
|
||||
impl
|
||||
TryFrom<(
|
||||
&types::PaymentsAuthorizeRouterData,
|
||||
&domain::BankRedirectData,
|
||||
)> for PaymentMethodData
|
||||
{
|
||||
type Error = Error;
|
||||
fn try_from(value: &domain::BankRedirectData) -> Result<Self, Self::Error> {
|
||||
fn try_from(
|
||||
(item, value): (
|
||||
&types::PaymentsAuthorizeRouterData,
|
||||
&domain::BankRedirectData,
|
||||
),
|
||||
) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
domain::BankRedirectData::Eps { .. } => Ok(Self::Eps),
|
||||
domain::BankRedirectData::Giropay { .. } => Ok(Self::Giropay),
|
||||
@ -243,11 +253,11 @@ impl TryFrom<&domain::BankRedirectData> for PaymentMethodData {
|
||||
})))
|
||||
}
|
||||
domain::BankRedirectData::Sofort { .. } => Ok(Self::Sofort),
|
||||
domain::BankRedirectData::Przelewy24 {
|
||||
billing_details, ..
|
||||
} => Ok(Self::Przelewy24(Box::new(Przelewy24MethodData {
|
||||
billing_email: billing_details.email.clone(),
|
||||
}))),
|
||||
domain::BankRedirectData::Przelewy24 { .. } => {
|
||||
Ok(Self::Przelewy24(Box::new(Przelewy24MethodData {
|
||||
billing_email: item.get_optional_billing_email(),
|
||||
})))
|
||||
}
|
||||
domain::BankRedirectData::BancontactCard { .. } => Ok(Self::Bancontact),
|
||||
_ => Err(errors::ConnectorError::NotImplemented("Payment method".to_string()).into()),
|
||||
}
|
||||
|
||||
@ -11,8 +11,8 @@ use url::Url;
|
||||
|
||||
use crate::{
|
||||
connector::utils::{
|
||||
self, to_connector_meta, AccessTokenRequestInfo, AddressDetailsData,
|
||||
BankRedirectBillingData, CardData, PaymentsAuthorizeRequestData, RouterData,
|
||||
self, to_connector_meta, AccessTokenRequestInfo, AddressDetailsData, CardData,
|
||||
PaymentsAuthorizeRequestData, RouterData,
|
||||
},
|
||||
consts,
|
||||
core::errors,
|
||||
@ -280,95 +280,59 @@ fn get_payment_source(
|
||||
bank_redirection_data: &domain::BankRedirectData,
|
||||
) -> Result<PaymentSourceItem, error_stack::Report<errors::ConnectorError>> {
|
||||
match bank_redirection_data {
|
||||
domain::BankRedirectData::Eps {
|
||||
billing_details,
|
||||
bank_name: _,
|
||||
country,
|
||||
} => Ok(PaymentSourceItem::Eps(RedirectRequest {
|
||||
name: billing_details
|
||||
.clone()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "eps.billing_details",
|
||||
})?
|
||||
.get_billing_name()?,
|
||||
country_code: country.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "eps.country",
|
||||
})?,
|
||||
experience_context: ContextStruct {
|
||||
return_url: item.request.complete_authorize_url.clone(),
|
||||
cancel_url: item.request.complete_authorize_url.clone(),
|
||||
shipping_preference: if item.get_optional_shipping().is_some() {
|
||||
ShippingPreference::SetProvidedAddress
|
||||
} else {
|
||||
ShippingPreference::GetFromFile
|
||||
domain::BankRedirectData::Eps { bank_name: _ } => {
|
||||
Ok(PaymentSourceItem::Eps(RedirectRequest {
|
||||
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(),
|
||||
shipping_preference: if item.get_optional_shipping().is_some() {
|
||||
ShippingPreference::SetProvidedAddress
|
||||
} else {
|
||||
ShippingPreference::GetFromFile
|
||||
},
|
||||
user_action: Some(UserAction::PayNow),
|
||||
},
|
||||
user_action: Some(UserAction::PayNow),
|
||||
},
|
||||
})),
|
||||
domain::BankRedirectData::Giropay {
|
||||
billing_details,
|
||||
country,
|
||||
..
|
||||
} => Ok(PaymentSourceItem::Giropay(RedirectRequest {
|
||||
name: billing_details
|
||||
.clone()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "giropay.billing_details",
|
||||
})?
|
||||
.get_billing_name()?,
|
||||
country_code: country.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "giropay.country",
|
||||
})?,
|
||||
experience_context: ContextStruct {
|
||||
return_url: item.request.complete_authorize_url.clone(),
|
||||
cancel_url: item.request.complete_authorize_url.clone(),
|
||||
shipping_preference: if item.get_optional_shipping().is_some() {
|
||||
ShippingPreference::SetProvidedAddress
|
||||
} else {
|
||||
ShippingPreference::GetFromFile
|
||||
}))
|
||||
}
|
||||
domain::BankRedirectData::Giropay { .. } => {
|
||||
Ok(PaymentSourceItem::Giropay(RedirectRequest {
|
||||
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(),
|
||||
shipping_preference: if item.get_optional_shipping().is_some() {
|
||||
ShippingPreference::SetProvidedAddress
|
||||
} else {
|
||||
ShippingPreference::GetFromFile
|
||||
},
|
||||
user_action: Some(UserAction::PayNow),
|
||||
},
|
||||
user_action: Some(UserAction::PayNow),
|
||||
},
|
||||
})),
|
||||
domain::BankRedirectData::Ideal {
|
||||
billing_details,
|
||||
bank_name: _,
|
||||
country,
|
||||
} => Ok(PaymentSourceItem::IDeal(RedirectRequest {
|
||||
name: billing_details
|
||||
.clone()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "ideal.billing_details",
|
||||
})?
|
||||
.get_billing_name()?,
|
||||
country_code: country.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "ideal.country",
|
||||
})?,
|
||||
experience_context: ContextStruct {
|
||||
return_url: item.request.complete_authorize_url.clone(),
|
||||
cancel_url: item.request.complete_authorize_url.clone(),
|
||||
shipping_preference: if item.get_optional_shipping().is_some() {
|
||||
ShippingPreference::SetProvidedAddress
|
||||
} else {
|
||||
ShippingPreference::GetFromFile
|
||||
}))
|
||||
}
|
||||
domain::BankRedirectData::Ideal { bank_name: _, .. } => {
|
||||
Ok(PaymentSourceItem::IDeal(RedirectRequest {
|
||||
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(),
|
||||
shipping_preference: if item.get_optional_shipping().is_some() {
|
||||
ShippingPreference::SetProvidedAddress
|
||||
} else {
|
||||
ShippingPreference::GetFromFile
|
||||
},
|
||||
user_action: Some(UserAction::PayNow),
|
||||
},
|
||||
user_action: Some(UserAction::PayNow),
|
||||
},
|
||||
})),
|
||||
}))
|
||||
}
|
||||
domain::BankRedirectData::Sofort {
|
||||
country,
|
||||
preferred_language: _,
|
||||
billing_details,
|
||||
} => Ok(PaymentSourceItem::Sofort(RedirectRequest {
|
||||
name: billing_details
|
||||
.clone()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "sofort.billing_details",
|
||||
})?
|
||||
.get_billing_name()?,
|
||||
country_code: country.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "sofort.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(),
|
||||
|
||||
@ -22,8 +22,7 @@ pub use self::connect::*;
|
||||
use crate::{
|
||||
collect_missing_value_keys,
|
||||
connector::utils::{
|
||||
self as connector_util, ApplePay, ApplePayDecrypt, BankRedirectBillingData,
|
||||
PaymentsPreProcessingData, RouterData,
|
||||
self as connector_util, ApplePay, ApplePayDecrypt, PaymentsPreProcessingData, RouterData,
|
||||
},
|
||||
consts,
|
||||
core::errors,
|
||||
@ -1057,106 +1056,6 @@ impl From<&domain::BankDebitData> for StripePaymentMethodType {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<(&domain::BankRedirectData, Option<bool>)> for StripeBillingAddress {
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
|
||||
fn try_from(
|
||||
(bank_redirection_data, is_customer_initiated_mandate_payment): (
|
||||
&domain::BankRedirectData,
|
||||
Option<bool>,
|
||||
),
|
||||
) -> Result<Self, Self::Error> {
|
||||
match bank_redirection_data {
|
||||
domain::BankRedirectData::Eps {
|
||||
billing_details, ..
|
||||
} => Ok({
|
||||
let billing_data = billing_details.clone().ok_or(
|
||||
errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "billing_details",
|
||||
},
|
||||
)?;
|
||||
Self {
|
||||
name: Some(BankRedirectBillingData::get_billing_name(&billing_data)?),
|
||||
..Self::default()
|
||||
}
|
||||
}),
|
||||
domain::BankRedirectData::Giropay {
|
||||
billing_details, ..
|
||||
} => Ok(Self {
|
||||
name: Some(
|
||||
billing_details
|
||||
.clone()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "giropay.billing_details",
|
||||
})?
|
||||
.get_billing_name()?,
|
||||
),
|
||||
..Self::default()
|
||||
}),
|
||||
domain::BankRedirectData::Ideal {
|
||||
billing_details, ..
|
||||
} => Ok(get_stripe_sepa_dd_mandate_billing_details(
|
||||
billing_details,
|
||||
is_customer_initiated_mandate_payment,
|
||||
)?),
|
||||
domain::BankRedirectData::Przelewy24 {
|
||||
billing_details, ..
|
||||
} => Ok(Self {
|
||||
email: billing_details.email.clone(),
|
||||
..Self::default()
|
||||
}),
|
||||
domain::BankRedirectData::BancontactCard {
|
||||
billing_details, ..
|
||||
} => {
|
||||
let billing_details = billing_details.as_ref().ok_or(
|
||||
errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "billing_details",
|
||||
},
|
||||
)?;
|
||||
Ok(Self {
|
||||
name: Some(
|
||||
billing_details
|
||||
.billing_name
|
||||
.as_ref()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "billing_details.billing_name",
|
||||
})?
|
||||
.to_owned(),
|
||||
),
|
||||
email: Some(
|
||||
billing_details
|
||||
.email
|
||||
.as_ref()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "billing_details.email",
|
||||
})?
|
||||
.to_owned(),
|
||||
),
|
||||
..Self::default()
|
||||
})
|
||||
}
|
||||
domain::BankRedirectData::Sofort {
|
||||
billing_details, ..
|
||||
} => Ok(get_stripe_sepa_dd_mandate_billing_details(
|
||||
billing_details,
|
||||
is_customer_initiated_mandate_payment,
|
||||
)?),
|
||||
|
||||
domain::BankRedirectData::Bizum {}
|
||||
| domain::BankRedirectData::Blik { .. }
|
||||
| domain::BankRedirectData::Interac { .. }
|
||||
| domain::BankRedirectData::OnlineBankingCzechRepublic { .. }
|
||||
| domain::BankRedirectData::OnlineBankingFinland { .. }
|
||||
| domain::BankRedirectData::OnlineBankingPoland { .. }
|
||||
| domain::BankRedirectData::OnlineBankingSlovakia { .. }
|
||||
| domain::BankRedirectData::Trustly { .. }
|
||||
| domain::BankRedirectData::OnlineBankingFpx { .. }
|
||||
| domain::BankRedirectData::OnlineBankingThailand { .. }
|
||||
| domain::BankRedirectData::OpenBankingUk { .. } => Ok(Self::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bank_debit_data(
|
||||
bank_debit_data: &domain::BankDebitData,
|
||||
) -> (StripePaymentMethodType, BankDebitData) {
|
||||
@ -1242,12 +1141,19 @@ fn create_stripe_payment_method(
|
||||
))
|
||||
}
|
||||
domain::PaymentMethodData::BankRedirect(bank_redirect_data) => {
|
||||
let billing_address = StripeBillingAddress::try_from((
|
||||
bank_redirect_data,
|
||||
is_customer_initiated_mandate_payment,
|
||||
))?;
|
||||
let billing_address = if is_customer_initiated_mandate_payment == Some(true) {
|
||||
mandatory_parameters_for_sepa_bank_debit_mandates(
|
||||
&Some(billing_address.to_owned()),
|
||||
is_customer_initiated_mandate_payment,
|
||||
)?
|
||||
} else {
|
||||
billing_address
|
||||
};
|
||||
let pm_type = StripePaymentMethodType::try_from(bank_redirect_data)?;
|
||||
let bank_redirect_data = StripePaymentMethodData::try_from(bank_redirect_data)?;
|
||||
let bank_redirect_data = StripePaymentMethodData::try_from((
|
||||
bank_redirect_data,
|
||||
Some(billing_address.to_owned()),
|
||||
))?;
|
||||
|
||||
Ok((bank_redirect_data, Some(pm_type), billing_address))
|
||||
}
|
||||
@ -1530,9 +1436,16 @@ impl TryFrom<(&domain::WalletData, Option<types::PaymentMethodToken>)> for Strip
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&domain::BankRedirectData> for StripePaymentMethodData {
|
||||
impl TryFrom<(&domain::BankRedirectData, Option<StripeBillingAddress>)>
|
||||
for StripePaymentMethodData
|
||||
{
|
||||
type Error = error_stack::Report<errors::ConnectorError>;
|
||||
fn try_from(bank_redirect_data: &domain::BankRedirectData) -> Result<Self, Self::Error> {
|
||||
fn try_from(
|
||||
(bank_redirect_data, billing_address): (
|
||||
&domain::BankRedirectData,
|
||||
Option<StripeBillingAddress>,
|
||||
),
|
||||
) -> Result<Self, Self::Error> {
|
||||
let payment_method_data_type = StripePaymentMethodType::try_from(bank_redirect_data)?;
|
||||
match bank_redirect_data {
|
||||
domain::BankRedirectData::BancontactCard { .. } => Ok(Self::BankRedirect(
|
||||
@ -1586,15 +1499,15 @@ impl TryFrom<&domain::BankRedirectData> for StripePaymentMethodData {
|
||||
))
|
||||
}
|
||||
domain::BankRedirectData::Sofort {
|
||||
country,
|
||||
preferred_language,
|
||||
..
|
||||
preferred_language, ..
|
||||
} => Ok(Self::BankRedirect(StripeBankRedirectData::StripeSofort(
|
||||
Box::new(StripeSofort {
|
||||
payment_method_data_type,
|
||||
country: country.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "sofort.country",
|
||||
})?,
|
||||
country: billing_address
|
||||
.and_then(|billing_data| billing_data.country)
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "billing_address.country",
|
||||
})?,
|
||||
preferred_language: preferred_language.clone(),
|
||||
}),
|
||||
))),
|
||||
@ -3050,7 +2963,7 @@ pub struct StripeShippingAddress {
|
||||
pub phone: Option<Secret<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize)]
|
||||
pub struct StripeBillingAddress {
|
||||
#[serde(rename = "payment_method_data[billing_details][email]")]
|
||||
pub email: Option<Email>,
|
||||
@ -3614,7 +3527,7 @@ impl
|
||||
payment_method_data_type: pm_type,
|
||||
})),
|
||||
domain::PaymentMethodData::BankRedirect(ref bank_redirect_data) => {
|
||||
Ok(Self::try_from(bank_redirect_data)?)
|
||||
Ok(Self::try_from((bank_redirect_data, None))?)
|
||||
}
|
||||
domain::PaymentMethodData::Wallet(ref wallet_data) => {
|
||||
Ok(Self::try_from((wallet_data, None))?)
|
||||
@ -3786,13 +3699,13 @@ pub struct Evidence {
|
||||
}
|
||||
|
||||
// Mandates for bank redirects - ideal and sofort happens through sepa direct debit in stripe
|
||||
fn get_stripe_sepa_dd_mandate_billing_details(
|
||||
billing_details: &Option<domain::BankRedirectBilling>,
|
||||
fn mandatory_parameters_for_sepa_bank_debit_mandates(
|
||||
billing_details: &Option<StripeBillingAddress>,
|
||||
is_customer_initiated_mandate_payment: Option<bool>,
|
||||
) -> Result<StripeBillingAddress, errors::ConnectorError> {
|
||||
let billing_name = billing_details
|
||||
.clone()
|
||||
.and_then(|billing_data| billing_data.billing_name.clone());
|
||||
.and_then(|billing_data| billing_data.name.clone());
|
||||
|
||||
let billing_email = billing_details
|
||||
.clone()
|
||||
|
||||
@ -1514,18 +1514,6 @@ impl AddressDetailsData for api::AddressDetails {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BankRedirectBillingData {
|
||||
fn get_billing_name(&self) -> Result<Secret<String>, Error>;
|
||||
}
|
||||
|
||||
impl BankRedirectBillingData for domain::BankRedirectBilling {
|
||||
fn get_billing_name(&self) -> Result<Secret<String>, Error> {
|
||||
self.billing_name
|
||||
.clone()
|
||||
.ok_or_else(missing_field_err("billing_details.billing_name"))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MandateData {
|
||||
fn get_end_date(&self, format: date_time::DateFormat) -> Result<String, Error>;
|
||||
fn get_metadata(&self) -> Result<pii::SecretSerdeValue, Error>;
|
||||
|
||||
@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
connector::utils::{self, BankRedirectBillingData, CardData, RouterData},
|
||||
connector::utils::{self, CardData, RouterData},
|
||||
core::errors,
|
||||
services,
|
||||
types::{
|
||||
@ -234,7 +234,7 @@ impl
|
||||
}
|
||||
domain::PaymentMethodData::BankRedirect(bank_redirect) => {
|
||||
WorldlinePaymentMethod::RedirectPaymentMethodSpecificInput(Box::new(
|
||||
make_bank_redirect_request(&item.router_data.request, bank_redirect)?,
|
||||
make_bank_redirect_request(item.router_data, bank_redirect)?,
|
||||
))
|
||||
}
|
||||
domain::PaymentMethodData::CardRedirect(_)
|
||||
@ -360,26 +360,19 @@ fn make_card_request(
|
||||
}
|
||||
|
||||
fn make_bank_redirect_request(
|
||||
req: &PaymentsAuthorizeData,
|
||||
req: &types::PaymentsAuthorizeRouterData,
|
||||
bank_redirect: &domain::BankRedirectData,
|
||||
) -> Result<RedirectPaymentMethod, error_stack::Report<errors::ConnectorError>> {
|
||||
let return_url = req.router_return_url.clone();
|
||||
let return_url = req.request.router_return_url.clone();
|
||||
let redirection_data = RedirectionData { return_url };
|
||||
let (payment_method_specific_data, payment_product_id) = match bank_redirect {
|
||||
domain::BankRedirectData::Giropay {
|
||||
billing_details,
|
||||
bank_account_iban,
|
||||
..
|
||||
bank_account_iban, ..
|
||||
} => (
|
||||
{
|
||||
PaymentMethodSpecificData::PaymentProduct816SpecificInput(Box::new(Giropay {
|
||||
bank_account_iban: BankAccountIban {
|
||||
account_holder_name: billing_details
|
||||
.clone()
|
||||
.ok_or(errors::ConnectorError::MissingRequiredField {
|
||||
field_name: "giropay.billing_details",
|
||||
})?
|
||||
.get_billing_name()?,
|
||||
account_holder_name: req.get_billing_full_name()?.to_owned(),
|
||||
iban: bank_account_iban.clone(),
|
||||
},
|
||||
}))
|
||||
|
||||
@ -237,39 +237,26 @@ pub enum BankRedirectData {
|
||||
card_number: Option<cards::CardNumber>,
|
||||
card_exp_month: Option<Secret<String>>,
|
||||
card_exp_year: Option<Secret<String>>,
|
||||
card_holder_name: Option<Secret<String>>,
|
||||
billing_details: Option<BankRedirectBilling>,
|
||||
},
|
||||
Bizum {},
|
||||
Blik {
|
||||
blik_code: Option<String>,
|
||||
},
|
||||
Eps {
|
||||
billing_details: Option<BankRedirectBilling>,
|
||||
bank_name: Option<common_enums::BankNames>,
|
||||
country: Option<common_enums::CountryAlpha2>,
|
||||
},
|
||||
Giropay {
|
||||
billing_details: Option<BankRedirectBilling>,
|
||||
bank_account_bic: Option<Secret<String>>,
|
||||
bank_account_iban: Option<Secret<String>>,
|
||||
country: Option<common_enums::CountryAlpha2>,
|
||||
},
|
||||
Ideal {
|
||||
billing_details: Option<BankRedirectBilling>,
|
||||
bank_name: Option<common_enums::BankNames>,
|
||||
country: Option<common_enums::CountryAlpha2>,
|
||||
},
|
||||
Interac {
|
||||
country: common_enums::CountryAlpha2,
|
||||
email: Email,
|
||||
},
|
||||
Interac {},
|
||||
OnlineBankingCzechRepublic {
|
||||
issuer: common_enums::BankNames,
|
||||
},
|
||||
OnlineBankingFinland {
|
||||
email: Option<Email>,
|
||||
},
|
||||
OnlineBankingFinland {},
|
||||
OnlineBankingPoland {
|
||||
issuer: common_enums::BankNames,
|
||||
},
|
||||
@ -278,20 +265,14 @@ pub enum BankRedirectData {
|
||||
},
|
||||
OpenBankingUk {
|
||||
issuer: Option<common_enums::BankNames>,
|
||||
country: Option<common_enums::CountryAlpha2>,
|
||||
},
|
||||
Przelewy24 {
|
||||
bank_name: Option<common_enums::BankNames>,
|
||||
billing_details: BankRedirectBilling,
|
||||
},
|
||||
Sofort {
|
||||
billing_details: Option<BankRedirectBilling>,
|
||||
country: Option<common_enums::CountryAlpha2>,
|
||||
preferred_language: Option<String>,
|
||||
},
|
||||
Trustly {
|
||||
country: common_enums::CountryAlpha2,
|
||||
},
|
||||
Trustly {},
|
||||
OnlineBankingFpx {
|
||||
issuer: common_enums::BankNames,
|
||||
},
|
||||
@ -300,12 +281,6 @@ pub enum BankRedirectData {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct BankRedirectBilling {
|
||||
pub billing_name: Option<Secret<String>>,
|
||||
pub email: Option<Email>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct CryptoData {
|
||||
@ -651,54 +626,34 @@ impl From<api_models::payments::BankRedirectData> for BankRedirectData {
|
||||
card_number,
|
||||
card_exp_month,
|
||||
card_exp_year,
|
||||
card_holder_name,
|
||||
billing_details,
|
||||
..
|
||||
} => Self::BancontactCard {
|
||||
card_number,
|
||||
card_exp_month,
|
||||
card_exp_year,
|
||||
card_holder_name,
|
||||
billing_details: billing_details.map(BankRedirectBilling::from),
|
||||
},
|
||||
api_models::payments::BankRedirectData::Bizum {} => Self::Bizum {},
|
||||
api_models::payments::BankRedirectData::Blik { blik_code } => Self::Blik { blik_code },
|
||||
api_models::payments::BankRedirectData::Eps {
|
||||
billing_details,
|
||||
bank_name,
|
||||
country,
|
||||
} => Self::Eps {
|
||||
billing_details: billing_details.map(BankRedirectBilling::from),
|
||||
bank_name,
|
||||
country,
|
||||
},
|
||||
api_models::payments::BankRedirectData::Giropay {
|
||||
billing_details,
|
||||
bank_account_bic,
|
||||
bank_account_iban,
|
||||
country,
|
||||
} => Self::Giropay {
|
||||
billing_details: billing_details.map(BankRedirectBilling::from),
|
||||
bank_account_bic,
|
||||
bank_account_iban,
|
||||
country,
|
||||
},
|
||||
api_models::payments::BankRedirectData::Ideal {
|
||||
billing_details,
|
||||
bank_name,
|
||||
country,
|
||||
} => Self::Ideal {
|
||||
billing_details: billing_details.map(BankRedirectBilling::from),
|
||||
bank_name,
|
||||
country,
|
||||
},
|
||||
api_models::payments::BankRedirectData::Interac { country, email } => {
|
||||
Self::Interac { country, email }
|
||||
api_models::payments::BankRedirectData::Eps { bank_name, .. } => {
|
||||
Self::Eps { bank_name }
|
||||
}
|
||||
api_models::payments::BankRedirectData::Giropay {
|
||||
bank_account_bic,
|
||||
bank_account_iban,
|
||||
..
|
||||
} => Self::Giropay {
|
||||
bank_account_bic,
|
||||
bank_account_iban,
|
||||
},
|
||||
api_models::payments::BankRedirectData::Ideal { bank_name, .. } => {
|
||||
Self::Ideal { bank_name }
|
||||
}
|
||||
api_models::payments::BankRedirectData::Interac { .. } => Self::Interac {},
|
||||
api_models::payments::BankRedirectData::OnlineBankingCzechRepublic { issuer } => {
|
||||
Self::OnlineBankingCzechRepublic { issuer }
|
||||
}
|
||||
api_models::payments::BankRedirectData::OnlineBankingFinland { email } => {
|
||||
Self::OnlineBankingFinland { email }
|
||||
api_models::payments::BankRedirectData::OnlineBankingFinland { .. } => {
|
||||
Self::OnlineBankingFinland {}
|
||||
}
|
||||
api_models::payments::BankRedirectData::OnlineBankingPoland { issuer } => {
|
||||
Self::OnlineBankingPoland { issuer }
|
||||
@ -706,31 +661,16 @@ impl From<api_models::payments::BankRedirectData> for BankRedirectData {
|
||||
api_models::payments::BankRedirectData::OnlineBankingSlovakia { issuer } => {
|
||||
Self::OnlineBankingSlovakia { issuer }
|
||||
}
|
||||
api_models::payments::BankRedirectData::OpenBankingUk { issuer, country } => {
|
||||
Self::OpenBankingUk { issuer, country }
|
||||
api_models::payments::BankRedirectData::OpenBankingUk { issuer, .. } => {
|
||||
Self::OpenBankingUk { issuer }
|
||||
}
|
||||
api_models::payments::BankRedirectData::Przelewy24 { bank_name, .. } => {
|
||||
Self::Przelewy24 { bank_name }
|
||||
}
|
||||
api_models::payments::BankRedirectData::Przelewy24 {
|
||||
bank_name,
|
||||
billing_details,
|
||||
} => Self::Przelewy24 {
|
||||
bank_name,
|
||||
billing_details: BankRedirectBilling {
|
||||
billing_name: billing_details.billing_name,
|
||||
email: billing_details.email,
|
||||
},
|
||||
},
|
||||
api_models::payments::BankRedirectData::Sofort {
|
||||
billing_details,
|
||||
country,
|
||||
preferred_language,
|
||||
} => Self::Sofort {
|
||||
billing_details: billing_details.map(BankRedirectBilling::from),
|
||||
country,
|
||||
preferred_language,
|
||||
},
|
||||
api_models::payments::BankRedirectData::Trustly { country } => {
|
||||
Self::Trustly { country }
|
||||
}
|
||||
preferred_language, ..
|
||||
} => Self::Sofort { preferred_language },
|
||||
api_models::payments::BankRedirectData::Trustly { .. } => Self::Trustly {},
|
||||
api_models::payments::BankRedirectData::OnlineBankingFpx { issuer } => {
|
||||
Self::OnlineBankingFpx { issuer }
|
||||
}
|
||||
@ -741,15 +681,6 @@ impl From<api_models::payments::BankRedirectData> for BankRedirectData {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<api_models::payments::BankRedirectBilling> for BankRedirectBilling {
|
||||
fn from(billing: api_models::payments::BankRedirectBilling) -> Self {
|
||||
Self {
|
||||
billing_name: billing.billing_name,
|
||||
email: billing.email,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<api_models::payments::CryptoData> for CryptoData {
|
||||
fn from(value: api_models::payments::CryptoData) -> Self {
|
||||
let api_models::payments::CryptoData { pay_currency } = value;
|
||||
|
||||
Reference in New Issue
Block a user