add support for 0. decimal values
This commit is contained in:
parent
e44aba9931
commit
46edfd8c94
7
api.py
7
api.py
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from flask import Flask, request, jsonify
|
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()
|
tx_benef_name = tx_data['benefName'].strip().lower()
|
||||||
|
|
||||||
if (tx_benef_name == benef_name.strip().lower() and
|
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)):
|
time_diff <= timedelta(minutes=30)):
|
||||||
return True
|
return True
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
app.logger.error(f"Error processing transaction: {str(e)}")
|
app.logger.error(f"Error processing transaction: {str(e)}")
|
||||||
return False
|
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'])
|
@app.route('/verify-payment', methods=['POST'])
|
||||||
def verify_payment():
|
def verify_payment():
|
||||||
data = request.json
|
data = request.json
|
||||||
|
Loading…
x
Reference in New Issue
Block a user