forked from 3wordchant/capsul-flask
started working on cron job task
This commit is contained in:
@ -55,12 +55,13 @@ def btcpay_payment():
|
||||
currency="USD",
|
||||
itemDesc="Capsul Cloud Compute",
|
||||
transactionSpeed="high",
|
||||
redirectURL=f"{current_app.config['BASE_URL']}/account-balance"
|
||||
redirectURL=f"{current_app.config['BASE_URL']}/account-balance",
|
||||
notificationURL=f"{current_app.config['BASE_URL']}/payment/btcpay/webhook"
|
||||
))
|
||||
# print(invoice)
|
||||
invoice_id = invoice["id"]
|
||||
|
||||
print(f"created btcpay invoice_id={invoice_id} ( {session['account']}, ${request.form['dollars']} )")
|
||||
print(f"created btcpay invoice_id={invoice_id} ( {session['account']}, ${dollars} )")
|
||||
|
||||
get_model().create_payment_session("btcpay", invoice_id, session["account"], dollars)
|
||||
|
||||
@ -72,6 +73,35 @@ def btcpay_payment():
|
||||
return render_template("btcpay.html", invoice_id=invoice_id)
|
||||
|
||||
|
||||
@bp.route("/btcpay/webhook", methods=("POST",))
|
||||
def 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']
|
||||
|
||||
# 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")
|
||||
|
||||
dollars = invoice['price']
|
||||
|
||||
if invoice['status'] == "paid" or invoice['status'] == "confirmed":
|
||||
success_account = get_model().consume_payment_session("btcpay", invoice_id, dollars)
|
||||
|
||||
if success_account:
|
||||
print(f"{success_account} paid ${dollars} successfully (btcpay_invoice_id={invoice_id})")
|
||||
|
||||
elif invoice['status'] == "complete":
|
||||
get_model().btcpay_invoice_resolved(invoice_id, True)
|
||||
elif invoice['status'] == "expired" or invoice['status'] == "invalid":
|
||||
get_model().btcpay_invoice_resolved(invoice_id, False)
|
||||
|
||||
|
||||
|
||||
@bp.route("/stripe", methods=("GET", "POST"))
|
||||
@account_required
|
||||
def stripe_payment():
|
||||
@ -142,7 +172,7 @@ def success():
|
||||
|
||||
#consume_payment_session deletes the checkout session row and inserts a payment row
|
||||
# its ok to call consume_payment_session more than once because it only takes an action if the session exists
|
||||
success_account = get_model().consume_payment_session(stripe_checkout_session_id, dollars)
|
||||
success_account = get_model().consume_payment_session("stripe", stripe_checkout_session_id, dollars)
|
||||
|
||||
if success_account:
|
||||
print(f"{success_account} paid ${dollars} successfully (stripe_checkout_session_id={stripe_checkout_session_id})")
|
||||
@ -168,7 +198,7 @@ def success():
|
||||
|
||||
# #consume_payment_session deletes the checkout session row and inserts a payment row
|
||||
# # its ok to call consume_payment_session more than once because it only takes an action if the session exists
|
||||
# success_account = get_model().consume_payment_session(stripe_checkout_session_id, dollars)
|
||||
# success_account = get_model().consume_payment_session("stripe", stripe_checkout_session_id, dollars)
|
||||
# if success_account:
|
||||
# print(f"{success_account} paid ${dollars} successfully (stripe_checkout_session_id={stripe_checkout_session_id})")
|
||||
|
||||
|
Reference in New Issue
Block a user