Add support for Verisign low balance mapping extension
This commit is contained in:
parent
6181d69b7c
commit
7e3006825f
|
@ -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::<MessagePoll>("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());
|
||||
}
|
||||
}
|
|
@ -107,6 +107,7 @@ pub mod xml;
|
|||
|
||||
pub mod extensions {
|
||||
pub mod consolidate;
|
||||
pub mod low_balance;
|
||||
pub mod namestore;
|
||||
pub mod rgp;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<response>
|
||||
<result code="1301">
|
||||
<msg>Command completed successfully; ack to dequeue</msg>
|
||||
</result>
|
||||
<msgQ count="41" id="123456789">
|
||||
<qDate>2023-01-02T05:02:37Z</qDate>
|
||||
<msg>Low Account Balance(COM/NET)</msg>
|
||||
</msgQ>
|
||||
<resData>
|
||||
<lowbalance-poll:pollData xmlns:lowbalance-poll="http://www.verisign.com/epp/lowbalance-poll-1.0">
|
||||
<lowbalance-poll:registrarName>Foobar, Inc.</lowbalance-poll:registrarName>
|
||||
<lowbalance-poll:creditLimit>0</lowbalance-poll:creditLimit>
|
||||
<lowbalance-poll:creditThreshold type="FIXED">500</lowbalance-poll:creditThreshold>
|
||||
<lowbalance-poll:availableCredit>491.31</lowbalance-poll:availableCredit>
|
||||
</lowbalance-poll:pollData>
|
||||
</resData>
|
||||
<trID>
|
||||
<clTRID>cltrid:1626454866</clTRID>
|
||||
<svTRID>RO-6879-1627224678242975</svTRID>
|
||||
</trID>
|
||||
</response>
|
||||
</epp>
|
Loading…
Reference in New Issue