switch to polling for btcpay payment sessions because btcpay web hooks

are super duper slow
This commit is contained in:
2020-05-16 22:04:51 -05:00
parent 155b0d579a
commit 2b04463e4e
3 changed files with 35 additions and 14 deletions

View File

@ -77,23 +77,12 @@ def btcpay_payment():
return render_template("btcpay.html", invoice_id=invoice_id)
@bp.route("/btcpay/webhook", methods=("POST",))
def btcpay_webhook():
current_app.logger.info(f"got btcpay webhook")
# IMPORTANT! there is no signature or credential for the data sent into this webhook :facepalm:
# its just a notification, thats all.
request_data = json.loads(request.data)
invoice_id = request_data['id']
current_app.logger.info(f"got btcpay webhook with invoice_id={invoice_id}")
def poll_btcpay_session(invoice_id):
# so you better make sure to get the invoice directly from the horses mouth!
invoice = current_app.config['BTCPAY_CLIENT'].get_invoice(invoice_id)
if invoice['currency'] != "USD":
abort(400, "invalid currency")
return [400, "invalid currency"]
dollars = invoice['price']
@ -110,7 +99,21 @@ def btcpay_webhook():
elif invoice['status'] == "expired" or invoice['status'] == "invalid":
get_model().btcpay_invoice_resolved(invoice_id, False)
return {"msg": "ok"}, 200
return [200, "ok"]
@bp.route("/btcpay/webhook", methods=("POST",))
def btcpay_webhook():
current_app.logger.info(f"got btcpay webhook")
# IMPORTANT! there is no signature or credential for the data sent into this webhook :facepalm:
# its just a notification, thats all.
request_data = json.loads(request.data)
invoice_id = request_data['id']
result = poll_btcpay_session(invoice_id)
abort(result[0], result[1])