Python

Features ›› Transaction ›› repayPartialLoan ›› Sample Code ››
Parent Previous Next

Repay Partial Loan


We will first import "request" and "json" module, as we need those module for calling the API

Then, we will import our own url from a file called functions.py, which can be referred to in the "Common Stuff" section linked at the bottom.



Next, we create a function repayPartialLoan

Inside the function, we will create the input variables.





Then we build the header and content object.




Then, we will create the final url, where we will use the url() function to get the API url, and append the headerObj t and contentObj o the API url.

We will then post the final_url and store the server response in the variable "response".

The GlobalErrorID is then retrieved and stored in variable "errorCode".





If the errorCode is '010000', it means that there is no error, and we will display 'the result.

If the errorCode is '010041', it means that the OTP provided has expired. We will then display 'OTP has expired. You will be receiving a SMS'.

Else, we will display the ErrorText.





Entire Code:


import requests, json

from functions import url


def repayPartialLoan():

   #Header

   serviceName = 'repayPartialLoan'

   userID = 'alan1960'

   PIN = '123'

   OTP = '123'


   accountID = "1040"

   repaymentAmount = "5"

   keepMaturityDate = "true"

         

   headerObj = {

                       'Header': {

                       'serviceName': serviceName,

                       'userID': userID,

                       'PIN': PIN,

                       'OTP': OTP

                       }

                       }

   

   contentObj = {

                       'Content': {

                       'accountID': accountID,

                       'repaymentAmount': repaymentAmount,

                       'keepMaturityDate': keepMaturityDate

                       }

                       }

   

   final_url="{0}?Header={1}&Content={2}".format(url(),json.dumps(headerObj),json.dumps(contentObj))

   response = requests.post(final_url)

   serviceRespHeader = response.json()['Content']['ServiceResponse']['ServiceRespHeader']

   errorCode = serviceRespHeader['GlobalErrorID']

   

   if errorCode == '010000':

       BalanceAfterObj = response.json()['Content']['ServiceResponse']['BalanceAfter']

       print('BalanceAfter: {}'.format(BalanceAfterObj['_content_']))


       BalanceBeforeObj = response.json()['Content']['ServiceResponse']['BalanceBefore']

       print('BalanceBefore: {}'.format(BalanceBeforeObj['_content_']))


       InstallmentAmountObj = response.json()['Content']['ServiceResponse']['InstallmentAmount']

       print('InstallmentAmount: {}'.format(InstallmentAmountObj['_content_']))


       LoanTermtObj = response.json()['Content']['ServiceResponse']['LoanTerm']

       print('LoanTerm: {}'.format(LoanTermtObj['_content_']))


       MaturityDateObj = response.json()['Content']['ServiceResponse']['MaturityDate']

       print('MaturityDate: {}'.format(MaturityDateObj['_content_']))


       PenaltyAmountObj = response.json()['Content']['ServiceResponse']['PenaltyAmount']

       print('PenaltyAmount: {}'.format(PenaltyAmountObj['_content_']))


       TransactionIDObj = response.json()['Content']['ServiceResponse']['TransactionID']

       print('TransactionID: {}'.format(TransactionIDObj['_content_']))

       

   elif errorCode == '010041':

      print("OTP has expired.\nYou will receiving a SMS")


   else:

      print(serviceRespHeader['ErrorText'])

           

repayPartialLoan()

   


Download


Go to Common Stuff Section

Created with the Personal Edition of HelpNDoc: Create iPhone web-based documentation