implment fetching name from number

This commit is contained in:
Shihaam Abdul Rahman 2024-10-20 01:10:48 +05:00
parent 5c8c0fc99e
commit 6e0fc175d9
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636

27
api.py
View File

@ -1,21 +1,42 @@
#!/usr/bin/env python3
import os
from dotenv import load_dotenv
from flask import Flask, request, jsonify
import subprocess
import json
from datetime import datetime, timedelta
import os
from dotenv import load_dotenv
load_dotenv() # This will load environment variables from a .env file if it exists
app = Flask(__name__)
def fetch_account_name(account_no):
try:
result = subprocess.run(['./fetchname.sh', account_no], capture_output=True, text=True, check=True)
response = json.loads(result.stdout)
if response.get('success'):
return response.get('accountName')
except (subprocess.CalledProcessError, json.JSONDecodeError) as e:
app.logger.error(f"Error fetching account name: {str(e)}")
return None
@app.route('/verify-payment', methods=['POST'])
def verify_payment():
# Get data from request
data = request.json
benef_name = data.get('benefName', '').strip().lower() # Normalize input name
benef_name = data.get('benefName', '').strip().lower()
abs_amount = data.get('absAmount')
time_str = data.get('time')
account_no = data.get('accountNo')
# Fetch account name if account number is provided
if account_no:
fetched_name = fetch_account_name(account_no)
if fetched_name:
benef_name = fetched_name.strip().lower()
else:
return jsonify({"success": False, "message": "Failed to fetch account name"}), 400
# Validate input
if not all([benef_name, abs_amount, time_str]):