add detailed tx info to output

This commit is contained in:
Shihaam Abdul Rahman 2024-12-09 00:19:00 +05:00
parent 098e268001
commit 203319aba9
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636

71
api.py
View File

@ -38,10 +38,11 @@ def verify_transaction(benef_name, abs_amount, request_time, tx_data_list):
if (tx_benef_name == benef_name.strip().lower() and if (tx_benef_name == benef_name.strip().lower() and
compare_amounts(tx_data['absAmount'], abs_amount) and compare_amounts(tx_data['absAmount'], abs_amount) and
time_diff <= timedelta(minutes=TIME_DIFF_LIMIT)): time_diff <= timedelta(minutes=TIME_DIFF_LIMIT)):
return True # Return both verification status and transaction data
return True, tx_data
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, None
def compare_amounts(amount1, amount2): def compare_amounts(amount1, amount2):
"""Compare two amount strings as Decimal objects.""" """Compare two amount strings as Decimal objects."""
@ -85,14 +86,72 @@ def verify_payment():
return jsonify({"success": False, "message": f"Error parsing tx.sh output: {str(e)}", "output": result.stdout}), 500 return jsonify({"success": False, "message": f"Error parsing tx.sh output: {str(e)}", "output": result.stdout}), 500
# First, try to verify with benefName if provided # First, try to verify with benefName if provided
if benef_name and verify_transaction(benef_name, abs_amount, request_time, tx_data_list): if benef_name:
return jsonify({"success": True, "message": "Payment verified using beneficiary name"}) verified, tx_data = verify_transaction(benef_name, abs_amount, request_time, tx_data_list)
if verified:
return jsonify({
"success": True,
"message": "Payment verified using beneficiary name",
"transaction": {
"accountNo": tx_data.get('accountNo'),
"curCode": tx_data.get('curCode'),
"curCodeDesc": tx_data.get('curCodeDesc'),
"trxNumber": tx_data.get('trxNumber'),
"trxNumber2": tx_data.get('trxNumber2'),
"trxDate": tx_data.get('trxDate'),
"trxValDate": tx_data.get('trxValDate'),
"absAmount": tx_data.get('absAmount'),
"baseAmount": tx_data.get('baseAmount'),
"foreignAmount": tx_data.get('foreignAmount'),
"descr1": tx_data.get('descr1'),
"descr2": tx_data.get('descr2'),
"descr3": tx_data.get('descr3'),
"trxType": tx_data.get('trxType'),
"AddDate": tx_data.get('AddDate'),
"bankCode": tx_data.get('bankCode'),
"bankName": tx_data.get('bankName'),
"benefName": tx_data.get('benefName'),
"otherAccountNo": tx_data.get('otherAccountNo'),
"fromAcc": tx_data.get('fromAcc'),
"imageHash": tx_data.get('imageHash'),
"bankColor": tx_data.get('bankColor')
}
})
# If benefName verification failed or wasn't provided, try with accountNo # If benefName verification failed or wasn't provided, try with accountNo
if account_no: if account_no:
fetched_name = fetch_account_name(account_no) fetched_name = fetch_account_name(account_no)
if fetched_name and verify_transaction(fetched_name, abs_amount, request_time, tx_data_list): if fetched_name:
return jsonify({"success": True, "message": "Payment verified using account number"}) verified, tx_data = verify_transaction(fetched_name, abs_amount, request_time, tx_data_list)
if verified:
return jsonify({
"success": True,
"message": "Payment verified using account number",
"transaction": {
"accountNo": tx_data.get('accountNo'),
"curCode": tx_data.get('curCode'),
"curCodeDesc": tx_data.get('curCodeDesc'),
"trxNumber": tx_data.get('trxNumber'),
"trxNumber2": tx_data.get('trxNumber2'),
"trxDate": tx_data.get('trxDate'),
"trxValDate": tx_data.get('trxValDate'),
"absAmount": tx_data.get('absAmount'),
"baseAmount": tx_data.get('baseAmount'),
"foreignAmount": tx_data.get('foreignAmount'),
"descr1": tx_data.get('descr1'),
"descr2": tx_data.get('descr2'),
"descr3": tx_data.get('descr3'),
"trxType": tx_data.get('trxType'),
"AddDate": tx_data.get('AddDate'),
"bankCode": tx_data.get('bankCode'),
"bankName": tx_data.get('bankName'),
"benefName": tx_data.get('benefName'),
"otherAccountNo": tx_data.get('otherAccountNo'),
"fromAcc": tx_data.get('fromAcc'),
"imageHash": tx_data.get('imageHash'),
"bankColor": tx_data.get('bankColor')
}
})
# If both verifications fail # If both verifications fail
return jsonify({"success": False, "message": "Transaction not found, contact support"}) return jsonify({"success": False, "message": "Transaction not found, contact support"})