K
K
kolomiec_artiom2020-04-06 15:05:30
Python
kolomiec_artiom, 2020-04-06 15:05:30

How to connect qiwi hooks to server (python)?

Hello! I didn’t fully understand how to make sure that I receive notifications to the server about a new payment in Qiwi? Perhaps someone faced a similar issue and found articles on the Internet?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-04-06
@kolomiec_artiom

I read and I understand everything.
https://developer.qiwi.com/ru/bill-payments/?shell...
Write what exactly is not clear in this documentation.
Here is an approximate example from the documentation:

import hmac
import hashlib
from base64 import b64encode

@app.route("/qiwi-notify", methods=['POST'])
def QiwiNotify():
    error = 1
    req = request.json.get("bill")
    qSignature = request.headers.get("X-Api-Signature-SHA256")#предположительно строка в base64
    hSignature = b64encode(hmac.new(config["SECRET_QIWI_KEY"],msg="{}|{}|{}|{}|{}".format(\
                                         req["amount"]["currency"],req["amount"]["value"],req["billId"],req["siteId"],req["status"]["value"]\
                                         ),digestmod=hashlib.sha256).digest())
    #для отладки
    print ([qSignature,hSignature])
    print (req)
    if qSignature == hSignature: 
        #заносим в базу данные о счете и меняем error если неудачно.
        error = 0
    return jsonify({"error":error})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question