Hello All,
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).
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.""
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.
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("https://test.authorize.net/gateway/transact.dll");
// 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< result.length; i++)
{
if(((int) result[i] & 0xff) < 0x10){
strbuf.append("0");
strbuf.append(Long.toString((int) result[i] & 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);
}
}
}
Thanks in advance,
Brandon
PS: If I forgot to mention any additional information that would help with solving my issue, please ask.
Solved! Go to Solution.
12-04-2012 12:46 PM
The way you are sending the data in java, not a html form, is AIM, not SIM.
in AIM you send parameter like param1=value1¶m2=value2 and there are sample code in java.
12-04-2012 04:07 PM
The way you are sending the data in java, not a html form, is AIM, not SIM.
in AIM you send parameter like param1=value1¶m2=value2 and there are sample code in java.
12-04-2012 04:07 PM
I will take a look, thank you.
Brandon
12-05-2012 07:01 AM