C#

Features ›› Customer ›› getCustomerDetails ›› Sample Code ››
Parent Previous Next

Get Customer Details



1. getCustomerDetailClass.cs



These four packages are required to be used.









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









2. getCustomerDetails.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 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 ‘getCustomerDetail’ class.









Step 5. Obtain error code. If error code is ‘010000’ which means invocation successful, populate attributes of the ‘creditTransfer’ 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 GetCustomerDetailsClass.cs



using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;


namespace Demo

{


   public class CustomerRootObject

   {

       public Content Content { get; set; }

   }


   public class Content

   {

       public Serviceresponse ServiceResponse { get; set; }

   }


   public class Serviceresponse

   {

       public Cdmcustomer CDMCustomer { get; set; }

       public Servicerespheader ServiceRespHeader { get; set; }

   }


   public class Cdmcustomer

   {

       public string dateOfBirth { get; set; }

       public string taxIdentifier { get; set; }

       public Phone phone { get; set; }

       public Certificate certificate { get; set; }

       public Address address { get; set; }

       public Cellphone cellphone { get; set; }

       public string familyName { get; set; }

       public Maintenacehistory maintenacehistory { get; set; }

       public string givenName { get; set; }

       public Customer customer { get; set; }

       public Profile profile { get; set; }

   }


   public class Phone

   {

       public object localNumber { get; set; }

       public object areaCode { get; set; }

       public string countryCode { get; set; }

   }


   public class Certificate

   {

       public object certificateIssuer { get; set; }

       public string certificateNo { get; set; }

       public object certificateExpiryDate { get; set; }

       public object certificateType { get; set; }

   }


   public class Address

   {

       public string postalCode { get; set; }

       public string streetAddress1 { get; set; }

       public object streetAddress2 { get; set; }

       public string state { get; set; }

       public string country { get; set; }

       public string city { get; set; }

   }


   public class Cellphone

   {

       public string phoneNumber { get; set; }

       public string countryCode { get; set; }

   }


   public class Maintenacehistory

   {

       public string registrationDate { get; set; }

       public string lastMaintenanceTellerId { get; set; }

   }


   public class Customer

   {

       public string customerID { get; set; }

   }


   public class Profile

   {

       public string isMerchant { get; set; }

       public string occupation { get; set; }

       public object fax { get; set; }

       public string nationality { get; set; }

       public string customerType { get; set; }

       public string email { get; set; }

       public string ethnicGroup { get; set; }

       public string gender { get; set; }

       public string isBillingOrg { get; set; }

       public string bankID { get; set; }

   }


   public class Servicerespheader

   {

       public string ErrorText { get; set; }

       public string GlobalErrorID { get; set; }

       public object ErrorDetails { get; set; }

   }


}



You can download "getCustomerDetailsClass.cs" below.



Download







Overview of getCustomerDetails.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 System.Collections.Specialized;

using System.Configuration;

using System.Net;

using System.IO;

using System.Windows.Forms;


namespace Demo

{

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

