net.authorize.admc.authnet
Class AimTransaction

java.lang.Object
  extended by net.authorize.admc.authnet.AimTransaction

public class AimTransaction
extends Object

Authorize.net client. N.b. It would be very easy for a scoundrel to modify this class to steal or use your credit card information. Therefore, only use a copy of this class from a source which you trust, and verify the checksums! N.b. the difference between "transaction key", my password; and "transaction ID", the identifier for a transaction. It seems that Authorize.net is trying to force AIM users into the hands of their own partners by no longer providing easy public access to the AIM API's, like they used to do. You can see the sample code at http://developer.authorize.net/samplecode/ but they leave a lot of questions unanswered, and the code is non-scalable and non-Object Oriented.


Nested Class Summary
static interface AimTransaction.Persistor
          An implementation of this interface may be passed to the postPurchase method to perform any custom post-purchase processing.
 
Field Summary
private  String address
          WRITEME
private  String amount
          WRITEME
private  String auth_code
          WRITEME
private  String card_code
          WRITEME
private  String card_num
          WRITEME
private  String city
          WRITEME
private  String company
          WRITEME
private  AimConfig config
          WRITEME
private  String country
          WRITEME
private  String cust_id
          WRITEME
 String[] data
          WRITEME
private  String description
          WRITEME
private  String email
          WRITEME
private  String exp_date
          WRITEME
private  String fax
          WRITEME
private  String first_name
          WRITEME
private static char[] hexChars
          Simple look-up table for hexadecimal digits
private  String invoice_num
          WRITEME
private  String last_name
          WRITEME
static String LS
          WRITEME: document this field (brpocock@star-hope.org, Oct 13, 2009) LS (AimTransaction)
private static int MAX_RESPONSE_SIZE
          WRITEME
private  String phone
          WRITEME
(package private)  char[] readBuffer
          WRITEME
private  BigDecimal requestedAmount
          WRITEME
private  String ship_to_address
          WRITEME
private  String ship_to_city
          WRITEME
private  String ship_to_company
          WRITEME
private  String ship_to_country
          WRITEME
private  String ship_to_first_name
          WRITEME
private  String ship_to_last_name
          WRITEME
private  String ship_to_state
          WRITEME
private  String ship_to_zip
          WRITEME
private  String state
          WRITEME
private  boolean test_request
          WRITEME
private  String trans_id
          WRITEME
private  String type
          WRITEME
private  String zip
          WRITEME
 
Constructor Summary
AimTransaction(AimConfig config1)
          Purposefully has only Package visibility.
 
Method Summary
 void checkMd5Hash()
           
static void checkMd5Hash(String md5hash, String login, String transID, String paid)
           
 BigDecimal getAmount()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 String getApproval()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 char getAVS()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 String getPhone()
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 int getRcode()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 int getRRcode()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 String getRRtext()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 boolean getTestMode()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 BigDecimal getTransId()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 String getTransType()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
private static char hexCharFor(int i)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 boolean isTestMode()
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 void postPurchase()
           Perform post-purchase validation.
 void postPurchase(AimTransaction.Persistor persistor)
          Purchase-specific post-processing.
