Class CardServiceImpl

All Implemented Interfaces:
CardService

@Service public class CardServiceImpl extends FinancialDataGenerator implements CardService
Implementation of the CardService interface for managing user bank cards. This service provides methods for adding, retrieving, and removing cards associated with bank accounts. It includes functionality for card encryption and data masking to ensure sensitive information is handled securely.
  • Field Details

    • MAX_AVAILABLE_CARDS

      public static final int MAX_AVAILABLE_CARDS
      Maximum number of cards that can be created per user.
      See Also:
    • MIN_AVAILABLE_CARDS

      public static final int MIN_AVAILABLE_CARDS
      Minimum number of cards that can be created per user.
      See Also:
  • Constructor Details

    • CardServiceImpl

      @Autowired public CardServiceImpl(CardRepository cardRepository, BankIdentityRepository bankIdentityRepository, BankAccountRepository bankAccountRepository, TokenVerifierService tokenVerifierService)
      Constructs a CardServiceImpl with the specified repositories and services.
      Parameters:
      cardRepository - the repository for card data
      bankIdentityRepository - the repository for bank identity data
      bankAccountRepository - the repository for bank account data
      tokenVerifierService - the service for extracting user token and getting user data from the request
  • Method Details

    • getAccountCards

      public List<Card> getAccountCards(String bankName, UUID accountId, jakarta.servlet.http.HttpServletRequest request)
      Retrieves all cards associated with a specific bank account.
      Specified by:
      getAccountCards in interface CardService
      Parameters:
      bankName - the name of the bank
      accountId - the ID of the bank account
      request - the HTTP request containing user data
      Returns:
      a list of cards associated with the specified account
      Throws:
      ApplicationException - if no cards are found for the specified account
    • getAccountCardById

      public Card getAccountCardById(String bankName, UUID accountId, UUID cardId, jakarta.servlet.http.HttpServletRequest request, String type)
      Retrieves a specific card associated with a bank account by card ID.
      Specified by:
      getAccountCardById in interface CardService
      Parameters:
      bankName - the name of the bank
      accountId - the ID of the bank account
      cardId - the ID of the card to retrieve
      request - the HTTP request containing user data
      type - the visibility type (e.g., "visible" or "hidden")
      Returns:
      the specified card if found
      Throws:
      ApplicationException - if the specified card is not found
    • decryptCardData

      public boolean decryptCardData(Card card, boolean unmask)
      Decrypts the sensitive data of a card, optionally unmasking it.
      Parameters:
      card - the card to decrypt
      unmask - whether to unmask the data
      Returns:
      true if decryption was successful; false otherwise
    • addAccountCard

      @Transactional public Card addAccountCard(String bankName, UUID accountId, jakarta.servlet.http.HttpServletRequest request) throws Exception
      Adds a new card associated with the specified bank account.
      Specified by:
      addAccountCard in interface CardService
      Parameters:
      bankName - the name of the bank
      accountId - the ID of the bank account
      request - the HTTP request containing user data
      Returns:
      the created Card
      Throws:
      Exception - if there is an error while adding the card
    • connectCards

      @Transactional public void connectCards(BankAccount account) throws Exception
      Connects a number of cards to a specified bank account.
      Specified by:
      connectCards in interface CardService
      Parameters:
      account - the bank account to connect cards to
      Throws:
      Exception - if there is an error while connecting cards
    • generateCard

      @Transactional protected Card generateCard(String cardNumber, String cvv, String pin, BankAccount account) throws Exception
      Generates and encrypts a new card with the provided details.
      Parameters:
      cardNumber - the card number
      cvv - the CVV of the card
      pin - the PIN for the card
      account - the bank account associated with the card
      Returns:
      the generated Card
      Throws:
      Exception - if there is an error while generating the card
    • removeAccountCard

      public void removeAccountCard(String bankName, UUID accountId, UUID cardId, jakarta.servlet.http.HttpServletRequest request)
      Removes a specific card associated with a bank account.
      Specified by:
      removeAccountCard in interface CardService
      Parameters:
      bankName - the name of the bank
      accountId - the ID of the bank account
      cardId - the ID of the card to remove
      request - the HTTP request containing user data
      Throws:
      ApplicationException - if the specified card is not found
    • removeAllCards

      @Transactional public void removeAllCards(BankAccount account)
      Removes all cards associated with a specified bank account.
      Specified by:
      removeAllCards in interface CardService
      Parameters:
      account - the bank account whose cards should be removed
      Throws:
      ApplicationException - if no cards are found for the specified account