Advertisement
disk6969

Telethon payment

Aug 5th, 2023 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. import json, requests
  2. from telethon.tl.functions.payments import SendPaymentFormRequest
  3. from telethon.tl.types import JsonObject, InputPaymentCredentials, InputInvoiceMessage
  4. from telethon.tl.types.payments import PaymentVerificationNeeded
  5.  
  6. card = {"number": "xxxxxxxxxxxxxxx", "month": "02", "year": "24", "cv": "111"}
  7.  
  8. def PaymentForm(msg, card=card):
  9.  
  10.     invoice = InputInvoiceMessage(peer=msg.input_chat, msg_id=msg.id)
  11.     formInfo = client(functions.payments.GetPaymentFormRequest(invoice=invoice))
  12.    
  13.     # validate the card info from the provider and get Token to pass to Telegram
  14.     token = json.loads(formInfo.native_params.data).get("public_token")
  15.  
  16.     cardinfo = json.dumps(
  17.         dict(
  18.             card={
  19.                 "number": card.get("number"),
  20.                 "expiration_month": card.get("month"),
  21.                 "expiration_year": card.get("year"),
  22.                 "security_code": card.get("cv"),
  23.             }
  24.         )
  25.     )
  26.  
  27.     url = "https://tgb.smart-glocal.com/cds/v1/tokenize/card"
  28.     headers = {"Content-Type": "application/json", "X-PUBLIC-TOKEN": token}
  29.  
  30.     req = requests.post(url, data=cardinfo, headers=headers)
  31.     code = req.status_code
  32.     if code >= 200 and code < 300:
  33.         Token = req.json().get("data").get("token")
  34.         paymentJson = json.dumps(dict(token=Token, type="card"))
  35.     else:
  36.         return
  37.     # confirm purchase, Server might require extra confirmation for abnormal activity which means failure.
  38.     SendData = client(
  39.         SendPaymentFormRequest(
  40.             form_id=formInfo.form_id,
  41.             invoice=invoice,
  42.             credentials=InputPaymentCredentials(data=JsonObject(paymentJson))))
  43.  
  44.     if not isinstance(SendData, PaymentVerificationNeeded):
  45.         return True
  46.  
  47. async def something():
  48.     if PaymentForm(next(x for x in (await client.get_messages("Bot", limit=4)) if x.invoice))
  49.         print("Success")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement