From 46edfd8c9425985d2d50770792ef74a572950cfb Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Sun, 20 Oct 2024 01:57:27 +0500 Subject: [PATCH] add support for 0. decimal values --- api.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index c15d258..6b2d7e0 100755 --- a/api.py +++ b/api.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from decimal import Decimal import os from dotenv import load_dotenv from flask import Flask, request, jsonify @@ -34,13 +35,17 @@ def verify_transaction(benef_name, abs_amount, request_time, tx_data_list): tx_benef_name = tx_data['benefName'].strip().lower() if (tx_benef_name == benef_name.strip().lower() and - str(tx_data['absAmount']) == str(abs_amount) and + compare_amounts(tx_data['absAmount'], abs_amount) and time_diff <= timedelta(minutes=30)): return True except ValueError as e: app.logger.error(f"Error processing transaction: {str(e)}") return False +def compare_amounts(amount1, amount2): + """Compare two amount strings as Decimal objects.""" + return Decimal(amount1) == Decimal(amount2) + @app.route('/verify-payment', methods=['POST']) def verify_payment(): data = request.json