java.lang.Object
com.aoapps.payments.CreditCard
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe prefix used forgetCardNumberDisplay(java.lang.String).static final StringThe middle separator used forgetExpirationDisplay(java.lang.Byte, java.lang.Short).static final shortThe maximum number of years in the future expected for an expiration year, inclusive.static final charThe character used representing a masked digit.static final intThe maximum number of ending digits kept when masked.static final intThe maximum number of starting digits kept when masked.static final shortThe minimum expected expiration year.static final charThe character used for an unknown digits.static final byteValue used to represent an unknown expiration month.static final shortValue used to represent an unknown expiration year.static final byteDeprecated, for removal: This API element is subject to removal in a future version.static final shortDeprecated, for removal: This API element is subject to removal in a future version.Please useUNKNOWN_EXPIRATION_YEARinstead.static final charWhen 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. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty CreditCard.CreditCard(String persistenceUniqueId, String principalName, String groupName, String providerId, String providerUniqueId, String cardNumber, String maskedCardNumber, byte expirationMonth, short expirationYear, String cardCode, String firstName, String lastName, String companyName, String email, String phone, String fax, String customerId, String customerTaxId, String streetAddress1, String streetAddress2, String city, String state, String postalCode, String countryCode, String comments) Creates a CreditCard providing all of the details. -
Method Summary
Modifier and TypeMethodDescriptionclone()Gets the three or four digit card security code.Gets the full credit card number.static StringgetCardNumberDisplay(String cardNumber) getCity()Gets the card holder's city.Gets the comments associated with this card.Gets the company name of the card holder.Gets the card holder's two-digit ISO 3166-1 alpha-2 country code.Gets the merchant-specific unique customer ID.Gets the customer SSN or Tax ID.getEmail()Gets the card holder's email address.Deprecated, for removal: This API element is subject to removal in a future version.Please usegetExpirationDateMMYY(boolean)allowing for unknown expirationsgetExpirationDateMMYY(boolean allowUnknownDate) Gets the expiration date in MMYY format, not including anyUNKNOWN_DIGIT.static StringgetExpirationDateMMYY(byte expirationMonth, short expirationYear) Deprecated, for removal: This API element is subject to removal in a future version.Please usegetExpirationDateMMYY(byte, short, boolean)allowing for unknown expirationsstatic StringgetExpirationDateMMYY(byte expirationMonth, short expirationYear, boolean allowUnknownDate) Gets an expiration date in MMYY format.static StringgetExpirationDisplay(Byte expirationMonth, Short expirationYear) Gets the expiration display in "MM / YYYY" format ornullwhen both month and year are unknown.byteGets the expiration month, where 1 is January and 12 is December.shortGets the expiration year, such as2007.getFax()Gets the card holder's fax number.Gets the first name of the card holder.static StringgetFullName(String firstName, String lastName) Combines the first and last names into a single name String.Gets the name of the group this card belongs to.Gets the last name of the card holder.Gets the masked card number.Gets the persistence unique identifier.getPhone()Gets the card holder's telephone number.Gets the card holder's postal code.Gets the name of the principal who added the card.Gets the id of the merchant services provider that is storing this card.Gets the provider-specific unique id representing this card.getState()Gets the card holder's state/province/prefecture.Gets the card holder's street address (first line).Gets the card holder's street address (second line).static StringmaskCreditCardNumber(String cardNumber) Only keeps the firstMASK_START_DIGITSand lastMASK_END_DIGITSdigits of a card number after trimming.static StringnumbersOnly(String value) Gets the numbers out of a String, not including anyUNKNOWN_DIGIT.static StringnumbersOnly(String value, boolean allowUnknownDigit) Gets the numbers out of a String.voidsetCardCode(String cardCode) Trims and sets the three or four digit card security code.voidsetCardNumber(String cardNumber) Trims and sets the full credit card number.voidTrims and sets the card holder's city.voidsetComments(String comments) Sets the comments associated with this card.voidsetCompanyName(String companyName) Trims and sets the company name of the card holder.voidsetCountryCode(String countryCode) Trims, converts to upper case, and sets the card holder's two-digit ISO 3166-1 alpha-2 country code.voidsetCustomerId(String customerId) Sets the merchant-specific unique customer ID.voidsetCustomerTaxId(String customerTaxId) Trims and sets the customer SSN or Tax ID, removes any spaces and hyphens.voidTrims and sets the card holder's email address.voidsetExpirationMonth(byte expirationMonth) Sets the expiration month, where 1 is January and 12 is December.voidsetExpirationYear(short expirationYear) Sets the expiration year, such as2007.voidTrims and sets the card holder's fax number.voidsetFirstName(String firstName) Trims and sets the first name of the card holder.voidsetGroupName(String groupName) Sets the name of the group this card belongs to.voidsetLastName(String lastName) Trims and sets the last name of the card holder.voidsetMaskedCardNumber(String maskedCardNumber) Sets the masked card number.voidsetPersistenceUniqueId(String persistenceUniqueId) Sets the persistence unique identifier.voidTrims and sets the card holder's telephone number.voidsetPostalCode(String postalCode) Trims and sets the card holder's postal code.voidsetPrincipalName(String principalName) Sets the name of the principal who added the card.voidsetProviderId(String providerId) Sets the id of the merchant services provider that is storing this card.voidsetProviderUniqueId(String providerUniqueId) Sets the provider-specific unique id representing this card.voidTrims and sets the card holder's state/province/prefecture.voidsetStreetAddress1(String streetAddress1) Trims and sets the card holder's street address (first line).voidsetStreetAddress2(String streetAddress2) Trims and sets the card holder's street address (second line).static StringvalidateCardCode(String cardCode) Checks a card code format.static bytevalidateExpirationMonth(byte expirationMonth, boolean allowUnknownDate) Validates an expiration month.static shortvalidateExpirationYear(short expirationYear, boolean allowUnknownDate) Validates an expiration year.
-
Field Details
-
MASK_START_DIGITS
public static final int MASK_START_DIGITSThe maximum number of starting digits kept when masked.- See Also:
-
MASK_END_DIGITS
public static final int MASK_END_DIGITSThe maximum number of ending digits kept when masked.- See Also:
-
MASK_CHARACTER
public static final char MASK_CHARACTERThe character used representing a masked digit.- See Also:
-
UNKNOWN_DIGIT
public static final char UNKNOWN_DIGITThe 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:
-
UNKNOWN_MIDDLE
public static final char UNKNOWN_MIDDLEWhen 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:
-
UNKNOWN_EXPIRATION_MONTH
public static final byte UNKNOWN_EXPIRATION_MONTHValue used to represent an unknown expiration month.- See Also:
-
UNKNOWN_EXPRIATION_MONTH
Deprecated, for removal: This API element is subject to removal in a future version.Please useUNKNOWN_EXPIRATION_MONTHinstead.Value used to represent an unknown expiration month.- See Also:
-
UNKNOWN_EXPIRATION_YEAR
public static final short UNKNOWN_EXPIRATION_YEARValue used to represent an unknown expiration year.- See Also:
-
UNKNOWN_EXPRIATION_YEAR
Deprecated, for removal: This API element is subject to removal in a future version.Please useUNKNOWN_EXPIRATION_YEARinstead.Value used to represent an unknown expiration year.- See Also:
-
MIN_EXPIRATION_YEAR
public static final short MIN_EXPIRATION_YEARThe minimum expected expiration year.- See Also:
-
EXPIRATION_YEARS_FUTURE
public static final short EXPIRATION_YEARS_FUTUREThe maximum number of years in the future expected for an expiration year, inclusive.- Stripe Dashboard allows +19 years
- Stack Overflow - Maximum Year in Expiry Date of Credit Card indicates +20 years for Amazon
- See Also:
-
CARD_NUMBER_DISPLAY_PREFIX
The prefix used forgetCardNumberDisplay(java.lang.String).- See Also:
-
EXPIRATION_DISPLAY_SEPARATOR
The middle separator used forgetExpirationDisplay(java.lang.Byte, java.lang.Short).- See Also:
-
-
Constructor Details
-
CreditCard
public CreditCard()Creates an empty CreditCard. The values should be set using the appropriate setter methods. -
CreditCard
public CreditCard(String persistenceUniqueId, String principalName, String groupName, String providerId, String providerUniqueId, String cardNumber, String maskedCardNumber, byte expirationMonth, short expirationYear, String cardCode, String firstName, String lastName, String companyName, String email, String phone, String fax, String customerId, String customerTaxId, String streetAddress1, String streetAddress2, String city, String state, String postalCode, String countryCode, String comments) Creates a CreditCard providing all of the details.- Throws:
IllegalArgumentException- if anything not valid
-
-
Method Details
-
maskCreditCardNumber
Only keeps the firstMASK_START_DIGITSand lastMASK_END_DIGITSdigits of a card number after trimming. Other digits are replaced withMASK_CHARACTER. All non-digit characters are left intact. If the number isnull, returns an empty string. -
numbersOnly
Gets the numbers out of a String.- Parameters:
value- the value to extract numbers fromallowUnknownDigit- selects inclusion ofUNKNOWN_DIGITin the result
-
numbersOnly
Gets the numbers out of a String, not including anyUNKNOWN_DIGIT. -
getCardNumberDisplay
-
validateExpirationMonth
public static byte validateExpirationMonth(byte expirationMonth, boolean allowUnknownDate) throws IllegalArgumentException Validates an expiration month.- Throws:
IllegalArgumentException
-
validateExpirationYear
public static short validateExpirationYear(short expirationYear, boolean allowUnknownDate) throws IllegalArgumentException Validates an expiration year.- Throws:
IllegalArgumentException
-
getExpirationDateMMYY
public static String getExpirationDateMMYY(byte expirationMonth, short expirationYear, boolean allowUnknownDate) throws IllegalArgumentException Gets an expiration date in MMYY format.- Parameters:
expirationMonth- the month orUNKNOWN_EXPIRATION_MONTHwhen unknownexpirationYear- the year orUNKNOWN_EXPIRATION_YEARwhen unknownallowUnknownDate- selects inclusion ofUNKNOWN_DIGITin the result- Throws:
IllegalArgumentException- if invalid date
-
getExpirationDateMMYY
@Deprecated(forRemoval=true) public static String getExpirationDateMMYY(byte expirationMonth, short expirationYear) Deprecated, for removal: This API element is subject to removal in a future version.Please usegetExpirationDateMMYY(byte, short, boolean)allowing for unknown expirationsGets an expiration date in MMYY format, not including anyUNKNOWN_DIGIT. -
getExpirationDisplay
public static String getExpirationDisplay(Byte expirationMonth, Short expirationYear) throws IllegalArgumentException Gets the expiration display in "MM / YYYY" format ornullwhen both month and year are unknown.- Throws:
IllegalArgumentException- if invalid date- See Also:
-
getFullName
Combines the first and last names into a single name String. -
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
getPersistenceUniqueId
Gets the persistence unique identifier. -
setPersistenceUniqueId
Sets the persistence unique identifier. -
getPrincipalName
Gets the name of the principal who added the card. -
setPrincipalName
Sets the name of the principal who added the card. -
getGroupName
Gets the name of the group this card belongs to. -
setGroupName
Sets the name of the group this card belongs to. -
getProviderId
Gets the id of the merchant services provider that is storing this card. -
setProviderId
Sets the id of the merchant services provider that is storing this card. -
getProviderUniqueId
Gets the provider-specific unique id representing this card. -
setProviderUniqueId
Sets the provider-specific unique id representing this card. -
getCardNumber
Gets the full credit card number. This may returnnullif the full card number is not available. -
setCardNumber
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
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. -
setMaskedCardNumber
Sets the masked card number. -
getCardNumberDisplay
-
getExpirationMonth
public byte getExpirationMonth()Gets the expiration month, where 1 is January and 12 is December.- See Also:
-
setExpirationMonth
public void setExpirationMonth(byte expirationMonth) Sets the expiration month, where 1 is January and 12 is December.- Throws:
IllegalArgumentException- if out of range.- See Also:
-
getExpirationYear
public short getExpirationYear()Gets the expiration year, such as2007.- See Also:
-
setExpirationYear
public void setExpirationYear(short expirationYear) Sets the expiration year, such as2007. It also accepts values 0 <= year <= 99. These values will be automatically added to the current century.- Throws:
IllegalArgumentException- if the resolved year is <MIN_EXPIRATION_YEARor > (current year +EXPIRATION_YEARS_FUTURE)- See Also:
-
getExpirationDateMMYY
Gets the expiration date in MMYY format, not including anyUNKNOWN_DIGIT.- Parameters:
allowUnknownDate- selects inclusion ofUNKNOWN_DIGITin the result- Throws:
IllegalArgumentException- if invalid date
-
getExpirationDateMMYY
Deprecated, for removal: This API element is subject to removal in a future version.Please usegetExpirationDateMMYY(boolean)allowing for unknown expirationsGets the expiration date in MMYY format, not including anyUNKNOWN_DIGIT.- Throws:
IllegalArgumentException- if invalid date
-
getExpirationDisplay
-
getCardCode
Gets the three or four digit card security code. This value is never stored and is therefore only available for a new card. -
validateCardCode
Checks a card code format.- Parameters:
cardCode- The card code to check- Returns:
- The card code to use
- Throws:
LocalizedIllegalArgumentException- if card code invalid
-
setCardCode
Trims and sets the three or four digit card security code.- Throws:
IllegalArgumentException- if the value is not eithernullor purely digits (after trimming) and 3 or 4 digits long.LocalizedIllegalArgumentException
-
getFirstName
Gets the first name of the card holder. -
setFirstName
Trims and sets the first name of the card holder. -
getLastName
Gets the last name of the card holder. -
setLastName
Trims and sets the last name of the card holder. -
getCompanyName
Gets the company name of the card holder. -
setCompanyName
Trims and sets the company name of the card holder. -
getEmail
Gets the card holder's email address. -
setEmail
Trims and sets the card holder's email address.- Throws:
IllegalArgumentException- if the address does is not in the proper format
-
getPhone
Gets the card holder's telephone number. -
setPhone
Trims and sets the card holder's telephone number. -
getFax
Gets the card holder's fax number. -
setFax
Trims and sets the card holder's fax number. -
getCustomerId
Gets the merchant-specific unique customer ID. -
setCustomerId
Sets the merchant-specific unique customer ID. -
getCustomerTaxId
Gets the customer SSN or Tax ID. -
setCustomerTaxId
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
Gets the card holder's street address (first line). -
setStreetAddress1
Trims and sets the card holder's street address (first line). -
getStreetAddress2
Gets the card holder's street address (second line). -
setStreetAddress2
Trims and sets the card holder's street address (second line). -
getCity
Gets the card holder's city. -
setCity
Trims and sets the card holder's city. -
getState
Gets the card holder's state/province/prefecture. -
setState
Trims and sets the card holder's state/province/prefecture. -
getPostalCode
Gets the card holder's postal code. -
setPostalCode
Trims and sets the card holder's postal code. -
getCountryCode
Gets the card holder's two-digit ISO 3166-1 alpha-2 country code. -
setCountryCode
Trims, converts to upper case, and sets the card holder's two-digit ISO 3166-1 alpha-2 country code.- Throws:
IllegalArgumentException- if not a two-character code (after trimming).
-
getComments
Gets the comments associated with this card. -
setComments
Sets the comments associated with this card.
-

UNKNOWN_EXPIRATION_MONTHinstead.