C#

Features ›› Account ›› getLoanAccountDetails ›› Sample Code ››
Parent Previous Next

Get Loan Accounts Details



1. getLoanAccountDetails.cs


These four packages are required to be used.









Step 1. Create class file to store content of the web response.









2. getLoanAccountDetails.aspx.cs



These 13 packages are required to be used.









Code in Common



(1). Check if user id and password is inside session. When the user id and password is inside user session, it will automatically populate into the user id and pin textbox, so that the user need not manually type his user id and password repeatedly.









Step 2. Store Details which entered by the user. If user id, password, and OTP exist in session, user need not enter again (refer to common staff).








Step 3. Create URL which will be post to the server. User inputs need to be stored in the class created, and serialize into JSON format. In this function, only header is needed.









Step 4. Post to the server, and store response. URL is sent using web request function, and a response will be send back from the server. The response need to be deserialized into the ‘getLoanAccountDetails’ class.









Step 5. Obtain error code. If error code is ‘010000’ which means invocation successful, populate attributes of the ‘getLoanAccountDetails’ class into the label. If error code is '010041', it means OTP has expired, and we will use the newOTP() function to prompt the user for the OTP again. Else, we will display the ErrorText and ErrorDetails.


The newOTP() function can be referred to under Common Stuff Section










Overview of  getLoanAccountDetails.cs



using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;


namespace Demo

{

   public class loanAccount

   {

       public loanAccountContent Content { get; set; }

   }


   public class loanAccountContent

   {

       public loanAccountServiceResponse ServiceResponse { get; set; }

   }


   public class loanAccountServiceResponse

   {

       public loanAccountServiceRespHeader ServiceRespHeader { get; set; }

       public SettlementAccount SettlementAccount { get; set; }

       public LendingAccount LendingAccount { get; set; }

   }


   public class SettlementAccount

   {

       public string Content { get; set; }

   }


   public class loanAccountServiceRespHeader

   {

       public string ErrorText { get; set; }

       public object ErrorDetails { get; set; }

       public string GlobalErrorId { get; set; }

   }


   public class LendingAccount

   {

       public string InterestRate { get; set; }

       public loanAccountProduct Product { get; set; }

       public string CurrentStatus { get; set; }

       public string Narrative { get; set; }

       public string IsServiceChargeWaived { get; set; }

       public string HomeBranch { get; set; }

       public DateTime AccountOpenDate { get; set; }

       public Dictionary<string, string> Loanaccount { get; set; }

       public string AssignedAccountForAccountManagementFeeDeduction { get; set; }

       public string PenaltyRate { get; set; }

       public string Balance { get; set; }

       public DateTime MaturityDate { get; set; }

       public string CustomerId { get; set; }

       public string Currency { get; set; }

       public loanAccountMaintenancehistory Maintenancehistory { get; set; }

       public string OfficerId { get; set; }

   }


   public class loanAccountProduct

   {

       public string ProductId { get; set; }

       public string CompoundInterestRateBasis { get; set; }

       public string RateChartCode { get; set; }

       public DateTime DateBasisForRate { get; set; }

       public string ProductName { get; set; }

   }


   public class loanAccountMaintenancehistory

   {

       public string LastTransactionBranch { get; set; }

       public string LastMaintenanceOfficer { get; set; }

   }


}



Download







Overview of  getLoanAccountDetails.aspx.cs




using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using DotNetOpenAuth.OAuth2;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

using System.Collections.Specialized;

using System.Configuration;

using System.Net;

using System.IO;

using System.Windows.Forms;

using System.Data;


namespace Demo

{

   public partial class getLoanAccountDetails : System.Web.UI.Page

   {

       protected void Page_Load(object sender, EventArgs e)

       {

           if (Session["userid"] != null)

           {

               txtUserID.Text = (string)Session["userid"];

               txtPassword.Text = (string)Session["pin"];

           }

       }


       protected void btnSend_Click(object sender, EventArgs e)

       {

           try

           {

               //store variables

               string userID = txtUserID.Text;

               Session["userid"] = userID;

               string pin = txtPassword.Text;

               Session["pin"] = pin;

               string otp;

               if (Session["otp"] == null)

               {

                   otp = "";

               }

               else

               {

                   otp = Session["otp"].ToString();

               }

               string accountID = txtAccountID.Text;


               //build header

               var header = new HeaderJson();

               header.userID = userID;

               header.PIN = pin;

               header.serviceName = "getLoanAccountDetails";

               header.OTP = otp;

               var headerJson = new HeaderJsonObject();

               headerJson.Header = header;

               string strHeader = JsonConvert.SerializeObject(headerJson);


               //build content

               var content = new ContentJson();

               content.accountID = accountID;

               var contentJson = new ContentJsonObject();

               contentJson.Content = content;

               string strContent = JsonConvert.SerializeObject(contentJson);


               string url = "http://tbankonline.com/SMUtBank_API/Gateway?Header=" + strHeader + "&Content=" + strContent;


               //send web request

               var webRequest = (HttpWebRequest)WebRequest.Create(url);

               webRequest.ContentType = "application/json";

               webRequest.Method = "POST";

               var result = "";

               var httpResponse = (HttpWebResponse)webRequest.GetResponse();

               using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))

               {

                   result = streamReader.ReadToEnd();

               }


               //store response in class

