Source code for hydrogram.raw.functions.payments.bot_cancel_stars_subscription
# Hydrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2023-present Hydrogram <https://hydrogram.org>
#
# This file is part of Hydrogram.
#
# Hydrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hydrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Hydrogram. If not, see <http://www.gnu.org/licenses/>.
from io import BytesIO
from hydrogram.raw.core.primitives import Int, Long, Int128, Int256, Bool, Bytes, String, Double, Vector
from hydrogram.raw.core import TLObject
from hydrogram import raw
from typing import List, Optional, Any
# # # # # # # # # # # # # # # # # # # # # # # #
# !!! WARNING !!! #
# This is a generated file! #
# All changes made in this file will be lost! #
# # # # # # # # # # # # # # # # # # # # # # # #
[docs]
class BotCancelStarsSubscription(TLObject): # type: ignore
"""Cancel a bot subscription
Details:
- Layer: ``223``
- ID: ``6DFA0622``
Parameters:
user_id (:obj:`InputUser <hydrogram.raw.base.InputUser>`):
The ID of the user whose subscription should be (un)cancelled
charge_id (``str``):
The provider_charge_id from the messageActionPaymentSentMe service message sent to the bot for the first subscription payment.
restore (``bool``, *optional*):
If not set, disables autorenewal of the subscriptions, and prevents the user from reactivating the subscription once the current period expires: a subscription cancelled by the bot will have the starsSubscription.bot_canceled flag set. The bot can can partially undo this operation by setting this flag: this will allow the user to reactivate the subscription.
Returns:
``bool``
"""
__slots__: List[str] = ["user_id", "charge_id", "restore"]
ID = 0x6dfa0622
QUALNAME = "functions.payments.BotCancelStarsSubscription"
def __init__(self, *, user_id: "raw.base.InputUser", charge_id: str, restore: Optional[bool] = None) -> None:
self.user_id = user_id # InputUser
self.charge_id = charge_id # string
self.restore = restore # flags.0?true
@staticmethod
def read(b: BytesIO, *args: Any) -> "BotCancelStarsSubscription":
flags = Int.read(b)
restore = True if flags & (1 << 0) else False
user_id = TLObject.read(b)
charge_id = String.read(b)
return BotCancelStarsSubscription(user_id=user_id, charge_id=charge_id, restore=restore)
def write(self, *args) -> bytes:
b = BytesIO()
b.write(Int(self.ID, False))
flags = 0
flags |= (1 << 0) if self.restore else 0
b.write(Int(flags))
b.write(self.user_id.write())
b.write(String(self.charge_id))
return b.getvalue()