cd /home/def/otb_billing/backend || exit 1 set -e STAMP="$(date +%Y%m%d-%H%M%S)" cp app.py "app.py.fix-dead-pending.${STAMP}.bak" python3 <<'PY' from pathlib import Path p = Path("app.py") text = p.read_text() needle = "if payment_id.isdigit():" if needle not in text: raise SystemExit("FAILED: anchor not found") inject = """ # === KILL DEAD PENDING PAYMENT (no txid + expired lock) === if pending_crypto_payment: try: txid = pending_crypto_payment.get("txid") lock_expired = pending_crypto_payment.get("lock_expired") if (not txid) and lock_expired: pending_crypto_payment = None payment_id = "" except Exception as e: print("[dead pending cleanup error]", e) """ text = text.replace(needle, inject + "\n" + needle, 1) p.write_text(text) print("OK: dead pending cleanup injected") PY echo "===== compile check =====" python3 -m py_compile app.py && echo "PY_COMPILE_OK" echo "===== restart service =====" sudo systemctl restart otb_billing echo "===== status =====" sudo systemctl status otb_billing --no-pager -l echo echo "DONE" echo "Now refresh your invoice page"