   {

       protected void Page_Load(object sender, EventArgs e)

       {

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

           {

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

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

           }

       }


       protected void btnLogin_Click(object sender, EventArgs e)

       {

           if (Page.IsPostBack == true)

           {


               try

               {

                   string userID = txtUserName.Text;

                   Session["userid"] = userID;

                   string pin = txtPassword.Text;

                   Session["pin"] = pin;

                   string otp;

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

                   {

                       otp = "";

                   }

                   else

                   {

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

                   }


                   var loginDetail = new HeaderJson();

                   loginDetail.serviceName = "getCustomerDetails";

                   loginDetail.userID = userID;

                   loginDetail.PIN = pin;

                   loginDetail.OTP = otp;


                   var headerObj = new HeaderJsonObject();

                   headerObj.Header = loginDetail;


                   string header = JsonConvert.SerializeObject(headerObj);


                   string url = "http://tbankonline.com/SMUtBank_API/Gateway?Header=" + header;


                   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();

                   }


                   CustomerRootObject customer = new CustomerRootObject();

                   customer = JsonConvert.DeserializeObject<CustomerRootObject>(result);


                   //lblTest.Text = result;


                   string GlobalErrorID = customer.Content.ServiceResponse.ServiceRespHeader.GlobalErrorID.ToString();

                   if (GlobalErrorID == "010000")

                   {

                       lblLoginStatus.Text = customer.Content.ServiceResponse.ServiceRespHeader.ErrorText.ToString();

                       txtCustomerID.Text = customer.Content.ServiceResponse.CDMCustomer.customer.customerID?.ToString() ?? "-";

                       txtDOB.Text = customer.Content.ServiceResponse.CDMCustomer.dateOfBirth?.ToString() ?? "-";

                       txtFamilyName.Text = customer.Content.ServiceResponse.CDMCustomer.familyName?.ToString() ?? "-";

                       txtGivenName.Text = customer.Content.ServiceResponse.CDMCustomer.givenName?.ToString() ?? "-";

                       txtCity.Text = customer.Content.ServiceResponse.CDMCustomer.address.city?.ToString() ?? "-";

                       txtCountry.Text = customer.Content.ServiceResponse.CDMCustomer.address.country?.ToString() ?? "-";

                       txtPostalCode.Text = customer.Content.ServiceResponse.CDMCustomer.address.postalCode?.ToString() ?? "-";

                       txtState.Text = customer.Content.ServiceResponse.CDMCustomer.address.state?.ToString() ?? "-";

                       txtStreetAddress1.Text = customer.Content.ServiceResponse.CDMCustomer.address.streetAddress1?.ToString() ?? "-";

                       txtStreetAddress2.Text = customer.Content.ServiceResponse.CDMCustomer.address.streetAddress2?.ToString() ?? "-";

                       txtCountryCode.Text = customer.Content.ServiceResponse.CDMCustomer.cellphone.countryCode?.ToString() ?? "-";

                       txtPhoneNumber.Text = customer.Content.ServiceResponse.CDMCustomer.cellphone.phoneNumber?.ToString() ?? "-";

                       txtCertificateExpiryDate.Text = customer.Content.ServiceResponse.CDMCustomer.certificate.certificateExpiryDate?.ToString() ?? "-";

                       txtCertificateIssuer.Text = customer.Content.ServiceResponse.CDMCustomer.certificate.certificateIssuer?.ToString() ?? "-";

                       txtCertificateNo.Text = customer.Content.ServiceResponse.CDMCustomer.certificate.certificateNo?.ToString() ?? "-";

                       txtLastMaintenanceTellerID.Text = customer.Content.ServiceResponse.CDMCustomer.maintenacehistory.lastMaintenanceTellerId?.ToString() ?? "-";

                       txtRegistrationDate.Text = customer.Content.ServiceResponse.CDMCustomer.maintenacehistory.registrationDate?.ToString() ?? "-";

                       txtAreaCode.Text = customer.Content.ServiceResponse.CDMCustomer.phone.areaCode?.ToString() ?? "-";

                       txtLocalNumber.Text = customer.Content.ServiceResponse.CDMCustomer.phone.countryCode?.ToString() ?? "-";

                       txtBankID.Text = customer.Content.ServiceResponse.CDMCustomer.profile.bankID?.ToString() ?? "-";


                       string custType = customer.Content.ServiceResponse.CDMCustomer.profile.customerType.ToString();

                       var p = utilities.getCustomerTypes();

                       for (int i = 0; i < p.Count(); i++)

                       {

                           if (custType == p[i].CustomerTypeID)

                           {

                               txtCustomerType.Text = p[i].CustomerTypeName;

                           }

                       }


                       txtEmail.Text = customer.Content.ServiceResponse.CDMCustomer.profile.email?.ToString() ?? "-";

                       txtEthnicGroup.Text = customer.Content.ServiceResponse.CDMCustomer.profile.ethnicGroup?.ToString() ?? "-";

                       txtFax.Text = customer.Content.ServiceResponse.CDMCustomer.profile.fax?.ToString() ?? "-";

                       txtGender.Text = customer.Content.ServiceResponse.CDMCustomer.profile.gender?.ToString() ?? "-";

                       txtIsBillingOrg.Text = customer.Content.ServiceResponse.CDMCustomer.profile.isBillingOrg?.ToString() ?? "-";

                       txtIsMerchant.Text = customer.Content.ServiceResponse.CDMCustomer.profile.isMerchant?.ToString() ?? "-";

                       txtNathionality.Text = customer.Content.ServiceResponse.CDMCustomer.profile.nationality?.ToString() ?? "-";

                       txtOccupation.Text = customer.Content.ServiceResponse.CDMCustomer.profile.occupation?.ToString() ?? "-";

                   }

                   else if (GlobalErrorID == "010041")

                   {

                       otp = utilities.newOTP();

                       Session["otp"] = otp;

                   }

                   else

                   {

                       lblLoginStatus.Text = customer.Content.ServiceResponse.ServiceRespHeader.ErrorText.ToString();

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

                       MessageBox.Show(errorMessage);

                   }

               }


               catch (Exception ex)

               {

                   lblTest2.Text = ex.Message;

               }

           }

       }

   }

}



You can download "getCustomerDetails.aspx.cs" below.



Download









Created with the Personal Edition of HelpNDoc: Easily create HTML Help documents