Class PaymentUserController

java.lang.Object
com.esprit.controllers.films.PaymentUserController
All Implemented Interfaces:
javafx.fxml.Initializable

public class PaymentUserController extends Object implements javafx.fxml.Initializable
Is responsible for handling payments for a Visa card. It has several methods for validating user input, creating a receipt PDF, and opening the PDF file. The class also initializes an Alert to display error messages if necessary.
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • client

      Client client
    • moviesession

      private MovieSession moviesession
    • selectedSeats

      private List<Seat> selectedSeats
    • total

      private javafx.scene.control.Label total
    • filmLabel_Payment

      private javafx.scene.control.Label filmLabel_Payment
    • Pay

      private javafx.scene.control.Button Pay
    • anchorpane_payment

      private javafx.scene.layout.AnchorPane anchorpane_payment
    • anneeExp

      private javafx.scene.control.TextField anneeExp
    • bord

      private javafx.scene.layout.AnchorPane bord
    • carte

      private javafx.scene.control.TextField carte
    • checkcomboboxmoviesession_res

      private org.controlsfx.control.CheckComboBox<String> checkcomboboxmoviesession_res
    • cinemacombox_res

      private javafx.scene.control.ComboBox<String> cinemacombox_res
    • cvc

      private javafx.scene.control.TextField cvc
    • filmm

      private javafx.scene.control.Button filmm
    • moisExp

      private javafx.scene.control.TextField moisExp
    • nbrplacepPayment_Spinner

      private javafx.scene.control.Spinner<Integer> nbrplacepPayment_Spinner
    • nomPrenom

      private javafx.scene.control.Label nomPrenom
    • viewPDF

      private javafx.scene.control.Button viewPDF
    • validationCache

    • CARD_NUMBER_PATTERN

      private static final Pattern CARD_NUMBER_PATTERN
    • CVC_PATTERN

      private static final Pattern CVC_PATTERN
  • Constructor Details

    • PaymentUserController

      public PaymentUserController()
  • Method Details

    • validatePaymentWithCache

      private boolean validatePaymentWithCache(String cardNumber)
    • validateCardNumber

      private boolean validateCardNumber(String cardNumber)
    • isNum

      public static boolean isNum(String str)
      Checks if a given string is a numerical value by matching it against a regular expression pattern of one or more digits.
      Parameters:
      str - String to be checked for matching the regular expression `\d+`.
    • doubleToInt

      public static int doubleToInt(double value)
      Converts a `float` argument into an `int` value by calling the `int` casting operator `(int)`.
      Parameters:
      value - floating-point number to be converted to an integer.
    • setData

      public void setData(Client client, String filmName)
      Sets the `client` field and displays the film name on a label. It also prints the value of `client` to the console.
      Parameters:
      client - Client object that provides the payment details for the film name set by the `filmName` parameter.
      filmName - name of a film that is being associated with the `Client` object passed as an argument to the `setData()` method.
    • initialize

      public void initialize(URL url, ResourceBundle rb)
      Reads the film and cinema data, creates a combobox for selecting cinemas and initializes the payment panel with disabled options. When the user selects a cinema, it calls the `readLoujain` method to retrieve the moviesession list for that cinema, which is then displayed in a spinner.
      Specified by:
      initialize in interface javafx.fxml.Initializable
      Parameters:
      url - URL of a resource bundle that provides localization keys for the function's output, such as film and cinema names.

      - `url`: The URL provided by the user, which contains information about the film and cinema. - `rb`: A `ResourceBundle` object containing key-value pairs of localized messages and resource keys.

      rb - ResourceBundle object, which provides localized messages and values for the Java application.

      - `rb`: A `ResourceBundle` object containing key-value pairs for resource string messages.

      The main properties of `rb` are:

      - Key-value pairs: Contains key-value pairs in the form of `(key, value)`, where `key` is a unique identifier for a message, and `value` is the corresponding message text. - Messages: `rb` provides a collection of messages that can be used to localize user interface elements, such as labels, buttons, and menus. - Culture-specific messages: `rb` allows developers to create culture-specific messages by providing separate key-value pairs for each culture.

    • Pay

      private void Pay(javafx.event.ActionEvent event) throws com.stripe.exception.StripeException
      Processes a payment for a ticket purchase by first checking if the input is valid, then calculating and charging the correct amount based on the ticket's price and quantity, and finally saving the order to the database.
      Parameters:
      event - Pay action event, which triggers the execution of the function and enables the processing of the payment request.

      - `event` is an ActionEvent that represents a user's action on the Pay button.

      Throws:
      com.stripe.exception.StripeException
    • isValidInput

      private boolean isValidInput()
      Validates input fields for a Visa card number, month and year of expiration, and CVC code. It returns `true` if all inputs are valid, otherwise it displays an error message and returns `false`.
    • isValidVisaCardNo

      private boolean isValidVisaCardNo(String text)
      Takes a string as input and checks if it matches the valid Visa card number format, which is a 13-digit number consisting of four digits followed by a hyphen and then another four digits.
      Parameters:
      text - 13-digit credit card number to be validated.
    • showError

      private void showError(String title, String message)
      Creates an Alert object with an error title and message, displays it using the `showAndWait()` method.
      Parameters:
      title - title of an error message that is displayed in the alert box when the `showError()` method is called.
      message - message to be displayed as the content of an error alert when the function is called.
    • init

      public void init(MovieSession p, Client client)
      Sets the values of class variables `client` and `moviesession`, and updates the text of a label `total`.
      Parameters:
      p - MovieSession object, which is assigned to the class instance variable `moviesession`.
      client - Client object that is associated with the MovieSession object being initialized.
    • initWithSeats

      public void initWithSeats(MovieSession moviesession, Client client, List<Seat> selectedSeats)
      Performs initWithSeats operation.
    • switchtfillmmaa

      public void switchtfillmmaa(javafx.event.ActionEvent event)
      Loads and displays a FXML file named "/ui/films/filmuser.fxml" using Java's `FXMLLoader` class, creating a new stage and scene to display the content.
      Parameters:
      event - ActionEvent object that triggered the method execution, providing the necessary information about the action that was performed.

      Event: An ActionEvent object representing a user event.

    • createReceiptPDF

      public void createReceiptPDF(String filename, Ticket ticket) throws IOException
      Creates a PDF receipt for a ticket purchase by adding text and graphics to a blank page using a PDPageContentStream, then saving the document with a specified filename.
      Parameters:
      filename - name of the output PDF file that the `createReceiptPDF` method will save.
      ticket - ticket for which a receipt is to be generated, and its contents are used to populate the receipt document.

      - Ticket is an instance of the `Ticket` class. - It contains information about the ticket purchase, such as the date and time of purchase, the amount paid, and any other relevant details.

      Throws:
      IOException
    • openPDF

      public void openPDF(String filename) throws IOException
      Opens a PDF file using the desktop application.
      Parameters:
      filename - name of the PDF file to be opened.
      Throws:
      IOException