add support for 0. decimal values
This commit is contained in:
		
							
								
								
									
										7
									
								
								api.py
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user