Browse Source

Auto-reconcile pending crypto from plain portal invoice view

main
def 6 days ago
parent
commit
2d4a104b0b
  1. 27
      backend/app.py
  2. 2
      templates/portal_invoice_detail.html

27
backend/app.py

@ -4505,6 +4505,30 @@ def portal_invoice_detail(invoice_id):
crypto_quote_window_expires_iso = None
crypto_quote_window_expires_local = None
if (invoice.get("status") or "").lower() != "paid":
if pay_mode != "crypto":
cursor.execute("""
SELECT id, invoice_id, client_id, payment_currency, payment_amount, cad_value_at_payment,
reference, wallet_address, payment_status, created_at, updated_at, txid, confirmations,
confirmation_required, notes
FROM payments
WHERE invoice_id = %s
AND client_id = %s
AND payment_status = 'pending'
AND notes LIKE '%%portal_crypto_intent:%%'
ORDER BY id DESC
LIMIT 1
""", (invoice_id, client["id"]))
auto_pending_payment = cursor.fetchone()
if auto_pending_payment:
pending_crypto_payment = auto_pending_payment
pay_mode = "crypto"
if not request.args.get("payment_id"):
selected_crypto_option = next(
(o for o in crypto_options if o["payment_currency"] == str(auto_pending_payment.get("payment_currency") or "").upper()),
None
)
if pay_mode == "crypto" and crypto_options and (invoice.get("status") or "").lower() != "paid":
quote_key = f"portal_crypto_quote_window_{invoice_id}_{client['id']}"
now_utc = datetime.now(timezone.utc)
@ -4532,6 +4556,9 @@ def portal_invoice_detail(invoice_id):
selected_crypto_option = next((o for o in crypto_options if o["symbol"] == selected_asset), None)
payment_id = (request.args.get("payment_id") or "").strip()
if not payment_id and pending_crypto_payment:
payment_id = str(pending_crypto_payment.get("id") or "").strip()
if payment_id.isdigit():
cursor.execute("""
SELECT id, invoice_id, client_id, payment_currency, payment_amount, cad_value_at_payment,

2
templates/portal_invoice_detail.html

@ -625,7 +625,7 @@ Reference: ${invoiceRef}`;
<script>
(function() {
const processingAutoRefreshEnabled = {{ 'true' if pending_crypto_payment and pending_crypto_payment.txid and (invoice.status or '')|lower != 'paid' else 'false' }};
const processingAutoRefreshEnabled = {{ 'true' if pending_crypto_payment and (invoice.status or '')|lower != 'paid' else 'false' }};
if (processingAutoRefreshEnabled) {
setTimeout(function() {
window.location.reload();

Loading…
Cancel
Save