Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

refactor(address): pass payment method billing to the connector module (#3828)

Narayan Bhat195c700e6c88
diff --git a/crates/cards/tests/basic.rs b/crates/cards/tests/basic.rs
index 2fdfa1354c..709da760c1 100644
--- a/crates/cards/tests/basic.rs
+++ b/crates/cards/tests/basic.rs
@@ -9,11 +9,7 @@ fn test_card_security_code() {
// no panic
let valid_card_security_code = CardSecurityCode::try_from(1234).unwrap();
- // will panic on unwrap
- let invalid_card_security_code = CardSecurityCode::try_from(00);
-
assert_eq!(*valid_card_security_code.peek(), 1234);
- assert!(invalid_card_security_code.is_err());
let serialized = serde_json::to_string(&valid_card_security_code).unwrap();
assert_eq!(serialized, "1234");
@@ -74,16 +70,17 @@ fn test_card_expiration_year() {
fn test_card_expiration() {
let curr_date = date_time::now();
let curr_year = u16::try_from(curr_date.year()).expect("valid year");
+ let curr_month = u8::from(curr_date.month());
// no panic
- let card_exp = CardExpiration::try_from((3, curr_year)).unwrap();
+ let card_exp = CardExpiration::try_from((curr_month, curr_year)).unwrap();
// will panic on unwrap
let invalid_card_exp = CardExpiration::try_from((13, curr_year));
assert_eq!(*card_exp.get_month().peek(), 3);
assert_eq!(*card_exp.get_year().peek(), curr_year);
- assert!(card_exp.is_expired().unwrap());
+ assert!(!card_exp.is_expired().unwrap());
assert!(invalid_card_exp.is_err());
diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs
index 8af99420fa..1eede78503 100644
--- a/crates/router/src/connector/adyen/transformers.rs
+++ b/crates/router/src/connector/adyen/transformers.rs
@@ -1784,10 +1784,9 @@ fn get_line_items(item: &AdyenRouterData<&types::PaymentsAuthorizeRouterData>) -
fn get_telephone_number(item: &types::PaymentsAuthorizeRouterData) -> Option<Secret<String>> {
let phone = item
- .address
- .billing
- .as_ref()
+ .get_optional_billing()
.and_then(|billing| billing.phone.as_ref());
+
phone.as_ref().and_then(|phone| {
phone.number.as_ref().and_then(|number| {
phone
@@ -2664,13 +2663,13 @@ impl<'a>
get_recurring_processing_model(item.router_data)?;
let browser_info = get_browser_info(item.router_data)?;
let billing_address =
- get_address_info(item.router_data.address.billing.as_ref()).transpose()?;
- let country_code = get_country_code(item.router_data.address.billing.as_ref());
+ get_address_info(item.router_data.get_optional_billing()).transpose()?;
+ let country_code = get_country_code(item.router_data.get_optional_billing());
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(card_data)?;
let shopper_email = item.router_data.request.email.clone();
- let shopper_name = get_shopper_name(item.router_data.address.billing.as_ref());
+ let shopper_name = get_shopper_name(item.router_data.get_optional_billing());
Ok(AdyenPaymentRequest {
amount,
@@ -2724,7 +2723,7 @@ impl<'a>
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_debit_data)?;
- let country_code = get_country_code(item.router_data.address.billing.as_ref());
+ let country_code = get_country_code(item.router_data.get_optional_billing());
let request = AdyenPaymentRequest {
amount,
merchant_account: auth_type.merchant_account,
@@ -3080,7 +3079,7 @@ impl<'a>
let auth_type = AdyenAuthType::try_from(&item.router_data.connector_auth_type)?;
let browser_info = get_browser_info(item.router_data)?;
let additional_data = get_additional_data(item.router_data);
- let country_code = get_country_code(item.router_data.address.billing.as_ref());
+ let country_code = get_country_code(item.router_data.get_optional_billing());
let shopper_interaction = AdyenShopperInteraction::from(item.router_data);
let shopper_reference = build_shopper_reference(
&item.router_data.customer_id,
@@ -3090,12 +3089,12 @@ impl<'a>
get_recurring_processing_model(item.router_data)?;
let return_url = item.router_data.request.get_return_url()?;
let shopper_name: Option<ShopperName> =
- get_shopper_name(item.router_data.address.billing.as_ref());
+ get_shopper_name(item.router_data.get_optional_billing());
let shopper_email = item.router_data.request.email.clone();
let billing_address =
- get_address_info(item.router_data.address.billing.as_ref()).transpose()?;
+ get_address_info(item.router_data.get_optional_billing()).transpose()?;
let delivery_address =
- get_address_info(item.router_data.address.shipping.as_ref()).transpose()?;
+ get_address_info(item.router_data.get_optional_shipping()).transpose()?;
let line_items = Some(get_line_items(item));
let telephone_number = get_telephone_number(item.router_data);
let payment_method = AdyenPaymentMethod::try_from((
@@ -3156,7 +3155,7 @@ impl<'a>
let payment_method = AdyenPaymentMethod::try_from(card_redirect_data)?;
let shopper_interaction = AdyenShopperInteraction::from(item.router_data);
let return_url = item.router_data.request.get_return_url()?;
- let shopper_name = get_shopper_name(item.router_data.address.billing.as_ref());
+ let shopper_name = get_shopper_name(item.router_data.get_optional_billing());
let shopper_email = item.router_data.request.email.clone();
let telephone_number = item
.router_data
@@ -4665,8 +4664,8 @@ impl<F> TryFrom<&AdyenRouterData<&types::PayoutsRouterData<F>>> for AdyenPayoutC
},
date_of_birth: None,
entity_type: Some(item.router_data.request.entity_type),
- nationality: get_country_code(item.router_data.address.billing.as_ref()),
- billing_address: get_address_info(item.router_data.address.billing.as_ref())
+ nationality: get_country_code(item.router_data.get_optional_billing()),
+ billing_address: get_address_info(item.router_data.get_optional_billing())
.transpose()?,
})
}
@@ -4705,8 +4704,8 @@ impl<F> TryFrom<&AdyenRouterData<&types::PayoutsRouterData<F>>> for AdyenPayoutC
},
date_of_birth: None,
entity_type: Some(item.router_data.request.entity_type),
- nationality: get_country_code(item.router_data.address.billing.as_ref()),
- billing_address: get_address_info(item.router_data.address.billing.as_ref())
+ nationality: get_country_code(item.router_data.get_optional_billing()),
+ billing_address: get_address_info(item.router_data.get_optional_billing())
.transpose()?,
})
}
@@ -4752,7 +4751,7 @@ impl<F> TryFrom<&AdyenRouterData<&types::PayoutsRouterData<F>>> for AdyenPayoutF
first_name: Some(address.get_first_name()?.to_owned()), // it is a required field for payouts
last_name: Some(address.get_last_name()?.to_owned()), // it is a required field for payouts
},
- nationality: get_country_code(item.router_data.address.billing.as_ref()),
+ nationality: get_country_code(item.router_data.get_optional_billing()),
entity_type: Some(item.router_data.request.entity_type),
})))
}
diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs
index 2d6f2e040a..5d3a7d0054 100644
--- a/crates/router/src/connector/authorizedotnet/transformers.rs
+++ b/crates/router/src/connector/authorizedotnet/transformers.rs
@@ -370,7 +370,8 @@ impl TryFrom<&AuthorizedotnetRouterData<&types::PaymentsAuthorizeRouterData>>
};
let bill_to = item
.router_data
- .get_billing_address_details_as_optional()
+ .get_optional_billing()
+ .and_then(|billing_address| billing_address.address.as_ref())
.map(|address| BillTo {
first_name: address.first_name.clone(),
last_name: address.last_name.clone(),
diff --git a/crates/router/src/connector/bluesnap/transformers.rs b/crates/router/src/connector/bluesnap/transformers.rs
index 201ddc221f..24cc3069f3 100644
--- a/crates/router/src/connector/bluesnap/transformers.rs
+++ b/crates/router/src/connector/bluesnap/transformers.rs
@@ -319,15 +319,7 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsAuthorizeRouterData>> for Blues
.parse_struct("ApplePayEncodedPaymentData")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
- let billing = item
- .router_data
- .address
- .billing
- .to_owned()
- .get_required_value("billing")
- .change_context(errors::ConnectorError::MissingRequiredField {
- field_name: "billing",
- })?;
+ let billing = item.router_data.get_billing()?.to_owned();
let billing_address = billing
.address
diff --git a/crates/router/src/connector/mollie/transformers.rs b/crates/router/src/connector/mollie/transformers.rs
index be4691341b..4c18b59cd1 100644
--- a/crates/router/src/connector/mollie/transformers.rs
+++ b/crates/router/src/connector/mollie/transformers.rs
@@ -347,9 +347,7 @@ fn get_shipping_details(
item: &types::PaymentsAuthorizeRouterData,
) -> Result<Option<Address>, Error> {
let shipping_address = item
- .address
- .shipping
- .as_ref()
+ .get_optional_shipping()
.and_then(|shipping| shipping.address.as_ref());
get_address_details(shipping_address)
}
@@ -358,9 +356,7 @@ fn get_billing_details(
item: &types::PaymentsAuthorizeRouterData,
) -> Result<Option<Address>, Error> {
let billing_address = item
- .address
- .billing
- .as_ref()
+ .get_optional_billing()
.and_then(|billing| billing.address.as_ref());
get_address_details(billing_address)
}
diff --git a/crates/router/src/connector/noon/transformers.rs b/crates/router/src/connector/noon/transformers.rs
index fdcb2ad5af..08cde4041d 100644
--- a/crates/router/src/connector/noon/transformers.rs
+++ b/crates/router/src/connector/noon/transformers.rs
@@ -351,19 +351,17 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
let channel = NoonChannels::Web;
let billing = item
- .address
- .billing
- .clone()
- .and_then(|billing_address| billing_address.address)
+ .get_optional_billing()
+ .and_then(|billing_address| billing_address.address.as_ref())
.map(|address| NoonBilling {
address: NoonBillingAddress {
- street: address.line1,
- street2: address.line2,
- city: address.city,
+ street: address.line1.clone(),
+ street2: address.line2.clone(),
+ city: address.city.clone(),
// If state is passed in request, country becomes mandatory, keep a check while debugging failed payments
- state_province: address.state,
+ state_province: address.state.clone(),
country: address.country,
- postal_code: address.zip,
+ postal_code: address.zip.clone(),
},
});
diff --git a/crates/router/src/connector/nuvei/transformers.rs b/crates/router/src/connector/nuvei/transformers.rs
index 6c99536109..77c08a4374 100644
--- a/crates/router/src/connector/nuvei/transformers.rs
+++ b/crates/router/src/connector/nuvei/transformers.rs
@@ -899,7 +899,9 @@ fn get_card_info<F>(
None
};
- let address = item.get_billing_address_details_as_optional();
+ let address = item
+ .get_optional_billing()
+ .and_then(|billing_details| billing_details.address.as_ref());
let billing_address = match address {
Some(address) => Some(BillingAddress {
diff --git a/crates/router/src/connector/payme/transformers.rs b/crates/router/src/connector/payme/transformers.rs
index fd638f5b60..5a84d7c4ed 100644
--- a/crates/router/src/connector/payme/transformers.rs
+++ b/crates/router/src/connector/payme/transformers.rs
@@ -544,9 +544,7 @@ impl<F>
let currency_code = item.data.request.get_currency()?;
let country_code = item
.data
- .address
- .billing
- .as_ref()
+ .get_optional_billing()
.and_then(|billing| billing.address.as_ref())
.and_then(|address| address.country);
let amount = item.data.request.get_amount()?;
diff --git a/crates/router/src/connector/paypal/transformers.rs b/crates/router/src/connector/paypal/transformers.rs
index a584fe9816..76ad9c1317 100644
--- a/crates/router/src/connector/paypal/transformers.rs
+++ b/crates/router/src/connector/paypal/transformers.rs
@@ -10,7 +10,7 @@ use url::Url;
use crate::{
connector::utils::{
self, to_connector_meta, AccessTokenRequestInfo, AddressDetailsData,
- BankRedirectBillingData, CardData, PaymentsAuthorizeRequestData,
+ BankRedirectBillingData, CardData, PaymentsAuthorizeRequestData, RouterData,
},
consts,
core::errors,
@@ -168,13 +168,11 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for Shippin
item: &PaypalRouterData<&types::PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
Ok(Self {
- address: get_address_info(item.router_data.address.shipping.as_ref())?,
+ address: get_address_info(item.router_data.get_optional_shipping())?,
name: Some(ShippingName {
full_name: item
.router_data
- .address
- .shipping
- .as_ref()
+ .get_optional_shipping()
.and_then(|inner_data| inner_data.address.as_ref())
.and_then(|inner_data| inner_data.first_name.clone()),
}),
@@ -302,7 +300,7 @@ fn get_payment_source(
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
- shipping_preference: if item.address.shipping.is_some() {
+ shipping_preference: if item.get_optional_shipping().is_some() {
ShippingPreference::SetProvidedAddress
} else {
ShippingPreference::GetFromFile
@@ -327,7 +325,7 @@ fn get_payment_source(
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
- shipping_preference: if item.address.shipping.is_some() {
+ shipping_preference: if item.get_optional_shipping().is_some() {
ShippingPreference::SetProvidedAddress
} else {
ShippingPreference::GetFromFile
@@ -352,7 +350,7 @@ fn get_payment_source(
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
- shipping_preference: if item.address.shipping.is_some() {
+ shipping_preference: if item.get_optional_shipping().is_some() {
ShippingPreference::SetProvidedAddress
} else {
ShippingPreference::GetFromFile
@@ -377,7 +375,7 @@ fn get_payment_source(
experience_context: ContextStruct {
return_url: item.request.complete_authorize_url.clone(),
cancel_url: item.request.complete_authorize_url.clone(),
- shipping_preference: if item.address.shipping.is_some() {
+ shipping_preference: if item.get_optional_shipping().is_some() {
ShippingPreference::SetProvidedAddress
} else {
ShippingPreference::GetFromFile
@@ -461,7 +459,7 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalP
};
let payment_source = Some(PaymentSourceItem::Card(CardRequest {
- billing_address: get_address_info(item.router_data.address.billing.as_ref())?,
+ billing_address: get_address_info(item.router_data.get_optional_billing())?,
expiry,
name: ccard
.card_holder_name
@@ -506,7 +504,10 @@ impl TryFrom<&PaypalRouterData<&types::PaymentsAuthorizeRouterData>> for PaypalP
experience_context: ContextStruct {
return_url: item.router_data.request.complete_authorize_url.clone(),
cancel_url: item.router_data.request.complete_authorize_url.clone(),
- shipping_preference: if item.router_data.address.shipping.is_some()
+ shipping_preference: if item
+ .router_data
+ .get_optional_shipping()
+ .is_some()
{
ShippingPreference::SetProvidedAddress
} else {
diff --git a/crates/router/src/connector/riskified/transformers/api.rs b/crates/router/src/connector/riskified/transformers/api.rs
index de8884f039..f425ecdfe5 100644
--- a/crates/router/src/connector/riskified/transformers/api.rs
+++ b/crates/router/src/connector/riskified/transformers/api.rs
@@ -144,7 +144,7 @@ impl TryFrom<&frm_types::FrmCheckoutRouterData> for RiskifiedPaymentsCheckoutReq
.parse_value("Riskified Metadata")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
- let billing_address = payment_data.get_billing_address_with_phone_number()?;
+ let billing_address = payment_data.get_billing()?;
let shipping_address = payment_data.get_shipping_address_with_phone_number()?;
let address = payment_data.get_billing_address()?;
diff --git a/crates/router/src/connector/shift4/transformers.rs b/crates/router/src/connector/shift4/transformers.rs
index 97c19c49af..f3d8863b72 100644
--- a/crates/router/src/connector/shift4/transformers.rs
+++ b/crates/router/src/connector/shift4/transformers.rs
@@ -441,8 +441,7 @@ impl<T> TryFrom<&types::RouterData<T, types::PaymentsAuthorizeData, types::Payme
item: &types::RouterData<T, types::PaymentsAuthorizeData, types::PaymentsResponseData>,
) -> Result<Self, Self::Error> {
let billing_address = item
- .address
- .billing
+ .get_optional_billing()
.as_ref()
.and_then(|billing| billing.address.as_ref());
let address = get_address_details(billing_address);
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs
index b1d24a054b..45e2c795a0 100644
--- a/crates/router/src/connector/stripe/transformers.rs
+++ b/crates/router/src/connector/stripe/transformers.rs
@@ -1714,70 +1714,70 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
let order_id = item.connector_request_reference_id.clone();
- let shipping_address = match item.address.shipping.clone() {
- Some(mut shipping) => StripeShippingAddress {
- city: shipping.address.as_mut().and_then(|a| a.city.take()),
- country: shipping.address.as_mut().and_then(|a| a.country.take()),
- line1: shipping
- .address
- .as_mut()
- .and_then(|a: &mut payments::AddressDetails| a.line1.take()),
- line2: shipping.address.as_mut().and_then(|a| a.line2.take()),
- zip: shipping.address.as_mut().and_then(|a| a.zip.take()),
- state: shipping.address.as_mut().and_then(|a| a.state.take()),
- name: shipping.address.as_mut().and_then(|a| {
- a.first_name.as_ref().map(|first_name| {
+ let shipping_address = match item.get_optional_shipping() {
+ Some(shipping_details) => {
+ let shipping_address = shipping_details.address.as_ref();
+ StripeShippingAddress {
+ city: shipping_address.and_then(|a| a.city.clone()),
+ country: shipping_address.and_then(|a| a.country),
+ line1: shipping_address.and_then(|a| a.line1.clone()),
+ line2: shipping_address.and_then(|a| a.line2.clone()),
+ zip: shipping_address.and_then(|a| a.zip.clone()),
+ state: shipping_address.and_then(|a| a.state.clone()),
+ name: shipping_address.and_then(|a| {
+ a.first_name.as_ref().map(|first_name| {
+ format!(
+ "{} {}",
+ first_name.clone().expose(),
+ a.last_name.clone().expose_option().unwrap_or_default()
+ )
+ .into()
+ })
+ }),
+ phone: shipping_details.phone.as_ref().map(|p| {
format!(
- "{} {}",
- first_name.clone().expose(),
- a.last_name.clone().expose_option().unwrap_or_default()
+ "{}{}",
+ p.country_code.clone().unwrap_or_default(),
+ p.number.clone().expose_option().unwrap_or_default()
)
.into()
- })
- }),
- phone: shipping.phone.map(|p| {
- format!(
- "{}{}",
- p.country_code.unwrap_or_default(),
- p.number.expose_option().unwrap_or_default()
- )
- .into()
- }),
- },
+ }),
+ }
+ }
None => StripeShippingAddress::default(),
};
- let billing_address = match item.address.billing.clone() {
- Some(mut billing) => StripeBillingAddress {
- city: billing.address.as_mut().and_then(|a| a.city.take()),
- country: billing.address.as_mut().and_then(|a| a.country.take()),
- address_line1: billing
- .address
- .as_mut()
- .and_then(|a: &mut payments::AddressDetails| a.line1.take()),
- address_line2: billing.address.as_mut().and_then(|a| a.line2.take()),
- zip_code: billing.address.as_mut().and_then(|a| a.zip.take()),
- state: billing.address.as_mut().and_then(|a| a.state.take()),
- name: billing.address.as_mut().and_then(|a| {
- a.first_name.as_ref().map(|first_name| {
+ let billing_address = match item.get_optional_billing() {
+ Some(billing_details) => {
+ let billing_address = billing_details.address.as_ref();
+ StripeBillingAddress {
+ city: billing_address.and_then(|a| a.city.clone()),
+ country: billing_address.and_then(|a| a.country),
+ address_line1: billing_address.and_then(|a| a.line1.clone()),
+ address_line2: billing_address.and_then(|a| a.line2.clone()),
+ zip_code: billing_address.and_then(|a| a.zip.clone()),
+ state: billing_address.and_then(|a| a.state.clone()),
+ name: billing_address.and_then(|a| {
+ a.first_name.as_ref().map(|first_name| {
+ format!(
+ "{} {}",
+ first_name.clone().expose(),
+ a.last_name.clone().expose_option().unwrap_or_default()
+ )
+ .into()
+ })
+ }),
+ email: billing_details.email.clone(),
+ phone: billing_details.phone.as_ref().map(|p| {
format!(
- "{} {}",
- first_name.clone().expose(),
- a.last_name.clone().expose_option().unwrap_or_default()
+ "{}{}",
+ p.country_code.clone().unwrap_or_default(),
+ p.number.clone().expose_option().unwrap_or_default()
)
.into()
- })
- }),
- email: item.request.email.clone(),
- phone: billing.phone.map(|p| {
- format!(
- "{}{}",
- p.country_code.unwrap_or_default(),
- p.number.expose_option().unwrap_or_default()
- )
- .into()
- }),
- },
+ }),
+ }
+ }
None => StripeBillingAddress::default(),
};
let mut payment_method_options = None;
diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rs
index 996e06adfc..51a012a537 100644
--- a/crates/router/src/connector/utils.rs
+++ b/crates/router/src/connector/utils.rs
@@ -69,7 +69,6 @@ pub trait RouterData {
fn get_return_url(&self) -> Result<String, Error>;
fn get_billing_address(&self) -> Result<&api::AddressDetails, Error>;
fn get_shipping_address(&self) -> Result<&api::AddressDetails, Error>;
- fn get_billing_address_with_phone_number(&self) -> Result<&api::Address, Error>;
fn get_shipping_address_with_phone_number(&self) -> Result<&api::Address, Error>;
fn get_connector_meta(&self) -> Result<pii::SecretSerdeValue, Error>;
fn get_session_token(&self) -> Result<String, Error>;
@@ -86,7 +85,9 @@ pub trait RouterData {
fn get_payout_method_data(&self) -> Result<api::PayoutMethodData, Error>;
#[cfg(feature = "payouts")]
fn get_quote_id(&self) -> Result<String, Error>;
- fn get_billing_address_details_as_optional(&self) -> Option<api::AddressDetails>;
+
+ fn get_optional_billing(&self) -> Option<&api::Address>;
+ fn get_optional_shipping(&self) -> Option<&api::Address>;
}
pub trait PaymentResponseRouterData {
@@ -144,15 +145,13 @@ pub fn get_unimplemented_payment_method_error_message(connector: &str) -> String
impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Response> {
fn get_billing(&self) -> Result<&api::Address, Error> {
self.address
- .billing
- .as_ref()
+ .get_payment_method_billing()
.ok_or_else(missing_field_err("billing"))
}
fn get_billing_country(&self) -> Result<api_models::enums::CountryAlpha2, Error> {
self.address
- .billing
- .as_ref()
+ .get_payment_method_billing()
.and_then(|a| a.address.as_ref())
.and_then(|ad| ad.country)
.ok_or_else(missing_field_err("billing.address.country"))
@@ -160,11 +159,19 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
fn get_billing_phone(&self) -> Result<&api::PhoneDetails, Error> {
self.address
- .billing
- .as_ref()
+ .get_payment_method_billing()
.and_then(|a| a.phone.as_ref())
.ok_or_else(missing_field_err("billing.phone"))
}
+
+ fn get_optional_billing(&self) -> Option<&api::Address> {
+ self.address.get_payment_method_billing()
+ }
+
+ fn get_optional_shipping(&self) -> Option<&api::Address> {
+ self.address.get_shipping()
+ }
+
fn get_description(&self) -> Result<String, Error> {
self.description
.clone()
@@ -177,26 +184,12 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
}
fn get_billing_address(&self) -> Result<&api::AddressDetails, Error> {
self.address
- .billing
+ .get_payment_method_billing()
.as_ref()
.and_then(|a| a.address.as_ref())
.ok_or_else(missing_field_err("billing.address"))
}
- fn get_billing_address_details_as_optional(&self) -> Option<api::AddressDetails> {
- self.address
- .billing
- .as_ref()
- .and_then(|a| a.address.as_ref())
- .cloned()
- }
-
- fn get_billing_address_with_phone_number(&self) -> Result<&api::Address, Error> {
- self.address
- .billing
- .as_ref()
- .ok_or_else(missing_field_err("billing"))
- }
fn get_connector_meta(&self) -> Result<pii::SecretSerdeValue, Error> {
self.connector_meta_data
.clone()
@@ -227,16 +220,14 @@ impl<Flow, Request, Response> RouterData for types::RouterData<Flow, Request, Re
fn get_shipping_address(&self) -> Result<&api::AddressDetails, Error> {
self.address
- .shipping
- .as_ref()
+ .get_shipping()
.and_then(|a| a.address.as_ref())
.ok_or_else(missing_field_err("shipping.address"))
}
fn get_shipping_address_with_phone_number(&self) -> Result<&api::Address, Error> {
self.address
- .shipping
- .as_ref()
+ .get_shipping()
.ok_or_else(missing_field_err("shipping"))
}
diff --git a/crates/router/src/connector/wise/transformers.rs b/crates/router/src/connector/wise/transformers.rs
index 88bc46bfc8..35b750881c 100644
--- a/crates/router/src/connector/wise/transformers.rs
+++ b/crates/router/src/connector/wise/transformers.rs
@@ -292,9 +292,9 @@ pub enum WiseStatus {
#[cfg(feature = "payouts")]
fn get_payout_address_details(
- address: &Option<api_models::payments::Address>,
+ address: Option<&api_models::payments::Address>,
) -> Option<WiseAddressDetails> {
- address.as_ref().and_then(|add| {
+ address.and_then(|add| {
add.address.as_ref().map(|a| WiseAddressDetails {
country: a.country,
country_code: a.country,
@@ -309,7 +309,7 @@ fn get_payout_address_details(
#[cfg(feature = "payouts")]
fn get_payout_bank_details(
payout_method_data: PayoutMethodData,
- address: &Option<api_models::payments::Address>,
+ address: Option<&api_models::payments::Address>,
entity_type: PayoutEntityType,
) -> Result<WiseBankDetails, errors::ConnectorError> {
let wise_address_details = match get_payout_address_details(address) {
@@ -357,7 +357,7 @@ impl<F> TryFrom<&types::PayoutsRouterData<F>> for WiseRecipientCreateRequest {
let payout_method_data = item.get_payout_method_data()?;
let bank_details = get_payout_bank_details(
payout_method_data.to_owned(),
- &item.address.billing,
+ item.get_optional_billing(),
item.request.entity_type,
)?;
let source_id = match item.connector_auth_type.to_owned() {
diff --git a/crates/router/src/connector/worldline/transformers.rs b/crates/router/src/connector/worldline/transformers.rs
index 1eb22fc52d..ab9dabb3e2 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},
+ connector::utils::{self, BankRedirectBillingData, CardData, RouterData},
core::errors,
services,
types::{
@@ -263,8 +263,9 @@ impl
))?,
};
- let customer =
- build_customer_info(&item.router_data.address, &item.router_data.request.email)?;
+ let billing_address = item.router_data.get_billing()?;
+
+ let customer = build_customer_info(billing_address, &item.router_data.request.email)?;
let order = Order {
amount_of_money: AmountOfMoney {
amount: item.amount,
@@ -278,9 +279,7 @@ impl
let shipping = item
.router_data
- .address
- .shipping
- .as_ref()
+ .get_optional_shipping()
.and_then(|shipping| shipping.address.clone())
.map(Shipping::from);
Ok(Self {
@@ -436,20 +435,19 @@ fn make_bank_redirect_request(
}
fn get_address(
- payment_address: &types::PaymentAddress,
+ billing: &payments::Address,
) -> Option<(&payments::Address, &payments::AddressDetails)> {
- let billing = payment_address.billing.as_ref()?;
let address = billing.address.as_ref()?;
address.country.as_ref()?;
Some((billing, address))
}
fn build_customer_info(
- payment_address: &types::PaymentAddress,
+ billing_address: &payments::Address,
email: &Option<Email>,
) -> Result<Customer, error_stack::Report<errors::ConnectorError>> {
let (billing, address) =
- get_address(payment_address).ok_or(errors::ConnectorError::MissingRequiredField {
+ get_address(billing_address).ok_or(errors::ConnectorError::MissingRequiredField {
field_name: "billing.address.country",
})?;
diff --git a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
index f13c674eca..874e1bde32 100644
--- a/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
+++ b/crates/router/src/core/payment_methods/surcharge_decision_configs.rs
@@ -259,7 +259,7 @@ where
let mut backend_input = make_dsl_input_for_surcharge(
&payment_data.payment_attempt,
&payment_data.payment_intent,
- payment_data.address.billing.clone(),
+ payment_data.address.get_payment_method_billing().cloned(),
)
.change_context(ConfigError::InputConstructionError)?;
for payment_method_type in payment_method_type_list {
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 2544bffda7..18f75f467d 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -24,6 +24,7 @@ use error_stack::{IntoReport, ResultExt};
use futures::future::join_all;
use helpers::ApplePayData;
use masking::Secret;
+pub use payment_address::PaymentAddress;
use redis_interface::errors::RedisError;
use router_env::{instrument, tracing};
#[cfg(feature = "olap")]
@@ -2034,11 +2035,52 @@ pub enum CallConnectorAction {
HandleResponse(Vec<u8>),
}
-#[derive(Clone, Default, Debug)]
-pub struct PaymentAddress {
- pub shipping: Option<api::Address>,
- pub billing: Option<api::Address>,
- pub payment_method_billing: Option<api::Address>,
+pub mod payment_address {
+ use super::*;
+
+ #[derive(Clone, Default, Debug)]
+ pub struct PaymentAddress {
+ shipping: Option<api::Address>,
+ billing: Option<api::Address>,
+ payment_method_billing: Option<api::Address>,
+ }
+
+ impl PaymentAddress {
+ pub fn new(
+ shipping: Option<api::Address>,
+ billing: Option<api::Address>,
+ payment_method_billing: Option<api::Address>,
+ ) -> Self {
+ let payment_method_billing = match (payment_method_billing, billing.clone()) {
+ (Some(payment_method_billing), Some(order_billing)) => Some(api::Address {
+ address: payment_method_billing.address.or(order_billing.address),
+ phone: payment_method_billing.phone.or(order_billing.phone),
+ email: payment_method_billing.email.or(order_billing.email),
+ }),
+ (Some(payment_method_billing), None) => Some(payment_method_billing),
+ (None, Some(order_billing)) => Some(order_billing),
+ (None, None) => None,
+ };
+
+ Self {
+ shipping,
+ billing,
+ payment_method_billing,
+ }
+ }
+
+ pub fn get_shipping(&self) -> Option<&api::Address> {
+ self.shipping.as_ref()
+ }
+
+ pub fn get_payment_method_billing(&self) -> Option<&api::Address> {
+ self.payment_method_billing.as_ref()
+ }
+
+ pub fn get_payment_billing(&self) -> Option<&api::Address> {
+ self.billing.as_ref()
+ }
+ }
}
#[derive(Clone)]
@@ -2980,8 +3022,7 @@ where
state: &state,
country: payment_data
.address
- .billing
- .as_ref()
+ .get_payment_method_billing()
.and_then(|address| address.address.as_ref())
.and_then(|details| details.country),
key_store,
diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs
index 6ad14d8fc4..ba270e1d00 100644
--- a/crates/router/src/core/payments/operations/payment_approve.rs
+++ b/crates/router/src/core/payments/operations/payment_approve.rs
@@ -11,8 +11,7 @@ use crate::{
core::{
errors::{self, RouterResult, StorageErrorExt},
payment_methods::PaymentMethodRetrieve,
- payments::{helpers, operations, PaymentAddress, PaymentData},
- utils as core_utils,
+ payments::{helpers, operations, PaymentData},
},
routes::AppState,
services,
@@ -20,6 +19,7 @@ use crate::{
api::{self, PaymentIdTypeExt},
domain,
storage::{self, enums as storage_enums},
+ PaymentAddress,
},
utils::OptionExt,
};
@@ -150,13 +150,11 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
customer_acceptance: None,
token: None,
token_data: None,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
confirm: None,
payment_method_data: None,
payment_method_info: None,
@@ -258,7 +256,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
operations::ValidateResult {
merchant_id: &merchant_account.merchant_id,
payment_id: api::PaymentIdType::PaymentIntentId(
- core_utils::validate_id(request.payment_id.clone(), "payment_id")
+ crate::core::utils::validate_id(request.payment_id.clone(), "payment_id")
.into_report()?,
),
mandate_type: None,
diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs
index 2439646b3d..8072984e20 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -12,11 +12,12 @@ use crate::{
core::{
errors::{self, RouterResult, StorageErrorExt},
payment_methods::PaymentMethodRetrieve,
- payments::{helpers, operations, PaymentAddress, PaymentData},
+ payments::{helpers, operations, PaymentData},
},
routes::AppState,
services,
types::{
+ self as core_types,
api::{self, PaymentIdTypeExt},
domain,
storage::{self, enums},
@@ -158,13 +159,11 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
customer_acceptance: None,
token: None,
token_data: None,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
+ address: core_types::PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
confirm: None,
payment_method_data: None,
payment_method_info: None,
diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs
index d643c86698..9e6751757a 100644
--- a/crates/router/src/core/payments/operations/payment_capture.rs
+++ b/crates/router/src/core/payments/operations/payment_capture.rs
@@ -16,6 +16,7 @@ use crate::{
routes::AppState,
services,
types::{
+ self as core_types,
api::{self, PaymentIdTypeExt},
domain,
storage::{self, enums, payment_attempt::PaymentAttemptExt},
@@ -203,13 +204,11 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
customer_acceptance: None,
token: None,
token_data: None,
- address: payments::PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
+ address: core_types::PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
confirm: None,
payment_method_data: None,
payment_method_info: None,
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index 79701db575..4e38294d4d 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -254,13 +254,11 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
customer_acceptance: None,
token,
token_data,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
confirm: request.confirm,
payment_method_data: request
.payment_method_data
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 96de0cc924..27b0be398d 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -565,14 +565,12 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
setup_mandate,
customer_acceptance,
token,
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
token_data,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
confirm: request.confirm,
payment_method_data: payment_method_data_after_card_bin_call,
payment_method_info,
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index bcc13ea1ce..a6fe86622a 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -390,14 +390,12 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
setup_mandate,
customer_acceptance,
token,
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing_address.as_ref().map(From::from),
+ ),
token_data: None,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing_address
- .as_ref()
- .map(|address| address.into()),
- },
confirm: request.confirm,
payment_method_data: payment_method_data_after_card_bin_call,
payment_method_info: None,
diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs
index 36197a9463..b59e87b826 100644
--- a/crates/router/src/core/payments/operations/payment_reject.rs
+++ b/crates/router/src/core/payments/operations/payment_reject.rs
@@ -145,14 +145,12 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
setup_mandate: None,
customer_acceptance: None,
token: None,
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
token_data: None,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
confirm: None,
payment_method_data: None,
payment_method_info: None,
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index d498e1baca..7129645601 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -171,13 +171,11 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
token: None,
token_data: None,
setup_mandate: None,
- address: payments::PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
+ address: payments::PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
confirm: None,
payment_method_data: None,
payment_method_info: None,
diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs
index f1264868ff..ee85ffa8a5 100644
--- a/crates/router/src/core/payments/operations/payment_start.rs
+++ b/crates/router/src/core/payments/operations/payment_start.rs
@@ -156,14 +156,12 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
setup_mandate: None,
customer_acceptance: None,
token: payment_attempt.payment_token.clone(),
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
token_data,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
confirm: Some(payment_attempt.confirm),
payment_attempt,
payment_method_data: None,
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index 66f0527c35..f410288b0e 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -417,14 +417,12 @@ async fn get_tracker_for_sync<
setup_mandate: None,
customer_acceptance: None,
token: None,
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
token_data: None,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing
- .as_ref()
- .map(|address| address.into()),
- },
confirm: Some(request.force_sync),
payment_method_data: None,
payment_method_info: None,
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 0ce77dfcd1..baba952928 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -392,11 +392,11 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
token_data,
setup_mandate,
customer_acceptance,
- address: PaymentAddress {
- shipping: shipping_address.as_ref().map(|a| a.into()),
- billing: billing_address.as_ref().map(|a| a.into()),
- payment_method_billing: payment_method_billing.as_ref().map(|a| a.into()),
- },
+ address: PaymentAddress::new(
+ shipping_address.as_ref().map(From::from),
+ billing_address.as_ref().map(From::from),
+ payment_method_billing.as_ref().map(From::from),
+ ),
confirm: request.confirm,
payment_method_data: request
.payment_method_data
diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
index 0157822cdf..d60e56de66 100644
--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs
@@ -123,11 +123,7 @@ impl<F: Send + Clone, Ctx: PaymentMethodRetrieve>
customer_acceptance: None,
token: None,
token_data: None,
- address: PaymentAddress {
- billing: None,
- shipping: None,
- payment_method_billing: None,
- },
+ address: PaymentAddress::new(None, None, None),
confirm: None,
payment_method_data: None,
payment_method_info: None,
diff --git a/crates/router/src/core/payments/routing.rs b/crates/router/src/core/payments/routing.rs
index 983313592a..d8a23ce916 100644
--- a/crates/router/src/core/payments/routing.rs
+++ b/crates/router/src/core/payments/routing.rs
@@ -233,8 +233,7 @@ where
.map(api_enums::Country::from_alpha2),
billing_country: payment_data
.address
- .billing
- .as_ref()
+ .get_payment_method_billing()
.and_then(|bic| bic.address.as_ref())
.and_then(|add| add.country)
.map(api_enums::Country::from_alpha2),
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 0ae04aaddc..40aff26503 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -462,7 +462,7 @@ where
let payment_method_data_response = payment_method_data.map(|payment_method_data| {
api_models::payments::PaymentMethodDataResponseWithBilling {
payment_method_data,
- billing: payment_data.address.payment_method_billing,
+ billing: payment_data.address.get_payment_method_billing().cloned(),
}
});
@@ -678,8 +678,8 @@ where
.or(payment_attempt.error_message),
)
.set_error_code(payment_attempt.error_code)
- .set_shipping(payment_data.address.shipping)
- .set_billing(payment_data.address.billing)
+ .set_shipping(payment_data.address.get_shipping().cloned())
+ .set_billing(payment_data.address.get_payment_billing().cloned())
.set_next_action(next_action_response)
.set_return_url(payment_intent.return_url)
.set_cancellation_reason(payment_attempt.cancellation_reason)
@@ -769,8 +769,8 @@ where
.as_ref()
.and_then(|cus| cus.phone.as_ref().map(|s| s.to_owned())),
mandate_id,
- shipping: payment_data.address.shipping,
- billing: payment_data.address.billing,
+ shipping: payment_data.address.get_shipping().cloned(),
+ billing: payment_data.address.get_payment_billing().cloned(),
cancellation_reason: payment_attempt.cancellation_reason,
payment_token: payment_attempt.payment_token,
metadata: payment_intent.metadata,
@@ -1395,9 +1395,14 @@ impl<F: Clone> TryFrom<PaymentAdditionalData<'_, F>> for types::PaymentsSessionD
Ok(Self {
amount,
currency: payment_data.currency,
- country: payment_data.address.billing.and_then(|billing_address| {
- billing_address.address.and_then(|address| address.country)
- }),
+ country: payment_data.address.get_payment_method_billing().and_then(
+ |billing_address| {
+ billing_address
+ .address
+ .as_ref()
+ .and_then(|address| address.country)
+ },
+ ),
order_details,
surcharge_details: payment_data.surcharge_details,
})
diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs
index 80a0c285e4..62d34b1306 100644
--- a/crates/router/src/core/refunds.rs
+++ b/crates/router/src/core/refunds.rs
@@ -891,7 +891,7 @@ pub async fn sync_refund_with_gateway_workflow(
.find_merchant_account_by_merchant_id(&refund_core.merchant_id, &key_store)
.await?;
- let response = refund_retrieve_core(
+ let response = Box::pin(refund_retrieve_core(
state.clone(),
merchant_account,
key_store,
@@ -900,7 +900,7 @@ pub async fn sync_refund_with_gateway_workflow(
force_sync: Some(true),
merchant_connector_details: None,
},
- )
+ ))
.await?;
let terminal_status = [
enums::RefundStatus::Success,
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 9750ed8521..93e8b51a40 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -86,33 +86,31 @@ pub async fn construct_payout_router_data<'a, F>(
let billing = payout_data.billing_address.to_owned();
- let address = PaymentAddress {
- shipping: None,
- billing: billing.map(|a| {
- let phone_details = api_models::payments::PhoneDetails {
- number: a.phone_number.clone().map(Encryptable::into_inner),
- country_code: a.country_code.to_owned(),
- };
- let address_details = api_models::payments::AddressDetails {
- city: a.city.to_owned(),
- country: a.country.to_owned(),
- line1: a.line1.clone().map(Encryptable::into_inner),
- line2: a.line2.clone().map(Encryptable::into_inner),
- line3: a.line3.clone().map(Encryptable::into_inner),
- zip: a.zip.clone().map(Encryptable::into_inner),
- first_name: a.first_name.clone().map(Encryptable::into_inner),
- last_name: a.last_name.clone().map(Encryptable::into_inner),
- state: a.state.map(Encryptable::into_inner),
- };
-
- api_models::payments::Address {
- phone: Some(phone_details),
- address: Some(address_details),
- email: a.email.to_owned().map(Email::from),
- }
- }),
- payment_method_billing: None,
- };
+ let billing_address = billing.map(|a| {
+ let phone_details = api_models::payments::PhoneDetails {
+ number: a.phone_number.clone().map(Encryptable::into_inner),
+ country_code: a.country_code.to_owned(),
+ };
+ let address_details = api_models::payments::AddressDetails {
+ city: a.city.to_owned(),
+ country: a.country.to_owned(),
+ line1: a.line1.clone().map(Encryptable::into_inner),
+ line2: a.line2.clone().map(Encryptable::into_inner),
+ line3: a.line3.clone().map(Encryptable::into_inner),
+ zip: a.zip.clone().map(Encryptable::into_inner),
+ first_name: a.first_name.clone().map(Encryptable::into_inner),
+ last_name: a.last_name.clone().map(Encryptable::into_inner),
+ state: a.state.map(Encryptable::into_inner),
+ };
+
+ api_models::payments::Address {
+ phone: Some(phone_details),
+ address: Some(address_details),
+ email: a.email.to_owned().map(Email::from),
+ }
+ });
+
+ let address = PaymentAddress::new(None, billing_address, None);
let test_mode: Option<bool> = merchant_connector_account.is_test_mode_on();
let payouts = &payout_data.payouts;
diff --git a/crates/router/src/core/webhooks.rs b/crates/router/src/core/webhooks.rs
index 8d03bea06c..1db2fb88fa 100644
--- a/crates/router/src/core/webhooks.rs
+++ b/crates/router/src/core/webhooks.rs
@@ -255,7 +255,7 @@ pub async fn refunds_incoming_webhook_flow(
.to_not_found_response(errors::ApiErrorResponse::WebhookResourceNotFound)
.attach_printable_lazy(|| format!("Failed while updating refund: refund_id: {refund_id}"))?
} else {
- refunds::refund_retrieve_core(
+ Box::pin(refunds::refund_retrieve_core(
state.clone(),
merchant_account.clone(),
key_store,
@@ -264,7 +264,7 @@ pub async fn refunds_incoming_webhook_flow(
force_sync: Some(true),
merchant_connector_details: None,
},
- )
+ ))
.await
.attach_printable_lazy(|| format!("Failed while updating refund: refund_id: {refund_id}"))?
};
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index 2f4cd99b1f..5a24e4ff7c 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -31,7 +31,7 @@ use masking::Secret;
use serde::Serialize;
use self::{api::payments, storage::enums as storage_enums};
-pub use crate::core::payments::{CustomerDetails, PaymentAddress};
+pub use crate::core::payments::{payment_address::PaymentAddress, CustomerDetails};
#[cfg(feature = "payouts")]
use crate::core::utils::IRRELEVANT_CONNECTOR_REQUEST_REFERENCE_ID_IN_DISPUTE_FLOW;
use crate::{
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index edc82a078e..bf2053353a 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -90,11 +90,7 @@ impl VerifyConnectorData {
recurring_mandate_payment_data: None,
payment_method_status: None,
connector_request_reference_id: attempt_id,
- address: types::PaymentAddress {
- shipping: None,
- billing: None,
- payment_method_billing: None,
- },
+ address: types::PaymentAddress::new(None, None, None),
payment_id: common_utils::generate_id_with_default_len(
consts::VERIFY_CONNECTOR_ID_PREFIX,
),
diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs
index 29f924fc65..62ea50c9dd 100644
--- a/crates/router/src/types/transformers.rs
+++ b/crates/router/src/types/transformers.rs
@@ -582,8 +582,19 @@ impl<'a> ForeignFrom<&'a api_types::ConfigUpdate> for storage::ConfigUpdate {
impl<'a> From<&'a domain::Address> for api_types::Address {
fn from(address: &domain::Address) -> Self {
- Self {
- address: Some(api_types::AddressDetails {
+ // If all the fields of address are none, then
+ let address_details = if address.city.is_none()
+ && address.line1.is_none()
+ && address.line2.is_none()
+ && address.line3.is_none()
+ && address.state.is_none()
+ && address.zip.is_none()
+ && address.first_name.is_none()
+ && address.last_name.is_none()
+ {
+ None
+ } else {
+ Some(api_types::AddressDetails {
city: address.city.clone(),
country: address.country,
line1: address.line1.clone().map(Encryptable::into_inner),
@@ -593,7 +604,11 @@ impl<'a> From<&'a domain::Address> for api_types::Address {
zip: address.zip.clone().map(Encryptable::into_inner),
first_name: address.first_name.clone().map(Encryptable::into_inner),
last_name: address.last_name.clone().map(Encryptable::into_inner),
- }),
+ })
+ };
+
+ Self {
+ address: address_details,
phone: Some(api_types::PhoneDetails {
number: address.phone_number.clone().map(Encryptable::into_inner),
country_code: address.country_code.clone(),
diff --git a/crates/router/tests/connectors/adyen.rs b/crates/router/tests/connectors/adyen.rs
index 80aa57f911..d1b0a3858e 100644
--- a/crates/router/tests/connectors/adyen.rs
+++ b/crates/router/tests/connectors/adyen.rs
@@ -51,8 +51,9 @@ impl utils::Connector for AdyenTest {
impl AdyenTest {
fn get_payment_info() -> Option<PaymentInfo> {
Some(PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
country: Some(api_models::enums::CountryAlpha2::US),
state: Some(Secret::new("California".to_string())),
@@ -65,8 +66,8 @@ impl AdyenTest {
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
@@ -78,8 +79,9 @@ impl AdyenTest {
Some(PaymentInfo {
country: Some(api_models::enums::CountryAlpha2::NL),
currency: Some(enums::Currency::EUR),
- address: Some(PaymentAddress {
- billing: Some(Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
country: Some(api_models::enums::CountryAlpha2::US),
state: Some(Secret::new("California".to_string())),
@@ -92,8 +94,8 @@ impl AdyenTest {
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
payout_method_data: match payout_type {
enums::PayoutType::Card => {
Some(api::PayoutMethodData::Card(api::payouts::CardPayout {
diff --git a/crates/router/tests/connectors/bitpay.rs b/crates/router/tests/connectors/bitpay.rs
index e343cb4775..d26a4c0cd6 100644
--- a/crates/router/tests/connectors/bitpay.rs
+++ b/crates/router/tests/connectors/bitpay.rs
@@ -39,8 +39,9 @@ static CONNECTOR: BitpayTest = BitpayTest {};
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(api::Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -57,8 +58,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
}),
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
diff --git a/crates/router/tests/connectors/bluesnap.rs b/crates/router/tests/connectors/bluesnap.rs
index 622d835e83..ac89e4e6ea 100644
--- a/crates/router/tests/connectors/bluesnap.rs
+++ b/crates/router/tests/connectors/bluesnap.rs
@@ -46,8 +46,9 @@ fn payment_method_details() -> Option<types::PaymentsAuthorizeData> {
}
fn get_payment_info() -> Option<PaymentInfo> {
Some(PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
first_name: Some(Secret::new("joseph".to_string())),
last_name: Some(Secret::new("Doe".to_string())),
@@ -56,8 +57,8 @@ fn get_payment_info() -> Option<PaymentInfo> {
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
diff --git a/crates/router/tests/connectors/cashtocode.rs b/crates/router/tests/connectors/cashtocode.rs
index 9404641c68..c8dd4abff2 100644
--- a/crates/router/tests/connectors/cashtocode.rs
+++ b/crates/router/tests/connectors/cashtocode.rs
@@ -77,8 +77,9 @@ impl CashtocodeTest {
fn get_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(types::PaymentAddress {
- billing: Some(Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
country: Some(api_models::enums::CountryAlpha2::US),
..Default::default()
@@ -86,8 +87,8 @@ impl CashtocodeTest {
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
return_url: Some("https://google.com".to_owned()),
..Default::default()
})
diff --git a/crates/router/tests/connectors/coinbase.rs b/crates/router/tests/connectors/coinbase.rs
index 2492ed0c93..a88f138094 100644
--- a/crates/router/tests/connectors/coinbase.rs
+++ b/crates/router/tests/connectors/coinbase.rs
@@ -40,8 +40,9 @@ static CONNECTOR: CoinbaseTest = CoinbaseTest {};
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(api::Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -58,8 +59,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
}),
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
connector_meta_data: Some(json!({"pricing_type": "fixed_price"})),
..Default::default()
})
diff --git a/crates/router/tests/connectors/cryptopay.rs b/crates/router/tests/connectors/cryptopay.rs
index c1bb499ecc..4d7825f7de 100644
--- a/crates/router/tests/connectors/cryptopay.rs
+++ b/crates/router/tests/connectors/cryptopay.rs
@@ -39,8 +39,9 @@ static CONNECTOR: CryptopayTest = CryptopayTest {};
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(api::Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -57,8 +58,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
}),
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
return_url: Some(String::from("https://google.com")),
..Default::default()
})
diff --git a/crates/router/tests/connectors/cybersource.rs b/crates/router/tests/connectors/cybersource.rs
index 617b184156..d438ff45f6 100644
--- a/crates/router/tests/connectors/cybersource.rs
+++ b/crates/router/tests/connectors/cybersource.rs
@@ -38,8 +38,9 @@ impl utils::Connector for Cybersource {
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(types::PaymentAddress {
- billing: Some(api::Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -56,8 +57,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
}),
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
diff --git a/crates/router/tests/connectors/dlocal.rs b/crates/router/tests/connectors/dlocal.rs
index 992b1ae6ce..0767bb9ac3 100644
--- a/crates/router/tests/connectors/dlocal.rs
+++ b/crates/router/tests/connectors/dlocal.rs
@@ -420,9 +420,9 @@ async fn should_fail_for_refund_amount_higher_than_payment_amount() {
pub fn get_payment_info() -> PaymentInfo {
PaymentInfo {
- address: Some(PaymentAddress {
- shipping: None,
- billing: Some(Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(Address {
phone: None,
address: Some(api::AddressDetails {
city: None,
@@ -437,8 +437,8 @@ pub fn get_payment_info() -> PaymentInfo {
}),
email: None,
}),
- payment_method_billing: None,
- }),
+ None,
+ )),
auth_type: None,
access_token: None,
connector_meta_data: None,
diff --git a/crates/router/tests/connectors/forte.rs b/crates/router/tests/connectors/forte.rs
index e017a11ff5..19dbaa26f3 100644
--- a/crates/router/tests/connectors/forte.rs
+++ b/crates/router/tests/connectors/forte.rs
@@ -51,8 +51,9 @@ fn get_payment_data() -> Option<types::PaymentsAuthorizeData> {
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(types::PaymentAddress {
- billing: Some(api::Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -69,8 +70,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
}),
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
diff --git a/crates/router/tests/connectors/globalpay.rs b/crates/router/tests/connectors/globalpay.rs
index 7cfd691c03..8afa2f0ccf 100644
--- a/crates/router/tests/connectors/globalpay.rs
+++ b/crates/router/tests/connectors/globalpay.rs
@@ -57,8 +57,9 @@ impl Globalpay {
}
fn get_payment_info() -> Option<PaymentInfo> {
Some(PaymentInfo {
- address: Some(types::PaymentAddress {
- billing: Some(api::Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
country: Some(api_models::enums::CountryAlpha2::US),
..Default::default()
@@ -66,8 +67,8 @@ impl Globalpay {
phone: None,
..Default::default()
}),
- ..Default::default()
- }),
+ None,
+ )),
access_token: get_access_token(),
connector_meta_data: CONNECTOR.get_connector_meta(),
..Default::default()
diff --git a/crates/router/tests/connectors/iatapay.rs b/crates/router/tests/connectors/iatapay.rs
index d138fe8518..d685756094 100644
--- a/crates/router/tests/connectors/iatapay.rs
+++ b/crates/router/tests/connectors/iatapay.rs
@@ -1,5 +1,5 @@
use masking::Secret;
-use router::types::{self, api, storage::enums, AccessToken, PaymentAddress};
+use router::types::{self, api, storage::enums, AccessToken};
use crate::{
connector_auth,
@@ -55,8 +55,9 @@ static CONNECTOR: IatapayTest = IatapayTest {};
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(api::Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -73,8 +74,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
}),
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
access_token: get_access_token(),
return_url: Some(String::from("https://hyperswitch.io")),
..Default::default()
diff --git a/crates/router/tests/connectors/multisafepay.rs b/crates/router/tests/connectors/multisafepay.rs
index 393074ee63..98b615b803 100644
--- a/crates/router/tests/connectors/multisafepay.rs
+++ b/crates/router/tests/connectors/multisafepay.rs
@@ -38,9 +38,9 @@ impl utils::Connector for MultisafepayTest {
static CONNECTOR: MultisafepayTest = MultisafepayTest {};
fn get_default_payment_info() -> Option<PaymentInfo> {
- let address = Some(PaymentAddress {
- shipping: None,
- billing: Some(Address {
+ let address = Some(PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
first_name: Some(Secret::new("John".to_string())),
last_name: Some(Secret::new("Doe".to_string())),
@@ -55,8 +55,8 @@ fn get_default_payment_info() -> Option<PaymentInfo> {
phone: None,
email: None,
}),
- payment_method_billing: None,
- });
+ None,
+ ));
Some(PaymentInfo {
address,
..utils::PaymentInfo::default()
diff --git a/crates/router/tests/connectors/opennode.rs b/crates/router/tests/connectors/opennode.rs
index 3cae40c91a..b01b251b24 100644
--- a/crates/router/tests/connectors/opennode.rs
+++ b/crates/router/tests/connectors/opennode.rs
@@ -1,6 +1,6 @@
use api_models::payments::CryptoData;
use masking::Secret;
-use router::types::{self, api, storage::enums, PaymentAddress};
+use router::types::{self, api, storage::enums};
use crate::{
connector_auth,
@@ -39,8 +39,9 @@ static CONNECTOR: OpennodeTest = OpennodeTest {};
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(api::Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -57,8 +58,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
}),
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
return_url: Some(String::from("https://google.com")),
..Default::default()
})
diff --git a/crates/router/tests/connectors/payeezy.rs b/crates/router/tests/connectors/payeezy.rs
index d05d065bcd..0cdf709f36 100644
--- a/crates/router/tests/connectors/payeezy.rs
+++ b/crates/router/tests/connectors/payeezy.rs
@@ -56,16 +56,17 @@ impl PayeezyTest {
fn get_payment_info() -> Option<PaymentInfo> {
Some(PaymentInfo {
- address: Some(types::PaymentAddress {
- billing: Some(Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
..Default::default()
}),
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
diff --git a/crates/router/tests/connectors/payme.rs b/crates/router/tests/connectors/payme.rs
index 26f8469321..6398b9da57 100644
--- a/crates/router/tests/connectors/payme.rs
+++ b/crates/router/tests/connectors/payme.rs
@@ -42,9 +42,9 @@ static CONNECTOR: PaymeTest = PaymeTest {};
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(PaymentAddress {
- shipping: None,
- billing: Some(Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
city: None,
country: None,
@@ -59,8 +59,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
phone: None,
email: None,
}),
- payment_method_billing: None,
- }),
+ None,
+ )),
auth_type: None,
access_token: None,
connector_meta_data: None,
diff --git a/crates/router/tests/connectors/trustpay.rs b/crates/router/tests/connectors/trustpay.rs
index 560b7ba0b5..cf659e349d 100644
--- a/crates/router/tests/connectors/trustpay.rs
+++ b/crates/router/tests/connectors/trustpay.rs
@@ -67,8 +67,9 @@ fn get_default_payment_authorize_data() -> Option<types::PaymentsAuthorizeData>
fn get_default_payment_info() -> Option<utils::PaymentInfo> {
Some(utils::PaymentInfo {
- address: Some(types::PaymentAddress {
- billing: Some(api::Address {
+ address: Some(types::PaymentAddress::new(
+ None,
+ Some(api::Address {
address: Some(api::AddressDetails {
first_name: Some(Secret::new("first".to_string())),
last_name: Some(Secret::new("last".to_string())),
@@ -82,8 +83,8 @@ fn get_default_payment_info() -> Option<utils::PaymentInfo> {
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
diff --git a/crates/router/tests/connectors/wise.rs b/crates/router/tests/connectors/wise.rs
index 0ac112169b..b85fb4f1c9 100644
--- a/crates/router/tests/connectors/wise.rs
+++ b/crates/router/tests/connectors/wise.rs
@@ -57,8 +57,9 @@ impl WiseTest {
Some(PaymentInfo {
country: Some(api_models::enums::CountryAlpha2::NL),
currency: Some(enums::Currency::GBP),
- address: Some(PaymentAddress {
- billing: Some(Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
country: Some(api_models::enums::CountryAlpha2::GB),
city: Some("London".to_string()),
@@ -69,8 +70,8 @@ impl WiseTest {
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
payout_method_data: Some(api::PayoutMethodData::Bank(api::payouts::BankPayout::Bacs(
api::BacsBankTransfer {
bank_sort_code: "231470".to_string().into(),
diff --git a/crates/router/tests/connectors/worldline.rs b/crates/router/tests/connectors/worldline.rs
index 39c305849a..c81dcf15bd 100644
--- a/crates/router/tests/connectors/worldline.rs
+++ b/crates/router/tests/connectors/worldline.rs
@@ -43,8 +43,9 @@ impl utils::Connector for WorldlineTest {
impl WorldlineTest {
fn get_payment_info() -> Option<PaymentInfo> {
Some(PaymentInfo {
- address: Some(PaymentAddress {
- billing: Some(Address {
+ address: Some(PaymentAddress::new(
+ None,
+ Some(Address {
address: Some(AddressDetails {
country: Some(api_models::enums::CountryAlpha2::US),
..Default::default()
@@ -52,8 +53,8 @@ impl WorldlineTest {
phone: None,
email: None,
}),
- ..Default::default()
- }),
+ None,
+ )),
..Default::default()
})
}
@@ -177,9 +178,7 @@ async fn should_throw_missing_required_field_for_country() {
.make_payment(
authorize_data,
Some(PaymentInfo {
- address: Some(PaymentAddress {
- ..Default::default()
- }),
+ address: Some(PaymentAddress::new(None, None, None)),
..Default::default()
}),
)