com.jcommercesql.gateway.authorizenet
Class AuthorizeNet

java.lang.Object
  |
  +--com.jcommercesql.gateway.authorizenet.AuthorizeNet
Direct Known Subclasses:
AuthorizeNetCC

public abstract class AuthorizeNet
extends java.lang.Object

This class was designed using the Authorize.net Advanced Integration Method Implementation Guide v1.0. It is recommended that you download a copy of this guide to fully understand what gateway methods should be used for your particular situation.


Field Summary
protected  java.lang.String host
           
protected  java.lang.String merchantMD5HashValue
           
protected  java.lang.String path
           
protected  int port
           
protected  java.lang.String postData
           
protected  byte[] rawResponse
           
protected  java.lang.String x_Amount
           
protected  char x_Delim_Char
           
protected  java.lang.String x_Delim_Data
           
protected  java.lang.String x_Login
           
protected  java.lang.String x_Tran_Key
           
protected  java.lang.String x_Version
           
 
Constructor Summary
protected AuthorizeNet()
           
 
Method Summary
 void addMerchantDefinedField(java.lang.String fieldName, java.lang.String fieldValue)
          Add Merchant Defined Field The Authorize.net transaction gateway has the ability to handle merchant defined fields in addition to the required and optional fields defined in the AIM manual.
 void addOptionalField(java.lang.String fieldName, java.lang.String fieldValue)
          Add an optional field to the Authorize.net transaction request.
protected  java.lang.String calcMD5Hash(java.lang.String input)
           
 java.lang.String getAmount()
          Returns the amount value for this transaction as set by the setAmount() method.
protected  char getDelimChar()
          get delimiter character
protected  boolean getDelimData()
          is data delimited
 java.lang.String getHost()
          Returns the Authorize.net gateway host value as set by the setHost() method.
 java.lang.String getLogin()
          Returns the Authorize.net Merchant Login ID as set by the setLogin method.
 java.lang.String getPath()
          Returns the path portion of the Authorize.net URL as set by setPath() or setURL().
 int getPort()
          Returns the Authorize.net gateway port as set by the setPort method or setURL().
 java.lang.String getPostData()
          Returns the request string that was submitted to the Authorize.net gateway.
 java.lang.String getResponseApprovalCode()
          Gets the ResponseApprovalCode after transaction has been submitted.
 java.lang.String getResponseAVSResultCode()
          Gets the Address Verification Result Code aftger the transaction has been submitted.
 byte[] getResponseBytes()
          Returns the response byte array received from the Authorize.net gateway.
 java.lang.String getResponseCode()
          Gets the response code after the transaction has been submitted.
 java.lang.String getResponseReasonCode()
          gets the response reason code after the transaction has been submitted.
 java.lang.String getResponseReasonText()
          Gets the Response Reason Text after the transaction has been submitted.
 java.lang.String getResponseSubCode()
          Gets the Response Sub Code after the transaction has been submitted.
 java.lang.String getResponseTransactionID()
          Gets Response Transaction ID after the transaction has been submitted.
 java.lang.String getResponseValue(int responsePosition)
          Get Response Value by index from Authorize.net Gateway Transaction.
 java.lang.String getTranKey()
          Returns the Authorize.net Merchant Transaction Key as set by the setTranKey() method.
protected  java.lang.String getVersion()
          get Version
protected  java.util.Properties loadPropFile(java.lang.String propFileName)
          Load the properties file
protected  void parseANetResponse(byte[] httpResponse)
           
 void reloadProperties()
          Re-Load the Properties File Useful if you want to modify the existing properties in real time without restarting the application.
 void reloadProperties(java.lang.String propFileName)
          Re-Load the Properties File Useful if you want to modify the properties in real time without restarting the application.
 java.lang.String removeOptionalField(java.lang.String fieldName)
          Remove Optional Field If you have previously set an optional field you can remove the field with the method.
 void removeTestMode()
          Remove Test Mode Remove Test Mode omits the argument x_Test_Request completely.
 void setAmount(java.lang.String amount)
          Sets the amount value for this transaction.
 void setDelimChar(char delimChar)
          set delimiter character
