diff --git a/backend/app.py b/backend/app.py index bb22c37..93a0098 100644 --- a/backend/app.py +++ b/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, diff --git a/templates/portal_invoice_detail.html b/templates/portal_invoice_detail.html index b4fc582..4fae514 100644 --- a/templates/portal_invoice_detail.html +++ b/templates/portal_invoice_detail.html @@ -625,7 +625,7 @@ Reference: ${invoiceRef}`;