From 76681a9f3631ab429c1bc43c2682136392d23d0f Mon Sep 17 00:00:00 2001 From: lennyaiko Date: Fri, 11 Apr 2025 09:38:53 +0100 Subject: [PATCH 1/3] fix the headers --- app/utils/auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/utils/auth.py b/app/utils/auth.py index 4792796..e693171 100644 --- a/app/utils/auth.py +++ b/app/utils/auth.py @@ -5,6 +5,6 @@ def get_headers(): return { "Content-Type": "application/json", "Accept": "application/json", - "api_key": settings.BANK_CALL_API_KEY, - "app_id": settings.BANK_CALL_APP_ID, + "x-api-key": settings.BANK_CALL_API_KEY, + "App-Id": settings.BANK_CALL_APP_ID, } From 5214594fabaf7ae0dd0612e9b61934af5bb645ea Mon Sep 17 00:00:00 2001 From: "oluyemi.a.simbrellang.com" Date: Fri, 11 Apr 2025 16:11:45 +0100 Subject: [PATCH 2/3] move action to SimbrellaClient integration --- .gitignore | 3 ++- app/integrations/__init__.py | 1 + app/integrations/kafka.py | 4 ++-- app/integrations/simbrella.py | 26 ++++++++++++++++++++++++++ wsgi.py | 26 +++++++++++++------------- 5 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 app/integrations/simbrella.py diff --git a/.gitignore b/.gitignore index 0ea0879..f5ccd79 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__/ */__pycache__/ .env -app.log \ No newline at end of file +app.log +.idea/ \ No newline at end of file diff --git a/app/integrations/__init__.py b/app/integrations/__init__.py index f19ae60..7e9a8e2 100644 --- a/app/integrations/__init__.py +++ b/app/integrations/__init__.py @@ -1 +1,2 @@ from .kafka import KafkaIntegration +from .simbrella import SimbrellaClient \ No newline at end of file diff --git a/app/integrations/kafka.py b/app/integrations/kafka.py index 0afc813..de1f661 100644 --- a/app/integrations/kafka.py +++ b/app/integrations/kafka.py @@ -3,7 +3,7 @@ import json from app.utils.logger import logger from app.config import settings import requests -from app.routes.loan import disbursement as disbursement_endpoint +from app.integrations.simbrella import SimbrellaClient class KafkaIntegration: @@ -96,7 +96,7 @@ class KafkaIntegration: logger.info(f"Calling disbursement endpoint with message: {message}") try: - response = disbursement_endpoint(message) + response = SimbrellaClient.disbursement(message) logger.info( f"Successfully sent message to disbursement endpoint: {response.status_code}" ) diff --git a/app/integrations/simbrella.py b/app/integrations/simbrella.py new file mode 100644 index 0000000..26ce965 --- /dev/null +++ b/app/integrations/simbrella.py @@ -0,0 +1,26 @@ +import requests +from app.config import settings +from app.utils.auth import get_headers +from app.utils.logger import logger +from flask import jsonify + +class SimbrellaClient: + + BASE_URL = settings.BANK_CALL_BASE_URL + + @staticmethod + def disbursement(data): + + api_url = f"{SimbrellaClient.BASE_URL}/Disbursement" + + logger.info(f"Calling disbursement endpoint with data: {data}") + + response = requests.post( + api_url, + json=data, + headers=get_headers() + ) + + logger.info(f"Disbursement response: {response.json()}") + + return jsonify(response.json()), response.status_code \ No newline at end of file diff --git a/wsgi.py b/wsgi.py index 1c3b9e8..32de55c 100644 --- a/wsgi.py +++ b/wsgi.py @@ -6,19 +6,19 @@ from app.utils.logger import logger app = create_app() if __name__ != "__main__": - - kafka = KafkaIntegration() - - logger.info("Starting Kafka consumer...") - while True: - message = kafka.receive_disbursement_messages( - topic=settings.KAFKA_PAYMENT_TOPIC, timeout=settings.KAFKA_TIMEOUT - ) - - if message: - logger.info(f"Processed message: {message}") - else: - logger.info("No message received within timeout") + # + # kafka = KafkaIntegration() + # + # logger.info("Starting Kafka consumer...") + # while True: + # message = kafka.receive_disbursement_messages( + # topic=settings.KAFKA_PAYMENT_TOPIC, timeout=settings.KAFKA_TIMEOUT + # ) + # + # if message: + # logger.info(f"Processed message: {message}") + # else: + # logger.info("No message received within timeout") # Expose WSGI app instance for Gunicorn wsgi_app = app From 4a708a76542f3428b603319bb1d225ac7aed226a Mon Sep 17 00:00:00 2001 From: "oluyemi.a.simbrellang.com" Date: Fri, 11 Apr 2025 16:35:33 +0100 Subject: [PATCH 3/3] work on the new endpoints --- app/routes/loan.py | 29 +++++++++++++++-------------- openapi.yml | 10 +++++----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/routes/loan.py b/app/routes/loan.py index caa99b6..9d6283b 100644 --- a/app/routes/loan.py +++ b/app/routes/loan.py @@ -153,25 +153,26 @@ def rac_check(): return jsonify(response), 200 -@loan_bp.route("/disbursement", methods=["POST"]) -def disbursement(data=None): - if data is None: - data = request.json +@loan_bp.route("/refresh-disbursement", methods=["GET"]) +def disbursement(): + + data = request.json() api_url = f"{BASE_URL}/Disbursement" logger.info(f"Calling disbursement endpoint with data: {data}") - response = requests.post( - api_url, - json=data, - headers=get_headers(), - ) - - logger.info(f"Disbursement response: {response.json()}") - - return jsonify(response.json()), response.status_code + return jsonify(data), 200 + # + # response = requests.post( + # api_url, + # json=data, + # headers=get_headers(), + # ) + # + # logger.info(f"Disbursement response: {response.json()}") + # return jsonify(response.json()), response.status_code @loan_bp.route("/collect-loan", methods=["POST"]) def collect_loan(): @@ -198,7 +199,7 @@ def collect_loan(): return jsonify(response), 200 -@loan_bp.route("/transaction-verify", methods=["POST"]) +@loan_bp.route("/verify-transactions", methods=["GET"]) def transaction_verify(): data = request.json api_url = f"{BASE_URL}/TransactionVerify" diff --git a/openapi.yml b/openapi.yml index e51274e..ba7ab31 100644 --- a/openapi.yml +++ b/openapi.yml @@ -330,9 +330,9 @@ paths: responses: 200: description: A successful response - /loans/disbursement: - post: - summary: Disburse a loan + /loans/refresh-disbursement: + get: + summary: Refresh disburse of a loan requestBody: required: true content: @@ -434,8 +434,8 @@ paths: responses: 200: description: A successful response - /loans/transaction-verify: - post: + /loans/verify-transactions: + get: summary: Verify a transaction requestBody: required: true