SatSale

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 440991b9ee447ab0387ae3137fdb2cf3241c5fc7
parent 7c2eb861500bad27bb9e9918fc99125953d41c22
Author: NicholasFarrow <nicholas.w.farrow@gmail.com>
Date:   Mon, 29 Mar 2021 02:22:15 +1100

Implement redirects

Diffstat:
Mconfig.py | 4++--
Mserver.py | 11+++--------
Mstatic/server_connection.js | 13+++++++++++++
3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/config.py b/config.py @@ -30,8 +30,8 @@ required_confirmations = 2 # Global connection attempts connection_attempts = 3 -# Redirect, not currently working.. -redirect = None +# Generic redirect url after payment +redirect = "https://github.com/nickfarrow/btcpyment" # Payment method pay_method = "bitcoind" diff --git a/server.py b/server.py @@ -53,6 +53,7 @@ def index(): # /pay is the main payment method for initiating a payment websocket. @app.route("/pay") def payment_page(): + # Arguments passed to HTML and also server_connection.js params = dict(request.args) params['lnd_enabled'] = (config.pay_method == "lnd") # Render payment page with the request arguments (?amount= etc.) @@ -111,14 +112,6 @@ def make_payment(payload): print("Successfully confirmed payment via webhook.") update_status(payment, "Order confirmed.") - # Redirect after payment - # TODO: add a delay here. Test. - if config.redirect is not None: - print("Redirecting to {}".format(config.redirect)) - return redirect(config.redirect) - else: - print("No redirect, closing.") - return @@ -140,6 +133,8 @@ def update_status(payment, status, console_status=True): "time_left": payment.time_left, "uuid": payment.uuid, "response": payment.response, + "paid": payment.paid, + "redirect": config.redirect # Can later expand to invoice specific redirects. }, ) return diff --git a/static/server_connection.js b/static/server_connection.js @@ -27,6 +27,19 @@ function initiate(payment_data) { // on the contents and status of the payment. conditionalPageLogic(msg) + console.log(msg); + + // Actions if paid + if (msg.paid == true) { + + // Redirect if paid + if (msg.redirect != null) { + sleep(5); + window.location.replace(msg.redirect); + } + } + + // If close? I forget.. if (cb) cb();