diff --git a/src/extensions/low_balance.rs b/src/extensions/low_balance.rs new file mode 100644 index 0000000..50891f9 --- /dev/null +++ b/src/extensions/low_balance.rs @@ -0,0 +1,73 @@ +//! Low Balance Mapping for the Extensible Provisioning Protocol (EPP) +//! +//! https://www.verisign.com/assets/epp-sdk/verisign_epp-extension_low-balance_v01.html + +use serde::Deserialize; + +#[derive(Clone, Debug, Deserialize, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct LowBalance { + pub registrar_name: String, + pub credit_limit: String, + pub credit_threshold: Threshold, + pub available_credit: String, +} + +#[derive(Clone, Debug, Deserialize, PartialEq)] +pub struct Threshold { + pub r#type: ThresholdType, + #[serde(rename = "$value")] + pub value: String, +} + +#[derive(Clone, Copy, Debug, Deserialize, PartialEq)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum ThresholdType { + Fixed, + Percent, +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::message::poll::{MessageData, MessagePollResponse}; + use crate::message::MessagePoll; + use crate::response::ResultCode; + use crate::tests::{response_from_file, CLTRID, SVTRID}; + + #[test] + fn low_balance() { + let object = response_from_file::("response/message/poll_low_balance.xml"); + dbg!(&object); + + let low_balance = match object.res_data { + Some(MessagePollResponse { + message_data: MessageData::LowBalance(low_balance), + }) => low_balance, + _ => panic!("Unexpected message data"), + }; + + assert_eq!(low_balance.registrar_name, "Foobar, Inc."); + assert_eq!(low_balance.credit_limit, "0"); + assert_eq!( + low_balance.credit_threshold, + Threshold { + r#type: ThresholdType::Fixed, + value: "500".into(), + } + ); + assert_eq!(low_balance.available_credit, "491.31"); + + assert_eq!( + object.result.code, + ResultCode::CommandCompletedSuccessfullyAckToDequeue + ); + assert_eq!( + object.result.message, + "Command completed successfully; ack to dequeue".into() + ); + + assert_eq!(object.tr_ids.client_tr_id.unwrap(), CLTRID.into()); + assert_eq!(object.tr_ids.server_tr_id, SVTRID.into()); + } +} diff --git a/src/lib.rs b/src/lib.rs index 88304a3..dba3205 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,6 +107,7 @@ pub mod xml; pub mod extensions { pub mod consolidate; + pub mod low_balance; pub mod namestore; pub mod rgp; } diff --git a/src/message/poll.rs b/src/message/poll.rs index ed87ae7..9cbeaf2 100644 --- a/src/message/poll.rs +++ b/src/message/poll.rs @@ -1,5 +1,6 @@ use crate::common::NoExtension; use crate::domain::transfer::DomainTransferResponseData; +use crate::extensions::low_balance::LowBalance; use crate::host::info::HostInfoResponseData; use crate::request::{Command, Transaction}; use serde::{Deserialize, Serialize}; @@ -38,13 +39,16 @@ pub enum MessageData { /// Data under the <host:infData> tag #[serde(rename = "infData")] HostInfo(HostInfoResponseData), + /// Data under the <lowbalance> tag + #[serde(rename = "pollData")] + LowBalance(LowBalance), } /// Type that represents the <resData> tag for message poll response #[derive(Deserialize, Debug)] pub struct MessagePollResponse { /// Data under the <trnData> tag - #[serde(rename = "trnData", alias = "infData")] + #[serde(rename = "trnData", alias = "infData", alias = "pollData")] pub message_data: MessageData, } diff --git a/tests/resources/response/message/poll_low_balance.xml b/tests/resources/response/message/poll_low_balance.xml new file mode 100644 index 0000000..381ead9 --- /dev/null +++ b/tests/resources/response/message/poll_low_balance.xml @@ -0,0 +1,24 @@ + + + + + Command completed successfully; ack to dequeue + + + 2023-01-02T05:02:37Z + Low Account Balance(COM/NET) + + + + Foobar, Inc. + 0 + 500 + 491.31 + + + + cltrid:1626454866 + RO-6879-1627224678242975 + + +