En esta publicaci贸n, aprenderemos c贸mo aceptar pagos en el bot de Telegram usando la API de Yoomoney.
Introducci贸n
Para empezar, recientemente quise crear una tienda de art铆culos electr贸nicos en Telegram. Y me encontr茅 con el problema de que en el momento del trabajo no hab铆a soluciones listas para usar. Quer铆a aceptar pagos sin empresarios individuales y todo este movimiento. Por lo tanto, mi elecci贸n fue entre Qiwi y Yoomoney (anteriormente Yandex Money). Yo mismo soy de Bielorrusia ... Por lo tanto, es m谩s f谩cil obtener una cuenta "Identificada" de Yoomoney.
Como resultado, cre茅 la biblioteca yoomoney para Python.
Si esta publicaci贸n te ayud贸, estrella en GitHub . 隆Estar茅 muy contento!
Descripci贸n
Obtenemos el token
Comprobando el token
C贸mo emitir una factura para el pago
Verificaci贸n de pago
Obtenemos el token
Para utilizar la API de Yoomoney, debe obtener un token especial. En primer lugar, registramos la aplicaci贸n:
1. Vaya a la billetera YuMoney. Si no hay billetera, cree una .
2. Vaya a la p谩gina de registro de la aplicaci贸n .
3. Especifique los par谩metros de la aplicaci贸n:
4. Haga clic en el bot贸n Confirmar .
, , (client_id) , , (client_secret).
!
client_id redirect_uri, .
: . .
pip install yoomoney
from yoomoney import Authorize
Authorize(
client_id="YOUR_CLIENT_ID",
redirect_uri="YOUR_REDIRECT_URI",
scope=["account-info",
"operation-history",
"operation-details",
"incoming-transfers",
"payment-p2p",
"payment-shop",
]
)
! !
YOUR_TOKEN :
from yoomoney import Client
token = "YOUR_TOKEN"
client = Client(token)
user = client.account_info()
print("Account number:", user.account)
print("Account balance:", user.balance)
print("Account currency code in ISO 4217 format:", user.currency)
print("Account status:", user.account_status)
print("Account type:", user.account_type)
print("Extended balance information:")
for pair in vars(user.balance_details):
print("\t-->", pair, ":", vars(user.balance_details).get(pair))
print("Information about linked bank cards:")
cards = user.cards_linked
if len(cards) != 0:
for card in cards:
print(card.pan_fragment, " - ", card.type)
else:
print("No card is linked to the account")
:
Account number: 410019014512803
Account balance: 999999999999.99
Account currency code in ISO 4217 format: 643
Account status: identified
Account type: personal
Extended balance information:
--> total : 999999999999.99
--> available : 999999999999.99
--> deposition_pending : None
--> blocked : None
--> debt : None
--> hold : None
Information about linked bank cards:
No card is linked to the account
! .
Quickpay.
from yoomoney import Quickpay
quickpay = Quickpay(
receiver="410019014512803",
quickpay_form="shop",
targets="Sponsor this project",
paymentType="SB",
sum=150,
)
print(quickpay.base_url)
print(quickpay.redirected_url)
:
https://yoomoney.ru/quickpay/confirm.xml?receiver=410019014512803&quickpay-form=shop&targets=Sponsor%20this%20project&paymentType=SB&sum=150
https://yoomoney.ru/transfer/quickpay?requestId=343532353937313933395f66326561316639656131626539326632616434376662373665613831373636393537613336383639
. . .
, .
: , ?
label - , . , .
:
from yoomoney import Quickpay
quickpay = Quickpay(
receiver="410019014512803",
quickpay_form="shop",
targets="Sponsor this project",
paymentType="SB",
sum=150,
lebel="a1b2c3d4e5"
)
print(quickpay.base_url)
print(quickpay.redirected_url)
.
Client.
Conociendo la etiqueta de la transacci贸n, podemos filtrar el historial de transacciones de la billetera. Simplemente ponga una etiqueta en client.operation_history ():
from yoomoney import Client
token = "YOUR_TOKEN"
client = Client(token)
history = client.operation_history(label="a1b2c3d4e5")
print("List of operations:")
print("Next page starts with: ", history.next_record)
for operation in history.operations:
print()
print("Operation:",operation.operation_id)
print("\tStatus -->", operation.status)
print("\tDatetime -->", operation.datetime)
print("\tTitle -->", operation.title)
print("\tPattern id -->", operation.pattern_id)
print("\tDirection -->", operation.direction)
print("\tAmount -->", operation.amount)
print("\tLabel -->", operation.label)
print("\tType -->", operation.type)
Como resultado, obtenemos una lista de todas las operaciones para nuestro filtro:
List of operations:
Next page starts with: None
Operation: 670278348725002105
Status --> success
Datetime --> 2021-10-10 10:10:10
Title --> ****4487
Pattern id --> None
Direction --> in
Amount --> 150.0
Label --> a1b2c3d4e5
Type --> deposition
Ahora sabemos si el pago se realiz贸.
隆Todo! No se necesita nada m谩s para recibir pagos.
Conclusi贸n
Si esta publicaci贸n te ayud贸, estrella en GitHub . 隆Estar茅 muy contento!