bug fix on application context with threads

This commit is contained in:
2025-04-15 16:39:05 +01:00
parent 32e3ca5bb0
commit 4685ddc1c8
5 changed files with 36 additions and 49 deletions
+14 -25
View File
@@ -2,7 +2,9 @@ import requests
from app.config import settings
from app.utils.auth import get_headers
from app.utils.logger import logger
from flask import jsonify
from flask import jsonify, current_app
from app.models.transactions import Transaction
class SimbrellaClient:
@@ -11,9 +13,14 @@ class SimbrellaClient:
@staticmethod
def disbursement(data):
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/Disbursement"
logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}")
logger.info(f"Calling Disbursement endpoint with data: {data}")
# Check if the transaction exists
logger.info(f"Checking if transaction exists")
with current_app.app_context():
transaction = Transaction.get_transaction_by_id(transaction_id=data['transactionId'])
logger.info(f"Response from database: {transaction}")
disbursement_data ={
"requestId": data['requestId'],
"transactionId": data['transactionId'],
@@ -45,7 +52,6 @@ class SimbrellaClient:
@staticmethod
def collect_loan(data):
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/CollectLoan"
logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}")
logger.info(f"Calling CollectLoan endpoint with data: {data}")
collect_loan_data = {
@@ -76,14 +82,7 @@ class SimbrellaClient:
@staticmethod
def verify_transaction():
# api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/TransactionVerify"
# logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}")
# logger.info(f"Calling TransactionVerify endpoint with data: {data}")
try:
# logger.info(f"Here is your TransactionVerify Request data ***** : {data}")
# response = requests.post(api_url, json=data, headers=get_headers())
# logger.info(f"TransactionVerify response: {response.json()}")
return {
"status": "00",
@@ -96,16 +95,9 @@ class SimbrellaClient:
@staticmethod
def refresh_disbursement(data):
# api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/Disbursement"
# logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}")
# logger.info(f"Calling Disbursement endpoint with data: {data}")
try:
logger.info(f"Here is your Disbursement Request data ***** : {data}")
# response = requests.post(api_url, json=data, headers=get_headers())
# logger.info(f"Disbursement response: {response.json()}")
# return response.json()
return data
@@ -115,19 +107,16 @@ class SimbrellaClient:
@staticmethod
def payment_callback(data):
# api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/Payment"
# logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}")
# logger.info(f"Calling Payment Callback endpoint with data: {data}")
try:
logger.info(f"Here is your Payment Callback Request data ***** : {data}")
# response = requests.post(api_url, json=data, headers=get_headers())
# logger.info(f"Payment Callback response: {response.json()}")
# return response.json()
return data
except Exception as e:
logger.info(f"Failed to call Payment Callback endpoint: {e}")
raise
raise
@staticmethod
def check_transaction(txn_id):
return run_in_app_context(Transaction.get_transaction_by_id(txn_id))