Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json, requests
- from telethon.tl.functions.payments import SendPaymentFormRequest
- from telethon.tl.types import JsonObject, InputPaymentCredentials, InputInvoiceMessage
- from telethon.tl.types.payments import PaymentVerificationNeeded
- card = {"number": "xxxxxxxxxxxxxxx", "month": "02", "year": "24", "cv": "111"}
- def PaymentForm(msg, card=card):
- invoice = InputInvoiceMessage(peer=msg.input_chat, msg_id=msg.id)
- formInfo = client(functions.payments.GetPaymentFormRequest(invoice=invoice))
- # validate the card info from the provider and get Token to pass to Telegram
- token = json.loads(formInfo.native_params.data).get("public_token")
- cardinfo = json.dumps(
- dict(
- card={
- "number": card.get("number"),
- "expiration_month": card.get("month"),
- "expiration_year": card.get("year"),
- "security_code": card.get("cv"),
- }
- )
- )
- url = "https://tgb.smart-glocal.com/cds/v1/tokenize/card"
- headers = {"Content-Type": "application/json", "X-PUBLIC-TOKEN": token}
- req = requests.post(url, data=cardinfo, headers=headers)
- code = req.status_code
- if code >= 200 and code < 300:
- Token = req.json().get("data").get("token")
- paymentJson = json.dumps(dict(token=Token, type="card"))
- else:
- return
- # confirm purchase, Server might require extra confirmation for abnormal activity which means failure.
- SendData = client(
- SendPaymentFormRequest(
- form_id=formInfo.form_id,
- invoice=invoice,
- credentials=InputPaymentCredentials(data=JsonObject(paymentJson))))
- if not isinstance(SendData, PaymentVerificationNeeded):
- return True
- async def something():
- if PaymentForm(next(x for x in (await client.get_messages("Bot", limit=4)) if x.invoice))
- print("Success")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement