Skip to content

Commit

Permalink
fix: [Gocardless] add region in customer create request based on coun…
Browse files Browse the repository at this point in the history
…try (#2389)
  • Loading branch information
ArjunKarthik authored Sep 28, 2023
1 parent c5ebb89 commit c293cb6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions crates/router/src/connector/gocardless/transformers.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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> {
Expand Down Expand Up @@ -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>,
Expand All @@ -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,
Expand All @@ -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(),
Expand All @@ -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,
Expand Down

0 comments on commit c293cb6

Please sign in to comment.