Skip to content

anjanx44/payment-system

Repository files navigation

Payment System

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.

Project Setup

Follow the instructions below to set up and run the project.

1. Database Setup

You need to create a PostgreSQL database to store the payment system's data. Follow these steps:

  1. 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.
  2. 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;
  3. Apply Migrations with Flyway: Flyway will automatically apply the necessary migrations when the application starts.

Environment Setup

To set up the environment variables for the project, follow these steps:

  1. Create a .env file in the project root directory by copying the example environment configuration file:

    cp .env.example .env
  2. Edit the .env file and update the values with your actual configuration:

    • Set the DB_URL, DB_USERNAME, and DB_PASSWORD to match your PostgreSQL database configuration.
    • If applicable, add any other necessary environment variables, such as API keys for payment providers.

    Example of .env file:

    # 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

Once you have set up the .env file, you can proceed with running the application.

Running the Application

1. Running the Application in Development Mode

In development mode, Quarkus provides live coding, allowing you to see changes instantly without restarting the application.

  1. Open a terminal in the project root directory.

  2. Run the following command to start the application in dev mode:

    ./mvnw quarkus:dev
  3. The application will start, and you can access it at http://localhost:8080.

  4. You can also access the Quarkus Dev UI at http://localhost:8080/q/dev/, where you can inspect logs, manage application settings, and more.

2. Running the Application in Production Mode

To run the application in production mode, you need to package it first and then execute the packaged application.

  1. Package the application:

    ./mvnw package

    This will generate a quarkus-run.jar file in the target/quarkus-app/ directory.

  2. 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.

3. Running the Application as an Uber-JAR (Optional)

If you want to build a single executable JAR file that includes all dependencies (an "uber-jar"), you can use this command:

  1. Build the uber-jar:

    ./mvnw package -Dquarkus.package.jar.type=uber-jar
  2. Run the uber-jar:

    java -jar target/*-runner.jar

4. Running the Application as a Native Executable (Optional)

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.

  1. Build the native executable:

    ./mvnw package -Dnative

    Or, if you don't have GraalVM installed:

    ./mvnw package -Dnative -Dquarkus.native.container-build=true
  2. Run the native executable:

    ./target/payment-system-1.0.0-SNAPSHOT-runner

Verify the Application

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.

Running the Application with Docker

You can containerize and run the application using Docker. Follow the steps below to build and run the application inside a Docker container.

1. Prerequisites

Ensure you have Docker installed on your machine. You can download and install Docker from Docker's official website.

2. Building the Docker Image

  1. Open a terminal in the project root directory.

  2. Build the Docker image using the following command:

    docker build -t payment-system .

    This command will create a Docker image named payment-system from the Dockerfile in the project directory.

3. Running the Docker Container

After building the Docker image, you can run the application in a Docker container.

  1. 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-system image in detached mode (-d).
    • Maps port 8080 from the container to port 8080 on your local machine (-p 8080:8080).
    • Loads environment variables from the .env file using --env-file .env.
  2. The application will be accessible at http://localhost:8080.

4. Stopping the Docker Container

To stop the running Docker container, first, find the container ID by running:

docker ps

Importing the Postman Collection

  1. 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.

  2. Open Postman: Launch the Postman application on your machine.

  3. 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.json file.
    • Click Open to import the collection into Postman.
  4. 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.

About

Generated by code.quarkus.io

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors