<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Help with SIM using Java in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Help-with-SIM-using-Java/m-p/31880#M16595</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to start by saying that I am new to these forums and I apologize ahead of time if what I am asking isn't that difficult to do or along those lines (aka newbish).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off I am currently in charge of creating a connection from our SharePoint portal (Forms) to Authorize.Net for our payment option. So what I figured would be best would attempt to get something working in a test enviorment . I chose Java as the lanuage and I am working in Netbeans. I have been following the some of the sample code in order to achieve some sort of connection to the Test.authorize.net just to see if I was doing it properly. Well so far I can generate the Finger Print, and I can open a connection to the site, but I just get the error ""The following errors have occurred. (13) The merchant login ID or password is invalid or the account is inactive.""&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have checked and recheck that my API Login ID is correct so for starters I do not believe that is the issue. Here is my current code so hopefully someone can point me in the right direction. As always I appreciate any help, concerns, or opinions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;package authorizednet;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.util.*;
import net.authorize.sim.*;
import java.text.SimpleDateFormat;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.net.*;
import javax.net.ssl.HttpsURLConnection;
import java.security.cert.*;


/**
 *
 * @author bln1
 */
public class AuthorizedNet {
    
    public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException, MalformedURLException, IOException {
       
        // Payment Variables
        
        String loginID                  = "my Api Login";
        String transactionKey           = "my Transaction Key";
        String amount			= "19.99";
        String description		= "Sample Transaction";
        String label 			= "Submit Payment"; // The is the label on the 'submit' button
        String testMode			= "false";
        URL url			= new URL("&lt;A href="https://test.authorize.net/gateway/transact.dll" target="_blank"&gt;https://test.authorize.net/gateway/transact.dll&lt;/A&gt;");
        
// Not Sure what this does.
/* If an amount or description were posted to this page, the defaults are overidden
if ( request.getParameter("amount") != null )
	{ amount = request.getParameter("amount"); }
if ( request.getParameter("description") != null )
	{ description = request.getParameter("description"); }
*/
        
// an invoice is generated using the date and time
        Date myDate = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String invoice = dateFormat.format(myDate);
    
// a sequence number is randomly generated
        Random generator = new Random();
        int sequence = generator.nextInt(1000);
        
// a timestamp is generated
        long timeStamp = System.currentTimeMillis()/1000;

//This section uses Java Cryptography functions to generate a fingerprint
      
        // First, the Transaction key is converted to a "SecretKey" object
        // Where is kg even being used?
	KeyGenerator kg = KeyGenerator.getInstance("HmacMD5");
	SecretKey key = new SecretKeySpec(transactionKey.getBytes(), "HmacMD5");
        
	// A MAC object is created to generate the hash using the HmacMD5 algorithm
	Mac mac = Mac.getInstance("HmacMD5");
	mac.init(key);
	String inputstring = loginID + "^" + sequence + "^" + timeStamp + "^" + amount + "^";
	byte[] result = mac.doFinal(inputstring.getBytes());
        
	// Convert the result from byte[] to hexadecimal format
	StringBuilder strbuf = new StringBuilder(result.length * 2);
        
	for(int i=0; i&amp;lt; result.length; i++)
            {
		if(((int) result[i] &amp;amp; 0xff) &amp;lt; 0x10){
			strbuf.append("0");
		strbuf.append(Long.toString((int) result[i] &amp;amp; 0xff, 16));
                }
            }
	String fingerprint = strbuf.toString();
// end of fingerprint generation

// printing variables to the screen just to make sure I have even used the response Code 99 tool to confirm 
// I am getting the correct Finger Print.
        
        System.out.println ("Amount: " + amount);
        System.out.println ("timeStamp: " + timeStamp);
        System.out.println ("Sequence: " + sequence);
        System.out.println ("Fingerprint: " + fingerprint);
        
        // Opening connection to the Site
        URLConnection conn = url.openConnection();
        // Post Method
        conn.setDoOutput(true); 
        
        OutputStreamWriter wr;
        wr = new OutputStreamWriter(conn.getOutputStream());
        
        wr.write("x_login"+loginID);
        wr.write("x_amount"+amount);
        wr.write("x_description"+description);
        wr.write("x_invoice_num"+invoice);
        wr.write("x_fp_sequence"+sequence);
        wr.write("x_fp_timestamp"+timeStamp);
        wr.write("x_fp_hash"+fingerprint);
        wr.write("x_test_request"+testMode);
        wr.flush();
        wr.close();
                
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) !=null){
            System.out.println(line);
         }
        
        }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brandon&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: If I forgot to mention any additional information that would help with solving my issue, please ask.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Dec 2012 20:46:24 GMT</pubDate>
    <dc:creator>blnigro1</dc:creator>
    <dc:date>2012-12-04T20:46:24Z</dc:date>
    <item>
      <title>Help with SIM using Java</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Help-with-SIM-using-Java/m-p/31880#M16595</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to start by saying that I am new to these forums and I apologize ahead of time if what I am asking isn't that difficult to do or along those lines (aka newbish).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off I am currently in charge of creating a connection from our SharePoint portal (Forms) to Authorize.Net for our payment option. So what I figured would be best would attempt to get something working in a test enviorment . I chose Java as the lanuage and I am working in Netbeans. I have been following the some of the sample code in order to achieve some sort of connection to the Test.authorize.net just to see if I was doing it properly. Well so far I can generate the Finger Print, and I can open a connection to the site, but I just get the error ""The following errors have occurred. (13) The merchant login ID or password is invalid or the account is inactive.""&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have checked and recheck that my API Login ID is correct so for starters I do not believe that is the issue. Here is my current code so hopefully someone can point me in the right direction. As always I appreciate any help, concerns, or opinions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;package authorizednet;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.util.*;
