tgbot/types/definitions/payment/
refund.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Method, Payload},
5    types::Integer,
6};
7
8/// Contains basic information about a refunded payment.
9#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
11pub struct RefundedPayment {
12    /// Three-letter ISO 4217 currency code, or “XTR” for payments in Telegram Stars. Currently, always “XTR”.
13    pub currency: String,
14    /// Bot-specified invoice payload.
15    pub invoice_payload: String,
16    /// Telegram payment identifier.
17    pub telegram_payment_charge_id: String,
18    /// Total refunded price in the smallest units of the currency (integer, not float/double).
19    ///
20    /// For example, for a price of `US$ 1.45`, `total_amount = 145`.
21    /// See the exp parameter in [currencies.json][1],
22    /// it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
23    ///
24    /// [1]: https://core.telegram.org/bots/payments/currencies.json
25    pub total_amount: Integer,
26    /// Provider payment identifier.
27    pub provider_payment_charge_id: Option<String>,
28}
29
30impl RefundedPayment {
31    /// Creates a new `RefundedPayment`.
32    ///
33    /// # Arguments
34    ///
35    /// * `currency` - Three-letter ISO 4217 currency code.
36    /// * `invoice_payload` - Bot-specified invoice payload.
37    /// * `telegram_payment_charge_id` - Telegram payment identifier.
38    /// * `total_amount` - Total refunded price in the smallest units of the currency.
39    pub fn new<A, B, C>(currency: A, invoice_payload: B, telegram_payment_charge_id: C, total_amount: Integer) -> Self
40    where
41        A: Into<String>,
42        B: Into<String>,
43        C: Into<String>,
44    {
45        Self {
46            currency: currency.into(),
47            invoice_payload: invoice_payload.into(),
48            telegram_payment_charge_id: telegram_payment_charge_id.into(),
49            total_amount,
50            provider_payment_charge_id: None,
51        }
52    }
53
54    /// Sets a new provider payment identifier.
55    ///
56    /// # Arguments
57    ///
58    /// * `value` - Provider payment identifier.
59    pub fn with_provider_payment_charge_id<T>(mut self, value: T) -> Self
60    where
61        T: Into<String>,
62    {
63        self.provider_payment_charge_id = Some(value.into());
64        self
65    }
66}
67
68/// Refunds a successful payment in Telegram Stars.
69#[derive(Clone, Debug, Serialize)]
70pub struct RefundStarPayment {
71    user_id: Integer,
72    telegram_payment_charge_id: String,
73}
74
75impl RefundStarPayment {
76    /// Creates a new `RefundStarPayment`.
77    ///
78    /// # Arguments
79    ///
80    /// * `user_id` - Identifier of the user whose payment will be refunded.
81    /// * `telegram_payment_charge_id` - Telegram payment identifier.
82    pub fn new<T>(user_id: Integer, telegram_payment_charge_id: T) -> Self
83    where
84        T: Into<String>,
85    {
86        Self {
87            user_id,
88            telegram_payment_charge_id: telegram_payment_charge_id.into(),
89        }
90    }
91}
92
93impl Method for RefundStarPayment {
94    type Response = bool;
95
96    fn into_payload(self) -> Payload {
97        Payload::json("refundStarPayment", self)
98    }
99}