stop giving false json
This commit is contained in:
parent
867b32e45e
commit
5fa2bf780d
27
api.py
27
api.py
@ -69,10 +69,25 @@ def compare_amounts(amount1, amount2):
|
|||||||
"""Compare two amount strings as Decimal objects."""
|
"""Compare two amount strings as Decimal objects."""
|
||||||
return Decimal(amount1) == Decimal(amount2)
|
return Decimal(amount1) == Decimal(amount2)
|
||||||
|
|
||||||
|
@app.errorhandler(400)
|
||||||
|
def bad_request(error):
|
||||||
|
return jsonify({"success": False, "message": "Invalid request: Malformed JSON"}), 400
|
||||||
|
|
||||||
|
@app.errorhandler(500)
|
||||||
|
def internal_error(error):
|
||||||
|
return jsonify({"success": False, "message": "Internal server error"}), 500
|
||||||
|
|
||||||
@app.route('/verify-payment', methods=['POST'])
|
@app.route('/verify-payment', methods=['POST'])
|
||||||
def verify_payment():
|
def verify_payment():
|
||||||
data = request.json
|
try:
|
||||||
benef_name = data.get('benefName', '').strip()
|
if not request.is_json:
|
||||||
|
return jsonify({"success": False, "message": "Request must be JSON"}), 400
|
||||||
|
|
||||||
|
data = request.get_json()
|
||||||
|
if data is None:
|
||||||
|
return jsonify({"success": False, "message": "Invalid JSON format"}), 400
|
||||||
|
|
||||||
|
benef_name = data.get('benefName', '').strip() if data.get('benefName') else ''
|
||||||
account_no = data.get('accountNo')
|
account_no = data.get('accountNo')
|
||||||
abs_amount = data.get('absAmount')
|
abs_amount = data.get('absAmount')
|
||||||
time_str = data.get('time')
|
time_str = data.get('time')
|
||||||
@ -102,9 +117,9 @@ def verify_payment():
|
|||||||
return jsonify({"success": False, "message": "No transaction data found"}), 404
|
return jsonify({"success": False, "message": "No transaction data found"}), 404
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
return jsonify({"success": False, "message": f"Error executing tx.sh: {str(e)}", "stderr": e.stderr}), 500
|
return jsonify({"success": False, "message": f"Error executing tx.sh: {str(e)}"}), 500
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
return jsonify({"success": False, "message": f"Error parsing tx.sh output: {str(e)}", "output": result.stdout}), 500
|
return jsonify({"success": False, "message": f"Error parsing tx.sh output: {str(e)}"}), 500
|
||||||
|
|
||||||
# First, try to verify with benefName if provided
|
# First, try to verify with benefName if provided
|
||||||
if benef_name:
|
if benef_name:
|
||||||
@ -131,6 +146,10 @@ def verify_payment():
|
|||||||
# If both verifications fail
|
# If both verifications fail
|
||||||
return jsonify({"success": False, "message": "Transaction not found, contact support"})
|
return jsonify({"success": False, "message": "Transaction not found, contact support"})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f"Unexpected error: {str(e)}")
|
||||||
|
return jsonify({"success": False, "message": "Internal server error"}), 500
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
debug_mode = os.getenv('APP_DEBUG', 'False').lower() in ('true', '1', 't')
|
debug_mode = os.getenv('APP_DEBUG', 'False').lower() in ('true', '1', 't')
|
||||||
port = int(os.getenv('PORT', 5000))
|
port = int(os.getenv('PORT', 5000))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user