import net.authorize.sim.*;
import java.text.SimpleDateFormat;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.net.*;
import javax.net.ssl.HttpsURLConnection;
import java.security.cert.*;


/**
 *
 * @author bln1
 */
public class AuthorizedNet {
    
    public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException, MalformedURLException, IOException {
       
        // Payment Variables
        
        String loginID                  = "my Api Login";
        String transactionKey           = "my Transaction Key";
        String amount			= "19.99";
        String description		= "Sample Transaction";
        String label 			= "Submit Payment"; // The is the label on the 'submit' button
        String testMode			= "false";
        URL url			= new URL("&lt;A href="https://test.authorize.net/gateway/transact.dll" target="_blank"&gt;https://test.authorize.net/gateway/transact.dll&lt;/A&gt;");
        
// Not Sure what this does.
/* If an amount or description were posted to this page, the defaults are overidden
if ( request.getParameter("amount") != null )
	{ amount = request.getParameter("amount"); }
if ( request.getParameter("description") != null )
	{ description = request.getParameter("description"); }
*/
        
// an invoice is generated using the date and time
        Date myDate = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String invoice = dateFormat.format(myDate);
    
// a sequence number is randomly generated
        Random generator = new Random();
        int sequence = generator.nextInt(1000);
        
// a timestamp is generated
        long timeStamp = System.currentTimeMillis()/1000;

//This section uses Java Cryptography functions to generate a fingerprint
      
        // First, the Transaction key is converted to a "SecretKey" object
        // Where is kg even being used?
	KeyGenerator kg = KeyGenerator.getInstance("HmacMD5");
	SecretKey key = new SecretKeySpec(transactionKey.getBytes(), "HmacMD5");
        
	// A MAC object is created to generate the hash using the HmacMD5 algorithm
	Mac mac = Mac.getInstance("HmacMD5");
	mac.init(key);
	String inputstring = loginID + "^" + sequence + "^" + timeStamp + "^" + amount + "^";
	byte[] result = mac.doFinal(inputstring.getBytes());
        
	// Convert the result from byte[] to hexadecimal format
	StringBuilder strbuf = new StringBuilder(result.length * 2);
        
	for(int i=0; i&amp;lt; result.length; i++)
            {
		if(((int) result[i] &amp;amp; 0xff) &amp;lt; 0x10){
			strbuf.append("0");
		strbuf.append(Long.toString((int) result[i] &amp;amp; 0xff, 16));
                }
            }
	String fingerprint = strbuf.toString();
// end of fingerprint generation

// printing variables to the screen just to make sure I have even used the response Code 99 tool to confirm 
// I am getting the correct Finger Print.
        
        System.out.println ("Amount: " + amount);
        System.out.println ("timeStamp: " + timeStamp);
        System.out.println ("Sequence: " + sequence);
        System.out.println ("Fingerprint: " + fingerprint);
        
        // Opening connection to the Site
        URLConnection conn = url.openConnection();
        // Post Method
        conn.setDoOutput(true); 
        
        OutputStreamWriter wr;
        wr = new OutputStreamWriter(conn.getOutputStream());
        
        wr.write("x_login"+loginID);
        wr.write("x_amount"+amount);
        wr.write("x_description"+description);
        wr.write("x_invoice_num"+invoice);
        wr.write("x_fp_sequence"+sequence);
        wr.write("x_fp_timestamp"+timeStamp);
        wr.write("x_fp_hash"+fingerprint);
        wr.write("x_test_request"+testMode);
        wr.flush();
        wr.close();
                
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) !=null){
            System.out.println(line);
         }
        
        }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brandon&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: If I forgot to mention any additional information that would help with solving my issue, please ask.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Dec 2012 20:46:24 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Help-with-SIM-using-Java/m-p/31880#M16595</guid>
      <dc:creator>blnigro1</dc:creator>
      <dc:date>2012-12-04T20:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help with SIM using Java</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Help-with-SIM-using-Java/m-p/31892#M16601</link>
      <description>&lt;P&gt;The way you are sending the data in java, not a html form, is AIM, not SIM.&lt;/P&gt;&lt;P&gt;in AIM you send parameter like param1=value1&amp;amp;param2=value2 and there are sample code in java.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2012 00:07:08 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Help-with-SIM-using-Java/m-p/31892#M16601</guid>
      <dc:creator>RaynorC1emen7</dc:creator>
      <dc:date>2012-12-05T00:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Help with SIM using Java</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Help-with-SIM-using-Java/m-p/31900#M16605</link>
      <description>&lt;P&gt;I will take a look, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Brandon&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2012 15:01:50 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Help-with-SIM-using-Java/m-p/31900#M16605</guid>
      <dc:creator>blnigro1</dc:creator>
      <dc:date>2012-12-05T15:01:50Z</dc:date>
    </item>
  </channel>
</rss>

