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

feat(connector): [checkout] Add additional fields in the request (#9888)

Vani Guptaa75c89002f57
diff --git a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
index aebdf6ccb5..d48184f7d8 100644
--- a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
@@ -5,7 +5,6 @@ use common_enums::{
use common_utils::{
errors::{CustomResult, ParsingError},
ext_traits::ByteSliceExt,
- id_type::CustomerId,
request::{Method, RequestContent},
types::MinorUnit,
};
@@ -200,6 +199,24 @@ impl<F, T> TryFrom<ResponseRouterData<F, CheckoutTokenResponse, T, PaymentsRespo
}
}
+#[skip_serializing_none]
+#[derive(Debug, Serialize)]
+pub struct CheckoutAddress {
+ pub address_line1: Option<Secret<String>>,
+ pub address_line2: Option<Secret<String>>,
+ pub city: Option<String>,
+ pub state: Option<Secret<String>>,
+ pub zip: Option<Secret<String>>,
+ pub country: Option<CountryAlpha2>,
+}
+
+#[skip_serializing_none]
+#[derive(Debug, Serialize)]
+pub struct CheckoutAccountHolderDetails {
+ pub first_name: Option<Secret<String>>,
+ pub last_name: Option<Secret<String>>,
+}
+
#[derive(Debug, Serialize)]
pub struct CardSource {
#[serde(rename = "type")]
@@ -208,6 +225,8 @@ pub struct CardSource {
pub expiry_month: Secret<String>,
pub expiry_year: Secret<String>,
pub cvv: Option<Secret<String>>,
+ pub billing_address: Option<CheckoutAddress>,
+ pub account_holder: Option<CheckoutAccountHolderDetails>,
}
#[derive(Debug, Serialize)]
@@ -215,6 +234,7 @@ pub struct WalletSource {
#[serde(rename = "type")]
pub source_type: CheckoutSourceTypes,
pub token: Secret<String>,
+ pub billing_address: Option<CheckoutAddress>,
}
#[derive(Debug, Serialize)]
@@ -223,6 +243,7 @@ pub struct MandateSource {
pub source_type: CheckoutSourceTypes,
#[serde(rename = "id")]
pub source_id: Option<String>,
+ pub billing_address: Option<CheckoutAddress>,
}
#[derive(Debug, Serialize)]
@@ -245,6 +266,7 @@ pub struct GooglePayPredecrypt {
expiry_year: Secret<String>,
eci: String,
cryptogram: Option<Secret<String>>,
+ pub billing_address: Option<CheckoutAddress>,
}
#[derive(Debug, Serialize)]
@@ -257,6 +279,7 @@ pub struct ApplePayPredecrypt {
expiry_year: Secret<String>,
eci: Option<String>,
cryptogram: Secret<String>,
+ pub billing_address: Option<CheckoutAddress>,
}
#[derive(Debug, Serialize)]
@@ -293,10 +316,19 @@ pub struct ReturnUrl {
#[skip_serializing_none]
#[derive(Debug, Default, Serialize)]
pub struct CheckoutCustomer {
- pub name: Option<CustomerId>,
+ pub name: Option<Secret<String>>,
+ pub email: Option<common_utils::pii::Email>,
+ pub phone: Option<CheckoutPhoneDetails>,
pub tax_number: Option<Secret<String>>,
}
+#[skip_serializing_none]
+#[derive(Debug, Default, Serialize)]
+pub struct CheckoutPhoneDetails {
+ pub country_code: Option<String>,
+ pub number: Option<Secret<String>>,
+}
+
#[skip_serializing_none]
#[derive(Debug, Default, Serialize)]
pub struct CheckoutProcessing {
@@ -308,17 +340,10 @@ pub struct CheckoutProcessing {
pub shipping_tax_amount: Option<MinorUnit>,
}
-#[skip_serializing_none]
-#[derive(Debug, Default, Serialize)]
-pub struct CheckoutShippingAddress {
- pub country: Option<CountryAlpha2>,
- pub zip: Option<Secret<String>>,
-}
-
#[skip_serializing_none]
#[derive(Debug, Default, Serialize)]
pub struct CheckoutShipping {
- pub address: Option<CheckoutShippingAddress>,
+ pub address: Option<CheckoutAddress>,
pub from_address_zip: Option<String>,
}
@@ -361,6 +386,7 @@ pub struct PaymentsRequest {
pub shipping: Option<CheckoutShipping>,
pub items: Option<Vec<CheckoutLineItem>>,
pub partial_authorization: Option<CheckoutPartialAuthorization>,
+ pub payment_ip: Option<Secret<String, common_utils::pii::IpAddress>>,
}
#[skip_serializing_none]
@@ -420,6 +446,24 @@ impl TryFrom<&ConnectorAuthType> for CheckoutAuthType {
}
}
+fn split_account_holder_name(
+ card_holder_name: Option<Secret<String>>,
+) -> (Option<Secret<String>>, Option<Secret<String>>) {
+ let account_holder_name = card_holder_name
+ .as_ref()
+ .map(|name| name.clone().expose().trim().to_string());
+ match account_holder_name {
+ Some(name) if !name.is_empty() => match name.rsplit_once(' ') {
+ Some((first, last)) => (
+ Some(Secret::new(first.to_string())),
+ Some(Secret::new(last.to_string())),
+ ),
+ None => (Some(Secret::new(name)), None),
+ },
+ _ => (None, None),
+ }
+}
+
impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(
@@ -451,6 +495,15 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
(CheckoutChallengeIndicator::ChallengeRequested, None)
};
+ let billing_details = Some(CheckoutAddress {
+ city: item.router_data.get_optional_billing_city(),
+ address_line1: item.router_data.get_optional_billing_line1(),
+ address_line2: item.router_data.get_optional_billing_line2(),
+ state: item.router_data.get_optional_billing_state(),
+ zip: item.router_data.get_optional_billing_zip(),
+ country: item.router_data.get_optional_billing_country(),
+ });
+
let (
source_var,
previous_payment_id,
@@ -459,12 +512,19 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
store_for_future_use,
) = match item.router_data.request.payment_method_data.clone() {
PaymentMethodData::Card(ccard) => {
+ let (first_name, last_name) = split_account_holder_name(ccard.card_holder_name);
+
let payment_source = PaymentSource::Card(CardSource {
source_type: CheckoutSourceTypes::Card,
number: ccard.card_number.clone(),
expiry_month: ccard.card_exp_month.clone(),
expiry_year: ccard.card_exp_year.clone(),
cvv: Some(ccard.card_cvc),
+ billing_address: billing_details,
+ account_holder: Some(CheckoutAccountHolderDetails {
+ first_name,
+ last_name,
+ }),
});
Ok((
payment_source,
@@ -480,6 +540,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
PaymentMethodToken::Token(token) => PaymentSource::Wallets(WalletSource {
source_type: CheckoutSourceTypes::Token,
token,
+ billing_address: billing_details,
}),
PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Checkout"),
@@ -514,6 +575,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
expiry_year,
eci: "06".to_string(),
cryptogram,
+ billing_address: billing_details,
}))
}
};
@@ -532,6 +594,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
let p_source = PaymentSource::Wallets(WalletSource {
source_type: CheckoutSourceTypes::Token,
token: apple_pay_payment_token,
+ billing_address: billing_details,
});
Ok((
p_source,
@@ -557,6 +620,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
expiry_year: expiry_year_4_digit,
eci: decrypt_data.payment_data.eci_indicator,
cryptogram: decrypt_data.payment_data.online_payment_cryptogram,
+ billing_address: billing_details,
}));
Ok((
p_source,
@@ -582,6 +646,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
let mandate_source = PaymentSource::MandatePayment(MandateSource {
source_type: CheckoutSourceTypes::SourceId,
source_id: item.router_data.request.connector_mandate_id(),
+ billing_address: billing_details,
});
let previous_id = Some(
item.router_data
@@ -597,12 +662,18 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
Ok((mandate_source, previous_id, Some(true), p_type, None))
}
PaymentMethodData::CardDetailsForNetworkTransactionId(ccard) => {
+ let (first_name, last_name) = split_account_holder_name(ccard.card_holder_name);
let payment_source = PaymentSource::Card(CardSource {
source_type: CheckoutSourceTypes::Card,
number: ccard.card_number.clone(),
expiry_month: ccard.card_exp_month.clone(),
expiry_year: ccard.card_exp_year.clone(),
cvv: None,
+ billing_address: billing_details,
+ account_holder: Some(CheckoutAccountHolderDetails {
+ first_name,
+ last_name,
+ }),
});
let previous_id = Some(
@@ -673,49 +744,59 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
let auth_type: CheckoutAuthType = connector_auth.try_into()?;
let processing_channel_id = auth_type.processing_channel_id;
let metadata = item.router_data.request.metadata.clone().map(Into::into);
- let (customer, processing, shipping, items) =
- if let Some(l2l3_data) = &item.router_data.l2_l3_data {
- (
- Some(CheckoutCustomer {
- name: l2l3_data.customer_id.clone(),
- tax_number: l2l3_data.customer_tax_registration_id.clone(),
- }),
- Some(CheckoutProcessing {
- order_id: l2l3_data.merchant_order_reference_id.clone(),
- tax_amount: l2l3_data.order_tax_amount,
- discount_amount: l2l3_data.discount_amount,
- duty_amount: l2l3_data.duty_amount,
- shipping_amount: l2l3_data.shipping_cost,
- shipping_tax_amount: l2l3_data.shipping_amount_tax,
- }),
- Some(CheckoutShipping {
- address: Some(CheckoutShippingAddress {
- country: l2l3_data.shipping_country,
- zip: l2l3_data.shipping_destination_zip.clone(),
- }),
- from_address_zip: l2l3_data.shipping_origin_zip.clone().map(|z| z.expose()),
+ let (customer, processing, shipping, items) = if let Some(l2l3_data) =
+ &item.router_data.l2_l3_data
+ {
+ (
+ Some(CheckoutCustomer {
+ name: l2l3_data.customer_name.clone(),
+ email: l2l3_data.customer_email.clone(),
+ phone: Some(CheckoutPhoneDetails {
+ country_code: l2l3_data.customer_phone_country_code.clone(),
+ number: l2l3_data.customer_phone_number.clone(),
}),
- l2l3_data.order_details.as_ref().map(|details| {
- details
- .iter()
- .map(|item| CheckoutLineItem {
- commodity_code: item.commodity_code.clone(),
- discount_amount: item.unit_discount_amount,
- name: Some(item.product_name.clone()),
- quantity: Some(item.quantity),
- reference: item.product_id.clone(),
- tax_exempt: None,
- tax_amount: item.total_tax_amount,
- total_amount: item.total_amount,
- unit_of_measure: item.unit_of_measure.clone(),
- unit_price: Some(item.amount),
- })
- .collect()
+ tax_number: l2l3_data.customer_tax_registration_id.clone(),
+ }),
+ Some(CheckoutProcessing {
+ order_id: l2l3_data.merchant_order_reference_id.clone(),
+ tax_amount: l2l3_data.order_tax_amount,
+ discount_amount: l2l3_data.discount_amount,
+ duty_amount: l2l3_data.duty_amount,
+ shipping_amount: l2l3_data.shipping_cost,
+ shipping_tax_amount: l2l3_data.shipping_amount_tax,
+ }),
+ Some(CheckoutShipping {
+ address: Some(CheckoutAddress {
+ country: l2l3_data.get_shipping_country(),
+ address_line1: l2l3_data.get_shipping_address_line1(),
+ address_line2: l2l3_data.get_shipping_address_line2(),
+ city: l2l3_data.get_shipping_city(),
+ state: l2l3_data.get_shipping_state(),
+ zip: l2l3_data.get_shipping_zip(),
}),
- )
- } else {
- (None, None, None, None)
- };
+ from_address_zip: l2l3_data.get_shipping_origin_zip().map(|zip| zip.expose()),
+ }),
+ l2l3_data.order_details.as_ref().map(|details| {
+ details
+ .iter()
+ .map(|item| CheckoutLineItem {
+ commodity_code: item.commodity_code.clone(),
+ discount_amount: item.unit_discount_amount,
+ name: Some(item.product_name.clone()),
+ quantity: Some(item.quantity),
+ reference: item.product_id.clone(),
+ tax_exempt: None,
+ tax_amount: item.total_tax_amount,
+ total_amount: item.total_amount,
+ unit_of_measure: item.unit_of_measure.clone(),
+ unit_price: Some(item.amount),
+ })
+ .collect()
+ }),
+ )
+ } else {
+ (None, None, None, None)
+ };
let partial_authorization = item.router_data.request.enable_partial_authorization.map(
|enable_partial_authorization| CheckoutPartialAuthorization {
@@ -723,6 +804,8 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
},
);
+ let payment_ip = item.router_data.request.get_ip_address_as_optional();
+
let request = Self {
source: source_var,
amount: item.amount.to_owned(),
@@ -742,6 +825,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
shipping,
items,
partial_authorization,
+ payment_ip,
};
Ok(request)
diff --git a/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs b/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs
index 5d9544a376..f9c2be7ef1 100644
--- a/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/nuvei/transformers.rs
@@ -1657,7 +1657,7 @@ where
})
}
fn get_l2_l3_items(
- l2_l3_data: &Option<L2L3Data>,
+ l2_l3_data: &Option<Box<L2L3Data>>,
currency: enums::Currency,
) -> Result<Option<Vec<NuveiItem>>, error_stack::Report<errors::ConnectorError>> {
l2_l3_data.as_ref().map_or(Ok(None), |data| {
@@ -1716,7 +1716,7 @@ fn get_l2_l3_items(
}
fn get_amount_details(
- l2_l3_data: &Option<L2L3Data>,
+ l2_l3_data: &Option<Box<L2L3Data>>,
currency: enums::Currency,
) -> Result<Option<NuveiAmountDetails>, error_stack::Report<errors::ConnectorError>> {
l2_l3_data.as_ref().map_or(Ok(None), |data| {
diff --git a/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs b/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs
index 2b4d28bd4b..fbc20dd92b 100644
--- a/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/worldpayvantiv/transformers.rs
@@ -1011,9 +1011,9 @@ where
discount_amount: l2_l3_data.discount_amount,
shipping_amount: l2_l3_data.shipping_cost,
duty_amount: l2_l3_data.duty_amount,
- ship_from_postal_code: l2_l3_data.shipping_origin_zip,
- destination_postal_code: l2_l3_data.shipping_destination_zip,
- destination_country_code: l2_l3_data.shipping_country,
+ ship_from_postal_code: l2_l3_data.get_shipping_origin_zip(),
+ destination_postal_code: l2_l3_data.get_shipping_zip(),
+ destination_country_code: l2_l3_data.get_shipping_country(),
detail_tax,
line_item_data,
};
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index 6c8de9a11d..717960e05b 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -555,7 +555,7 @@ pub trait RouterData {
fn get_optional_billing_last_name(&self) -> Option<Secret<String>>;
fn get_optional_billing_phone_number(&self) -> Option<Secret<String>>;
fn get_optional_billing_email(&self) -> Option<Email>;
- fn get_optional_l2_l3_data(&self) -> Option<L2L3Data>;
+ fn get_optional_l2_l3_data(&self) -> Option<Box<L2L3Data>>;
}
impl<Flow, Request, Response> RouterData
@@ -1086,7 +1086,7 @@ impl<Flow, Request, Response> RouterData
.ok_or_else(missing_field_err("quote_id"))
}
- fn get_optional_l2_l3_data(&self) -> Option<L2L3Data> {
+ fn get_optional_l2_l3_data(&self) -> Option<Box<L2L3Data>> {
self.l2_l3_data.clone()
}
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
index d0bffe8888..a86279a5f7 100644
--- a/crates/hyperswitch_domain_models/src/router_data.rs
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -4,7 +4,7 @@ use common_types::{payments as common_payment_types, primitive_wrappers};
use common_utils::{
errors::IntegrityCheckError,
ext_traits::{OptionExt, ValueExt},
- id_type,
+ id_type::{self},
types::MinorUnit,
};
use error_stack::ResultExt;
@@ -12,8 +12,8 @@ use masking::{ExposeInterface, Secret};
use serde::{Deserialize, Serialize};
use crate::{
- network_tokenization::NetworkTokenNumber, payment_address::PaymentAddress, payment_method_data,
- payments,
+ address::AddressDetails, network_tokenization::NetworkTokenNumber,
+ payment_address::PaymentAddress, payment_method_data, payments,
};
#[cfg(feature = "v2")]
use crate::{
@@ -105,7 +105,7 @@ pub struct RouterData<Flow, Request, Response> {
pub connector_mandate_request_reference_id: Option<String>,
- pub l2_l3_data: Option<L2L3Data>,
+ pub l2_l3_data: Option<Box<L2L3Data>>,
pub authentication_id: Option<id_type::AuthenticationId>,
/// Contains the type of sca exemption required for the transaction
@@ -132,12 +132,57 @@ pub struct L2L3Data {
pub order_tax_amount: Option<MinorUnit>,
pub merchant_order_reference_id: Option<String>,
pub customer_id: Option<id_type::CustomerId>,
- pub shipping_origin_zip: Option<Secret<String>>,
- pub shipping_state: Option<Secret<String>>,
- pub shipping_country: Option<common_enums::CountryAlpha2>,
- pub shipping_destination_zip: Option<Secret<String>>,
pub billing_address_city: Option<String>,
pub merchant_tax_registration_id: Option<Secret<String>>,
+ pub customer_email: Option<common_utils::pii::Email>,
+ pub customer_name: Option<Secret<String>>,
+ pub customer_phone_number: Option<Secret<String>>,
+ pub customer_phone_country_code: Option<String>,
+ pub shipping_details: Option<AddressDetails>,
+}
+
+impl L2L3Data {
+ pub fn get_shipping_country(&self) -> Option<common_enums::enums::CountryAlpha2> {
+ self.shipping_details
+ .as_ref()
+ .and_then(|address| address.country)
+ }
+
+ pub fn get_shipping_city(&self) -> Option<String> {
+ self.shipping_details
+ .as_ref()
+ .and_then(|address| address.city.clone())
+ }
+
+ pub fn get_shipping_state(&self) -> Option<Secret<String>> {
+ self.shipping_details
+ .as_ref()
+ .and_then(|address| address.state.clone())
+ }
+
+ pub fn get_shipping_origin_zip(&self) -> Option<Secret<String>> {
+ self.shipping_details
+ .as_ref()
+ .and_then(|address| address.origin_zip.clone())
+ }
+
+ pub fn get_shipping_zip(&self) -> Option<Secret<String>> {
+ self.shipping_details
+ .as_ref()
+ .and_then(|address| address.zip.clone())
+ }
+
+ pub fn get_shipping_address_line1(&self) -> Option<Secret<String>> {
+ self.shipping_details
+ .as_ref()
+ .and_then(|address| address.line1.clone())
+ }
+
+ pub fn get_shipping_address_line2(&self) -> Option<Secret<String>> {
+ self.shipping_details
+ .as_ref()
+ .and_then(|address| address.line2.clone())
+ }
}
// Different patterns of authentication.
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 01fb260b23..7733cc8a7a 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -1773,7 +1773,7 @@ where
.get_merchant_account()
.get_merchant_tax_registration_id();
- types::L2L3Data {
+ Box::new(types::L2L3Data {
order_date: payment_data.payment_intent.order_date,
tax_status: payment_data.payment_intent.tax_status,
customer_tax_registration_id: customer.as_ref().and_then(|c| {
@@ -1795,27 +1795,25 @@ where
.merchant_order_reference_id
.clone(),
customer_id: payment_data.payment_intent.customer_id.clone(),
- shipping_origin_zip: shipping_address
- .and_then(|addr| addr.address.as_ref())
- .and_then(|details| details.origin_zip.clone()),
- shipping_state: shipping_address
- .as_ref()
- .and_then(|addr| addr.address.as_ref())
- .and_then(|details| details.state.clone()),
- shipping_country: shipping_address
- .as_ref()
- .and_then(|addr| addr.address.as_ref())
- .and_then(|details| details.country),
- shipping_destination_zip: shipping_address
- .as_ref()
- .and_then(|addr| addr.address.as_ref())
- .and_then(|details| details.zip.clone()),
billing_address_city: billing_address
.as_ref()
.and_then(|addr| addr.address.as_ref())
.and_then(|details| details.city.clone()),
merchant_tax_registration_id,
- }
+ customer_name: customer
+ .as_ref()
+ .and_then(|c| c.name.as_ref().map(|e| e.clone().into_inner())),
+ customer_email: payment_data.email,
+ customer_phone_number: customer
+ .as_ref()
+ .and_then(|c| c.phone.as_ref().map(|e| e.clone().into_inner())),
+ customer_phone_country_code: customer
+ .as_ref()
+ .and_then(|c| c.phone_country_code.clone()),
+ shipping_details: shipping_address
+ .and_then(|address| address.address.as_ref())
+ .cloned(),
+ })
});
crate::logger::debug!("unified address details {:?}", unified_address);