tgbot/types/definitions/payment/
subscription.rs

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