Class CreditCard
java.lang.Object
com.goldenleaf.shop.model.CreditCard
Entity representing a customer's credit/debit card used for payments.
Stores card details required for processing payments. The CVV is marked as transient
and is never persisted to the database for security reasons (PCI DSS compliance).
This entity has a mandatory many-to-one relationship with Customer.
Each card belongs to exactly one customer.
- Since:
- 1.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclearCvv()Clears the CVV from memory after use (recommended for security).booleanReturns the credit card number.Returns the customer who owns this credit card.getCvv()Returns the CVV code (only available in memory during active payment flow).Returns the card's expiration date.Returns the cardholder's name.getId()Returns the unique database identifier of this card.Returns a masked version of the card number for display purposes.inthashCode()voidsetCardNumber(String cardNumber) Sets the credit card number.voidsetCustomer(Customer customer) Assigns this card to a customer.voidTemporarily sets the CVV code during payment processing.voidSets the card expiration date.voidsetHolderName(String holderName) Sets the cardholder name.toString()
-
Constructor Details
-
CreditCard
public CreditCard()Default constructor required by JPA.
-
-
Method Details
-
getId
Returns the unique database identifier of this card.- Returns:
- the card ID, or
nullif not yet persisted
-
getCustomer
-
getHolderName
Returns the cardholder's name.- Returns:
- the name as printed on the card
-
getCardNumber
Returns the credit card number.Warning: In real production systems, consider masking (e.g., "•••• •••• •••• 7275") when displaying or logging.
- Returns:
- full card number
-
getExpiry
-
getCvv
Returns the CVV code (only available in memory during active payment flow).- Returns:
- the CVV, or
nullif not set or already cleared
-
setCustomer
Assigns this card to a customer.Establishes the ownership relationship. Customer must not be
null.- Parameters:
customer- the owner of this card- Throws:
NullCustomerException- if customer isnull
-
setHolderName
Sets the cardholder name.- Parameters:
holderName- name as it appears on the card- Throws:
EmptyNameException- if the name isnullor blank
-
setCardNumber
Sets the credit card number.- Parameters:
cardNumber- the full card number (spaces or dashes optional)- Throws:
EmptyCardNumberException- if the number isnullor blank
-
setExpiry
Sets the card expiration date.- Parameters:
expiry- expiration date asYearMonth- Throws:
EmptyExpiryException- if expiry isnull
-
setCvv
Temporarily sets the CVV code during payment processing.This value is held only in memory and never persisted.
- Parameters:
cvv- the 3- or 4-digit security code- Throws:
EmptyCvvException- if CVV isnullor blank
-
clearCvv
public void clearCvv()Clears the CVV from memory after use (recommended for security).Should be called immediately after the payment attempt succeeds or fails.
-
getMaskedCardNumber
Returns a masked version of the card number for display purposes.Example: "•••• •••• •••• 1234"
- Returns:
- masked card number
-
toString
-
equals
-
hashCode
-