use serde::Deserialize;
use serde_json::Value;
use crate::core::models::common::Currency;
pub type AuthenticationStatus = String;
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct AuthenticationResponse {
pub authentication_id: String,
pub merchant_id: String,
pub status: AuthenticationStatus,
pub amount: i64,
pub currency: Currency,
#[serde(default)]
pub client_secret: Option<String>,
#[serde(default)]
pub authentication_connector: Option<String>,
#[serde(default)]
pub force_3ds_challenge: Option<bool>,
#[serde(default)]
pub return_url: Option<String>,
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl std::fmt::Debug for AuthenticationResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AuthenticationResponse")
.field("authentication_id", &self.authentication_id)
.field("merchant_id", &self.merchant_id)
.field("status", &self.status)
.field("amount", &self.amount)
.field("currency", &self.currency)
.field(
"client_secret",
&self.client_secret.as_ref().map(|_| "[redacted]"),
)
.field("authentication_connector", &self.authentication_connector)
.field("force_3ds_challenge", &self.force_3ds_challenge)
.field("return_url", &self.return_url)
.field("extra", &self.extra)
.finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn de(json: &str) -> AuthenticationResponse {
serde_json::from_str(json).expect("fixture deserializes")
}
const BASE: &str = r#""authentication_id":"auth_1","merchant_id":"mer_1",
"status":"started","amount":1000,"currency":"USD""#;
#[test]
fn authentication_response_debug_redacts_the_client_secret() {
let res = de(&format!(
r#"{{{BASE},"client_secret":"auth_1_secret_abc","return_url":"https://shop.example/r"}}"#
));
let rendered = format!("{res:?}");
assert!(!rendered.contains("auth_1_secret_abc"), "{rendered}");
assert!(rendered.contains("auth_1"), "{rendered}");
assert!(rendered.contains("https://shop.example/r"), "{rendered}");
assert!(rendered.contains("Some("), "{rendered}");
}
#[test]
fn authentication_response_debug_shows_none_when_no_client_secret() {
let res = de(&format!(r#"{{{BASE}}}"#));
assert!(format!("{res:?}").contains("client_secret: None"));
}
#[test]
fn authentication_response_keeps_unknown_fields_in_extra() {
let res = de(&format!(r#"{{{BASE},"three_ds_server_id":"srv_9"}}"#));
assert_eq!(res.amount, 1000);
assert_eq!(res.currency, "USD");
assert_eq!(res.extra["three_ds_server_id"], "srv_9");
assert_eq!(res.force_3ds_challenge, None);
}
}