mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
fix: [Gocardless] add region in customer create request based on country (#2389)
This commit is contained in:
@ -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<T> {
|
||||
@ -55,6 +55,7 @@ pub struct GocardlessCustomer {
|
||||
address_line2: Option<Secret<String>>,
|
||||
address_line3: Option<Secret<String>>,
|
||||
city: Option<Secret<String>>,
|
||||
region: Option<Secret<String>>,
|
||||
country_code: Option<CountryAlpha2>,
|
||||
email: pii::Email,
|
||||
given_name: Secret<String>,
|
||||
@ -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<Option<Secret<String>>, error_stack::Report<errors::ConnectorError>> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user