add more logs

This commit is contained in:
2025-12-19 15:04:53 +02:00
parent bcca5ed270
commit d5e092c37a

View File

@@ -37,40 +37,41 @@ app.logger.addHandler(_handler)
def healthz():
return {"ok": True}, 200
# @app.post("/api/payments/ipn")
# def ipn():
# try:
# # Pass the whole request object, not just request.data
# data = verify_ipn(request)
# app.logger.info("IPN OK: %s", data)
# return jsonify({"errorCode": 0}), 200
# except Exception as e:
# app.logger.exception("IPN verification failed: %s", e)
# return jsonify({"errorCode": 0}), 200
@app.post("/api/payments/ipn")
def ipn():
# 1. Get the signature from the 'Verification-Token' header
token = request.headers.get('Verification-Token')
# 2. If it exists, inject it into the location the SDK expects
if token:
request.headers.environ['HTTP_X_NETOPIA_SIGNATURE'] = token
app.logger.info("Mapped Verification-Token to X-Netopia-Signature")
try:
app.logger.info("--- RAW REQUEST INSPECTION ---")
app.logger.info(f"Headers: {dict(request.headers)}")
app.logger.info(f"Form Data: {dict(request.form)}")
app.logger.info(f"JSON Data: {request.get_json(silent=True)}")
# Check common Netopia signature locations
sig = (request.headers.get('X-Netopia-Signature') or
request.form.get('data') or
(request.get_json(silent=True) or {}).get('data'))
if sig:
app.logger.info(f"FOUND SIGNATURE: {sig[:50]}...")
try:
import jwt
decoded = jwt.decode(sig, options={"verify_signature": False})
app.logger.info(f"DECODED POS FROM NETOPIA: {decoded.get('posSignature')}")
except Exception as e:
app.logger.error(f"Could not decode found signature: {e}")
else:
app.logger.error("NO SIGNATURE FOUND IN HEADERS, FORM, OR JSON")
# Pass the whole request object, not just request.data
# Now the SDK will find the signature in X-Netopia-Signature
data = verify_ipn(request)
app.logger.info("IPN OK: %s", data)
# NOTE: Your log shows "status: 12" and "Invalid card number"
# The verification should now pass, even if the payment failed.
app.logger.info("IPN Verification Result: %s", data)
return jsonify({"errorCode": 0}), 200
except Exception as e:
app.logger.exception("IPN verification failed: %s", e)
return jsonify({"errorCode": 0}), 200
return jsonify({"ok": False, "error": str(e)}), 400
@app.get("/api/payments/status")