Python

Parent Previous Next

Get Direct Debit Authorization List


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

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

We will also be importing a reference data API 'getBillingOrganizations', as one of the output for 'getCustomerAccounts' is 'BillingOrgID', and we want to show the billingOrgName instead.



Next, we create a function getBeneficiaryList.

Inside the function, we will create the input variables.



Then we build the header 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 proceed to check whether there are any records. If there are no records, we will display 'No record Found'.

If there are records, we will use the getRecord() function to check whether there is only 1 record, or more than 1 records, and display the results accordingly.

**NOTE: JSON output for 1 record and more than 1 record is different due to JSON structure. Hence, we use getRecord() function to retrieve the number of records.

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,getRecord

from getBillingOrganizations import getBillingOrganizations


def getDirectDebitAuthorizationList():

   #Header

   serviceName = 'getDirectDebitAuthorizationList'

   userID = 'bobsmith1'

   PIN = '123456'

   OTP = '123456'

   headerObj = {

                       'Header': {

                       'serviceName': serviceName,

                       'userID': userID,

                       'PIN': PIN,

                       'OTP': OTP

                       }

                       }

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

   response = requests.post(final_url)


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

   errorCode = serviceRespHeader['GlobalErrorID']


   if errorCode == '010000':

       dda_list = response.json()['Content']['ServiceResponse']['AuthorizationList']

       if dda_list == {}:

           print("No record found!")

       else:

           dda_list = dda_list['Authorization']

           recordCount = getRecord(dda_list)

           if recordCount>1:                

               for i in range(0,recordCount,1):

                       directDebitAuthorizationList = dda_list[i]

                       print("\nBilling Organisation code Bank Code : {}".format(directDebitAuthorizationList['BillingOrgBankCode']))

                       print("Customer Bank Code : {}".format(directDebitAuthorizationList['CustomerBankCode']))

                       print("Customer Account ID : {}".format(directDebitAuthorizationList['CustomerAccountID']))

                       print("Billing Organisation ID : {}".format(directDebitAuthorizationList['BillingOrgID']))

                       print("CustomerID : {}".format(directDebitAuthorizationList['CustomerID']))

                       print("Billing Organisation Account ID : {}".format(directDebitAuthorizationList['BillingOrgAccountID']))

                       print("Billing Organisation: {}".format(getBillingOrganizations(directDebitAuthorizationList['BillingOrgAccountID'])))

                       print("Creation Date : {}".format(directDebitAuthorizationList['CreationDate']))

                       print("Direct Debit Authorization ID : {}".format(directDebitAuthorizationList['DirectDebitAuthorizationID']))

           elif recordCount == 0:

               print("\nBilling Organisation code Bank Code : {}".format(dda_list['BillingOrgBankCode']))

               print("Customer Bank Code : {}".format(dda_list['CustomerBankCode']))

               print("Customer Account ID : {}".format(dda_list['CustomerAccountID']))

               print("Billing Organisation ID : {}".format(dda_list['BillingOrgID']))

               print("CustomerID : {}".format(dda_list['CustomerID']))

               print("Billing Organisation Account ID : {}".format(dda_list['BillingOrgAccountID']))

               print("Billing Organisation: {}".format(getBillingOrganizations(dda_list['BillingOrgAccountID'])))

               print("Creation Date : {}".format(dda_list['CreationDate']))

   elif errorCode == '010041':

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

   else:

       print(serviceRespHeader['ErrorText'])

                           

getDirectDebitAuthorizationList()


Download


Go to Common Stuff Section

Created with the Personal Edition of HelpNDoc: Free HTML Help documentation generator