fix netopia issue

This commit is contained in:
2025-12-18 14:41:41 +02:00
parent ab62585ed0
commit 9e7d1afd1d
2 changed files with 18 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ import logging
from logging.handlers import RotatingFileHandler from logging.handlers import RotatingFileHandler
from flask import Flask, request, jsonify from flask import Flask, request, jsonify
from flask_cors import CORS from flask_cors import CORS
from flask import Response
try: try:
from dotenv import load_dotenv from dotenv import load_dotenv
@@ -31,16 +32,28 @@ app.logger.addHandler(_handler)
def healthz(): def healthz():
return {"ok": True}, 200 return {"ok": True}, 200
from flask import Response # Add this import at the top
@app.post("/api/payments/ipn") @app.post("/api/payments/ipn")
def ipn(): def ipn():
try: try:
# Pass the whole request object, not just request.data # 1. Verify the request with the SDK
data = verify_ipn(request) data = verify_ipn(request)
app.logger.info("IPN OK: %s", data) app.logger.info("IPN OK: %s", data)
return jsonify({"ok": True, "data": data}), 200
# 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
except Exception as e: except Exception as e:
app.logger.exception("IPN verification failed: %s", e) app.logger.exception("IPN verification failed: %s", e)
return jsonify({"ok": False, "error": str(e)}), 400
# 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
@app.get("/api/payments/status") @app.get("/api/payments/status")

View File

@@ -2,4 +2,5 @@ flet==0.28.3
netopia-sdk==2.1.1 netopia-sdk==2.1.1
python-dotenv==1.2.0 python-dotenv==1.2.0
Flask==3.1.2 Flask==3.1.2
flask-cors==6.0.1 flask-cors==6.0.1
flet-audio-0.1.0