private  void postPurchaseValidate()
          Validate that a normal purchase transaction completed successfully.
 void setAmount(BigDecimal inInt)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setAmount(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setAuthCode(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillAddress(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillCity(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillCountry(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillFax(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillFirstName(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillLastName(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillOrg(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillPhone(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillStateName(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setBillZip(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setCardCode(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setCardNum(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setCustId(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setDescription(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setEmail(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setExp(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setInvoiceNum(int i)
          Convenience data type conversion
 void setInvoiceNum(String inString)
          Misnomer taken from the AIM documentation.
 void setPhone(String phone1)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipAddress(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipCity(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipCountry(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipFirstName(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipLastName(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipOrg(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipStateName(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setShipZip(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setTestMode(boolean is_this_a_test_request_QQ)
          Set the test mode for this one transaction.
 void setTransId(int inInt)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void setType(String inString)
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
 void submit()
          WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)
static String toHex(byte[] byteArray)
          Run with no parameters to see syntax, like:
 String toString()
          Dumps entire response data array, except for empty elements, which are skipped.
static String truncateIfLonger(String inString, int maxLen)
          Public utility method.
 void validateInput(String vehicle)
          Verify that input data is good to submit a payment request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hexChars

private static char[] hexChars
Simple look-up table for hexadecimal digits


LS

public static final String LS
WRITEME: document this field (brpocock@star-hope.org, Oct 13, 2009) LS (AimTransaction)


MAX_RESPONSE_SIZE

private static final int MAX_RESPONSE_SIZE
WRITEME


address

private String address
WRITEME


amount

private String amount
WRITEME


auth_code

private String auth_code
WRITEME


card_code

private String card_code
WRITEME


card_num

private String card_num
WRITEME


city

private String city
WRITEME


company

private String company
WRITEME


config

private AimConfig config
WRITEME


country

private String country
WRITEME


cust_id

private String cust_id
WRITEME


data

public String[] data
WRITEME


description

private String description
WRITEME


email

private String email
WRITEME


exp_date

private String exp_date
WRITEME


fax

private String fax
WRITEME


first_name

private String first_name
WRITEME


invoice_num

private String invoice_num
WRITEME


last_name

private String last_name
WRITEME


phone

private String phone
WRITEME


readBuffer

char[] readBuffer
WRITEME


requestedAmount

private BigDecimal requestedAmount
WRITEME


ship_to_address

private String ship_to_address
WRITEME


ship_to_city

private String ship_to_city
WRITEME


ship_to_company

private String ship_to_company
WRITEME


ship_to_country

private String ship_to_country
WRITEME


ship_to_first_name

private String ship_to_first_name
WRITEME


ship_to_last_name

private String ship_to_last_name
WRITEME


ship_to_state

private String ship_to_state
WRITEME


ship_to_zip

private String ship_to_zip
WRITEME


state

private String state
WRITEME


test_request

private boolean test_request
WRITEME


trans_id

private String trans_id
WRITEME


type

private String type
WRITEME


zip

private String zip
WRITEME

Constructor Detail

AimTransaction

AimTransaction(AimConfig config1)
Purposefully has only Package visibility. It's probably most convenient to get your AimTransaction objects from the factory method AimConfig.newTransaction()

Parameters:
config1 - WRITEME
See Also:
AimConfig.newTransaction()
Method Detail

checkMd5Hash

public static void checkMd5Hash(String md5hash,
                                String login,
                                String transID,
                                String paid)
                         throws AuthNetException
Parameters:
md5hash - WRITEME
login - WRITEME
transID - WRITEME
paid - WRITEME
Throws:
AuthNetException - if received hash does not match calculated hash.

hexCharFor

private static char hexCharFor(int i)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
i - WRITEME
Returns:
WRITEME

toHex

public static String toHex(byte[] byteArray)
Run with no parameters to see syntax, like:
     java com.admc.authnet.AimTransaction
 
N.b. THIS IS FOR NON-SECURE TESTING! Make sure your computer (and your nework connection to it, if any) is secure before running this method, because the command-line parameters you give to this command can be observerd by others.

Parameters:
byteArray - WRITEME
Returns:
WRITEME

truncateIfLonger

public static String truncateIfLonger(String inString,
                                      int maxLen)
Public utility method. Returns the given String if lenth is less than or equal to the specified limit. Otherwise returns a newly constructed, truncated version of the given String.

Parameters:
inString - WRITEME
maxLen - WRITEME
Returns:
WRITEME

checkMd5Hash

public void checkMd5Hash()
                  throws AuthNetException
Throws:
AuthNetException - if received hash does not match calculated hash.

getAmount

public BigDecimal getAmount()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getApproval

public String getApproval()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getAVS

public char getAVS()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getPhone

public String getPhone()
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Returns:
WRITEME

getRcode

public int getRcode()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getRRcode

public int getRRcode()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getRRtext

public String getRRtext()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getTestMode

public boolean getTestMode()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getTransId

public BigDecimal getTransId()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

getTransType

public String getTransType()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

isTestMode

public boolean isTestMode()
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Returns:
WRITEME

postPurchase

public void postPurchase()
                  throws AuthNetException

Perform post-purchase validation.

User should call either postPurchase(Persistor) or postPurchase() after submitting a purchase transaction.

Throws:
AuthNetException - Your postPurchase call should handle these.

postPurchase

public void postPurchase(AimTransaction.Persistor persistor)
                  throws SQLException,
                         AuthNetException
Purchase-specific post-processing.

User should call either postPurchase(Persistor) or postPurchase() after submitting a purchase transaction.

Does purchase-specific post-validation, and invokes the user-specified persist method.

Parameters:
persistor - WRITEME
Throws:
AuthNetException - It is very important that these critical exceptions be handled appropriately, because the customer has been charged but you may not have a record of it. You just need to set up a SMTP Appender or write these to a critical log file so you know to check the details with the Authorize.net console.
SQLException - If you did not pass a Persistor which can throw a SQLException, then just catch SQLException and rethrow a RuntimeException, because you won't get it unless your app is messed up. If you may throw SQLException, same comment as for AuthNetException applies.

postPurchaseValidate

private void postPurchaseValidate()
                           throws AuthNetException
Validate that a normal purchase transaction completed successfully.

Throws:
AuthNetException - WRITEME

setAmount

public void setAmount(BigDecimal inInt)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inInt - WRITEME

setAmount

public void setAmount(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setAuthCode

public void setAuthCode(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillAddress

public void setBillAddress(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillCity

public void setBillCity(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillCountry

public void setBillCountry(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillFax

public void setBillFax(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillFirstName

public void setBillFirstName(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillLastName

public void setBillLastName(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillOrg

public void setBillOrg(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillPhone

public void setBillPhone(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillStateName

public void setBillStateName(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setBillZip

public void setBillZip(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setCardCode

public void setCardCode(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setCardNum

public void setCardNum(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setCustId

public void setCustId(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setDescription

public void setDescription(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setEmail

public void setEmail(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setExp

public void setExp(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setInvoiceNum

public void setInvoiceNum(int i)
Convenience data type conversion

Parameters:
i - WRITEME

setInvoiceNum

public void setInvoiceNum(String inString)
Misnomer taken from the AIM documentation. This is an invoice identifier, not necessary a number.

Parameters:
inString - WRITEME

setPhone

public void setPhone(String phone1)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
phone1 - WRITEME

setShipAddress

public void setShipAddress(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setShipCity

public void setShipCity(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setShipCountry

public void setShipCountry(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setShipFirstName

public void setShipFirstName(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setShipLastName

public void setShipLastName(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setShipOrg

public void setShipOrg(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setShipStateName

public void setShipStateName(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setShipZip

public void setShipZip(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

setTestMode

public void setTestMode(boolean is_this_a_test_request_QQ)
Set the test mode for this one transaction.

Parameters:
is_this_a_test_request_QQ - WRITEME

setTransId

public void setTransId(int inInt)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inInt - WRITEME

setType

public void setType(String inString)
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Parameters:
inString - WRITEME

submit

public void submit()
            throws IOException
WRITEME: document this method (brpocock@star-hope.org, Oct 13, 2009)

Throws:
IOException - WRITEME

toString

public String toString()
Dumps entire response data array, except for empty elements, which are skipped.

Overrides:
toString in class Object
Returns:
WRITEME

validateInput

public void validateInput(String vehicle)
                   throws AuthNetException
Verify that input data is good to submit a payment request. We assume that the addresses have already been validated.

Parameters:
vehicle - WRITEME
Throws:
AuthNetException - WRITEME