diff --git a/src/core/types/label_price.rs b/src/core/types/label_price.rs index a9ced54e..d7816ef3 100644 --- a/src/core/types/label_price.rs +++ b/src/core/types/label_price.rs @@ -1,5 +1,29 @@ -#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize)] +/// This object represents a portion of the price for goods or services. pub struct LabeledPrice { + /// Portion label pub label: String, + /// Price of the product in the smallest units of the + /// [currency](https://core.telegram.org/bots/payments#supported-currencies) + /// (integer, not float/double). For example, for a price of US$ 1.45 pass + /// amount = 145. See the exp parameter in [`currencies.json`](https://core.telegram.org/bots/payments/currencies.json), + /// it shows the number of digits past the decimal point for each currency + /// (2 for the majority of currencies). pub amount: i64, } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn serialize() { + let labeled_price = LabeledPrice { + label: "Label".to_string(), + amount: 60 + }; + let expected = r#"{"label":"Label","amount":60}"#; + let actual = serde_json::to_string(&labeled_price).unwrap(); + assert_eq!(actual, expected); + } +} diff --git a/src/core/types/send_invoice.rs b/src/core/types/send_invoice.rs index 87c26524..07698819 100644 --- a/src/core/types/send_invoice.rs +++ b/src/core/types/send_invoice.rs @@ -1,6 +1,6 @@ use crate::core::types::{InlineKeyboardMarkup, LabeledPrice}; -#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Hash, PartialEq, Eq, Clone)] pub struct SendInvoice { pub chat_id: i64, pub title: String, diff --git a/src/core/types/shipping_option.rs b/src/core/types/shipping_option.rs index 4dc1835c..9a6e4e8e 100644 --- a/src/core/types/shipping_option.rs +++ b/src/core/types/shipping_option.rs @@ -1,8 +1,31 @@ use crate::core::types::LabeledPrice; -#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize)] +/// This object represents one shipping option. pub struct ShippingOption { - pub id: i64, + /// Shipping option identifier + pub id: String, + /// Option title pub title: String, + /// List of price portions pub prices: Vec, } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn serialize() { + let shipping_option = ShippingOption { + id: "0".to_string(), + title: "Option".to_string(), + prices: vec![ + LabeledPrice { label: "Label".to_string(), amount: 60 } + ] + }; + let expected = r#"{"id":"0","title":"Option","prices":[{"label":"Label","amount":60}]}"#; + let actual = serde_json::to_string(&shipping_option).unwrap(); + assert_eq!(actual, expected); + } +}