In diesem Beitrag erfahren Sie, wie Sie Zahlungen im Telegramm-Bot mithilfe der Yoomoney-API akzeptieren.
Einführung
Zunächst wollte ich kürzlich ein Geschäft für elektronische Waren auf Telegram einrichten. Und ich stieß auf das Problem, dass es zum Zeitpunkt der Arbeit keine vorgefertigten Lösungen gab. Ich wollte Zahlungen ohne einzelne Unternehmer und all diese Bewegung akzeptieren. Daher habe ich mich zwischen Qiwi und Yoomoney (ehemals Yandex Money) entschieden. Ich selbst komme aus Weißrussland ... Daher ist es einfacher, ein "identifiziertes" Konto bei Yoomoney zu erhalten.
Als Ergebnis habe ich die Yoomoney-Bibliothek für Python erstellt.
Wenn dieser Beitrag Ihnen geholfen hat, spielen Sie bitte auf GitHub . Ich werde mich sehr freuen!
Beschreibung
Wir bekommen den Token
Token überprüfen
So stellen Sie eine Rechnung zur Zahlung aus
Zahlungsüberprüfung
Wir bekommen den Token
Um die Yoomoney-API verwenden zu können, benötigen Sie ein spezielles Token. Zunächst registrieren wir die Bewerbung:
1. Gehen Sie zur YuMoney-Brieftasche. Wenn keine Brieftasche vorhanden ist, erstellen Sie eine .
2. Wechseln Sie zur Seite Anwendungsregistrierung .
3. Geben Sie die Anwendungsparameter an:
4. Klicken Sie auf die Schaltfläche Bestätigen .
, , (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.
Das Wissen Transaktion Etikett , können wir die Brieftasche des Transaktionshistorie filtern. Fügen Sie einfach ein Label in client.operation_history () ein:
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)
Als Ergebnis erhalten wir eine Liste aller Operationen für unseren Filter:
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
Jetzt wissen wir, ob die Zahlung durchgegangen ist.
Alles! Für den Erhalt von Zahlungen ist nichts anderes erforderlich.
Fazit
Wenn dieser Beitrag Ihnen geholfen hat, spielen Sie bitte auf GitHub . Ich werde mich sehr freuen!