tgbot/types/payment/subscription/
mod.rs

1use serde::Serialize;
2
3use crate::{
4    api::{Method, Payload},
5    types::Integer,
6};
7
8#[cfg(test)]
9mod tests;
10
11/// Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars.
12#[derive(Clone, Debug, Serialize)]
13pub struct EditUserStarSubscription {
14    user_id: Integer,
15    telegram_payment_charge_id: String,
16    is_canceled: bool,
17}
18
19impl EditUserStarSubscription {
20    /// Creates a new `EditUserStarSubscription`.
21    ///
22    /// # Arguments
23    ///
24    /// * `user_id` - Identifier of the user whose subscription will be edited.
25    /// * `telegram_payment_charge_id` - Telegram payment identifier for the subscription.
26    /// * `is_canceled` - Whether to cancel extension of the user subscription;
27    ///   the subscription must be active up to the end of the current subscription period;
28    ///   use false to allow the user to re-enable a subscription that was previously canceled by the bot.
29    pub fn new<T>(user_id: Integer, telegram_payment_charge_id: T, is_canceled: bool) -> Self
30    where
31        T: Into<String>,
32    {
33        Self {
34            user_id,
35            telegram_payment_charge_id: telegram_payment_charge_id.into(),
36            is_canceled,
37        }
38    }
39}
40
41impl Method for EditUserStarSubscription {
42    type Response = bool;
43
44    fn into_payload(self) -> Payload {
45        Payload::json("editUserStarSubscription", self)
46    }
47}