Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json, requests
- from telethon.tl.types import DataJSON, InputPaymentCredentials, InputInvoiceMessage
- from telethon.tl.types.payments import PaymentVerificationNeeded
- card = {"number": "xxxxxxxxxxxxxxx", "month": "02", "year": "24", "cv": "111"}
- async def pay_invoice(msg, card=card):
- invoice = InputInvoiceMessage(peer=msg.input_chat, msg_id=msg.id)
- form_info = await client(functions.payments.GetPaymentFormRequest(invoice=invoice))
- public_token = json.loads(form_info.native_params.data).get("public_token")
- card_info = json.dumps(
- dict(
- card={
- "number": card['number'],
- "expiration_month": card['month'],
- "expiration_year": card['year'],
- "security_code": card['cv'],
- }
- )
- )
- url = "https://tgb.smart-glocal.com/cds/v1/tokenize/card"
- headers = {"Content-Type": "application/json", "X-PUBLIC-TOKEN": public_token}
- req = requests.post(url, data=card_info, headers=headers)
- if 200 <= req.status_code < 300:
- token = req.json()['data']['token']
- paymentJson = json.dumps(dict(token=token, type="card"))
- else:
- return
- # Card might require manual verification, which is considered a failure.
- SendData = await client(
- functions.payments.SendPaymentFormRequest(
- form_id=form_info.form_id,
- invoice=invoice,
- credentials=InputPaymentCredentials(data=DataJSON(paymentJson))))
- if not isinstance(SendData, PaymentVerificationNeeded):
- return True
- else:
- print('Payment failed:', SendData.stringify())
- PREMIUM_BOT = 'PremiumBot'
- async def something():
- await client.send_message(PREMIUM_BOT, '/start')
- invoice_msg = next(x for x in (await client.get_messages(PREMIUM_BOT, limit=4)) if x.invoice)
- if await pay_invoice(invoice_msg):
- print("Success")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement