clean up transaction output
This commit is contained in:
parent
155e56d7b6
commit
c91a4c06fd
73
api.py
73
api.py
@ -23,6 +23,28 @@ def fetch_account_name(account_no):
|
|||||||
app.logger.error(f"Error fetching account name: {str(e)}")
|
app.logger.error(f"Error fetching account name: {str(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_transaction_details(tx_data):
|
||||||
|
"""Extract reference and sourceBank based on transaction type"""
|
||||||
|
descr1 = tx_data.get('descr1', '')
|
||||||
|
|
||||||
|
if descr1 == "Favara Credit":
|
||||||
|
reference = tx_data.get('descr2', '')
|
||||||
|
# Extract sourceBank from descr3 (part before the first '-')
|
||||||
|
descr3 = tx_data.get('descr3', '')
|
||||||
|
sourceBank = descr3.split(' - ')[0] if ' - ' in descr3 else ''
|
||||||
|
elif descr1 == "IB Acc to Acc":
|
||||||
|
reference = tx_data.get('trxNumber', '')
|
||||||
|
sourceBank = "MIB"
|
||||||
|
else:
|
||||||
|
reference = tx_data.get('trxNumber', '')
|
||||||
|
sourceBank = ""
|
||||||
|
|
||||||
|
return {
|
||||||
|
"ref": reference,
|
||||||
|
"trxDate": tx_data.get('trxDate', ''),
|
||||||
|
"sourceBank": sourceBank
|
||||||
|
}
|
||||||
|
|
||||||
def verify_transaction(benef_name, abs_amount, request_time, tx_data_list):
|
def verify_transaction(benef_name, abs_amount, request_time, tx_data_list):
|
||||||
for tx_data in tx_data_list:
|
for tx_data in tx_data_list:
|
||||||
required_keys = ['trxDate', 'benefName', 'absAmount']
|
required_keys = ['trxDate', 'benefName', 'absAmount']
|
||||||
@ -38,7 +60,6 @@ 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 both verification status and transaction data
|
|
||||||
return True, tx_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)}")
|
||||||
@ -92,30 +113,7 @@ def verify_payment():
|
|||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": "Payment verified using beneficiary name",
|
"message": "Payment verified using beneficiary name",
|
||||||
"transaction": {
|
"transaction": get_transaction_details(tx_data)
|
||||||
"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
|
||||||
@ -127,30 +125,7 @@ def verify_payment():
|
|||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": "Payment verified using account number",
|
"message": "Payment verified using account number",
|
||||||
"transaction": {
|
"transaction": get_transaction_details(tx_data)
|
||||||
"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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user