From 099c3546805abff428f439a816745c2fdd6a3cfc Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Mon, 17 Feb 2025 11:25:54 -0500 Subject: [PATCH] verify loan --- app/app.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/app/app.py b/app/app.py index c9de7b5..0e43713 100644 --- a/app/app.py +++ b/app/app.py @@ -229,6 +229,77 @@ def salary_loanoffers(): "product_data": offers_data, }, 200 +@app.route('/salary/loanselect', methods=["POST"]) +def salary_loanselect(): + try: + data = request.json + if not data: + return { + "message": "Please provide bvn and loan", + "data": None, + "error": "Bad request" + }, 400 + # validate input + loan = data["loan"] + bvn = data["bvn"] + if username == 'loan' and password == 'loan' : + loan = load_offer(loan,bvn) + return { + "message": "REQUEST_PIN", + "loan": loan, + "active_loan_count": 0, + "active_loan": [] + }, 201 + else: + return { + "message": "Error fetching loan!, invalid bvn or loan", + "data": None, + "error": "Unauthorized" + }, 404 + + except Exception as e: + return { + "message": "Something went wrong!", + "error": str(e), + "data": None + }, 500 + + +@app.route('/salary/verifloan', methods=["POST"]) +def salary_verifloan(): + try: + data = request.json + if not data: + return { + "message": "Please provide pin", + "data": None, + "error": "Bad request" + }, 400 + # validate input + bvn = data["bvn"] + pin = data["pin"] + loan = data["loan"] + SELECT_ACC = "SELECT id, uid,pin,bvn FROM demo_bank_accounts WHERE bvn='" + bvn + "' AND pin = '" + pin + "' " + with connection: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(SELECT_ACC) + account = cursor.fetchall() + + account_found = count = len( account ) + + if account_found == 1 : + return { + "status": "1", + "data": account + }, 201 + else: + return { + "status": "-1", + "data": None, + "message" : "Invalid Pin", + "error": "1" + }, 404 + def products(): product_data = [ {"cid": "1", "description": "Product Loan 01" , "active" : 0 }, @@ -237,6 +308,15 @@ def products(): ] return product_data +def load_offer(loan,bvn): + OFFER_QUERY = "SELECT uid AS cid,loan,amount,description,days_duration,active FROM loan_offers WHERE loan='" + loan +"'" + with connection: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(OFFER_QUERY) + select_demoS = cursor.fetchall() + + loan_data = json.dumps( [dict(ix) for ix in select_demoS] ) + return json.loads( loan_data ) def offers(): OFFER_QUERY = "SELECT uid AS cid,loan,amount,description,days_duration,active FROM loan_offers ORDER BY amount ASC"