Skip to content

Commit

Permalink
use shipping address
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrudul Vajpayee authored and Mrudul Vajpayee committed Nov 13, 2024
1 parent a365645 commit 25455f0
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,30 @@ pub struct Order {
#[serde(rename_all = "camelCase")]
pub struct CustomerInfo {
card_holder_name: Secret<String>,
billing_address: Address,
shipping_address: Option<Address>,
billing_address: BillingAddress,
shipping_address: Option<ShippingAddress>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Address {
pub struct BillingAddress {
name: Secret<String>,
street: Secret<String>,
city: String,
post_code: Secret<String>,
country: enums::CountryAlpha2,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ShippingAddress {
name: Option<Secret<String>>,
street: Option<Secret<String>>,
city: Option<String>,
post_code: Option<Secret<String>>,
country: Option<enums::CountryAlpha2>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NexixpayCard {
Expand Down Expand Up @@ -435,17 +445,47 @@ impl TryFrom<&NexixpayRouterData<&PaymentsAuthorizeRouterData>> for NexixpayPaym
fn try_from(
item: &NexixpayRouterData<&PaymentsAuthorizeRouterData>,
) -> Result<Self, Self::Error> {
let billing_address = Address {
let billing_address_street = format!(
"{}, {}",
item.router_data.get_billing_line1()?.expose(),
item.router_data.get_billing_line2()?.expose()
);

let billing_address = BillingAddress {
name: item.router_data.get_billing_full_name()?,
street: item.router_data.get_billing_line1()?,
street: Secret::new(billing_address_street),
city: item.router_data.get_billing_city()?,
post_code: item.router_data.get_billing_zip()?,
country: item.router_data.get_billing_country()?,
};
let shipping_address_street = match (
item.router_data.get_optional_shipping_line1(),
item.router_data.get_optional_shipping_line2(),
) {
(Some(line1), Some(line2)) => Some(Secret::new(format!(
"{}, {}",
line1.expose(),
line2.expose()
))),
(Some(line1), None) => Some(Secret::new(line1.expose())),
(None, Some(line2)) => Some(Secret::new(line2.expose())),
(None, None) => None,
};

let shipping_address = item
.router_data
.get_optional_billing()
.map(|_| ShippingAddress {
name: item.router_data.get_optional_shipping_full_name(),
street: shipping_address_street,
city: item.router_data.get_optional_shipping_city(),
post_code: item.router_data.get_optional_shipping_zip(),
country: item.router_data.get_optional_shipping_country(),
});
let customer_info = CustomerInfo {
card_holder_name: item.router_data.get_billing_full_name()?,
billing_address: billing_address.clone(),
shipping_address: Some(billing_address),
shipping_address: shipping_address.clone(),
};
let order = Order {
order_id: item.router_data.connector_request_reference_id.clone(),
Expand Down Expand Up @@ -944,17 +984,47 @@ impl TryFrom<&NexixpayRouterData<&PaymentsCompleteAuthorizeRouterData>>

let order_id = item.router_data.connector_request_reference_id.clone();
let amount = item.amount.clone();
let billing_address = Address {
let billing_address_street = format!(
"{}, {}",
item.router_data.get_billing_line1()?.expose(),
item.router_data.get_billing_line2()?.expose()
);

let billing_address = BillingAddress {
name: item.router_data.get_billing_full_name()?,
street: item.router_data.get_billing_line1()?,
street: Secret::new(billing_address_street),
city: item.router_data.get_billing_city()?,
post_code: item.router_data.get_billing_zip()?,
country: item.router_data.get_billing_country()?,
};
let shipping_address_street = match (
item.router_data.get_optional_shipping_line1(),
item.router_data.get_optional_shipping_line2(),
) {
(Some(line1), Some(line2)) => Some(Secret::new(format!(
"{}, {}",
line1.expose(),
line2.expose()
))),
(Some(line1), None) => Some(Secret::new(line1.expose())),
(None, Some(line2)) => Some(Secret::new(line2.expose())),
(None, None) => None,
};

let shipping_address = item
.router_data
.get_optional_billing()
.map(|_| ShippingAddress {
name: item.router_data.get_optional_shipping_full_name(),
street: shipping_address_street,
city: item.router_data.get_optional_shipping_city(),
post_code: item.router_data.get_optional_shipping_zip(),
country: item.router_data.get_optional_shipping_country(),
});
let customer_info = CustomerInfo {
card_holder_name: item.router_data.get_billing_full_name()?,
billing_address: billing_address.clone(),
shipping_address: Some(billing_address),
shipping_address: shipping_address.clone(),
};
let order_data = Order {
order_id,
Expand Down
7 changes: 7 additions & 0 deletions crates/hyperswitch_connectors/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ pub trait RouterData {
fn get_optional_shipping_state(&self) -> Option<Secret<String>>;
fn get_optional_shipping_first_name(&self) -> Option<Secret<String>>;
fn get_optional_shipping_last_name(&self) -> Option<Secret<String>>;
fn get_optional_shipping_full_name(&self) -> Option<Secret<String>>;
fn get_optional_shipping_phone_number(&self) -> Option<Secret<String>>;
fn get_optional_shipping_email(&self) -> Option<Email>;

Expand Down Expand Up @@ -368,6 +369,12 @@ impl<Flow, Request, Response> RouterData
})
}

fn get_optional_shipping_full_name(&self) -> Option<Secret<String>> {
self.get_optional_shipping()
.and_then(|shipping_details| shipping_details.address.as_ref())
.and_then(|shipping_address| shipping_address.get_optional_full_name())
}

fn get_optional_shipping_line1(&self) -> Option<Secret<String>> {
self.address.get_shipping().and_then(|shipping_address| {
shipping_address
Expand Down

0 comments on commit 25455f0

Please sign in to comment.