Advertisement
disk6969

Untitled

Jun 17th, 2024 (edited)
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. import json, requests
  2. from telethon.tl.types import DataJSON, InputPaymentCredentials, InputInvoiceMessage
  3. from telethon.tl.types.payments import PaymentVerificationNeeded
  4.  
  5. card = {"number": "xxxxxxxxxxxxxxx", "month": "02", "year": "24", "cv": "111"}
  6.  
  7. async def pay_invoice(msg, card=card):
  8.     invoice = InputInvoiceMessage(peer=msg.input_chat, msg_id=msg.id)
  9.     form_info = await client(functions.payments.GetPaymentFormRequest(invoice=invoice))
  10.    
  11.     public_token = json.loads(form_info.native_params.data).get("public_token")
  12.  
  13.     card_info = json.dumps(
  14.         dict(
  15.             card={
  16.                 "number": card['number'],
  17.                 "expiration_month": card['month'],
  18.                 "expiration_year": card['year'],
  19.                 "security_code": card['cv'],
  20.             }
  21.         )
  22.     )
  23.  
  24.     url = "https://tgb.smart-glocal.com/cds/v1/tokenize/card"
  25.     headers = {"Content-Type": "application/json", "X-PUBLIC-TOKEN": public_token}
  26.  
  27.     req = requests.post(url, data=card_info, headers=headers)
  28.     if 200 <= req.status_code < 300:
  29.         token = req.json()['data']['token']
  30.         paymentJson = json.dumps(dict(token=token, type="card"))
  31.     else:
  32.         return
  33.     # Card might require manual verification, which is considered a failure.
  34.     SendData = await client(
  35.         functions.payments.SendPaymentFormRequest(
  36.             form_id=form_info.form_id,
  37.             invoice=invoice,
  38.             credentials=InputPaymentCredentials(data=DataJSON(paymentJson))))
  39.  
  40.     if not isinstance(SendData, PaymentVerificationNeeded):
  41.         return True
  42.     else:
  43.         print('Payment failed:', SendData.stringify())
  44.  
  45.  
  46. PREMIUM_BOT = 'PremiumBot'
  47.  
  48. async def something():
  49.     await client.send_message(PREMIUM_BOT, '/start')
  50.     invoice_msg = next(x for x in (await client.get_messages(PREMIUM_BOT, limit=4)) if x.invoice)
  51.     if await pay_invoice(invoice_msg):
  52.         print("Success")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement