add support for 0. decimal values

This commit is contained in:
Shihaam Abdul Rahman 2024-10-20 01:57:27 +05:00
parent e44aba9931
commit 46edfd8c94
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636

7
api.py
View File

@ -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