Advertisement
disk6969

pyro gift premium

Sep 26th, 2023 (edited)
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.38 KB | None | 0 0
  1. import json, aiohttp
  2. from pyrogram.raw import functions
  3. from pyrogram.raw.types import DataJSON, InputPaymentCredentials, InputInvoiceSlug
  4. from pyrogram.raw.types.payments import PaymentVerificationNeeded
  5.  
  6. smart_glocal_url = "https://tgb.smart-glocal.com/cds/v1/tokenize/card"
  7.  
  8. card = {
  9.     "number": "________________",
  10.     "expiration_month": "00",
  11.     "expiration_year": "00",
  12.     "security_code": "000",
  13. }
  14.  
  15. async def payment_form(slug):
  16.     invoice = InputInvoiceSlug(slug=slug)
  17.     form_info = await client.invoke(functions.payments.GetPaymentForm(invoice=invoice))
  18.     if (provider := form_info.native_provider) != "smartglocal":
  19.         return print("Invlid provider:", provider)
  20.  
  21.     public_token = json.loads(form_info.native_params.data).get("public_token")
  22.     card_info = json.dumps(dict(card=card))
  23.  
  24.     headers = {"Content-Type": "application/json", "X-PUBLIC-TOKEN": public_token}
  25.  
  26.     async with aiohttp.ClientSession(headers=headers) as session:
  27.         res = await session.post(smart_glocal_url, data=card_info)
  28.  
  29.         if res.status >= 200 and res.status < 300:
  30.             token = (await res.json())["data"]["token"]
  31.             payment_json = json.dumps(dict(token=token, type="card"))
  32.         else:
  33.             return print("Failed to get token:", await res.json())
  34.  
  35.     send_confirm_data = await client.invoke(
  36.         functions.payments.SendPaymentForm(
  37.             form_id=form_info.form_id,
  38.             invoice=invoice,
  39.             credentials=InputPaymentCredentials(data=DataJSON(data=payment_json)),
  40.         )
  41.     )
  42.     if not isinstance(send_confirm_data, PaymentVerificationNeeded):
  43.         return True
  44.     print(f"Payment Failed, server returned:", send_confirm_data)
  45.  
  46. async def gift_premium(user_id):
  47.     full_user = (
  48.         await client.invoke(
  49.             functions.users.GetFullUser(id=await client.resolve_peer(user_id))
  50.         )
  51.     ).full_user
  52.     if not (gifts := full_user.premium_gifts):
  53.         raise ValueError("User can't be gifted premium")
  54.     month_slugs = {
  55.         str(option.months): option.bot_url.split("$")[-1]
  56.         for option in gifts
  57.         if option.bot_url
  58.     }
  59.     print("Enter one of the available months:", ", ".join(month_slugs))
  60.     if not (option := month_slugs.get(input(">>> "))):
  61.         raise ValueError("Invalid option")
  62.     if await payment_form(option):
  63.         return print("Gifted successfully")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement