diff --git a/crates/router/src/connector/gocardless/transformers.rs b/crates/router/src/connector/gocardless/transformers.rs index 222855db6710..e8e7b1ebc246 100644 --- a/crates/router/src/connector/gocardless/transformers.rs +++ b/crates/router/src/connector/gocardless/transformers.rs @@ -1,6 +1,6 @@ use api_models::{ - enums::{BankType, CountryAlpha2}, - payments::BankDebitData, + enums::{BankType, CountryAlpha2, UsStatesAbbreviation}, + payments::{AddressDetails, BankDebitData}, }; use common_utils::pii::{self, IpAddress}; use masking::{ExposeInterface, Secret}; @@ -12,7 +12,7 @@ use crate::{ ConnectorCustomerData, PaymentsAuthorizeRequestData, PaymentsPreProcessingData, RouterData, }, core::errors, - types::{self, api, storage::enums, MandateReference}, + types::{self, api, storage::enums, transformers::ForeignTryFrom, MandateReference}, }; pub struct GocardlessRouterData { @@ -55,6 +55,7 @@ pub struct GocardlessCustomer { address_line2: Option>, address_line3: Option>, city: Option>, + region: Option>, country_code: Option, email: pii::Email, given_name: Secret, @@ -80,6 +81,7 @@ impl TryFrom<&types::ConnectorCustomerRouterData> for GocardlessCustomerRequest let metadata = CustomerMetaData { crm_id: item.customer_id.clone().map(Secret::new), }; + let region = get_region(billing_address)?; Ok(Self { customers: GocardlessCustomer { email, @@ -90,6 +92,7 @@ impl TryFrom<&types::ConnectorCustomerRouterData> for GocardlessCustomerRequest address_line2: billing_address.line2.to_owned(), address_line3: billing_address.line3.to_owned(), country_code: billing_address.country, + region, // Should be populated based on the billing country danish_identity_number: None, postal_code: billing_address.zip.to_owned(), @@ -101,6 +104,20 @@ impl TryFrom<&types::ConnectorCustomerRouterData> for GocardlessCustomerRequest } } +fn get_region( + address_details: &AddressDetails, +) -> Result>, error_stack::Report> { + match address_details.country { + Some(CountryAlpha2::US) => { + let state = address_details.get_state()?.to_owned(); + Ok(Some(Secret::new( + UsStatesAbbreviation::foreign_try_from(state.expose())?.to_string(), + ))) + } + _ => Ok(None), + } +} + #[derive(Debug, Clone, Deserialize)] pub struct GocardlessCustomerResponse { customers: Customers,