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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): [globalpay] handle edge case where currency comes as empty upon payment decline (#7812)
Pa1NarK689e738f7e12
diff --git a/crates/hyperswitch_connectors/src/connectors/globalpay/response.rs b/crates/hyperswitch_connectors/src/connectors/globalpay/response.rsindex f0f7851a41..11bd9e1a04 100644--- a/crates/hyperswitch_connectors/src/connectors/globalpay/response.rs+++ b/crates/hyperswitch_connectors/src/connectors/globalpay/response.rs@@ -4,6 +4,7 @@ use masking::Secret;use serde::{Deserialize, Serialize};use super::requests;+use crate::utils::deserialize_optional_currency;#[derive(Debug, Serialize, Deserialize)]pub struct GlobalpayPaymentsResponse {@@ -31,6 +32,7 @@ pub struct GlobalpayPaymentsResponse {/// The country in ISO-3166-1(alpha-2 code) format.pub country: Option<String>,/// The currency of the amount in ISO-4217(alpha-3)+ #[serde(deserialize_with = "deserialize_optional_currency")]pub currency: Option<Currency>,/// Information relating to a currency conversion.pub currency_conversion: Option<requests::CurrencyConversion>,diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rsindex ef5559d545..60cb878d9a 100644--- a/crates/hyperswitch_connectors/src/utils.rs+++ b/crates/hyperswitch_connectors/src/utils.rs@@ -6073,3 +6073,21 @@ pub fn normalize_string(value: String) -> Result<String, regex::Error> {let normalized = regex.replace_all(&lowercase_value, "").to_string();Ok(normalized)}++/// Custom deserializer for Option<Currency> that treats empty strings as None+pub fn deserialize_optional_currency<'de, D>(+ deserializer: D,+) -> Result<Option<enums::Currency>, D::Error>+where+ D: serde::Deserializer<'de>,+{+ let string_data: Option<String> = Option::deserialize(deserializer)?;+ match string_data {+ Some(ref value) if !value.is_empty() => value+ .clone()+ .parse_enum("Currency")+ .map(Some)+ .map_err(|_| serde::de::Error::custom(format!("Invalid currency code: {}", value))),+ _ => Ok(None),+ }+}