Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json, aiohttp
- from pyrogram.raw import functions
- from pyrogram.raw.types import DataJSON, InputPaymentCredentials, InputInvoiceSlug
- from pyrogram.raw.types.payments import PaymentVerificationNeeded
- smart_glocal_url = "https://tgb.smart-glocal.com/cds/v1/tokenize/card"
- card = {
- "number": "________________",
- "expiration_month": "00",
- "expiration_year": "00",
- "security_code": "000",
- }
- async def payment_form(slug):
- invoice = InputInvoiceSlug(slug=slug)
- form_info = await client.invoke(functions.payments.GetPaymentForm(invoice=invoice))
- if (provider := form_info.native_provider) != "smartglocal":
- return print("Invlid provider:", provider)
- public_token = json.loads(form_info.native_params.data).get("public_token")
- card_info = json.dumps(dict(card=card))
- headers = {"Content-Type": "application/json", "X-PUBLIC-TOKEN": public_token}
- async with aiohttp.ClientSession(headers=headers) as session:
- res = await session.post(smart_glocal_url, data=card_info)
- if res.status >= 200 and res.status < 300:
- token = (await res.json())["data"]["token"]
- payment_json = json.dumps(dict(token=token, type="card"))
- else:
- return print("Failed to get token:", await res.json())
- send_confirm_data = await client.invoke(
- functions.payments.SendPaymentForm(
- form_id=form_info.form_id,
- invoice=invoice,
- credentials=InputPaymentCredentials(data=DataJSON(data=payment_json)),
- )
- )
- if not isinstance(send_confirm_data, PaymentVerificationNeeded):
- return True
- print(f"Payment Failed, server returned:", send_confirm_data)
- async def gift_premium(user_id):
- full_user = (
- await client.invoke(
- functions.users.GetFullUser(id=await client.resolve_peer(user_id))
- )
- ).full_user
- if not (gifts := full_user.premium_gifts):
- raise ValueError("User can't be gifted premium")
- month_slugs = {
- str(option.months): option.bot_url.split("$")[-1]
- for option in gifts
- if option.bot_url
- }
- print("Enter one of the available months:", ", ".join(month_slugs))
- if not (option := month_slugs.get(input(">>> "))):
- raise ValueError("Invalid option")
- if await payment_form(option):
- return print("Gifted successfully")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement