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