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
Modifier and TypeFieldDescriptionstatic final String
The prefix used forgetCardNumberDisplay(java.lang.String)
.static final String
The middle separator used forgetExpirationDisplay(java.lang.Byte, java.lang.Short)
.static final short
The maximum number of years in the future expected for an expiration year, inclusive.static final char
The character used representing a masked digit.static final int
The maximum number of ending digits kept when masked.static final int
The maximum number of starting digits kept when masked.static final short
The minimum expected expiration year.static final char
The character used for an unknown digits.static final byte
Value used to represent an unknown expiration month.static final short
Value used to represent an unknown expiration year.static final byte
Deprecated, for removal: This API element is subject to removal in a future version.static final short
Deprecated, for removal: This API element is subject to removal in a future version.Please useUNKNOWN_EXPIRATION_YEAR
instead.static final char
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. -
Constructor Summary
ConstructorDescriptionCreates 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 String
getCardNumberDisplay
(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 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 expirationsstatic String
getExpirationDateMMYY
(byte expirationMonth, short expirationYear, boolean allowUnknownDate) Gets an expiration date in MMYY format.static String
getExpirationDisplay
(Byte expirationMonth, Short expirationYear) Gets the expiration display in "MM / YYYY" format ornull
when both month and year are unknown.byte
Gets the expiration month, where 1 is January and 12 is December.short
Gets the expiration year, such as2007
.getFax()
Gets the card holder's fax number.Gets the first name of the card holder.static String
getFullName
(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 String
maskCreditCardNumber
(String cardNumber) Only keeps the firstMASK_START_DIGITS
and lastMASK_END_DIGITS
digits of a card number after trimming.static String
numbersOnly
(String value) Gets the numbers out of a String, not including anyUNKNOWN_DIGIT
.static String
numbersOnly
(String value, boolean allowUnknownDigit) Gets the numbers out of a String.void
setCardCode
(String cardCode) Trims and sets the three or four digit card security code.void
setCardNumber
(String cardNumber) Trims and sets the full credit card number.void
Trims and sets the card holder's city.void
setComments
(String comments) Sets the comments associated with this card.void
setCompanyName
(String companyName) Trims and sets the company name of the card holder.void
setCountryCode
(String countryCode) Trims, converts to upper case, and sets the card holder's two-digit ISO 3166-1 alpha-2 country code.void
setCustomerId
(String customerId) Sets the merchant-specific unique customer ID.void
setCustomerTaxId
(String customerTaxId) Trims and sets the customer SSN or Tax ID, removes any spaces and hyphens.void
Trims and sets the card holder's email address.void
setExpirationMonth
(byte expirationMonth) Sets the expiration month, where 1 is January and 12 is December.void
setExpirationYear
(short expirationYear) Sets the expiration year, such as2007
.void
Trims and sets the card holder's fax number.void
setFirstName
(String firstName) Trims and sets the first name of the card holder.void
setGroupName
(String groupName) Sets the name of the group this card belongs to.void
setLastName
(String lastName) Trims and sets the last name of the card holder.void
setMaskedCardNumber
(String maskedCardNumber) Sets the masked card number.void
setPersistenceUniqueId
(String persistenceUniqueId) Sets the persistence unique identifier.void
Trims and sets the card holder's telephone number.void
setPostalCode
(String postalCode) Trims and sets the card holder's postal code.void
setPrincipalName
(String principalName) Sets the name of the principal who added the card.void
setProviderId
(String providerId) Sets the id of the merchant services provider that is storing this card.void
setProviderUniqueId
(String providerUniqueId) Sets the provider-specific unique id representing this card.void
Trims and sets the card holder's state/province/prefecture.void
setStreetAddress1
(String streetAddress1) Trims and sets the card holder's street address (first line).void
setStreetAddress2
(String streetAddress2) Trims and sets the card holder's street address (second line).static String
validateCardCode
(String cardCode) Checks a card code format.static byte
validateExpirationMonth
(byte expirationMonth, boolean allowUnknownDate) Validates an expiration month.static short
validateExpirationYear
(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_MONTH
instead.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_YEAR
instead.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_DIGITS
and lastMASK_END_DIGITS
digits 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_DIGIT
in 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_MONTH
when unknownexpirationYear
- the year orUNKNOWN_EXPIRATION_YEAR
when unknownallowUnknownDate
- selects inclusion ofUNKNOWN_DIGIT
in 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 ornull
when 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:
clone
in 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 returnnull
if 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_YEAR
or > (current year +EXPIRATION_YEARS_FUTURE
)- See Also:
-
getExpirationDateMMYY
Gets the expiration date in MMYY format, not including anyUNKNOWN_DIGIT
.- Parameters:
allowUnknownDate
- selects inclusion ofUNKNOWN_DIGIT
in 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 eithernull
or 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_MONTH
instead.