fix netopia issue
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from flask import Flask, request, jsonify
|
||||
from flask_cors import CORS
|
||||
from flask import Response
|
||||
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
@@ -31,16 +32,28 @@ 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:
|
||||
# Pass the whole request object, not just request.data
|
||||
# 1. Verify the request with the SDK
|
||||
data = verify_ipn(request)
|
||||
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:
|
||||
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")
|
||||
|
||||
@@ -3,3 +3,4 @@ netopia-sdk==2.1.1
|
||||
python-dotenv==1.2.0
|
||||
Flask==3.1.2
|
||||
flask-cors==6.0.1
|
||||
flet-audio-0.1.0
|
||||
Reference in New Issue
Block a user