From 4b05e9dd69900d532a4eb5c6aae51f6a0ca5a6a6 Mon Sep 17 00:00:00 2001 From: jc Date: Sat, 24 Aug 2024 13:01:51 +0400 Subject: [PATCH 1/3] Replace Currency enum with String, mention XTR special currency in docs --- crates/teloxide-core/schema.ron | 12 +- .../src/payloads/create_invoice_link.rs | 5 +- .../src/payloads/send_invoice.rs | 5 +- crates/teloxide-core/src/types.rs | 3 +- .../src/types/input_message_content.rs | 21 +- crates/teloxide-core/src/types/invoice.rs | 6 +- .../src/types/non_telegram_types/currency.rs | 365 ------------------ .../src/types/pre_checkout_query.rs | 10 +- .../src/types/successful_payment.rs | 10 +- 9 files changed, 50 insertions(+), 387 deletions(-) delete mode 100644 crates/teloxide-core/src/types/non_telegram_types/currency.rs diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 4a0c41e8..25636a6f 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -4041,7 +4041,11 @@ Schema( Param( name: "currency", ty: String, - descr: Doc(md: "Three-letter ISO 4217 currency code, see more on currencies"), + descr: Doc(md: "Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars]."), + md_links: { + "more on currencies":"https://core.telegram.org/bots/payments#supported-currencies", + "Telegram Stars": "Telegram Stars" + } ), Param( name: "prices", @@ -4187,7 +4191,11 @@ Schema( Param( name: "currency", ty: String, - descr: Doc(md: "Three-letter ISO 4217 currency code, see more on currencies"), + descr: Doc(md: "Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars]."), + md_links: { + "more on currencies":"https://core.telegram.org/bots/payments#supported-currencies", + "Telegram Stars": "Telegram Stars" + } ), Param( name: "prices", diff --git a/crates/teloxide-core/src/payloads/create_invoice_link.rs b/crates/teloxide-core/src/payloads/create_invoice_link.rs index 72748157..3640889c 100644 --- a/crates/teloxide-core/src/payloads/create_invoice_link.rs +++ b/crates/teloxide-core/src/payloads/create_invoice_link.rs @@ -19,7 +19,10 @@ impl_payload! { /// /// [Botfather]: https://t.me/botfather pub provider_token: String [into], - /// Three-letter ISO 4217 currency code, see more on currencies + /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars]. + /// + /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies + /// [Telegram Stars]: https://t.me/BotNews/90 pub currency: String [into], /// Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) pub prices: Vec [collect], diff --git a/crates/teloxide-core/src/payloads/send_invoice.rs b/crates/teloxide-core/src/payloads/send_invoice.rs index 3c199157..342863a2 100644 --- a/crates/teloxide-core/src/payloads/send_invoice.rs +++ b/crates/teloxide-core/src/payloads/send_invoice.rs @@ -26,7 +26,10 @@ impl_payload! { /// /// [Botfather]: https://t.me/botfather pub provider_token: String [into], - /// Three-letter ISO 4217 currency code, see more on currencies + /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars]. + /// + /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies + /// [Telegram Stars]: https://t.me/BotNews/90 pub currency: String [into], /// Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) pub prices: Vec [collect], diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index bbdd499c..5992e1bc 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -306,10 +306,9 @@ mod passport_data; mod passport_element_error; mod passport_file; -pub use non_telegram_types::{country_code::*, currency::*, until_date::*}; +pub use non_telegram_types::{country_code::*, until_date::*}; mod non_telegram_types { pub(super) mod country_code; - pub(super) mod currency; pub(crate) mod mime; pub(super) mod until_date; } diff --git a/crates/teloxide-core/src/types/input_message_content.rs b/crates/teloxide-core/src/types/input_message_content.rs index 62c7da33..989eb5d2 100644 --- a/crates/teloxide-core/src/types/input_message_content.rs +++ b/crates/teloxide-core/src/types/input_message_content.rs @@ -1,7 +1,7 @@ use reqwest::Url; use serde::{Deserialize, Serialize}; -use crate::types::{Currency, LabeledPrice, LinkPreviewOptions, MessageEntity, ParseMode}; +use crate::types::{LabeledPrice, LinkPreviewOptions, MessageEntity, ParseMode}; /// This object represents the content of a message to be sent as a result of an /// inline query. @@ -329,10 +329,12 @@ pub struct InputMessageContentInvoice { /// [@Botfather]: https://t.me/Botfather pub provider_token: String, - /// Three-letter ISO 4217 currency code, see [more on currencies] + /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass + /// `XTR` for payments in [Telegram Stars]. /// /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies - pub currency: Currency, + /// [Telegram Stars]: https://t.me/BotNews/90 + pub currency: String, /// Price breakdown, list of components (e.g. product price, tax, discount, /// delivery cost, delivery tax, bonus, etc.) @@ -396,12 +398,12 @@ pub struct InputMessageContentInvoice { } impl InputMessageContentInvoice { - pub fn new( + pub fn new( title: T, description: D, payload: PA, provider_token: PT, - currency: Currency, + currency: C, prices: PR, ) -> Self where @@ -409,12 +411,14 @@ impl InputMessageContentInvoice { D: Into, PA: Into, PT: Into, + C: Into, PR: IntoIterator, { let title = title.into(); let description = description.into(); let payload = payload.into(); let provider_token = provider_token.into(); + let currency = currency.into(); let prices = prices.into_iter().collect(); Self { @@ -474,8 +478,11 @@ impl InputMessageContentInvoice { } #[must_use] - pub fn currency(mut self, val: Currency) -> Self { - self.currency = val; + pub fn currency(mut self, val: T) -> Self + where + T: Into, + { + self.currency = val.into(); self } diff --git a/crates/teloxide-core/src/types/invoice.rs b/crates/teloxide-core/src/types/invoice.rs index efeb627b..d7176cf6 100644 --- a/crates/teloxide-core/src/types/invoice.rs +++ b/crates/teloxide-core/src/types/invoice.rs @@ -16,7 +16,11 @@ pub struct Invoice { /// invoice. pub start_parameter: String, - /// Three-letter ISO 4217 currency code. + /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass + /// `XTR` for payments in [Telegram Stars]. + /// + /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies + /// [Telegram Stars]: https://t.me/BotNews/90 pub currency: String, /// Total price in the smallest units of the currency (integer, **not** diff --git a/crates/teloxide-core/src/types/non_telegram_types/currency.rs b/crates/teloxide-core/src/types/non_telegram_types/currency.rs deleted file mode 100644 index a252b48b..00000000 --- a/crates/teloxide-core/src/types/non_telegram_types/currency.rs +++ /dev/null @@ -1,365 +0,0 @@ -use serde::{Deserialize, Serialize}; - -/// ISO 4217 currency. -#[allow(clippy::upper_case_acronyms)] -#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] -pub enum Currency { - /// United Arab Emirates dirham - AED, - /// Afghan afghani - AFN, - /// Albanian lek - ALL, - /// Armenian dram - AMD, - /// Netherlands Antillean guilder - ANG, - /// Angolan kwanza - AOA, - /// Argentine peso - ARS, - /// Australian dollar - AUD, - /// Aruban florin - AWG, - /// Azerbaijani manat - AZN, - /// Bosnia and Herzegovina convertible mark - BAM, - /// Barbados dollar - BBD, - /// Bangladeshi taka - BDT, - /// Bulgarian lev - BGN, - /// Bahraini dinar - BHD, - /// Burundian franc - BIF, - /// Bermudian dollar - BMD, - /// Brunei dollar - BND, - /// Boliviano - BOB, - /// Bolivian Mvdol (funds code) - BOV, - /// Brazilian real - BRL, - /// Bahamian dollar - BSD, - /// Bhutanese ngultrum - BTN, - /// Botswana pula - BWP, - /// Belarusian ruble - BYN, - /// Belize dollar - BZD, - /// Canadian dollar - CAD, - /// Congolese franc - CDF, - /// WIR euro (complementary currency) - CHE, - /// Swiss franc - CHF, - /// WIR franc (complementary currency) - CHW, - /// Unidad de Fomento (funds code) - CLF, - /// Chilean peso - CLP, - /// Chinese yuan - CNY, - /// Colombian peso - COP, - /// Unidad de Valor Real (UVR) (funds code) - COU, - /// Costa Rican colon - CRC, - /// Cuban convertible peso - CUC, - /// Cuban peso - CUP, - /// Cape Verdean escudo - CVE, - /// Czech koruna - CZK, - /// Djiboutian franc - DJF, - /// Danish krone - DKK, - /// Dominican peso - DOP, - /// Algerian dinar - DZD, - /// Egyptian pound - EGP, - /// Eritrean nakfa - ERN, - /// Ethiopian birr - ETB, - /// Euro - EUR, - /// Fiji dollar - FJD, - /// Falkland Islands pound - FKP, - /// Pound sterling - GBP, - /// Georgian lari - GEL, - /// Ghanaian cedi - GHS, - /// Gibraltar pound - GIP, - /// Gambian dalasi - GMD, - /// Guinean franc - GNF, - /// Guatemalan quetzal - GTQ, - /// Guyanese dollar - GYD, - /// Hong Kong dollar - HKD, - /// Honduran lempira - HNL, - /// Croatian kuna - HRK, - /// Haitian gourde - HTG, - /// Hungarian forint - HUF, - /// Indonesian rupiah - IDR, - /// Israeli new shekel - ILS, - /// Indian rupee - INR, - /// Iraqi dinar - IQD, - /// Iranian rial - IRR, - /// Icelandic króna - ISK, - /// Jamaican dollar - JMD, - /// Jordanian dinar - JOD, - /// Japanese yen - JPY, - /// Kenyan shilling - KES, - /// Kyrgyzstani som - KGS, - /// Cambodian riel - KHR, - /// Comoro franc - KMF, - /// North Korean won - KPW, - /// South Korean won - KRW, - /// Kuwaiti dinar - KWD, - /// Cayman Islands dollar - KYD, - /// Kazakhstani tenge - KZT, - /// Lao kip - LAK, - /// Lebanese pound - LBP, - /// Sri Lankan rupee - LKR, - /// Liberian dollar - LRD, - /// Lesotho loti - LSL, - /// Libyan dinar - LYD, - /// Moroccan dirham - MAD, - /// Moldovan leu - MDL, - /// Malagasy ariary - MGA, - /// Macedonian denar - MKD, - /// Myanmar kyat - MMK, - /// Mongolian tögrög - MNT, - /// Macanese pataca - MOP, - /// Mauritanian ouguiya - MRU, - /// Mauritian rupee - MUR, - /// Maldivian rufiyaa - MVR, - /// Malawian kwacha - MWK, - /// Mexican peso - MXN, - /// Mexican Unidad de Inversion (UDI) (funds code) - MXV, - /// Malaysian ringgit - MYR, - /// Mozambican metical - MZN, - /// Namibian dollar - NAD, - /// Nigerian naira - NGN, - /// Nicaraguan córdoba - NIO, - /// Norwegian krone - NOK, - /// Nepalese rupee - NPR, - /// New Zealand dollar - NZD, - /// Omani rial - OMR, - /// Panamanian balboa - PAB, - /// Peruvian sol - PEN, - /// Papua New Guinean kina - PGK, - /// Philippine peso - PHP, - /// Pakistani rupee - PKR, - /// Polish złoty - PLN, - /// Paraguayan guaraní - PYG, - /// Qatari riyal - QAR, - /// Romanian leu - RON, - /// Serbian dinar - RSD, - /// Russian ruble - RUB, - /// Rwandan franc - RWF, - /// Saudi riyal - SAR, - /// Solomon Islands dollar - SBD, - /// Seychelles rupee - SCR, - /// Sudanese pound - SDG, - /// Swedish krona/kronor - SEK, - /// Singapore dollar - SGD, - /// Saint Helena pound - SHP, - /// Sierra Leonean leone - SLL, - /// Somali shilling - SOS, - /// Surinamese dollar - SRD, - /// South Sudanese pound - SSP, - /// São Tomé and Príncipe dobra - STN, - /// Salvadoran colón - SVC, - /// Syrian pound - SYP, - /// Swazi lilangeni - SZL, - /// Thai baht - THB, - /// Tajikistani somoni - TJS, - /// Turkmenistan manat - TMT, - /// Tunisian dinar - TND, - /// Tongan paʻanga - TOP, - /// Turkish lira - TRY, - /// Trinidad and Tobago dollar - TTD, - /// New Taiwan dollar - TWD, - /// Tanzanian shilling - TZS, - /// Ukrainian hryvnia - UAH, - /// Ugandan shilling - UGX, - /// United States dollar - USD, - /// United States dollar (next day) (funds code) - USN, - /// Uruguay Peso en Unidades Indexadas (URUIURUI) (funds code) - UYI, - /// Uruguayan peso - UYU, - /// Unidad previsional - UYW, - /// Uzbekistan som - UZS, - /// Venezuelan bolívar soberano - VES, - /// Vietnamese đồng - VND, - /// Vanuatu vatu - VUV, - /// Samoan tala - WST, - /// CFA franc BEAC - XAF, - /// Silver (one troy ounce) - XAG, - /// Gold (one troy ounce) - XAU, - /// European Composite Unit (EURCO) (bond market unit) - XBA, - /// European Monetary Unit (E.M.U.-6) (bond market unit) - XBB, - /// European Unit of Account 9 (E.U.A.-9) (bond market unit) - XBC, - /// European Unit of Account 17 (E.U.A.-17) (bond market unit) - XBD, - /// East Caribbean dollar - XCD, - /// Special drawing rights - XDR, - /// CFA franc BCEAO - XOF, - /// Palladium (one troy ounce) - XPD, - /// CFP franc (franc Pacifique) - XPF, - /// Platinum (one troy ounce) - XPT, - /// SUCRE - XSU, - /// Code reserved for testing - XTS, - /// ADB Unit of Account - XUA, - /// No currency - XXX, - /// Yemeni rial - YER, - /// South African rand - ZAR, - /// Zambian kwacha - ZMW, - /// Zimbabwean dollar - ZWL, -} diff --git a/crates/teloxide-core/src/types/pre_checkout_query.rs b/crates/teloxide-core/src/types/pre_checkout_query.rs index 10628626..c9b6d029 100644 --- a/crates/teloxide-core/src/types/pre_checkout_query.rs +++ b/crates/teloxide-core/src/types/pre_checkout_query.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{Currency, OrderInfo, User}; +use crate::types::{OrderInfo, User}; /// This object contains information about an incoming pre-checkout query. /// @@ -14,10 +14,12 @@ pub struct PreCheckoutQuery { /// User who sent the query. pub from: User, - /// Three-letter ISO 4217 [currency] code. + /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass + /// "XTR" for payments in [Telegram Stars]. /// - /// [currency]: https://core.telegram.org/bots/payments#supported-currencies - pub currency: Currency, + /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies + /// [Telegram Stars]: https://t.me/BotNews/90 + pub currency: String, /// Total price in the _smallest units_ of the currency (integer, **not** /// float/double). For example, for a price of `US$ 1.45` pass `amount = diff --git a/crates/teloxide-core/src/types/successful_payment.rs b/crates/teloxide-core/src/types/successful_payment.rs index 8f5a4144..ac9153f6 100644 --- a/crates/teloxide-core/src/types/successful_payment.rs +++ b/crates/teloxide-core/src/types/successful_payment.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::types::{Currency, OrderInfo}; +use crate::types::OrderInfo; /// This object contains basic information about a successful payment. /// @@ -8,10 +8,12 @@ use crate::types::{Currency, OrderInfo}; #[serde_with::skip_serializing_none] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct SuccessfulPayment { - /// Three-letter ISO 4217 [currency] code. + /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass + /// "XTR" for payments in [Telegram Stars]. /// - /// [currency]: https://core.telegram.org/bots/payments#supported-currencies - pub currency: Currency, + /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies + /// [Telegram Stars]: https://t.me/BotNews/90 + pub currency: String, /// Total price in the smallest units of the currency (integer, not /// float/double). For example, for a price of `US$ 1.45` pass `amount = From b15ba1d31acf052804b175f8d2e7866195deef8f Mon Sep 17 00:00:00 2001 From: jc Date: Sat, 24 Aug 2024 16:29:28 +0400 Subject: [PATCH 2/3] Fix RON schema, prettify doc comments --- crates/teloxide-core/schema.ron | 24 +++++++++++-------- .../src/types/pre_checkout_query.rs | 2 +- .../src/types/successful_payment.rs | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index 25636a6f..f96b7fe2 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -4041,11 +4041,13 @@ Schema( Param( name: "currency", ty: String, - descr: Doc(md: "Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars]."), - md_links: { - "more on currencies":"https://core.telegram.org/bots/payments#supported-currencies", - "Telegram Stars": "Telegram Stars" - } + descr: Doc( + md: "Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars].", + md_links: { + "more on currencies":"https://core.telegram.org/bots/payments#supported-currencies", + "Telegram Stars": "https://t.me/BotNews/90" + } + ), ), Param( name: "prices", @@ -4191,11 +4193,13 @@ Schema( Param( name: "currency", ty: String, - descr: Doc(md: "Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars]."), - md_links: { - "more on currencies":"https://core.telegram.org/bots/payments#supported-currencies", - "Telegram Stars": "Telegram Stars" - } + descr: Doc( + md: "Three-letter ISO 4217 currency code, see [more on currencies]. Pass `XTR` for payments in [Telegram Stars].", + md_links: { + "more on currencies":"https://core.telegram.org/bots/payments#supported-currencies", + "Telegram Stars": "https://t.me/BotNews/90" + } + ), ), Param( name: "prices", diff --git a/crates/teloxide-core/src/types/pre_checkout_query.rs b/crates/teloxide-core/src/types/pre_checkout_query.rs index c9b6d029..0dc24b08 100644 --- a/crates/teloxide-core/src/types/pre_checkout_query.rs +++ b/crates/teloxide-core/src/types/pre_checkout_query.rs @@ -15,7 +15,7 @@ pub struct PreCheckoutQuery { pub from: User, /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass - /// "XTR" for payments in [Telegram Stars]. + /// `XTR` for payments in [Telegram Stars]. /// /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies /// [Telegram Stars]: https://t.me/BotNews/90 diff --git a/crates/teloxide-core/src/types/successful_payment.rs b/crates/teloxide-core/src/types/successful_payment.rs index ac9153f6..fbd81e6d 100644 --- a/crates/teloxide-core/src/types/successful_payment.rs +++ b/crates/teloxide-core/src/types/successful_payment.rs @@ -9,7 +9,7 @@ use crate::types::OrderInfo; #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct SuccessfulPayment { /// Three-letter ISO 4217 currency code, see [more on currencies]. Pass - /// "XTR" for payments in [Telegram Stars]. + /// `XTR` for payments in [Telegram Stars]. /// /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies /// [Telegram Stars]: https://t.me/BotNews/90 From 178db8a027b94cfd2fbf893aeb29e56cc18e9c52 Mon Sep 17 00:00:00 2001 From: jc Date: Sat, 24 Aug 2024 18:02:56 +0400 Subject: [PATCH 3/3] Update CHANGELOG.md --- crates/teloxide-core/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 3198fadc..989b6395 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -56,6 +56,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr1134]: https://github.com/teloxide/teloxide/pull/1134 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 +### Removed + +- `Currency` enum removed, its usages replaced with `String`. + ## 0.10.1 - 2024-08-17 ### Fixed