Skip to content

Commit 689e738

Browse files
authored
fix(connector): [globalpay] handle edge case where currency comes as empty upon payment decline (#7812)
1 parent 8a737d5 commit 689e738

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

crates/hyperswitch_connectors/src/connectors/globalpay/response.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use masking::Secret;
44
use serde::{Deserialize, Serialize};
55

66
use super::requests;
7+
use crate::utils::deserialize_optional_currency;
78

89
#[derive(Debug, Serialize, Deserialize)]
910
pub struct GlobalpayPaymentsResponse {
@@ -31,6 +32,7 @@ pub struct GlobalpayPaymentsResponse {
3132
/// The country in ISO-3166-1(alpha-2 code) format.
3233
pub country: Option<String>,
3334
/// The currency of the amount in ISO-4217(alpha-3)
35+
#[serde(deserialize_with = "deserialize_optional_currency")]
3436
pub currency: Option<Currency>,
3537
/// Information relating to a currency conversion.
3638
pub currency_conversion: Option<requests::CurrencyConversion>,

crates/hyperswitch_connectors/src/utils.rs

+18
Original file line numberDiff line numberDiff line change
@@ -6073,3 +6073,21 @@ pub fn normalize_string(value: String) -> Result<String, regex::Error> {
60736073
let normalized = regex.replace_all(&lowercase_value, "").to_string();
60746074
Ok(normalized)
60756075
}
6076+
6077+
/// Custom deserializer for Option<Currency> that treats empty strings as None
6078+
pub fn deserialize_optional_currency<'de, D>(
6079+
deserializer: D,
6080+
) -> Result<Option<enums::Currency>, D::Error>
6081+
where
6082+
D: serde::Deserializer<'de>,
6083+
{
6084+
let string_data: Option<String> = Option::deserialize(deserializer)?;
6085+
match string_data {
6086+
Some(ref value) if !value.is_empty() => value
6087+
.clone()
6088+
.parse_enum("Currency")
6089+
.map(Some)
6090+
.map_err(|_| serde::de::Error::custom(format!("Invalid currency code: {}", value))),
6091+
_ => Ok(None),
6092+
}
6093+
}

0 commit comments

Comments
 (0)