feat(core): Added support for unified_connector_service CardNumber and Secret<String> Type (#9044)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Debarshi Gupta
2025-08-27 21:07:24 +05:30
committed by GitHub
parent 4b7f2093db
commit cf64d2a9dc
5 changed files with 186 additions and 91 deletions

132
Cargo.lock generated
View File

@ -357,7 +357,7 @@ dependencies = [
"error-stack 0.4.1", "error-stack 0.4.1",
"futures 0.3.31", "futures 0.3.31",
"hyperswitch_interfaces", "hyperswitch_interfaces",
"masking", "masking 0.1.0",
"opensearch", "opensearch",
"reqwest 0.11.27", "reqwest 0.11.27",
"router_env", "router_env",
@ -462,7 +462,7 @@ dependencies = [
"deserialize_form_style_query_parameter", "deserialize_form_style_query_parameter",
"error-stack 0.4.1", "error-stack 0.4.1",
"euclid", "euclid",
"masking", "masking 0.1.0",
"mime", "mime",
"nutype", "nutype",
"reqwest 0.11.27", "reqwest 0.11.27",
@ -1620,7 +1620,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"common_utils", "common_utils",
"error-stack 0.4.1", "error-stack 0.4.1",
"masking", "masking 0.1.0",
"regex", "regex",
"router_env", "router_env",
"serde", "serde",
@ -1846,7 +1846,7 @@ name = "common_enums"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"diesel", "diesel",
"masking", "masking 0.1.0",
"router_derive", "router_derive",
"serde", "serde",
"serde_json", "serde_json",
@ -1865,7 +1865,7 @@ dependencies = [
"diesel", "diesel",
"error-stack 0.4.1", "error-stack 0.4.1",
"euclid", "euclid",
"masking", "masking 0.1.0",
"serde", "serde",
"serde_json", "serde_json",
"time", "time",
@ -1889,7 +1889,7 @@ dependencies = [
"globset", "globset",
"hex", "hex",
"http 0.2.12", "http 0.2.12",
"masking", "masking 0.1.0",
"md5", "md5",
"nanoid", "nanoid",
"nutype", "nutype",
@ -2633,7 +2633,7 @@ dependencies = [
"common_utils", "common_utils",
"diesel", "diesel",
"error-stack 0.4.1", "error-stack 0.4.1",
"masking", "masking 0.1.0",
"router_derive", "router_derive",
"router_env", "router_env",
"serde", "serde",
@ -2721,7 +2721,7 @@ dependencies = [
"error-stack 0.4.1", "error-stack 0.4.1",
"external_services", "external_services",
"hyperswitch_interfaces", "hyperswitch_interfaces",
"masking", "masking 0.1.0",
"mime", "mime",
"redis_interface", "redis_interface",
"reqwest 0.11.27", "reqwest 0.11.27",
@ -3020,7 +3020,7 @@ name = "events"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"error-stack 0.4.1", "error-stack 0.4.1",
"masking", "masking 0.1.0",
"router_env", "router_env",
"serde", "serde",
"serde_json", "serde_json",
@ -3053,7 +3053,7 @@ dependencies = [
"hyper-util", "hyper-util",
"hyperswitch_interfaces", "hyperswitch_interfaces",
"lettre", "lettre",
"masking", "masking 0.1.0",
"once_cell", "once_cell",
"prost", "prost",
"prost-types", "prost-types",
@ -3377,8 +3377,9 @@ dependencies = [
[[package]] [[package]]
name = "g2h" name = "g2h"
version = "0.4.0" version = "0.5.0"
source = "git+https://github.com/NishantJoshi00/g2h?branch=fixing-response-serializing#fd2c856b2c6c88a85d6fe51d95b4d3342b788d31" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d843f7c70cdae8a2452e0b2f463b7e483a57cece7687da89371d952d44e0445d"
dependencies = [ dependencies = [
"cargo_metadata 0.19.2", "cargo_metadata 0.19.2",
"heck 0.5.0", "heck 0.5.0",
@ -3540,19 +3541,21 @@ dependencies = [
[[package]] [[package]]
name = "grpc-api-types" name = "grpc-api-types"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/juspay/connector-service?rev=aae51574fed25b0a7849e3832cff8904bc310cf5#aae51574fed25b0a7849e3832cff8904bc310cf5" source = "git+https://github.com/juspay/connector-service?rev=a56de0a4ee393af5c401f02b6b4344cb263f4cac#a56de0a4ee393af5c401f02b6b4344cb263f4cac"
dependencies = [ dependencies = [
"axum 0.8.4", "axum 0.8.4",
"error-stack 0.5.0", "error-stack 0.5.0",
"g2h", "g2h",
"heck 0.5.0", "heck 0.5.0",
"http 1.3.1", "http 1.3.1",
"masking 0.1.0 (git+https://github.com/juspay/hyperswitch?tag=v1.116.0)",
"prost", "prost",
"prost-build", "prost-build",
"prost-types", "prost-types",
"serde", "serde",
"tonic 0.13.1", "tonic 0.13.1",
"tonic-build", "tonic-build",
"ucs_cards",
] ]
[[package]] [[package]]
@ -4046,7 +4049,7 @@ dependencies = [
"isocountry", "isocountry",
"josekit", "josekit",
"lazy_static", "lazy_static",
"masking", "masking 0.1.0",
"mime", "mime",
"nanoid", "nanoid",
"num-traits", "num-traits",
@ -4104,7 +4107,7 @@ dependencies = [
"error-stack 0.4.1", "error-stack 0.4.1",
"futures 0.3.31", "futures 0.3.31",
"http 0.2.12", "http 0.2.12",
"masking", "masking 0.1.0",
"mime", "mime",
"router_derive", "router_derive",
"router_env", "router_env",
@ -4131,7 +4134,7 @@ dependencies = [
"error-stack 0.4.1", "error-stack 0.4.1",
"http 0.2.12", "http 0.2.12",
"hyperswitch_domain_models", "hyperswitch_domain_models",
"masking", "masking 0.1.0",
"mime", "mime",
"reqwest 0.11.27", "reqwest 0.11.27",
"router_env", "router_env",
@ -4392,7 +4395,7 @@ dependencies = [
"async-trait", "async-trait",
"common_utils", "common_utils",
"error-stack 0.4.1", "error-stack 0.4.1",
"masking", "masking 0.1.0",
"nom 7.1.3", "nom 7.1.3",
"reqwest 0.12.7", "reqwest 0.12.7",
"router_env", "router_env",
@ -4603,7 +4606,7 @@ dependencies = [
"criterion", "criterion",
"euclid", "euclid",
"hyperswitch_constraint_graph", "hyperswitch_constraint_graph",
"masking", "masking 0.1.0",
"serde", "serde",
"serde_json", "serde_json",
"strum 0.26.3", "strum 0.26.3",
@ -4843,6 +4846,23 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "masking"
version = "0.1.0"
source = "git+https://github.com/juspay/hyperswitch?tag=v1.116.0#672d749e20bec7800613878e36a0ab3885177326"
dependencies = [
"bytes 1.10.1",
"diesel",
"erased-serde 0.4.6",
"prost",
"serde",
"serde_json",
"subtle",
"time",
"url",
"zeroize",
]
[[package]] [[package]]
name = "matchers" name = "matchers"
version = "0.1.0" version = "0.1.0"
@ -5702,7 +5722,7 @@ dependencies = [
"error-stack 0.4.1", "error-stack 0.4.1",
"hyperswitch_domain_models", "hyperswitch_domain_models",
"hyperswitch_interfaces", "hyperswitch_interfaces",
"masking", "masking 0.1.0",
"rdkafka", "rdkafka",
"router_env", "router_env",
"scheduler", "scheduler",
@ -5958,7 +5978,7 @@ dependencies = [
"common_utils", "common_utils",
"error-stack 0.4.1", "error-stack 0.4.1",
"http 0.2.12", "http 0.2.12",
"masking", "masking 0.1.0",
"mime", "mime",
"serde", "serde",
"serde_json", "serde_json",
@ -6810,7 +6830,7 @@ dependencies = [
"josekit", "josekit",
"jsonwebtoken", "jsonwebtoken",
"kgraph_utils", "kgraph_utils",
"masking", "masking 0.1.0",
"maud", "maud",
"mimalloc", "mimalloc",
"mime", "mime",
@ -6855,6 +6875,7 @@ dependencies = [
"tokio 1.45.1", "tokio 1.45.1",
"totp-rs", "totp-rs",
"tracing-futures", "tracing-futures",
"ucs_cards",
"unicode-segmentation", "unicode-segmentation",
"url", "url",
"urlencoding", "urlencoding",
@ -6940,7 +6961,7 @@ dependencies = [
[[package]] [[package]]
name = "rust-grpc-client" name = "rust-grpc-client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/juspay/connector-service?rev=aae51574fed25b0a7849e3832cff8904bc310cf5#aae51574fed25b0a7849e3832cff8904bc310cf5" source = "git+https://github.com/juspay/connector-service?rev=a56de0a4ee393af5c401f02b6b4344cb263f4cac#a56de0a4ee393af5c401f02b6b4344cb263f4cac"
dependencies = [ dependencies = [
"grpc-api-types", "grpc-api-types",
] ]
@ -8146,7 +8167,7 @@ dependencies = [
"error-stack 0.4.1", "error-stack 0.4.1",
"futures 0.3.31", "futures 0.3.31",
"hyperswitch_domain_models", "hyperswitch_domain_models",
"masking", "masking 0.1.0",
"moka", "moka",
"redis_interface", "redis_interface",
"router_derive", "router_derive",
@ -8442,7 +8463,7 @@ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"clap", "clap",
"common_enums", "common_enums",
"masking", "masking 0.1.0",
"rand 0.8.5", "rand 0.8.5",
"regex", "regex",
"reqwest 0.11.27", "reqwest 0.11.27",
@ -9324,6 +9345,69 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
[[package]]
name = "ucs_cards"
version = "0.1.0"
source = "git+https://github.com/juspay/connector-service?rev=a56de0a4ee393af5c401f02b6b4344cb263f4cac#a56de0a4ee393af5c401f02b6b4344cb263f4cac"
dependencies = [
"bytes 1.10.1",
"error-stack 0.4.1",
"masking 0.1.0 (git+https://github.com/juspay/hyperswitch?tag=v1.116.0)",
"prost",
"regex",
"serde",
"thiserror 1.0.69",
"time",
"ucs_common_utils",
]
[[package]]
name = "ucs_common_enums"
version = "0.1.0"
source = "git+https://github.com/juspay/connector-service?rev=a56de0a4ee393af5c401f02b6b4344cb263f4cac#a56de0a4ee393af5c401f02b6b4344cb263f4cac"
dependencies = [
"serde",
"strum 0.26.3",
"thiserror 1.0.69",
"utoipa",
]
[[package]]
name = "ucs_common_utils"
version = "0.1.0"
source = "git+https://github.com/juspay/connector-service?rev=a56de0a4ee393af5c401f02b6b4344cb263f4cac#a56de0a4ee393af5c401f02b6b4344cb263f4cac"
dependencies = [
"anyhow",
"blake3",
"bytes 1.10.1",
"chrono",
"error-stack 0.4.1",
"hex",
"http 1.3.1",
"masking 0.1.0 (git+https://github.com/juspay/hyperswitch?tag=v1.116.0)",
"md5",
"nanoid",
"once_cell",
"quick-xml",
"rand 0.8.5",
"regex",
"reqwest 0.11.27",
"ring 0.17.14",
"rust_decimal",
"semver 1.0.26",
"serde",
"serde_json",
"serde_urlencoded",
"strum 0.26.3",
"thiserror 1.0.69",
"time",
"tracing",
"ucs_common_enums",
"url",
"utoipa",
"uuid",
]
[[package]] [[package]]
name = "unarray" name = "unarray"
version = "0.1.4" version = "0.1.4"

View File

@ -66,7 +66,7 @@ reqwest = { version = "0.11.27", features = ["rustls-tls"] }
http = "0.2.12" http = "0.2.12"
url = { version = "2.5.4", features = ["serde"] } url = { version = "2.5.4", features = ["serde"] }
quick-xml = { version = "0.31.0", features = ["serialize"] } quick-xml = { version = "0.31.0", features = ["serialize"] }
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "aae51574fed25b0a7849e3832cff8904bc310cf5", package = "rust-grpc-client" } unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "a56de0a4ee393af5c401f02b6b4344cb263f4cac", package = "rust-grpc-client" }
# First party crates # First party crates

View File

@ -89,7 +89,8 @@ reqwest = { version = "0.11.27", features = ["json", "rustls-tls", "gzip", "mult
ring = "0.17.14" ring = "0.17.14"
rust_decimal = { version = "1.37.1", features = ["serde-with-float", "serde-with-str"] } rust_decimal = { version = "1.37.1", features = ["serde-with-float", "serde-with-str"] }
rust-i18n = { git = "https://github.com/kashif-m/rust-i18n", rev = "f2d8096aaaff7a87a847c35a5394c269f75e077a" } rust-i18n = { git = "https://github.com/kashif-m/rust-i18n", rev = "f2d8096aaaff7a87a847c35a5394c269f75e077a" }
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "aae51574fed25b0a7849e3832cff8904bc310cf5", package = "rust-grpc-client" } unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "a56de0a4ee393af5c401f02b6b4344cb263f4cac", package = "rust-grpc-client" }
unified-connector-service-cards = { git = "https://github.com/juspay/connector-service", rev = "a56de0a4ee393af5c401f02b6b4344cb263f4cac", package = "ucs_cards" }
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
rustls = "0.22" rustls = "0.22"
rustls-pemfile = "2" rustls-pemfile = "2"

View File

@ -18,6 +18,7 @@ use hyperswitch_domain_models::{
}; };
use masking::{ExposeInterface, PeekInterface, Secret}; use masking::{ExposeInterface, PeekInterface, Secret};
use router_env::logger; use router_env::logger;
use unified_connector_service_cards::CardNumber;
use unified_connector_service_client::payments::{ use unified_connector_service_client::payments::{
self as payments_grpc, payment_method::PaymentMethod, CardDetails, CardPaymentMethodType, self as payments_grpc, payment_method::PaymentMethod, CardDetails, CardPaymentMethodType,
PaymentServiceAuthorizeResponse, RewardPaymentMethodType, PaymentServiceAuthorizeResponse, RewardPaymentMethodType,
@ -277,11 +278,17 @@ pub fn build_unified_connector_service_payment_method(
.transpose()?; .transpose()?;
let card_details = CardDetails { let card_details = CardDetails {
card_number: card.card_number.get_card_no(), card_number: Some(
card_exp_month, CardNumber::from_str(&card.card_number.get_card_no()).change_context(
card_exp_year: card.get_expiry_year_4_digit().peek().to_string(), UnifiedConnectorServiceError::RequestEncodingFailedWithReason(
card_cvc: card.card_cvc.peek().to_string(), "Failed to parse card number".to_string(),
card_holder_name: card.card_holder_name.map(|name| name.expose()), ),
)?,
),
card_exp_month: Some(card_exp_month.into()),
card_exp_year: Some(card.get_expiry_year_4_digit().expose().into()),
card_cvc: Some(card.card_cvc.expose().into()),
card_holder_name: card.card_holder_name.map(|name| name.expose().into()),
card_issuer: card.card_issuer.clone(), card_issuer: card.card_issuer.clone(),
card_network: card_network.map(|card_network| card_network.into()), card_network: card_network.map(|card_network| card_network.into()),
card_type: card.card_type.clone(), card_type: card.card_type.clone(),
@ -316,12 +323,13 @@ pub fn build_unified_connector_service_payment_method(
hyperswitch_domain_models::payment_method_data::UpiData::UpiCollect( hyperswitch_domain_models::payment_method_data::UpiData::UpiCollect(
upi_collect_data, upi_collect_data,
) => { ) => {
let vpa_id = upi_collect_data.vpa_id.map(|vpa| vpa.expose()); let upi_details = payments_grpc::UpiCollect {
let upi_details = payments_grpc::UpiCollect { vpa_id }; vpa_id: upi_collect_data.vpa_id.map(|vpa| vpa.expose().into()),
};
PaymentMethod::UpiCollect(upi_details) PaymentMethod::UpiCollect(upi_details)
} }
hyperswitch_domain_models::payment_method_data::UpiData::UpiIntent(_) => { hyperswitch_domain_models::payment_method_data::UpiData::UpiIntent(_) => {
let upi_details = payments_grpc::UpiIntent {}; let upi_details = payments_grpc::UpiIntent { app_name: None };
PaymentMethod::UpiIntent(upi_details) PaymentMethod::UpiIntent(upi_details)
} }
}; };
@ -369,13 +377,13 @@ pub fn build_unified_connector_service_payment_method_for_external_proxy(
.map(payments_grpc::CardNetwork::foreign_try_from) .map(payments_grpc::CardNetwork::foreign_try_from)
.transpose()?; .transpose()?;
let card_details = CardDetails { let card_details = CardDetails {
card_number: external_vault_card.card_number.peek().to_string(), card_number: Some(CardNumber::from_str(external_vault_card.card_number.peek()).change_context(
card_exp_month: external_vault_card.card_exp_month.peek().to_string(), UnifiedConnectorServiceError::RequestEncodingFailedWithReason("Failed to parse card number".to_string())
card_exp_year: external_vault_card.card_exp_year.peek().to_string(), )?),
card_cvc: external_vault_card.card_cvc.peek().to_string(), card_exp_month: Some(external_vault_card.card_exp_month.expose().into()),
card_holder_name: external_vault_card card_exp_year: Some(external_vault_card.card_exp_year.expose().into()),
.card_holder_name card_cvc: Some(external_vault_card.card_cvc.expose().into()),
.map(|name| name.expose()), card_holder_name: external_vault_card.card_holder_name.map(|name| name.expose().into()),
card_issuer: external_vault_card.card_issuer.clone(), card_issuer: external_vault_card.card_issuer.clone(),
card_network: card_network.map(|card_network| card_network.into()), card_network: card_network.map(|card_network| card_network.into()),
card_type: external_vault_card.card_type.clone(), card_type: external_vault_card.card_type.clone(),

View File

@ -141,7 +141,7 @@ impl ForeignTryFrom<&RouterData<Authorize, PaymentsAuthorizeData, PaymentsRespon
.request .request
.email .email
.clone() .clone()
.map(|e| e.expose().expose()), .map(|e| e.expose().expose().into()),
browser_info, browser_info,
access_token: None, access_token: None,
session_token: None, session_token: None,
@ -193,6 +193,7 @@ impl ForeignTryFrom<&RouterData<Authorize, PaymentsAuthorizeData, PaymentsRespon
.collect::<HashMap<String, String>>() .collect::<HashMap<String, String>>()
}) })
.unwrap_or_default(), .unwrap_or_default(),
test_mode: None,
}) })
} }
} }
@ -264,7 +265,7 @@ impl
.request .request
.email .email
.clone() .clone()
.map(|e| e.expose().expose()), .map(|e| e.expose().expose().into()),
browser_info, browser_info,
access_token: None, access_token: None,
session_token: None, session_token: None,
@ -316,6 +317,7 @@ impl
.collect::<HashMap<String, String>>() .collect::<HashMap<String, String>>()
}) })
.unwrap_or_default(), .unwrap_or_default(),
test_mode: None,
}) })
} }
} }
@ -372,7 +374,7 @@ impl ForeignTryFrom<&RouterData<SetupMandate, SetupMandateRequestData, PaymentsR
.request .request
.email .email
.clone() .clone()
.map(|e| e.expose().expose()), .map(|e| e.expose().expose().into()),
customer_name: router_data customer_name: router_data
.request .request
.customer_name .customer_name
@ -495,8 +497,10 @@ impl ForeignTryFrom<&RouterData<Authorize, PaymentsAuthorizeData, PaymentsRespon
.request .request
.email .email
.clone() .clone()
.map(|e| e.expose().expose()), .map(|e| e.expose().expose().into()),
browser_info, browser_info,
test_mode: None,
payment_method_type: None,
}) })
} }
} }
@ -861,11 +865,6 @@ impl ForeignTryFrom<hyperswitch_domain_models::payment_address::PaymentAddress>
let shipping = payment_address.get_shipping().map(|address| { let shipping = payment_address.get_shipping().map(|address| {
let details = address.address.as_ref(); let details = address.address.as_ref();
let get_str =
|opt: &Option<masking::Secret<String>>| opt.as_ref().map(|s| s.peek().to_owned());
let get_plain = |opt: &Option<String>| opt.clone();
let country = details.and_then(|details| { let country = details.and_then(|details| {
details details
.country .country
@ -875,20 +874,23 @@ impl ForeignTryFrom<hyperswitch_domain_models::payment_address::PaymentAddress>
}); });
payments_grpc::Address { payments_grpc::Address {
first_name: get_str(&details.and_then(|d| d.first_name.clone())), first_name: details.and_then(|d| d.first_name.as_ref().map(|s| s.clone().expose())),
last_name: get_str(&details.and_then(|d| d.last_name.clone())), last_name: details.and_then(|d| d.last_name.as_ref().map(|s| s.clone().expose())),
line1: get_str(&details.and_then(|d| d.line1.clone())), line1: details.and_then(|d| d.line1.as_ref().map(|s| s.clone().expose().into())),
line2: get_str(&details.and_then(|d| d.line2.clone())), line2: details.and_then(|d| d.line2.as_ref().map(|s| s.clone().expose().into())),
line3: get_str(&details.and_then(|d| d.line3.clone())), line3: details.and_then(|d| d.line3.as_ref().map(|s| s.clone().expose().into())),
city: get_plain(&details.and_then(|d| d.city.clone())), city: details.and_then(|d| d.city.as_ref().map(|s| s.clone().into())),
state: get_str(&details.and_then(|d| d.state.clone())), state: details.and_then(|d| d.state.as_ref().map(|s| s.clone().expose().into())),
zip_code: get_str(&details.and_then(|d| d.zip.clone())), zip_code: details.and_then(|d| d.zip.as_ref().map(|s| s.clone().expose().into())),
country_alpha2_code: country, country_alpha2_code: country,
email: address.email.as_ref().map(|e| e.peek().to_string()), email: address
.email
.as_ref()
.map(|e| e.clone().expose().expose().into()),
phone_number: address phone_number: address
.phone .phone
.as_ref() .as_ref()
.and_then(|phone| phone.number.as_ref().map(|n| n.peek().to_string())), .and_then(|phone| phone.number.as_ref().map(|n| n.clone().expose().into())),
phone_country_code: address.phone.as_ref().and_then(|p| p.country_code.clone()), phone_country_code: address.phone.as_ref().and_then(|p| p.country_code.clone()),
} }
}); });
@ -896,11 +898,6 @@ impl ForeignTryFrom<hyperswitch_domain_models::payment_address::PaymentAddress>
let billing = payment_address.get_payment_billing().map(|address| { let billing = payment_address.get_payment_billing().map(|address| {
let details = address.address.as_ref(); let details = address.address.as_ref();
let get_str =
|opt: &Option<masking::Secret<String>>| opt.as_ref().map(|s| s.peek().to_owned());
let get_plain = |opt: &Option<String>| opt.clone();
let country = details.and_then(|details| { let country = details.and_then(|details| {
details details
.country .country
@ -910,20 +907,21 @@ impl ForeignTryFrom<hyperswitch_domain_models::payment_address::PaymentAddress>
}); });
payments_grpc::Address { payments_grpc::Address {
first_name: get_str(&details.and_then(|d| d.first_name.clone())), first_name: details
last_name: get_str(&details.and_then(|d| d.last_name.clone())), .and_then(|d| d.first_name.as_ref().map(|s| s.peek().to_string())),
line1: get_str(&details.and_then(|d| d.line1.clone())), last_name: details.and_then(|d| d.last_name.as_ref().map(|s| s.peek().to_string())),
line2: get_str(&details.and_then(|d| d.line2.clone())), line1: details.and_then(|d| d.line1.as_ref().map(|s| s.peek().to_string().into())),
line3: get_str(&details.and_then(|d| d.line3.clone())), line2: details.and_then(|d| d.line2.as_ref().map(|s| s.peek().to_string().into())),
city: get_plain(&details.and_then(|d| d.city.clone())), line3: details.and_then(|d| d.line3.as_ref().map(|s| s.peek().to_string().into())),
state: get_str(&details.and_then(|d| d.state.clone())), city: details.and_then(|d| d.city.as_ref().map(|s| s.clone().into())),
zip_code: get_str(&details.and_then(|d| d.zip.clone())), state: details.and_then(|d| d.state.as_ref().map(|s| s.peek().to_string().into())),
zip_code: details.and_then(|d| d.zip.as_ref().map(|s| s.peek().to_string().into())),
country_alpha2_code: country, country_alpha2_code: country,
email: address.email.as_ref().map(|e| e.peek().to_string()), email: address.email.as_ref().map(|e| e.peek().to_string().into()),
phone_number: address phone_number: address
.phone .phone
.as_ref() .as_ref()
.and_then(|phone| phone.number.as_ref().map(|n| n.peek().to_string())), .and_then(|phone| phone.number.as_ref().map(|n| n.peek().to_string().into())),
phone_country_code: address.phone.as_ref().and_then(|p| p.country_code.clone()), phone_country_code: address.phone.as_ref().and_then(|p| p.country_code.clone()),
} }
}); });
@ -932,12 +930,6 @@ impl ForeignTryFrom<hyperswitch_domain_models::payment_address::PaymentAddress>
payment_address.get_payment_method_billing().map(|address| { payment_address.get_payment_method_billing().map(|address| {
let details = address.address.as_ref(); let details = address.address.as_ref();
let get_str = |opt: &Option<masking::Secret<String>>| {
opt.as_ref().map(|s| s.peek().to_owned())
};
let get_plain = |opt: &Option<String>| opt.clone();
let country = details.and_then(|details| { let country = details.and_then(|details| {
details details
.country .country
@ -947,20 +939,30 @@ impl ForeignTryFrom<hyperswitch_domain_models::payment_address::PaymentAddress>
}); });
payments_grpc::Address { payments_grpc::Address {
first_name: get_str(&details.and_then(|d| d.first_name.clone())), first_name: details
last_name: get_str(&details.and_then(|d| d.last_name.clone())), .and_then(|d| d.first_name.as_ref().map(|s| s.peek().to_string())),
line1: get_str(&details.and_then(|d| d.line1.clone())), last_name: details
line2: get_str(&details.and_then(|d| d.line2.clone())), .and_then(|d| d.last_name.as_ref().map(|s| s.peek().to_string())),
line3: get_str(&details.and_then(|d| d.line3.clone())), line1: details
city: get_plain(&details.and_then(|d| d.city.clone())), .and_then(|d| d.line1.as_ref().map(|s| s.peek().to_string().into())),
state: get_str(&details.and_then(|d| d.state.clone())), line2: details
zip_code: get_str(&details.and_then(|d| d.zip.clone())), .and_then(|d| d.line2.as_ref().map(|s| s.peek().to_string().into())),
line3: details
.and_then(|d| d.line3.as_ref().map(|s| s.peek().to_string().into())),
city: details.and_then(|d| d.city.as_ref().map(|s| s.clone().into())),
state: details
.and_then(|d| d.state.as_ref().map(|s| s.peek().to_string().into())),
zip_code: details
.and_then(|d| d.zip.as_ref().map(|s| s.peek().to_string().into())),
country_alpha2_code: country, country_alpha2_code: country,
email: address.email.as_ref().map(|e| e.peek().to_string()), email: address
.email
.as_ref()
.map(|e| e.clone().expose().expose().into()),
phone_number: address phone_number: address
.phone .phone
.as_ref() .as_ref()
.and_then(|phone| phone.number.as_ref().map(|n| n.peek().to_string())), .and_then(|phone| phone.number.as_ref().map(|n| n.clone().expose().into())),
phone_country_code: address.phone.as_ref().and_then(|p| p.country_code.clone()), phone_country_code: address.phone.as_ref().and_then(|p| p.country_code.clone()),
} }
}); });