commit 4b6b4f722acb1747b17437ccf00506e11073f9d9
parent 044272a46c228311dc603f0896c6c47399ef18fb
Author: NicholasFarrow <nicholas.w.farrow@gmail.com>
Date: Fri, 22 Jan 2021 10:47:09 +1100
small changes to lnd branch before merge
Diffstat:
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/invoice/payment_invoice.py b/invoice/payment_invoice.py
@@ -21,11 +21,11 @@ class invoice:
def create_qr(self):
- if payment.pay_method = 'lnd':
+ if payment.pay_method == 'lnd':
qr_str = "{}".format(self.address.upper())
else:
qr_str = "{}?amount={}&label={}".format(self.address.upper(), self.value, self.label)
-
+
img = qrcode.make(qr_str)
img.save('static/qr_codes/{}.png'.format(self.uuid))
return
diff --git a/pay/lnd.py b/pay/lnd.py
@@ -40,8 +40,8 @@ class lnd(invoice):
macaroon_filepath="admin.macaroon",
cert_filepath="tls.cert")
- print("Getting lnd balance...")
- info = self.lnd.channel_balance()
+ print("Getting lnd info...")
+ info = self.lnd.get_info()
print(info)
print("Successfully contacted lnd.")
@@ -105,6 +105,9 @@ class lnd(invoice):
unconf_paid = 0
else:
print("WEEEEEEEEEEEEEEEEEEEE")
+
+ #print(self.lnd.lookup_invoice(r_hash=self.hash))
+ print("Invoice ^")
# print(str(b64decode(self.hash.strip('\\'))))
# invoice_status = json.loads(MessageToJson(self.lnd.lookup_invoice(self.hash)))
diff --git a/server.py b/server.py
@@ -2,6 +2,7 @@ from flask import Flask, render_template, session
from flask_socketio import SocketIO, emit, disconnect
from markupsafe import escape
import time
+import os
import ssh_tunnel
import config
@@ -12,7 +13,17 @@ from pay import lnd
# Begin websocket
async_mode = None
app = Flask(__name__)
-app.config['SECRET_KEY'] = 'secret!'
+
+# Load API key
+if os.path.exists("BTCPyment_API_key"):
+ with open("BTCPyment_API_key", 'r') as f:
+ app.config['SECRET_KEY'] = f.read()
+else:
+ with open("BTCPyment_API_key", 'w') as f:
+ app.config['SECRET_KEY'] = os.urandom(64).hex()
+ f.write(app.config['SECRET_KEY'])
+
+print("Initialised Flask with secret key: {}".format(app.config['SECRET_KEY']))
socket_ = SocketIO(app, async_mode=async_mode, cors_allowed_origins="*")
# Render html
@@ -61,6 +72,10 @@ def make_payment(payload):
invoice.success.success()
+ # Call webhook if woocommerce webhook url has been provided.
+ if 'w_url' in payload.keys():
+ response = woo_webhook.hook(app.config['SECRET_KEY'], payload)
+
### DO SOMETHING
# Depends on config
# Get redirected?
@@ -151,5 +166,4 @@ print("Connection successful.")
if __name__ == '__main__':
- socket_.run(app, debug=True)
socket_.run(app, debug=False)