               loanAccount a = new loanAccount();

               a = JsonConvert.DeserializeObject<loanAccount>(result);


               string errorID = a.Content.ServiceResponse.ServiceRespHeader.GlobalErrorId?.ToString() ?? "";



               if (errorID == "010000")

               {

                   txtInterestRate.Text = a.Content.ServiceResponse.LendingAccount.InterestRate?.ToString() ?? "";

                   txtProductID.Text = a.Content.ServiceResponse.LendingAccount.Product.ProductId?.ToString() ?? "";

                   txtCompoundInterestRateBasis.Text = a.Content.ServiceResponse.LendingAccount.Product.CompoundInterestRateBasis?.ToString() ?? "";

                   txtRateChartCode.Text = a.Content.ServiceResponse.LendingAccount.Product.RateChartCode?.ToString() ?? "";

                   txtDateBasisForRate.Text = a.Content.ServiceResponse.LendingAccount.Product.DateBasisForRate.ToString();

                   txtProductName.Text = a.Content.ServiceResponse.LendingAccount.Product.ProductName?.ToString() ?? "";

                   txtCurrentStatus.Text = a.Content.ServiceResponse.LendingAccount.CurrentStatus?.ToString() ?? "";

                   txtNarrative.Text = a.Content.ServiceResponse.LendingAccount.Narrative?.ToString() ?? "";

                   txtIsServiceChargeWaived.Text = a.Content.ServiceResponse.LendingAccount.IsServiceChargeWaived?.ToString() ?? "";

                   txtHomeBranch.Text = a.Content.ServiceResponse.LendingAccount.HomeBranch?.ToString() ?? "";

                   txtAccountOpenDate.Text = a.Content.ServiceResponse.LendingAccount.AccountOpenDate.ToString();

                   txtWriteOffFlag.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["writeOffFlag"];

                   txtItvRatio.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["ltvRatio"];

                   txtPenaltyRateBasis.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["penaltyRateBasis"];

                   txtWriteOffDate.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["writeOffDate"];

                   txtInstallmentAcount.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["installmentAmount"];

                   txtLoanClosureReason.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["loanClosureReason"];

                   txtRepricingDate.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["repricingDate"];

                   txtLoanClosureDate.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["loanClosureDate"];

                   txtAssetValue.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["assetValue"];

                   txtRescheduleOption.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["rescheduleOption"];

                   txtAgreementNumber.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["agreementNumber"];

                   txtTitle.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["title"];

                   txtFixedTerm.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["fixedTerm"];

                   txtRepaymentMode.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["repaymentMode"];

                   txtRepaymentGraceDay.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["repaymentGraceDay"];

                   txtAgreementSignDate.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["agreementSignDate"];

                   txtPledgeOrStopPaymentAmount.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["pledgeOrStopPaymentAmount"];

                   txtLoanTerm.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["loanTerm"];

                   txtWriteOffAmount.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["writeOffAmount"];

                   txtLoanPurpose.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["loanPurpose"];

                   txtLetterOfOfferDate.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["letterOfOfferDate"];

                   txtDisburseAmount.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["disburseAmount"];

                   txtApplicationID.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["applicationID"];

                   txtIsInterestWaived.Text = a.Content.ServiceResponse.LendingAccount.Loanaccount["isInterestWaived"];

                   txtAssignedAccountForAccountManagementFeeDeduction.Text = a.Content.ServiceResponse.LendingAccount.AssignedAccountForAccountManagementFeeDeduction?.ToString() ?? "";

                   txtPenaltyRate.Text = a.Content.ServiceResponse.LendingAccount.PenaltyRate?.ToString() ?? "";

                   txtBalance.Text = a.Content.ServiceResponse.LendingAccount.Balance?.ToString() ?? "";

                   txtMaturityDate.Text = a.Content.ServiceResponse.LendingAccount.MaturityDate.ToString();

                   txtCustomerID.Text = a.Content.ServiceResponse.LendingAccount.CustomerId?.ToString() ?? "";

                   txtCurrency.Text = a.Content.ServiceResponse.LendingAccount.Currency?.ToString() ?? "";

                   txtMaintenanceHistory.Text = a.Content.ServiceResponse.LendingAccount.Maintenancehistory?.ToString() ?? "";

                   txtOfficerID.Text = a.Content.ServiceResponse.LendingAccount.OfficerId?.ToString() ?? "";

                   txtLastTransactionBranch.Text = a.Content.ServiceResponse.LendingAccount.Maintenancehistory.LastTransactionBranch?.ToString() ?? "";

                   txtLastMaintenanceOfficer.Text = a.Content.ServiceResponse.LendingAccount.Maintenancehistory.LastMaintenanceOfficer?.ToString() ?? "";

               }

               else if (errorID == "010041")

               {

                   otp = utilities.newOTP();

                   Session["otp"] = otp;

               }

               else

               {

                   lblTest.Text = a.Content.ServiceResponse.ServiceRespHeader.ErrorText.ToString();

                   string errorMessage = a.Content.ServiceResponse.ServiceRespHeader.ErrorDetails.ToString();

                   MessageBox.Show(errorMessage);

               }

           }

           catch (Exception ex)

           {

               lblExceptionMsg.Text = ex.ToString();

           }

       }

   }

}



Download



Created with the Personal Edition of HelpNDoc: Full-featured Help generator