Python

Parent Previous Next

Get Deposit Accounts Details


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

Then, we will import our own url function 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 getDepositAccountDetails

Inside the function, we will create the input variables.



Then we build both 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 and contentObj to 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 getDepositAccountDetails():

   #Header

   serviceName = 'getDepositAccountDetails'

   userID = 'bobsmith1'

   PIN = '123456'

   OTP = '123456'

   #Content

   accountID = '3223'

   

   headerObj = {

                       'Header': {

                       'serviceName': serviceName,

                       'userID': userID,

                       'PIN': PIN,

                       'OTP': OTP

                       }

                       }

   contentObj = {

                       'Content': {

                       'accountID': accountID

                       }

                       }

   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':

       depositAccount = response.json()['Content']['ServiceResponse']['DepositAccount']

       print("Is Service Charge Waived: {}".format(depositAccount['isServiceChargeWaived']))

       print("Minor Status: {}".format(depositAccount['casaaccount']['minorStatus']))

       print("Due Interest Amount: {}".format(depositAccount['casaaccount']['dueInterestAmount']))

       print("Is Restricted: {}".format(depositAccount['casaaccount']['isRestricted']))

       print("Deposit Term: {}".format(depositAccount['casaaccount']['depositTerm']))

       print("Interest Payout Account: {}".format(depositAccount['casaaccount']['interestPayoutAccount']))

       print("Parent Account Flag: {}".format(depositAccount['casaaccount']['parentAccountFlag']))

       print("Account Close Date: {}".format(depositAccount['casaaccount']['accountCloseDate']))

       print("Minimum Amount: {}".format(depositAccount['casaaccount']['minimumAmount']))

       print("Accrue Interest Amount: {}".format(depositAccount['casaaccount']['accrueInterestAmount']))

       print("Account Open Date: {}".format(depositAccount['accountOpenDate']))

       print("Narrative: {}".format(depositAccount['narrative']))

       print("Last Maintenance Officer: {}".format(depositAccount['maintenancehistory']['lastMaintenanceOfficer']))

       print("Last Transaction Branch: {}".format(depositAccount['maintenancehistory']['lastTransactionBranch']))

       print("Maturity Date: {}".format(depositAccount['maturityDate']))

       print("Interest Rate: {}".format(depositAccount['interestRate']))

       print("Officer ID: {}".format(depositAccount['officerID']))

       print("Current Status: {}".format(depositAccount['currentStatus']))

       print("Currency: {}".format(depositAccount['currency']))

       print("Assigned Account For Account Management Fee Deduction: {}".format(depositAccount['assignedAccountForAccountManagementFeeDeduction']))

       print("Compound Interest Rate Basis: {}".format(depositAccount['product']['compoundInterestRateBasis']))

       print("Date Basis For Rate: {}".format(depositAccount['product']['dateBasisForRate']))

       print("Product Name: {}".format(depositAccount['product']['productName']))

       print("Product ID: {}".format(depositAccount['product']['productID']))

       print("Rate Chart Code: {}".format(depositAccount['product']['rateChartCode']))

       print("Balance: {}".format(depositAccount['balance']))

       print("Penalty Rate: {}".format(depositAccount['penaltyRate']))

       print("Home Branch: {}".format(depositAccount['homeBranch']))

       print("Customer ID: {}".format(depositAccount['customerID']))

   elif errorCode == '010041':

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

   else:

       print(serviceRespHeader['ErrorText'])

   

getDepositAccountDetails()


Download


Go to Common Stuff Section

Created with the Personal Edition of HelpNDoc: Create HTML Help, DOC, PDF and print manuals from 1 single source