Browse Source

fixing bugs in btcpay server down detection

pull/34/head
forest 4 months ago
parent
commit
6c57e45cdd
  1. 2
      capsulflask/__init__.py
  2. 15
      capsulflask/payment.py
  3. 3
      capsulflask/static/style.css
  4. 6
      capsulflask/templates/account-balance.html

2
capsulflask/__init__.py

@ -143,7 +143,7 @@ else:
app.config['HTTP_CLIENT'] = MyHTTPClient(timeout_seconds=int(app.config['INTERNAL_HTTP_TIMEOUT_SECONDS']))
if app.config['BTCPAY_URL'] != "":
try_reconnnect_btcpay()
try_reconnnect_btcpay(app)
# only start the scheduler and attempt to migrate the database if we are running the app.
# otherwise we are running a CLI command.

15
capsulflask/payment.py

@ -1,4 +1,5 @@
import stripe
import requests
import json
import time
import decimal
@ -58,7 +59,7 @@ def btcpay_payment():
flash("BTCPay is not enabled on this server")
return redirect(url_for("console.account_balance"))
elif 'BTCPAY_CLIENT' not in current_app.config:
if not try_reconnnect_btcpay():
if not try_reconnnect_btcpay(current_app):
flash("can't contact the BTCPay server right now")
return redirect(url_for("console.account_balance"))
@ -100,7 +101,7 @@ def btcpay_payment():
def poll_btcpay_session(invoice_id):
if 'BTCPAY_CLIENT' not in current_app.config:
if not try_reconnnect_btcpay():
if not try_reconnnect_btcpay(current_app):
return [503, "can't contact btcpay server"]
invoice = None
@ -139,17 +140,17 @@ def poll_btcpay_session(invoice_id):
return [200, "ok"]
def try_reconnnect_btcpay():
def try_reconnnect_btcpay(app):
try:
response = requests.get(current_app.config['BTCPAY_URL'])
response = requests.get(app.config['BTCPAY_URL'])
if response.status_code == 200:
current_app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=current_app.config['BTCPAY_URL'], pem=current_app.config['BTCPAY_PRIVATE_KEY'])
app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY'])
return True
else:
current_app.logger.warn(f"Can't reach BTCPAY_URL {current_app.config['BTCPAY_URL']}: Response status code: {response.status_code}. Capsul will work fine except cryptocurrency payments will not work.")
app.logger.warn(f"Can't reach BTCPAY_URL {app.config['BTCPAY_URL']}: Response status code: {response.status_code}. Capsul will work fine except cryptocurrency payments will not work.")
return False
except:
current_app.logger.warn("unable to create btcpay client. Capsul will work fine except cryptocurrency payments will not work. The error was: " + my_exec_info_message(sys.exc_info()))
app.logger.warn("unable to create btcpay client. Capsul will work fine except cryptocurrency payments will not work. The error was: " + my_exec_info_message(sys.exc_info()))
return False

3
capsulflask/static/style.css

@ -53,9 +53,6 @@ a:hover, a:active, a:visited {
.error {
color: rgb(173, 74, 8);
font-weight: bold;
border: 1px dashed rgb(173, 74, 8);
border-radius: 0.5em;
padding: 1em;
}
.disabled {

6
capsulflask/templates/account-balance.html

@ -52,7 +52,11 @@
{% else %}
<li>
<span class="disabled">Add funds with Bitcoin/Litecoin/Monero (btcpay)</span>
<span class="error"> ERROR: the BTCPay server cannot be reached</span>
<ul>
<li>
<span class="error"> ERROR: the BTCPay server cannot be reached</span>
</li>
</ul>
</li>
{% endif %}

Loading…
Cancel
Save