From c76d3075aff56ff233b23bb09b2147ddfb2d8bb0 Mon Sep 17 00:00:00 2001 From: "oluyemi.a.simbrellang.com" Date: Mon, 14 Apr 2025 13:44:56 +0100 Subject: [PATCH] done with collect loan setup --- app/config.py | 2 -- app/integrations/kafka.py | 30 +++++++++++++++++++-------- app/integrations/simbrella.py | 38 ++++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/app/config.py b/app/config.py index ff2ffb8..9a20816 100644 --- a/app/config.py +++ b/app/config.py @@ -14,8 +14,6 @@ class Config: KAFKA_PAYMENT_TOPIC = "PROCESS_PAYMENT" KAFKA_TIMEOUT = float( os.getenv("KAFKA_TIMEOUT", 1000.0) ) - - JWT_SECRET_KEY = os.getenv("JWT_SECRET_KEY", "secret-key") JWT_ACCESS_TOKEN_EXPIRES = os.getenv("JWT_ACCESS_TOKEN_EXPIRES", timedelta(hours=1)) JWT_REFRESH_TOKEN_EXPIRES = os.getenv( "JWT_REFRESH_TOKEN_EXPIRES", timedelta(days=30) diff --git a/app/integrations/kafka.py b/app/integrations/kafka.py index 34513d9..8a35a7c 100644 --- a/app/integrations/kafka.py +++ b/app/integrations/kafka.py @@ -59,7 +59,7 @@ class KafkaIntegration: logger.info( f"Waiting for messages from topic {topic} with this timeout: {timeout}..." ) - message =[] + message = [] try: msg = consumer.poll(timeout=timeout) @@ -100,10 +100,10 @@ class KafkaIntegration: current_topic = msg.topic() if current_topic=="PROCESS_PAYMENT": - KafkaIntegration._call_disbursement_endpoint(message) + KafkaIntegration._call_disbursement_service(message) if current_topic=="LOAN_REPAYMENT": - # Do loan repayment call here + KafkaIntegration._call_collect_loan_service(message) logger.info( f"Loan Repayment message from {msg.topic()} [{msg.partition()}] @ offset {msg.offset()}: {message}" ) @@ -124,15 +124,29 @@ class KafkaIntegration: logger.info("Kafka consumer closed") @staticmethod - def _call_disbursement_endpoint(message): - """Call the disbursement endpoint with the received message""" - logger.info(f"Calling disbursement endpoint with message: {message}") + def _call_disbursement_service(message): + """Call the disbursement service with the received message""" + logger.info(f"Calling disbursement service with message: {message}") try: response = SimbrellaClient.disbursement(message) logger.info( - f"Successfully sent message to disbursement endpoint: {response.status_code}" + f"Successfully sent message to disbursement service: {response.status_code}" ) except Exception as e: - logger.info(f"Failed to call disbursement endpoint: {e}") + logger.info(f"Failed to call disbursement service: {e}") #raise + + @staticmethod + def _call_collect_loan_service(message): + """Call the collect loan service with the received message""" + logger.info(f"Calling collect_loan service with message: {message}") + + try: + response = SimbrellaClient.collect_loan(message) + logger.info( + f"Successfully sent message to collect_loan service: {response.status_code}" + ) + except Exception as e: + logger.info(f"Failed to call collect_loan service: {e}") + # raise diff --git a/app/integrations/simbrella.py b/app/integrations/simbrella.py index df1c2b6..6a38fa8 100644 --- a/app/integrations/simbrella.py +++ b/app/integrations/simbrella.py @@ -6,7 +6,6 @@ from flask import jsonify class SimbrellaClient: - BASE_URL = settings.BANK_CALL_BASE_URL BANK_CALL_BASE_URL = settings.BANK_CALL_BASE_URL @staticmethod @@ -14,7 +13,7 @@ class SimbrellaClient: BANK_CALL_BASE_URL = "https://bank-emulator.dev.simbrellang.net" api_url = f"{BANK_CALL_BASE_URL}/Disbursement" logger.info(f"BANK_CALL_BASE_URL = {BANK_CALL_BASE_URL}") - logger.info(f"Calling disbursement endpoint with data: {data}") + logger.info(f"Calling Disbursement endpoint with data: {data}") data={ "requestId": "RQID1743987402764", @@ -47,9 +46,42 @@ class SimbrellaClient: logger.info(f"Disbursement response: {response.json()}") except Exception as e: - logger.info(f"Failed to call disbursement endpoint: {e}") + logger.info(f"Failed to call Disbursement endpoint: {e}") #raise return 0 # return jsonify(response.json()), response.status_code + return 1 + + @staticmethod + def collect_loan(data): + BANK_CALL_BASE_URL = "https://bank-emulator.dev.simbrellang.net" + api_url = f"{BANK_CALL_BASE_URL}/CollectLoan" + logger.info(f"BANK_CALL_BASE_URL = {BANK_CALL_BASE_URL}") + logger.info(f"Calling CollectLoan endpoint with data: {data}") + + collect_loan_data = { + "transactionId": "T002", + "fbnTransactionId": "FBN20231123", + "debtId": "273194670", + "customerId": "CN621868", + "accountId": "2017821799", + "productId": "101", + "collectAmount": 80000, + "penalCharge": 0, + "collectionMethod": 1, + "lienAmount": 80000, + "countryId": "01", + "comment": "Testing CollectionLoanRequest" + } + + try: + logger.info(f"Here is your CollectLoan Request data ***** : {collect_loan_data}") + response = requests.post(api_url, json=collect_loan_data, headers=get_headers()) + logger.info(f"CollectLoan response: {response.json()}") + + except Exception as e: + logger.info(f"Failed to call CollectLoan endpoint: {e}") + return 0 + return 1 \ No newline at end of file