diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 343763321d..dcabbde7eb 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -1450,9 +1450,9 @@ impl GetAddressFromPaymentMethodData for PaymentMethodData { Self::CardRedirect(_) => None, Self::Wallet(wallet_data) => wallet_data.get_billing_address(), Self::PayLater(pay_later) => pay_later.get_billing_address(), - Self::BankRedirect(_) => None, + Self::BankRedirect(bank_redirect_data) => bank_redirect_data.get_billing_address(), Self::BankDebit(bank_debit_data) => bank_debit_data.get_billing_address(), - Self::BankTransfer(_) => None, + Self::BankTransfer(bank_transfer_data) => bank_transfer_data.get_billing_address(), Self::Voucher(voucher_data) => voucher_data.get_billing_address(), Self::Crypto(_) | Self::Reward @@ -1814,11 +1814,11 @@ pub enum BankRedirectData { }, Interac { /// The country for bank payment - #[schema(value_type = CountryAlpha2, example = "US")] - country: api_enums::CountryAlpha2, + #[schema(value_type = Option, example = "US")] + country: Option, - #[schema(value_type = String, example = "john.doe@example.com")] - email: Email, + #[schema(value_type = Option, example = "john.doe@example.com")] + email: Option, }, OnlineBankingCzechRepublic { // Issuer banks @@ -1978,7 +1978,7 @@ impl GetAddressFromPaymentMethodData for BankRedirectData { .. } => get_billing_address_inner(billing_details.as_ref(), country.as_ref(), None), Self::Interac { country, email } => { - get_billing_address_inner(None, Some(country), Some(email)) + get_billing_address_inner(None, country.as_ref(), email.as_ref()) } Self::OnlineBankingFinland { email } => { get_billing_address_inner(None, None, email.as_ref()) diff --git a/crates/router/src/connector/aci/transformers.rs b/crates/router/src/connector/aci/transformers.rs index 9353b848bd..d818fb80db 100644 --- a/crates/router/src/connector/aci/transformers.rs +++ b/crates/router/src/connector/aci/transformers.rs @@ -163,14 +163,10 @@ impl ) -> Result { 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(), diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index ab01f9e70c..6e86bfb305 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -2242,17 +2242,26 @@ impl<'a> } } -impl<'a> TryFrom<(&domain::BankRedirectData, Option)> for AdyenPaymentMethod<'a> { +impl<'a> + TryFrom<( + &domain::BankRedirectData, + Option, + &types::PaymentsAuthorizeRouterData, + )> for AdyenPaymentMethod<'a> +{ type Error = Error; fn try_from( - (bank_redirect_data, test_mode): (&domain::BankRedirectData, Option), + (bank_redirect_data, test_mode, item): ( + &domain::BankRedirectData, + Option, + &types::PaymentsAuthorizeRouterData, + ), ) -> Result { 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)> 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, Option), errors::ConnectorError> { +) -> errors::CustomResult<(Option, Option), 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)), diff --git a/crates/router/src/connector/mollie/transformers.rs b/crates/router/src/connector/mollie/transformers.rs index 4a6c5b314e..a9fe46cb59 100644 --- a/crates/router/src/connector/mollie/transformers.rs +++ b/crates/router/src/connector/mollie/transformers.rs @@ -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 { + fn try_from( + (item, value): ( + &types::PaymentsAuthorizeRouterData, + &domain::BankRedirectData, + ), + ) -> Result { 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()), } diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs index 338b8c5ba4..171d07f651 100644 --- a/crates/router/src/connector/paypal/transformers.rs +++ b/crates/router/src/connector/paypal/transformers.rs @@ -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> { 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(), diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 20c1b4e70f..da524bea4c 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -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)> for StripeBillingAddress { - type Error = error_stack::Report; - - fn try_from( - (bank_redirection_data, is_customer_initiated_mandate_payment): ( - &domain::BankRedirectData, - Option, - ), - ) -> Result { - 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)> for Strip } } -impl TryFrom<&domain::BankRedirectData> for StripePaymentMethodData { +impl TryFrom<(&domain::BankRedirectData, Option)> + for StripePaymentMethodData +{ type Error = error_stack::Report; - fn try_from(bank_redirect_data: &domain::BankRedirectData) -> Result { + fn try_from( + (bank_redirect_data, billing_address): ( + &domain::BankRedirectData, + Option, + ), + ) -> Result { 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>, } -#[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, @@ -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, +fn mandatory_parameters_for_sepa_bank_debit_mandates( + billing_details: &Option, is_customer_initiated_mandate_payment: Option, ) -> Result { 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() diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs index 6a569e76a6..3ebbc0dc9c 100644 --- a/crates/router/src/connector/utils.rs +++ b/crates/router/src/connector/utils.rs @@ -1514,18 +1514,6 @@ impl AddressDetailsData for api::AddressDetails { } } -pub trait BankRedirectBillingData { - fn get_billing_name(&self) -> Result, Error>; -} - -impl BankRedirectBillingData for domain::BankRedirectBilling { - fn get_billing_name(&self) -> Result, 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; fn get_metadata(&self) -> Result; diff --git a/crates/router/src/connector/worldline/transformers.rs b/crates/router/src/connector/worldline/transformers.rs index 795133f602..1966c65a0a 100644 --- a/crates/router/src/connector/worldline/transformers.rs +++ b/crates/router/src/connector/worldline/transformers.rs @@ -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> { - 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(), }, })) diff --git a/crates/router/src/types/domain/payments.rs b/crates/router/src/types/domain/payments.rs index 1ea9c673fa..9dc85c103e 100644 --- a/crates/router/src/types/domain/payments.rs +++ b/crates/router/src/types/domain/payments.rs @@ -237,39 +237,26 @@ pub enum BankRedirectData { card_number: Option, card_exp_month: Option>, card_exp_year: Option>, - card_holder_name: Option>, - billing_details: Option, }, Bizum {}, Blik { blik_code: Option, }, Eps { - billing_details: Option, bank_name: Option, - country: Option, }, Giropay { - billing_details: Option, bank_account_bic: Option>, bank_account_iban: Option>, - country: Option, }, Ideal { - billing_details: Option, bank_name: Option, - country: Option, - }, - Interac { - country: common_enums::CountryAlpha2, - email: Email, }, + Interac {}, OnlineBankingCzechRepublic { issuer: common_enums::BankNames, }, - OnlineBankingFinland { - email: Option, - }, + OnlineBankingFinland {}, OnlineBankingPoland { issuer: common_enums::BankNames, }, @@ -278,20 +265,14 @@ pub enum BankRedirectData { }, OpenBankingUk { issuer: Option, - country: Option, }, Przelewy24 { bank_name: Option, - billing_details: BankRedirectBilling, }, Sofort { - billing_details: Option, - country: Option, preferred_language: Option, }, - 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>, - pub email: Option, -} - #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)] #[serde(rename_all = "snake_case")] pub struct CryptoData { @@ -651,54 +626,34 @@ impl From 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 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 for BankRedirectData { } } -impl From for BankRedirectBilling { - fn from(billing: api_models::payments::BankRedirectBilling) -> Self { - Self { - billing_name: billing.billing_name, - email: billing.email, - } - } -} - impl From for CryptoData { fn from(value: api_models::payments::CryptoData) -> Self { let api_models::payments::CryptoData { pay_currency } = value; diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index efb084e16b..91eaf35958 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -5888,17 +5888,19 @@ "properties": { "interac": { "type": "object", - "required": [ - "country", - "email" - ], "properties": { "country": { - "$ref": "#/components/schemas/CountryAlpha2" + "allOf": [ + { + "$ref": "#/components/schemas/CountryAlpha2" + } + ], + "nullable": true }, "email": { "type": "string", - "example": "john.doe@example.com" + "example": "john.doe@example.com", + "nullable": true } } } diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario15-Bank Redirect-Ideal/Payments - Confirm/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario15-Bank Redirect-Ideal/Payments - Confirm/request.json index 529dab2b10..863e03c525 100644 --- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario15-Bank Redirect-Ideal/Payments - Confirm/request.json +++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario15-Bank Redirect-Ideal/Payments - Confirm/request.json @@ -43,12 +43,8 @@ "payment_method_data": { "bank_redirect": { "ideal": { - "billing_details": { - "billing_name": "John Doe" - }, "bank_name": "ing", - "preferred_language": "en", - "country": "DE" + "preferred_language": "en" } } }, diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario16-Bank Redirect-sofort/Payments - Confirm/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario16-Bank Redirect-sofort/Payments - Confirm/request.json index fd2297e984..686ac64b60 100644 --- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario16-Bank Redirect-sofort/Payments - Confirm/request.json +++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario16-Bank Redirect-sofort/Payments - Confirm/request.json @@ -43,12 +43,8 @@ "payment_method_data": { "bank_redirect": { "sofort": { - "billing_details": { - "billing_name": "John Doe" - }, "bank_name": "hypo_noe_lb_fur_niederosterreich_u_wien", - "preferred_language": "en", - "country": "DE" + "preferred_language": "en" } } }, diff --git a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario22- Update address and List Payment method/Payments - Update/request.json b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario22- Update address and List Payment method/Payments - Update/request.json index da347e0d0b..d75c1b0161 100644 --- a/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario22- Update address and List Payment method/Payments - Update/request.json +++ b/postman/collection-dir/stripe/Flow Testcases/Happy Cases/Scenario22- Update address and List Payment method/Payments - Update/request.json @@ -51,7 +51,8 @@ "phone": { "number": "8796455689", "country_code": "+91" - } + }, + "email": "swangi@gmail.com" } } }, diff --git a/postman/collection-json/stripe.postman_collection.json b/postman/collection-json/stripe.postman_collection.json index a492d70f7c..a067791ecb 100644 --- a/postman/collection-json/stripe.postman_collection.json +++ b/postman/collection-json/stripe.postman_collection.json @@ -14716,7 +14716,7 @@ "language": "json" } }, - "raw": "{\"payment_method\":\"bank_redirect\",\"payment_method_type\":\"ideal\",\"payment_method_data\":{\"bank_redirect\":{\"ideal\":{\"billing_details\":{\"billing_name\":\"John Doe\"},\"bank_name\":\"ing\",\"preferred_language\":\"en\",\"country\":\"DE\"}}},\"client_secret\":\"{{client_secret}}\"}" + "raw": "{\"payment_method\":\"bank_redirect\",\"payment_method_type\":\"ideal\",\"payment_method_data\":{\"bank_redirect\":{\"ideal\":{\"bank_name\":\"ing\",\"preferred_language\":\"en\"}}},\"client_secret\":\"{{client_secret}}\"}" }, "url": { "raw": "{{baseUrl}}/payments/:id/confirm", @@ -15146,7 +15146,7 @@ "language": "json" } }, - "raw": "{\"payment_method\":\"bank_redirect\",\"payment_method_type\":\"sofort\",\"payment_method_data\":{\"bank_redirect\":{\"sofort\":{\"billing_details\":{\"billing_name\":\"John Doe\"},\"bank_name\":\"hypo_noe_lb_fur_niederosterreich_u_wien\",\"preferred_language\":\"en\",\"country\":\"DE\"}}},\"client_secret\":\"{{client_secret}}\"}" + "raw": "{\"payment_method\":\"bank_redirect\",\"payment_method_type\":\"sofort\",\"payment_method_data\":{\"bank_redirect\":{\"sofort\":{\"bank_name\":\"hypo_noe_lb_fur_niederosterreich_u_wien\",\"preferred_language\":\"en\"}}},\"client_secret\":\"{{client_secret}}\"}" }, "url": { "raw": "{{baseUrl}}/payments/:id/confirm", @@ -17569,7 +17569,7 @@ "language": "json" } }, - "raw": "{\"currency\":\"EUR\",\"shipping\":{\"address\":{\"line1\":\"1468\",\"line2\":\"Koramangala \",\"line3\":\"Koramangala \",\"city\":\"Bangalore\",\"state\":\"Karnataka\",\"zip\":\"560065\",\"country\":\"NL\",\"first_name\":\"Preeetam\",\"last_name\":\"Rev\"},\"phone\":{\"number\":\"8796455689\",\"country_code\":\"+91\"}},\"billing\":{\"address\":{\"line1\":\"1468\",\"line2\":\"Koramangala \",\"line3\":\"Koramangala \",\"city\":\"Bangalore\",\"state\":\"Karnataka\",\"zip\":\"560065\",\"country\":\"NL\",\"first_name\":\"Preeetam\",\"last_name\":\"Rev\"},\"phone\":{\"number\":\"8796455689\",\"country_code\":\"+91\"}}}" + "raw": "{\"currency\":\"EUR\",\"shipping\":{\"address\":{\"line1\":\"1468\",\"line2\":\"Koramangala\",\"line3\":\"Koramangala\",\"city\":\"Bangalore\",\"state\":\"Karnataka\",\"zip\":\"560065\",\"country\":\"NL\",\"first_name\":\"Preeetam\",\"last_name\":\"Rev\"},\"phone\":{\"number\":\"8796455689\",\"country_code\":\"+91\"}},\"billing\":{\"address\":{\"line1\":\"1468\",\"line2\":\"Koramangala\",\"line3\":\"Koramangala\",\"city\":\"Bangalore\",\"state\":\"Karnataka\",\"zip\":\"560065\",\"country\":\"NL\",\"first_name\":\"Preeetam\",\"last_name\":\"Rev\"},\"phone\":{\"number\":\"8796455689\",\"country_code\":\"+91\"},\"email\":\"swangi@gmail.com\"}}" }, "url": { "raw": "{{baseUrl}}/payments/:id",