"""Stufe 2: Rechnungs-PDF per Direktlink laden (Stripe, Paddle, ThriveCart, *.pdf).""" import urllib.request from typing import Optional MAX_BYTES = 20 * 1024 * 1024 def fetch_pdf(url: str, timeout: int = 30) -> Optional[bytes]: """-> PDF-Bytes oder None (kein PDF, z.B. HTML-Login-Seite). URL ist bereits per DIRECT_LINK geprüft (nur https).""" if not url.lower().startswith("https://"): return None req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0 (C-Stone Invoice Picker)"}) with urllib.request.urlopen(req, timeout=timeout) as r: data = r.read(MAX_BYTES + 1) if len(data) > MAX_BYTES or not data.startswith(b"%PDF-"): return None return data