Interface CreditCardRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<CreditCard, Long>,org.springframework.data.jpa.repository.JpaRepository<CreditCard, Long>,org.springframework.data.repository.ListCrudRepository<CreditCard, Long>,org.springframework.data.repository.ListPagingAndSortingRepository<CreditCard, Long>,org.springframework.data.repository.PagingAndSortingRepository<CreditCard, Long>,org.springframework.data.repository.query.QueryByExampleExecutor<CreditCard>,org.springframework.data.repository.Repository<CreditCard, Long>
CreditCard entities.
Provides standard CRUD operations inherited from JpaRepository
and specialized query/deletion methods for payment method management.
Credit cards are sensitive data. Although the full card number is stored in this example (for simplicity), in production systems it is strongly recommended to:
- Store only the last 4 digits + masked version
- Use tokenization (e.g., Stripe, Adyen, bank vault)
- Encrypt at rest and never log full card numbers
This repository is automatically implemented by Spring at runtime — no manual implementation needed.
- Since:
- 1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteByCardNumber(String number) Deletes a credit card by its full card number.findByNumber(String number) Finds a credit card by its full card number.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByNumber
Finds a credit card by its full card number.Used primarily during:
- Checkout when customer selects a previously saved card
- Duplicate card detection before saving a new payment method
- Admin or support tools looking up a card by number (with proper authorization)
Security note: Full card numbers are PCI-sensitive data. Access to this method should be strictly limited and audited.
- Parameters:
number- the full credit card number (digits only, no spaces/dashes)- Returns:
- an
Optionalcontaining the matchingCreditCardif found, orOptional.empty()if no card with this number exists
-
deleteByCardNumber
Deletes a credit card by its full card number.Provides a convenient way to remove a saved payment method without first loading the entity. Useful in scenarios such as:
- User explicitly removing a saved card from their account
- Admin/support permanently deleting a compromised card
- Scheduled cleanup of expired or flagged cards
Security invalid input: '&' auditing: This is a destructive operation on sensitive data. Should be protected by proper authorization and logged for compliance.
- Parameters:
number- the full card number of the card to delete
-