implment fetching name from number
This commit is contained in:
parent
5c8c0fc99e
commit
6e0fc175d9
27
api.py
27
api.py
@ -1,21 +1,42 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, timedelta
|
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__)
|
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'])
|
@app.route('/verify-payment', methods=['POST'])
|
||||||
def verify_payment():
|
def verify_payment():
|
||||||
# Get data from request
|
# Get data from request
|
||||||
data = request.json
|
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')
|
abs_amount = data.get('absAmount')
|
||||||
time_str = data.get('time')
|
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
|
# Validate input
|
||||||
if not all([benef_name, abs_amount, time_str]):
|
if not all([benef_name, abs_amount, time_str]):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user