Compare commits
3 Commits
629aeeabec
...
f8bb951ee3
Author | SHA1 | Date | |
---|---|---|---|
f8bb951ee3 | |||
a7b80c5702 | |||
d594b3373f |
73
api.py
Normal file
73
api.py
Normal file
@ -0,0 +1,73 @@
|
||||
from flask import Flask, request, jsonify
|
||||
import subprocess
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@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
|
||||
abs_amount = data.get('absAmount')
|
||||
time_str = data.get('time')
|
||||
|
||||
# Validate input
|
||||
if not all([benef_name, abs_amount, time_str]):
|
||||
return jsonify({"success": False, "message": "Missing required parameters"}), 400
|
||||
|
||||
try:
|
||||
# Parse the input time
|
||||
request_time = datetime.strptime(time_str, "%Y-%m-%d %H:%M")
|
||||
except ValueError:
|
||||
return jsonify({"success": False, "message": "Invalid time format"}), 400
|
||||
|
||||
# Execute tx.sh and get the output
|
||||
try:
|
||||
result = subprocess.run(['./tx.sh'], capture_output=True, text=True, check=True)
|
||||
tx_response = json.loads(result.stdout)
|
||||
|
||||
# Debug: Print the entire tx_response
|
||||
app.logger.debug(f"tx_response: {json.dumps(tx_response, indent=2)}")
|
||||
|
||||
if not tx_response.get('success'):
|
||||
return jsonify({"success": False, "message": f"Error from tx.sh: {tx_response.get('reasonText', 'Unknown error')}"}), 500
|
||||
|
||||
tx_data_list = tx_response.get('data', [])
|
||||
if not tx_data_list:
|
||||
return jsonify({"success": False, "message": "No transaction data found"}), 404
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
return jsonify({"success": False, "message": f"Error executing tx.sh: {str(e)}", "stderr": e.stderr}), 500
|
||||
except json.JSONDecodeError as e:
|
||||
return jsonify({"success": False, "message": f"Error parsing tx.sh output: {str(e)}", "output": result.stdout}), 500
|
||||
|
||||
# Check transactions
|
||||
for tx_data in tx_data_list:
|
||||
# Check if the required keys exist in tx_data
|
||||
required_keys = ['trxDate', 'benefName', 'absAmount']
|
||||
missing_keys = [key for key in required_keys if key not in tx_data]
|
||||
if missing_keys:
|
||||
continue # Skip this transaction if it's missing required keys
|
||||
|
||||
try:
|
||||
tx_time = datetime.strptime(tx_data['trxDate'], "%Y-%m-%d %H:%M:%S")
|
||||
time_diff = abs(tx_time - request_time)
|
||||
|
||||
# Normalize transaction beneficiary name for comparison
|
||||
tx_benef_name = tx_data['benefName'].strip().lower()
|
||||
|
||||
if (tx_benef_name == benef_name and
|
||||
str(tx_data['absAmount']) == str(abs_amount) and
|
||||
time_diff <= timedelta(minutes=30)):
|
||||
return jsonify({"success": True, "message": "Payment verified"})
|
||||
except ValueError as e:
|
||||
app.logger.error(f"Error processing transaction: {str(e)}")
|
||||
continue # Skip this transaction if there's an error processing it
|
||||
|
||||
# If we've checked all transactions and found no match
|
||||
return jsonify({"success": False, "message": "Transaction not found, contact support"})
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
12
tx.sh
12
tx.sh
@ -4,19 +4,9 @@ source .env
|
||||
|
||||
curl 'https://faisanet.mib.com.mv/ajaxAccounts/trxHistory' \
|
||||
-H 'accept: */*' \
|
||||
-H 'accept-language: en-US,en;q=0.8' \
|
||||
-H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' \
|
||||
-H "cookie: prefTheme=1; ql_0=${QL_0}; IBSID=${IBSID}; dashboardStatsMode=1; _zwaf_ua=Brave" \
|
||||
-H 'origin: https://faisanet.mib.com.mv' \
|
||||
-H 'priority: u=1, i' \
|
||||
-H 'referer: https://faisanet.mib.com.mv/accountDetails?accountNo=90101400028321000' \
|
||||
-H 'sec-ch-ua: "Chromium";v="130", "Brave";v="130", "Not?A_Brand";v="99"' \
|
||||
-H 'sec-ch-ua-mobile: ?0' \
|
||||
-H 'sec-ch-ua-platform: "Linux"' \
|
||||
-H 'sec-fetch-dest: empty' \
|
||||
-H 'sec-fetch-mode: cors' \
|
||||
-H 'sec-fetch-site: same-origin' \
|
||||
-H 'sec-gpc: 1' \
|
||||
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36' \
|
||||
-H 'x-requested-with: XMLHttpRequest' \
|
||||
--data-raw 'accountNo=90101400028321000&trxNo=&trxType=0&sortTrx=date&sortDir=desc&fromDate=&toDate=&start=1&end=10&includeCount=1' -s | jq
|
||||
--data-raw 'accountNo=90101400028321000&trxNo=&trxType=0&sortTrx=date&sortDir=desc&fromDate=&toDate=&start=1&end=2&includeCount=1' -s | sed 's/"benefName":"BML - /"benefName":"/g'
|
||||
|
Loading…
x
Reference in New Issue
Block a user