Class CreditCard

  • All Implemented Interfaces:
    Cloneable

    public class CreditCard
    extends Object
    implements Cloneable
    Encapsulates the credit card details that are sent to the bank, retrieved from the database, or manipulated in any way. The credit card details include card numbers and related billing address details. If this card is retrieved from an encrypted/protected source, not all the information will necessarily be available.
    Author:
    AO Industries, Inc.
    • Field Detail

      • MASK_START_DIGITS

        public static final int MASK_START_DIGITS
        The maximum number of starting digits kept when masked.
        See Also:
        Constant Field Values
      • MASK_END_DIGITS

        public static final int MASK_END_DIGITS
        The maximum number of ending digits kept when masked.
        See Also:
        Constant Field Values
      • MASK_CHARACTER

        public static final char MASK_CHARACTER
        The character used representing a masked digit.
        See Also:
        Constant Field Values
      • UNKNOWN_DIGIT

        public static final char UNKNOWN_DIGIT
        The character used for an unknown digits. Unknown digits would not be masked if available, but are simply not available. This is used when converting from card type + last4 back to a masked card number. In a future version of the API, when both card type and last4 are stored, this mechanism will be unnecessary.
        See Also:
        Constant Field Values
      • UNKNOWN_MIDDLE

        public static final char UNKNOWN_MIDDLE
        When the number of digits is unknown, such as generating a possible masked card number from type + last4, this can be used as a filler between beginning and end of the card number.
        See Also:
        Constant Field Values
      • UNKNOWN_EXPRIATION_MONTH

        public static final byte UNKNOWN_EXPRIATION_MONTH
        Value used to represent an unknown expiration month.
        See Also:
        Constant Field Values
      • UNKNOWN_EXPRIATION_YEAR

        public static final short UNKNOWN_EXPRIATION_YEAR
        Value used to represent an unknown expiration year.
        See Also:
        Constant Field Values
      • MIN_EXPIRATION_YEAR

        public static final short MIN_EXPIRATION_YEAR
        The minimum expected expiration year.
        See Also:
        Constant Field Values
    • Method Detail

      • maskCreditCardNumber

        public static String maskCreditCardNumber​(String cardNumber)
        Only keeps the first MASK_START_DIGITS and last MASK_END_DIGITS digits of a card number after trimming. Other digits are replaced with MASK_CHARACTER. All non-digit characters are left intact. If the number is null, returns an empty string.
      • numbersOnly

        public static String numbersOnly​(String value,
                                         boolean allowUnknownDigit)
        Gets the numbers out of a String.
        Parameters:
        value - the value to extract numbers from
        allowUnknownDigit - selects inclusion of UNKNOWN_DIGIT in the result
      • numbersOnly

        public static String numbersOnly​(String value)
        Gets the numbers out of a String, not including any UNKNOWN_DIGIT.
      • getFullName

        public static String getFullName​(String firstName,
                                         String lastName)
        Combines the first and last names into a single name String.
      • getPersistenceUniqueId

        public String getPersistenceUniqueId()
        Gets the persistence unique identifier.
      • setPersistenceUniqueId

        public void setPersistenceUniqueId​(String persistenceUniqueId)
        Sets the persistence unique identifier.
      • getPrincipalName

        public String getPrincipalName()
        Gets the name of the principal who added the card.
      • setPrincipalName

        public void setPrincipalName​(String principalName)
        Sets the name of the principal who added the card.
      • getGroupName

        public String getGroupName()
        Gets the name of the group this card belongs to.
      • setGroupName

        public void setGroupName​(String groupName)
        Sets the name of the group this card belongs to.
      • getProviderId

        public String getProviderId()
        Gets the id of the merchant services provider that is storing this card.
      • setProviderId

        public void setProviderId​(String providerId)
        Sets the id of the merchant services provider that is storing this card.
      • getProviderUniqueId

        public String getProviderUniqueId()
        Gets the provider-specific unique id representing this card.
      • setProviderUniqueId

        public void setProviderUniqueId​(String providerUniqueId)
        Sets the provider-specific unique id representing this card.
      • getCardNumber

        public String getCardNumber()
        Gets the full credit card number. This may return null if the full card number is not available.
      • setCardNumber

        public void setCardNumber​(String cardNumber)
        Trims and sets the full credit card number. Also sets the masked card number if cardNumber is not null.
        Throws:
        IllegalArgumentException - if invalid credit card number
      • getMaskedCardNumber

        public String getMaskedCardNumber()
        Gets the masked card number. This contains the first two and last four digits of the card number. This value will usually be available while the card number will is only available for new transactions.
      • getExpirationMonth

        public byte getExpirationMonth()
        Gets the expiration month, where 1 is January and 12 is December.
        See Also:
        UNKNOWN_EXPRIATION_MONTH
      • getExpirationYear

        public short getExpirationYear()
        Gets the expiration year, such as 2007.
        See Also:
        UNKNOWN_EXPRIATION_YEAR
      • getExpirationDateMMYY

        public String getExpirationDateMMYY​(boolean allowUnknownDate)
        Gets the expiration date in MMYY format, not including any UNKNOWN_DIGIT.
        Parameters:
        allowUnknownDate - selects inclusion of UNKNOWN_DIGIT in the result
        Throws:
        IllegalArgumentException - if invalid date
      • getCardCode

        public String getCardCode()
        Gets the three or four digit card security code. This value is never stored and is therefore only available for a new card.
      • getFirstName

        public String getFirstName()
        Gets the first name of the card holder.
      • setFirstName

        public void setFirstName​(String firstName)
        Trims and sets the first name of the card holder.
      • getLastName

        public String getLastName()
        Gets the last name of the card holder.
      • setLastName

        public void setLastName​(String lastName)
        Trims and sets the last name of the card holder.
      • getCompanyName

        public String getCompanyName()
        Gets the company name of the card holder.
      • setCompanyName

        public void setCompanyName​(String companyName)
        Trims and sets the company name of the card holder.
      • getEmail

        public String getEmail()
        Gets the card holder's email address.
      • setEmail

        public void setEmail​(String email)
        Trims and sets the card holder's email address.
        Throws:
        IllegalArgumentException - if the address does is not in the proper format
      • getPhone

        public String getPhone()
        Gets the card holder's telephone number.
      • setPhone

        public void setPhone​(String phone)
        Trims and sets the card holder's telephone number.
      • getFax

        public String getFax()
        Gets the card holder's fax number.
      • setFax

        public void setFax​(String fax)
        Trims and sets the card holder's fax number.
      • getCustomerId

        public String getCustomerId()
        Gets the merchant-specific unique customer ID.
      • setCustomerId

        public void setCustomerId​(String customerId)
        Sets the merchant-specific unique customer ID.
      • getCustomerTaxId

        public String getCustomerTaxId()
        Gets the customer SSN or Tax ID.
      • setCustomerTaxId

        public void setCustomerTaxId​(String customerTaxId)
        Trims and sets the customer SSN or Tax ID, removes any spaces and hyphens.
        Throws:
        IllegalArgumentException - if not a nine digit number after trimming.
      • getStreetAddress1

        public String getStreetAddress1()
        Gets the card holder's street address (first line).
      • setStreetAddress1

        public void setStreetAddress1​(String streetAddress1)
        Trims and sets the card holder's street address (first line).
      • getStreetAddress2

        public String getStreetAddress2()
        Gets the card holder's street address (second line).
      • setStreetAddress2

        public void setStreetAddress2​(String streetAddress2)
        Trims and sets the card holder's street address (second line).
      • getCity

        public String getCity()
        Gets the card holder's city.
      • setCity

        public void setCity​(String city)
        Trims and sets the card holder's city.
      • getState

        public String getState()
        Gets the card holder's state/province/prefecture.
      • setState

        public void setState​(String state)
        Trims and sets the card holder's state/province/prefecture.
      • getPostalCode

        public String getPostalCode()
        Gets the card holder's postal code.
      • setPostalCode

        public void setPostalCode​(String postalCode)
        Trims and sets the card holder's postal code.
      • getComments

        public String getComments()
        Gets the comments associated with this card.
      • setComments

        public void setComments​(String comments)
        Sets the comments associated with this card.