protected  void setDelimData(boolean delimData)
          set Delimit Data
 void setHost(java.lang.String host)
          Sets the Authorize.net gateway host.
 void setLogin(java.lang.String loginID)
          Sets the Authorize.net Merchant Login ID
 void setMerchantInfo(java.lang.String loginID, java.lang.String tranKey)
          Sets the Authorize.net Merchant Login ID and Transaction Key.
 void setPath(java.lang.String path)
          Sets the Authorize.net gateway path.
 void setPort(int port)
          Sets the Authorize.net gateway port Defaults to 443.
 void setTestMode(boolean value)
          Set Test Mode Authorize.net supports testing by passing the argument x_Test_Request=true.
 void setTranKey(java.lang.String tranKey)
          Sets the Authorize.net Merchant Transaction Key
 void setURL(java.lang.String host, int port, java.lang.String path)
          set the components of the Authorize.net URL
protected  void setVersion(java.lang.String version)
          set Version
abstract  void submit()
           
protected  void submitANetGet()
           
protected  void submitANetPost(java.lang.String host, int port, java.lang.String path, byte[] postdata)
           
protected  void submitANetPost(java.lang.String host, int port, java.lang.String path, java.lang.String postdata)
           
protected  void validateProperties(java.util.Properties p)
          Validate Properties
protected  boolean verifyMD5Hash()
           
protected  boolean verifyMD5Hash(java.lang.String md5HashValue)
           
protected  boolean verifyMinimumFieldsSet()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

host

protected java.lang.String host

port

protected int port

path

protected java.lang.String path

x_Delim_Char

protected char x_Delim_Char

postData

protected java.lang.String postData

merchantMD5HashValue

protected java.lang.String merchantMD5HashValue

rawResponse

protected byte[] rawResponse

x_Version

protected java.lang.String x_Version

x_Delim_Data

protected java.lang.String x_Delim_Data

x_Login

protected java.lang.String x_Login

x_Tran_Key

protected java.lang.String x_Tran_Key

x_Amount

protected java.lang.String x_Amount
Constructor Detail

AuthorizeNet

protected AuthorizeNet()
Method Detail

loadPropFile

protected java.util.Properties loadPropFile(java.lang.String propFileName)
                                     throws java.io.IOException,
                                            InvalidPropException
Load the properties file

java.io.IOException
InvalidPropException

reloadProperties

public void reloadProperties()
                      throws java.io.IOException,
                             InvalidPropException
Re-Load the Properties File Useful if you want to modify the existing properties in real time without restarting the application. Reloads the properties from the file name used in the class initializer. If class was initialized without a properties file then an IOException occurs;

java.io.IOException
InvalidPropException

reloadProperties

public void reloadProperties(java.lang.String propFileName)
                      throws java.io.IOException,
                             InvalidPropException
Re-Load the Properties File Useful if you want to modify the properties in real time without restarting the application. If an exception is thrown, it will not affect the existing properties.

Parameters:
propFileName - the name of the file to read the properties from.
java.io.IOException
InvalidPropException

validateProperties

protected void validateProperties(java.util.Properties p)
                           throws InvalidPropException
Validate Properties

Parameters:
p - Properties object
InvalidPropException

setVersion

protected void setVersion(java.lang.String version)
set Version


getVersion

protected java.lang.String getVersion()
get Version


setDelimData

protected void setDelimData(boolean delimData)
set Delimit Data

Parameters:
delimData - The default value is true.

getDelimData

protected boolean getDelimData()
is data delimited


setDelimChar

public void setDelimChar(char delimChar)
set delimiter character

Parameters:
delimChar - the character used to delimit data in the response

getDelimChar

protected char getDelimChar()
get delimiter character


