|
|
|
@ -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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|