This guide explains how to start the payment gateway locally after reopening the project.
Install and confirm:
- Java 21, or the Java version configured in the project
- Maven, or the included Maven Wrapper
- PostgreSQL
- Postman, Insomnia, or Thunder Client
- Docker Desktop only if the project depends on Docker services such as the mock bank API
Check Java:
java -versionCheck Maven:
mvn -versionIf the project includes Maven Wrapper, prefer:
./mvnw.cmd -version./mvnw -versionOpen the project root folder in IntelliJ IDEA or VS Code.
The root should contain:
pom.xml
src/
mvnw
mvnw.cmd
Make sure PostgreSQL is running.
Expected database:
payment_gateway
Typical local details:
Host: localhost
Port: 5432
Database: payment_gateway
Create it once if it does not exist:
CREATE DATABASE payment_gateway;Open:
src/main/resources/application.properties
Confirm the datasource values match your PostgreSQL setup:
spring.datasource.url=jdbc:postgresql://localhost:5432/payment_gateway
spring.datasource.username=YOUR_POSTGRES_USERNAME
spring.datasource.password=YOUR_POSTGRES_PASSWORD
spring.flyway.enabled=trueAvoid committing real passwords to GitHub.
If the project uses environment variables, make sure they are available before starting the application.
Possible names:
DB_URL
DB_USERNAME
DB_PASSWORD
If the project has docker-compose.yml or compose.yml, run this from the project root:
docker compose up -dCheck containers:
docker psView logs:
docker compose logsStop them later with:
docker compose downSkip this section if PostgreSQL and the mock bank are not running through Docker.
./mvnw.cmd clean install./mvnw clean installWithout Maven Wrapper:
mvn clean installThis downloads dependencies, compiles the project, runs tests, and checks the build.
For a quicker compile check:
mvn clean compileFlyway normally runs automatically when Spring Boot starts.
Migration files belong in:
src/main/resources/db/migration
Example:
V1__create_payments_table.sql
If migration startup fails:
- Read the first Flyway error in the console
- Check the migration filename
- Check for conflicting tables or columns
- Do not edit an already-applied migration in a shared database
- Create a new migration for later schema changes
./mvnw.cmd spring-boot:run./mvnw spring-boot:runWithout Maven Wrapper:
mvn spring-boot:runYou can also run the main application class from IntelliJ IDEA.
Typical local address:
http://localhost:8080
Endpoint:
POST http://localhost:8080/api/v1/payments/authorize
Header:
Content-Type: application/json
Example body:
{
"orderId": "ORDER-1001",
"customerId": "CUSTOMER-1001",
"amountInCents": 250000,
"currency": "NGN"
}Expected result:
- A generated payment reference
- Status
PENDING - A success message
Copy the returned payment reference.
Endpoint:
POST http://localhost:8080/api/v1/payments/capture
Header:
Content-Type: application/json
Example body:
{
"paymentReference": "PASTE_THE_REFERENCE_HERE"
}Expected result:
- The same payment reference
- Status
CAPTURED - A success message
Expected:
409 Conflict
Meaning:
Payment has already been processed
Expected:
404 Not Found
Meaning:
Payment reference not found
Examples:
- Blank
orderId - Blank
customerId - Zero or negative
amountInCents - Blank
currency
Expected:
400 Bad Request
This requires @Valid together with @RequestBody in the controller.
Run:
SELECT *
FROM payments
ORDER BY created_at DESC;After authorization:
PENDING
After capture:
CAPTURED
After the initial setup:
- Start PostgreSQL.
- Start required Docker services.
- Open the project.
- Confirm environment variables.
- Run Spring Boot.
- Test authorize.
- Use the returned reference to test capture.
You do not need clean install every time. Use it after dependency changes, migration changes, build issues, or before an important push.
Stop the process using it, or use another port:
server.port=8081Check:
- PostgreSQL is running
- Port
5432is correct - Database name is correct
- Username and password are correct
- The Docker container is running, if PostgreSQL is containerized
Possible causes:
- An applied migration was edited
- Migration checksums changed
- A migration partially failed
- Database schema and Flyway history differ
Read the Flyway error before repairing or deleting migration history.
Check the console stack trace for:
- Database failures
- Null values
- Missing configuration
- Unhandled exceptions
Confirm the controller uses:
@Valid
@RequestBody
Also confirm the validation dependency exists in pom.xml.
Stop Spring Boot with:
Ctrl + C
Stop Docker services if used:
docker compose downAuthorize payment
↓
Payment created with PENDING status
↓
Payment reference returned
↓
Capture request uses payment reference
↓
PENDING payment becomes CAPTURED
Current endpoints:
POST /api/v1/payments/authorize
POST /api/v1/payments/capture
Current custom errors:
PaymentRefNotFoundException → 404 Not Found
PaymentAlreadyProcessedException → 409 Conflict