org.starhope.appius.pay.util
Class PaymentCredential

java.lang.Object
  extended by org.starhope.appius.pay.util.PaymentCredential

public class PaymentCredential
extends Object

Author:
brpocock@star-hope.org

Field Summary
private  UserAddress address
          WRITEME
private  String buyerCompany
          WRITEME
private  String buyerFamilyName
          WRITEME
private  String buyerGivenName
          WRITEME
private  BigDecimal cardCode
          The CCV, Card Code.
private  String cardCodeString
          Deprecated. 
private  BigInteger cardNumber
          The credit-card number
private  CredentialType credentialType
          The type of credentials presented.
private  Date expiry
          The expiry date of a credit card (used for validation)
 
Constructor Summary
PaymentCredential()
           
 
Method Summary
 void applyTo(AimTransaction xact)
           Apply a (credit-card only) set of payment credentials to an Authorize.Net one-time-purchase (AIM, Advanced Integration Method) object.
 void applyTo(ARBNameAndAddress billTo)
          Apply these payment credentials' data to an Authorize.Net Automatic Recurring Billing name and address object, needed for Auth-net-ARB submission.
 void applyTo(ARBPayment payment)
           Apply the credit-card information to the Authorize.net ARBPayment object.
private static boolean doesNumberMatchLuhnChecksum(BigInteger number)
          Perform Luhn algorithm validation upon the credit-card number supplied.
 UserAddress getAddress()
           
 String getBuyerCompany()
           
 String getBuyerFamilyName()
           
 String getBuyerGivenName()
           
 CredentialType getCredentialType()
           
 int getExpiryMonth()
          WRITEME: document this method (brpocock@star-hope.org, Sep 11, 2009)
 int getExpiryYear()
          WRITEME: document this method (brpocock@star-hope.org, Sep 11, 2009)
static String getFriendlyName(CredentialType type)
           
private  String getLastFour()
           
 boolean isReadyToGo()
           
 void setBuyerCompany(String company)
          WRITEME: document this method (brpocock@star-hope.org, Sep 11, 2009)
 void setBuyerFamilyName(String parameter)
           
 void setBuyerGivenName(String parameter)
           
 void setBuyerInfo(String buyerGivenName1, String buyerFamilyName1, UserAddress address1)
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 void setCardCode(BigDecimal num)
           
 void setCardCode(String num)
           
 void setCardCodeAsString(String code)
          Deprecated. use setCardCode(BigDecimal)
 void setCardNumber(BigInteger newCardNumber)
           
 void setCardNumber(String num)
          Set a card number from a user-supplied string.
 void setCredentialType(CredentialType credentialType1)
           
 void setExpiry(Date d)
           
 void setExpiryMonth(int expiryMonth)
           
 void setExpiryYear(int expiryYear)
           
 void setIBCCard(String ibcCode)
          This was to have been part of Project Risqué and was never implemented.
 void shred()
          Discard all credential information
 String toString()
          This is an overriding method.
 void verifyCredentials()
           Perform basic validation upon the credentials.
static int verifyIBC(String ibcCode)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

address

private volatile UserAddress address
WRITEME


buyerCompany

private volatile String buyerCompany
WRITEME


buyerFamilyName

private volatile String buyerFamilyName
WRITEME


buyerGivenName

private volatile String buyerGivenName
WRITEME


cardCode

private volatile BigDecimal cardCode
The CCV, Card Code.


cardCodeString

@Deprecated
private volatile String cardCodeString
Deprecated. 
The CCV, Card Code, stored as a string. This is an historical hack due to issues with properly formatting CCVs for Authorize.Net and should be phased out as soon as those bugs have been fixed.


cardNumber

private volatile BigInteger cardNumber
The credit-card number


credentialType

private CredentialType credentialType
The type of credentials presented. See CredentialType for all valid values. Note that at present we only actually support credit cards and gift cards.


expiry

private Date expiry
The expiry date of a credit card (used for validation)

Constructor Detail

PaymentCredential

public PaymentCredential()
Method Detail

doesNumberMatchLuhnChecksum

private static boolean doesNumberMatchLuhnChecksum(BigInteger number)
Perform Luhn algorithm validation upon the credit-card number supplied.

Parameters:
number - An arbitrary-length credit-card number
Returns:
True, if the number given is potentially valid as a credit-card number

getFriendlyName

public static String getFriendlyName(CredentialType type)
Parameters:
type - a type of credentials
Returns:
a "friendly" (but possibly verbose) description of the type of transaction credentials, suitable for displaying to the end-user. This is used by, e.g. UnsupportedCredentialException to display "pretty" error messages.

verifyIBC

public static int verifyIBC(String ibcCode)
                     throws NotImplementedException,
                            AlreadyUsedException,
                            NotFoundException
Parameters:
ibcCode - WRITEME
Returns:
WRITEME
Throws:
NotImplementedException - WRITEME
AlreadyUsedException - WRITEME
NotFoundException - WRITEME

applyTo

public void applyTo(AimTransaction xact)
             throws UnsupportedCredentialException

Apply a (credit-card only) set of payment credentials to an Authorize.Net one-time-purchase (AIM, Advanced Integration Method) object.

At present, this (or applyTo(ARBPayment)) are the only supported way to extract the card information once it's entered into this object; however, the last 4 digits of the card number are visible via #toString()

