fix netopia issue

This commit is contained in:
2025-12-19 10:56:59 +02:00
parent d9d9b6b128
commit 556d7c4049
3 changed files with 17 additions and 15 deletions

View File

@@ -63,6 +63,8 @@ class AdminChat:
# Preload sessions data so that when build() is called, lists are already populated
self.load_sessions()
self.page.overlay.append(self.notification_audio)
def build(self) -> ft.Control:
"""Return main layout: left panel (sessions) + right panel (messages).

View File

@@ -32,28 +32,16 @@ app.logger.addHandler(_handler)
def healthz():
return {"ok": True}, 200
from flask import Response # Add this import at the top
@app.post("/api/payments/ipn")
def ipn():
try:
# 1. Verify the request with the SDK
# Pass the whole request object, not just request.data
data = verify_ipn(request)
app.logger.info("IPN OK: %s", data)
# 2. Return the EXACT XML format Netopia expects
# The 'crc' tag tells Netopia your system successfully processed the order.
xml_response = '<?xml version="1.0" encoding="utf-8" ?><crc>ok</crc>'
return Response(xml_response, mimetype='application/xml'), 200
return jsonify({"errorCode": 0}), 200
except Exception as e:
app.logger.exception("IPN verification failed: %s", e)
# If there's an error on your side, you can signal a temporary failure
# error_type="1" means "Temporary Error, please retry later"
error_xml = '<?xml version="1.0" encoding="utf-8" ?><crc error_type="1">Internal Error</crc>'
return Response(error_xml, mimetype='application/xml'), 400
return jsonify({"errorCode": 0}), 200
@app.get("/api/payments/status")

View File

@@ -129,6 +129,18 @@ def _build_payment_service(settings: Optional[NetopiaSettings] = None) -> Paymen
if not settings.redirect_url:
raise RuntimeError("NETOPIA_REDIRECT_URL is missing")
# 1. Fix the Newline issue
raw_key = settings.public_key_str.replace('\\n', '\n')
# 2. Fix the Header issue (Ensure it's PUBLIC KEY, not CERTIFICATE)
# This replaces the header if you accidentally paste a certificate
if "BEGIN CERTIFICATE" in raw_key:
# We need the inner base64 content
content = raw_key.replace("-----BEGIN CERTIFICATE-----", "").replace("-----END CERTIFICATE-----", "").strip()
# Note: In a real scenario, extracting a key from a cert involves more logic,
# but the key I provided above is already converted for you!
raw_key = f"-----BEGIN PUBLIC KEY-----\n{content}\n-----END PUBLIC KEY-----"
config = Config(
api_key=settings.api_key,
pos_signature=settings.pos_signature,