Saturday, February 18, 2017

Integration with Knet Payment Gateway - Pin Pad Device

in this article series i will suggest way to control Pinpad Device (payment through device) from ADF application . the story started when we received java Api (jar) from knet payment Gateway (Kuwait payment gateway ) , with target to implement it through ADF application .

first approach was implementing it using java applet which not worked because java Applet became out dated . we looked to alternative solutions but we failed .

later , we found implementation using windows service (hosting Wcf over windows Service) but the challenge still exist because we don't have dll . so we converted the jar to dll .  

the proposed solution have the following steps :

  1. Convert jar to dll (to convert library from java technology to .net)
  2. develop WCF Service (rest) over windows 
  3. import the Dll and execute the payment process through web operation
  4. run and start windows Service
  5. call the service from java script
Below the details :

conversion library from jar to dll :
we searched a lot to find the appropriate too to do this task . until we found ikvm tool which enable you to convert your jars to dlls and exe (check this)  after downloading and unzipping it you can execute this task using the following command line :

ikvmc your jar.jar

after execution you will find your dll in the same directory , did you find it ? good job 😏
now let us go to the next step .

 Hosting WCF on windows service :
this approach suggested by Microsoft to host web services on end user PC with full privileges to access user resources and hardware check this.

  Create java script Caller :

in this part i will show how to create java script code that should be used to call Rest service that hosted on ADF application  . below sample for it .

<script type="text/javascript">
       function test() 
             {
                var xhttp = new XMLHttpRequest();
                xhttp.open("POST", "http://localhost:8000/ServiceModelSamples/service/knetPayment",                     true) ;
               xhttp.setRequestHeader("Content-type", "application/json");
               
                xhttp.onload = function (e) 
                   {
                      if (xhttp.readyState === 4) 
                           {
                              if (xhttp.status === 200) 
                                       {
                                           alert(xhttp.responseText);
                                        } 
                              else 
                                        {
                                           alert(xhttp.statusText);
                                         }
                               }
                     };
              xhttp.onerror = function (e) 
                    {
                       alert(xhttp.responseText);
                    };
              xhttp.send('{"Amount":"10"}');
              alert("3");
           
         }



    </script>


Enjoy !