setMerchantInfo

public void setMerchantInfo(java.lang.String loginID,
                            java.lang.String tranKey)
Sets the Authorize.net Merchant Login ID and Transaction Key.

This is an alternative method to setting the login ID and transaction key with individual calls.

Parameters:
loginID - Merchant Login ID
tranKey -

setLogin

public void setLogin(java.lang.String loginID)
Sets the Authorize.net Merchant Login ID

Parameters:
loginID - Merchant Login ID
See Also:
setMerchantInfo()

getLogin

public java.lang.String getLogin()
Returns the Authorize.net Merchant Login ID as set by the setLogin method.


setTranKey

public void setTranKey(java.lang.String tranKey)
Sets the Authorize.net Merchant Transaction Key

Parameters:
tranKey - transaction key
See Also:
setMerchantInfo()

getTranKey

public java.lang.String getTranKey()
Returns the Authorize.net Merchant Transaction Key as set by the setTranKey() method.


setAmount

public void setAmount(java.lang.String amount)
Sets the amount value for this transaction.

Parameters:
amount - the amount of the transaction.

getAmount

public java.lang.String getAmount()
Returns the amount value for this transaction as set by the setAmount() method.


setHost

public void setHost(java.lang.String host)
Sets the Authorize.net gateway host.

Parameters:
host - the Authorize.net gatway host
See Also:
setURL()

getHost

public java.lang.String getHost()
Returns the Authorize.net gateway host value as set by the setHost() method.


setPort

public void setPort(int port)
Sets the Authorize.net gateway port Defaults to 443.

Parameters:
port - the port the gateway is running on
See Also:
setURL()

getPort

public int getPort()
Returns the Authorize.net gateway port as set by the setPort method or setURL().


setPath

public void setPath(java.lang.String path)
Sets the Authorize.net gateway path.

Parameters:
path - the Authorize.net gateway path
See Also:
setURL()

getPath

public java.lang.String getPath()
Returns the path portion of the Authorize.net URL as set by setPath() or setURL().


setURL

public void setURL(java.lang.String host,
                   int port,
                   java.lang.String path)
set the components of the Authorize.net URL

Parameters:
host - tbd
port - tbd
path - tbd

getPostData

public java.lang.String getPostData()
Returns the request string that was submitted to the Authorize.net gateway. Can be used for troubleshooting and will only return data after submit() has been called.


getResponseBytes

public byte[] getResponseBytes()
Returns the response byte array received from the Authorize.net gateway. Can be used for troubleshooting and will only return data after submit() has been called.


setTestMode

public void setTestMode(boolean value)
Set Test Mode Authorize.net supports testing by passing the argument x_Test_Request=true. When test mode is set to true all transactions appear to be processed as real transactions but are not passed on to a financial institution. Accordingly, all transactions will be approved by the gatway when test mode is turned on.

Parameters:
value - true or false
See Also:
removeTestMode()

removeTestMode

public void removeTestMode()
Remove Test Mode Remove Test Mode omits the argument x_Test_Request completely. This is the default behavior.

See Also:
setTestMode()

addOptionalField

public void addOptionalField(java.lang.String fieldName,
                             java.lang.String fieldValue)
Add an optional field to the Authorize.net transaction request. The Authorize.net transaction gateway has a number of optional fields that can be passed when submitting a transaction. For example if you wish to utilize the Address Verification System you must pass the customer's street address and zip code as part of the request. According to the Advanced Implementation Manual the correct field for the customers address is x_Address and for the zip it is x_Zip. Therefore you would call this method twice with the following values:
         addOptionalField("x_Address","123 Main St.")
         addOptionalField("x_Zip","10101")
 
 

Parameters:
fieldName - field name as defined in the AIM
fieldValue - value of field being set

removeOptionalField

public java.lang.String removeOptionalField(java.lang.String fieldName)
Remove Optional Field If you have previously set an optional field you can remove the field with the method. Nothing is done if the fieldName passed does not previously exist.

