Merge pull request #1144 from goostman-ai/master

Replace Currency enum with String, mention XTR special currency in docs
This commit is contained in:
Сырцев Вадим Игоревич 2024-08-24 14:10:42 +00:00 committed by GitHub
commit 0c0a024cec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 58 additions and 387 deletions

View file

@ -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 [pr1134]: https://github.com/teloxide/teloxide/pull/1134
[pr1146]: https://github.com/teloxide/teloxide/pull/1146 [pr1146]: https://github.com/teloxide/teloxide/pull/1146
### Removed
- `Currency` enum removed, its usages replaced with `String`.
## 0.10.1 - 2024-08-17 ## 0.10.1 - 2024-08-17
### Fixed ### Fixed

View file

@ -4172,7 +4172,13 @@ Schema(
Param( Param(
name: "currency", name: "currency",
ty: String, 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": "https://t.me/BotNews/90"
}
),
), ),
Param( Param(
name: "prices", name: "prices",
@ -4318,7 +4324,13 @@ Schema(
Param( Param(
name: "currency", name: "currency",
ty: String, 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": "https://t.me/BotNews/90"
}
),
), ),
Param( Param(
name: "prices", name: "prices",

View file

@ -19,7 +19,10 @@ impl_payload! {
/// ///
/// [Botfather]: https://t.me/botfather /// [Botfather]: https://t.me/botfather
pub provider_token: String [into], 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], pub currency: String [into],
/// Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) /// Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
pub prices: Vec<LabeledPrice> [collect], pub prices: Vec<LabeledPrice> [collect],

View file

@ -26,7 +26,10 @@ impl_payload! {
/// ///
/// [Botfather]: https://t.me/botfather /// [Botfather]: https://t.me/botfather
pub provider_token: String [into], 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], pub currency: String [into],
/// Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) /// Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
pub prices: Vec<LabeledPrice> [collect], pub prices: Vec<LabeledPrice> [collect],

View file

@ -326,10 +326,9 @@ mod passport_data;
mod passport_element_error; mod passport_element_error;
mod passport_file; 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 { mod non_telegram_types {
pub(super) mod country_code; pub(super) mod country_code;
pub(super) mod currency;
pub(crate) mod mime; pub(crate) mod mime;
pub(super) mod until_date; pub(super) mod until_date;
} }

View file

@ -1,7 +1,7 @@
use reqwest::Url; use reqwest::Url;
use serde::{Deserialize, Serialize}; 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 /// This object represents the content of a message to be sent as a result of an
/// inline query. /// inline query.
@ -329,10 +329,12 @@ pub struct InputMessageContentInvoice {
/// [@Botfather]: https://t.me/Botfather /// [@Botfather]: https://t.me/Botfather
pub provider_token: String, 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 /// [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, /// Price breakdown, list of components (e.g. product price, tax, discount,
/// delivery cost, delivery tax, bonus, etc.) /// delivery cost, delivery tax, bonus, etc.)
@ -396,12 +398,12 @@ pub struct InputMessageContentInvoice {
} }
impl InputMessageContentInvoice { impl InputMessageContentInvoice {
pub fn new<T, D, PA, PT, PR>( pub fn new<T, D, PA, PT, C, PR>(
title: T, title: T,
description: D, description: D,
payload: PA, payload: PA,
provider_token: PT, provider_token: PT,
currency: Currency, currency: C,
prices: PR, prices: PR,
) -> Self ) -> Self
where where
@ -409,12 +411,14 @@ impl InputMessageContentInvoice {
D: Into<String>, D: Into<String>,
PA: Into<String>, PA: Into<String>,
PT: Into<String>, PT: Into<String>,
C: Into<String>,
PR: IntoIterator<Item = LabeledPrice>, PR: IntoIterator<Item = LabeledPrice>,
{ {
let title = title.into(); let title = title.into();
let description = description.into(); let description = description.into();
let payload = payload.into(); let payload = payload.into();
let provider_token = provider_token.into(); let provider_token = provider_token.into();
let currency = currency.into();
let prices = prices.into_iter().collect(); let prices = prices.into_iter().collect();
Self { Self {
@ -474,8 +478,11 @@ impl InputMessageContentInvoice {
} }
#[must_use] #[must_use]
pub fn currency(mut self, val: Currency) -> Self { pub fn currency<T>(mut self, val: T) -> Self
self.currency = val; where
T: Into<String>,
{
self.currency = val.into();
self self
} }

View file

@ -16,7 +16,11 @@ pub struct Invoice {
/// invoice. /// invoice.
pub start_parameter: String, 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, pub currency: String,
/// Total price in the smallest units of the currency (integer, **not** /// Total price in the smallest units of the currency (integer, **not**

View file

@ -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,
}

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; 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. /// This object contains information about an incoming pre-checkout query.
/// ///
@ -14,10 +14,12 @@ pub struct PreCheckoutQuery {
/// User who sent the query. /// User who sent the query.
pub from: User, 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 /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies
pub currency: Currency, /// [Telegram Stars]: https://t.me/BotNews/90
pub currency: String,
/// Total price in the _smallest units_ of the currency (integer, **not** /// Total price in the _smallest units_ of the currency (integer, **not**
/// float/double). For example, for a price of `US$ 1.45` pass `amount = /// float/double). For example, for a price of `US$ 1.45` pass `amount =

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::types::{Currency, OrderInfo}; use crate::types::OrderInfo;
/// This object contains basic information about a successful payment. /// This object contains basic information about a successful payment.
/// ///
@ -8,10 +8,12 @@ use crate::types::{Currency, OrderInfo};
#[serde_with::skip_serializing_none] #[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct SuccessfulPayment { 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 /// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies
pub currency: Currency, /// [Telegram Stars]: https://t.me/BotNews/90
pub currency: String,
/// Total price in the smallest units of the currency (integer, not /// Total price in the smallest units of the currency (integer, not
/// float/double). For example, for a price of `US$ 1.45` pass `amount = /// float/double). For example, for a price of `US$ 1.45` pass `amount =