Class CreditCard

java.lang.Object
com.goldenleaf.shop.model.CreditCard

@Entity public class CreditCard extends Object
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 Details

    • CreditCard

      public CreditCard()
      Default constructor required by JPA.
  • Method Details

    • getId

      public Long getId()
      Returns the unique database identifier of this card.
      Returns:
      the card ID, or null if not yet persisted
    • getCustomer

      public Customer getCustomer()
      Returns the customer who owns this credit card.
      Returns:
      the associated Customer, never null after proper assignment
    • getHolderName

      public String getHolderName()
      Returns the cardholder's name.
      Returns:
      the name as printed on the card
    • getCardNumber

      public String 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

      public YearMonth getExpiry()
      Returns the card's expiration date.
      Returns:
      expiration YearMonth, never null
    • getCvv

      public String getCvv()
      Returns the CVV code (only available in memory during active payment flow).
      Returns:
      the CVV, or null if not set or already cleared
    • setCustomer

      public void setCustomer(Customer customer) throws NullCustomerException
      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 is null
    • setHolderName

      public void setHolderName(String holderName) throws EmptyNameException
      Sets the cardholder name.
      Parameters:
      holderName - name as it appears on the card
      Throws:
      EmptyNameException - if the name is null or blank
    • setCardNumber

      public void setCardNumber(String cardNumber) throws EmptyCardNumberException
      Sets the credit card number.
      Parameters:
      cardNumber - the full card number (spaces or dashes optional)
      Throws:
      EmptyCardNumberException - if the number is null or blank
    • setExpiry

      public void setExpiry(YearMonth expiry) throws EmptyExpiryException
      Sets the card expiration date.
      Parameters:
      expiry - expiration date as YearMonth
      Throws:
      EmptyExpiryException - if expiry is null
    • setCvv

      public void setCvv(String cvv) throws EmptyCvvException
      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 is null or 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

      public String getMaskedCardNumber()
      Returns a masked version of the card number for display purposes.

      Example: "•••• •••• •••• 1234"

      Returns:
      masked card number
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object