Parameters:
xact - An Authorize.Net transaction in the form of AimTransaction
Throws:
UnsupportedCredentialException - if attempting to apply a credential type other than MasterCard or VISA

applyTo

public void applyTo(ARBNameAndAddress billTo)
Apply these payment credentials' data to an Authorize.Net Automatic Recurring Billing name and address object, needed for Auth-net-ARB submission.

Parameters:
billTo - The ARBNameAndAddress object, which will be a part of the billing submission

applyTo

public void applyTo(ARBPayment payment)
             throws UnsupportedCredentialException

Apply the credit-card information to the Authorize.net ARBPayment object.

At present, this (or applyTo(AimTransaction)) are the only supported way to extract the card information once it's entered into this object; however, the last 4 digits of the card number are visible via #toString()

Parameters:
payment - The ARB Payment object to which we want to append the card information.
Throws:
UnsupportedCredentialException - if this is not a credit-card credentials bundle

getAddress

public UserAddress getAddress()
Returns:
UserAddress address

getBuyerCompany

public String getBuyerCompany()
Returns:
the buyerCompany

getBuyerFamilyName

public String getBuyerFamilyName()
Returns:
String buyerFamilyName

getBuyerGivenName

public String getBuyerGivenName()
Returns:
String buyerGivenName

getCredentialType

public CredentialType getCredentialType()
Returns:
the credentialType

getExpiryMonth

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

Returns:
WRITEME

getExpiryYear

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

Returns:
WRITEME

getLastFour

private String getLastFour()
Returns:
The last four digits of a credit-card number. Used by toString() and only accessible thereby.

isReadyToGo

public boolean isReadyToGo()
Returns:
true, if these credentials seem plausible to present

setBuyerCompany

public void setBuyerCompany(String company)
WRITEME: document this method (brpocock@star-hope.org, Sep 11, 2009)

Parameters:
company - WRITEME

setBuyerFamilyName

public void setBuyerFamilyName(String parameter)
Parameters:
parameter - the buyerFamilyName to set

setBuyerGivenName

public void setBuyerGivenName(String parameter)
Parameters:
parameter - buyer's given name

setBuyerInfo

public void setBuyerInfo(String buyerGivenName1,
                         String buyerFamilyName1,
                         UserAddress address1)
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Parameters:
buyerGivenName1 - WRITEME
buyerFamilyName1 - WRITEME
address1 - WRITEME

setCardCode

public void setCardCode(BigDecimal num)
Parameters:
num - The CCV, Card Code Verification, number (3 or 4 digits)

setCardCode

public void setCardCode(String num)
Parameters:
num - The CCV, Card Code Verification, number (3 or 4 digits)

setCardCodeAsString

@Deprecated
public void setCardCodeAsString(String code)
Deprecated. use setCardCode(BigDecimal)

This is an historical hack from a problem with properly formatting card codes beginning with zeroes.

Parameters:
code - The CCV, Card Code Verification, number (3 or 4 digits)

setCardNumber

public void setCardNumber(BigInteger newCardNumber)
                   throws NumberFormatException
Parameters:
newCardNumber - The credit-card number (usually 16 digits)
Throws:
NumberFormatException - if the card number does not match checksum

setCardNumber

public void setCardNumber(String num)
                   throws NumberFormatException
Set a card number from a user-supplied string. This method removes non-digit contents before attempting to store the value as a BigDecimal, so it should be used for user-supplied inputs that might contain spaces or dashes, or other random line noise.

Parameters:
num - The presumed credit-card number, possibly containing spaces or dashes.
Throws:
NumberFormatException - if the card number has an invalid length, non-digit contents, or does not match a correct checksumming for the type of card provided

setCredentialType

public void setCredentialType(CredentialType credentialType1)
Parameters:
credentialType1 - the credentialType to set

setExpiry

public void setExpiry(Date d)
               throws CredentialExpiredException
Parameters:
d - The expiration date. Only the month and year are used: the day can be "1" for validity
Throws:
CredentialExpiredException - if the expiry date is in the past

setExpiryMonth

public void setExpiryMonth(int expiryMonth)
Parameters:
expiryMonth - expiry month

setExpiryYear

public void setExpiryYear(int expiryYear)
Parameters:
expiryYear - expiry year

setIBCCard

public void setIBCCard(String ibcCode)
                throws NotImplementedException
This was to have been part of Project Risqué and was never implemented. The vestiges of Risqué could potentially be useful in future, so they have not been removed.

Parameters:
ibcCode - WRITEME
Throws:
NotImplementedException - WRITEME

shred

public void shred()
Discard all credential information


toString

public String toString()
This is an overriding method.

Overrides:
toString in class Object
See Also:
Object.toString()

verifyCredentials

public void verifyCredentials()
                       throws DataException

Perform basic validation upon the credentials.

For credit-cards, verify that the credentials appear to have a valid credit-card number.

For electronic payments of other kinds, perform basic validation of credential values to ensure that they appear to be basically plausible.

XXX right now, this only actually checks the first digit against VISA/MasterCard selection. This should do proper checksum checks against the full number...

Throws:
DataException - if the card number is invalid (impossible), or the type of credentials for payment presented are not set to a valid/supported type (currently VISA or MasterCard)