Parameters:
fieldName - Name of optional parameter to be removed

parseANetResponse

protected void parseANetResponse(byte[] httpResponse)

verifyMD5Hash

protected boolean verifyMD5Hash()

verifyMD5Hash

protected boolean verifyMD5Hash(java.lang.String md5HashValue)

calcMD5Hash

protected java.lang.String calcMD5Hash(java.lang.String input)

getResponseValue

public java.lang.String getResponseValue(int responsePosition)
Get Response Value by index from Authorize.net Gateway Transaction.

When a transaction is submitted to the Authoirze.net gateway, a comma seperated list of result fields is returned. The first seven fields are accessible using method from this class as they are the most important in determining whether a transaction was successful or not. The remaining 50+ fields can be access by index number using this method. Refer to the AIM manual for definitions of what other response fields are available.

Parameters:
responsePosition - index number of the reponse field
See Also:
getResponseCode(), getResponseSubCode(), getResponseReasonCode(), getResponseReasonText(), getResponseApprovalCode(), getResponseAVSResultCode(), getResponseTransactionID

getResponseCode

public java.lang.String getResponseCode()
Gets the response code after the transaction has been submitted. Possible values are: 1=Success, 2=Declined, 3=Error. See the Advanced Integration Method Implementation Guide for more information.


getResponseSubCode

public java.lang.String getResponseSubCode()
Gets the Response Sub Code after the transaction has been submitted. See the Advanced Integration Method Implementation Guide for more information.


getResponseReasonCode

public java.lang.String getResponseReasonCode()
gets the response reason code after the transaction has been submitted. See the Advanced Integration Method Implementation Guide for more information.


getResponseReasonText

public java.lang.String getResponseReasonText()
Gets the Response Reason Text after the transaction has been submitted. See the Advanced Integration Method Implementation Guide for more information.


getResponseApprovalCode

public java.lang.String getResponseApprovalCode()
Gets the ResponseApprovalCode after transaction has been submitted. See the Advanced Integration Method Implementation Guide for more information.


getResponseAVSResultCode

public java.lang.String getResponseAVSResultCode()
Gets the Address Verification Result Code aftger the transaction has been submitted. See the Advanced Integration Method Implementation Guide for more information.


getResponseTransactionID

public java.lang.String getResponseTransactionID()
Gets Response Transaction ID after the transaction has been submitted. See the Advanced Integration Method Implementation Guide for more information.


addMerchantDefinedField

public void addMerchantDefinedField(java.lang.String fieldName,
                                    java.lang.String fieldValue)
Add Merchant Defined Field The Authorize.net transaction gateway has the ability to handle merchant defined fields in addition to the required and optional fields defined in the AIM manual. The transaction gateway will accept any key/value String pair if the key is not already defined by the AIM manual. The merchant defined fields will be echoed back in the response API starting in position 69 in the same order they were entered.
         // echoed in position 69 of the response API
         addMerchantDefinedField("any_key_you_want","This can be any information you want associated with the transaction")
         // echoed in position 70 of the response API
         addMerchantDefinedField("another_key","Some more information")
         // echoed in position 71 of the responseAPI
         addMerchantDefinedField("merchant_comment","This is a test transaction") 
 

Parameters:
fieldName - name
fieldValue - value

verifyMinimumFieldsSet

protected boolean verifyMinimumFieldsSet()

submitANetGet

protected void submitANetGet()

submitANetPost

protected void submitANetPost(java.lang.String host,
                              int port,
                              java.lang.String path,
                              java.lang.String postdata)
                       throws java.lang.Exception
java.lang.Exception

submitANetPost

protected void submitANetPost(java.lang.String host,
                              int port,
                              java.lang.String path,
                              byte[] postdata)
                       throws java.lang.Exception
java.lang.Exception

submit

public abstract void submit()
                     throws java.lang.Exception
java.lang.Exception