This project uses Quarkus, the Supersonic Subatomic Java Framework, and implements a multi-provider payment system with PostgreSQL integration, Flyway for schema management, and multi-threaded processing.
If you want to learn more about Quarkus, visit the official website: Quarkus.
Follow the instructions below to set up and run the project.
You need to create a PostgreSQL database to store the payment system's data. Follow these steps:
-
Install PostgreSQL (if not already installed):
- On Linux:
sudo apt-get install postgresql postgresql-contrib - On macOS (via Homebrew):
brew install postgresql - On Windows: Use the installer from the PostgreSQL website.
- On Linux:
-
Create the Database:
- Connect to PostgreSQL using the command line or pgAdmin.
- Run the following SQL command to create the database:
CREATE DATABASE payment_system;
-
Apply Migrations with Flyway: Flyway will automatically apply the necessary migrations when the application starts.
To set up the environment variables for the project, follow these steps:
-
Create a
.envfile in the project root directory by copying the example environment configuration file:cp .env.example .env
-
Edit the
.envfile and update the values with your actual configuration:- Set the
DB_URL,DB_USERNAME, andDB_PASSWORDto match your PostgreSQL database configuration. - If applicable, add any other necessary environment variables, such as API keys for payment providers.
Example of
.envfile:# Database Configuration DB_URL=jdbc:postgresql://localhost:5432/payment_system DB_USERNAME=your_db_username DB_PASSWORD=your_db_password # Optional: Add payment provider API keys if needed # PROVIDER_1_API_KEY=your_provider_1_api_key # PROVIDER_2_API_KEY=your_provider_2_api_key
- Set the
Once you have set up the .env file, you can proceed with running the application.
In development mode, Quarkus provides live coding, allowing you to see changes instantly without restarting the application.
-
Open a terminal in the project root directory.
-
Run the following command to start the application in dev mode:
./mvnw quarkus:dev
-
The application will start, and you can access it at http://localhost:8080.
-
You can also access the Quarkus Dev UI at http://localhost:8080/q/dev/, where you can inspect logs, manage application settings, and more.
To run the application in production mode, you need to package it first and then execute the packaged application.
-
Package the application:
./mvnw package
This will generate a
quarkus-run.jarfile in thetarget/quarkus-app/directory. -
Run the application:
java -jar target/quarkus-app/quarkus-run.jar
Your application will now be running in production mode. You can access it at http://localhost:8080.
If you want to build a single executable JAR file that includes all dependencies (an "uber-jar"), you can use this command:
-
Build the uber-jar:
./mvnw package -Dquarkus.package.jar.type=uber-jar
-
Run the uber-jar:
java -jar target/*-runner.jar
If you prefer to build a native executable for faster startup times and reduced memory usage, you can build it using GraalVM or via a container if GraalVM is not installed.
-
Build the native executable:
./mvnw package -Dnative
Or, if you don't have GraalVM installed:
./mvnw package -Dnative -Dquarkus.native.container-build=true
-
Run the native executable:
./target/payment-system-1.0.0-SNAPSHOT-runner
Once the application is running, you can verify that it works correctly by accessing the API endpoints using Postman or by visiting the exposed REST endpoints in a web browser, depending on your project setup.
You can containerize and run the application using Docker. Follow the steps below to build and run the application inside a Docker container.
Ensure you have Docker installed on your machine. You can download and install Docker from Docker's official website.
-
Open a terminal in the project root directory.
-
Build the Docker image using the following command:
docker build -t payment-system .This command will create a Docker image named
payment-systemfrom theDockerfilein the project directory.
After building the Docker image, you can run the application in a Docker container.
-
Run the container using the following command:
docker run -d -p 8080:8080 --env-file .env payment-system
This command does the following:
- Runs the
payment-systemimage in detached mode (-d). - Maps port
8080from the container to port8080on your local machine (-p 8080:8080). - Loads environment variables from the
.envfile using--env-file .env.
- Runs the
-
The application will be accessible at http://localhost:8080.
To stop the running Docker container, first, find the container ID by running:
docker ps-
Download or locate the Postman collection file: The Postman collection file (
payment-system.postman_collection.json) should be included in the project repository. Ensure the file is available in the project directory or download it if needed. -
Open Postman: Launch the Postman application on your machine.
-
Import the collection:
- Click on the Import button in the top left corner of the Postman interface.
- Select the File tab and browse to the
payment-system.postman_collection.jsonfile. - Click Open to import the collection into Postman.
-
Use the imported collection: Once the collection is imported, you can view and test all available API endpoints for the Payment System. Ensure your application is running before sending requests from Postman.
This will enable you to interact with the Payment System API directly and test the endpoints.