A robust Virtual Account (VA) payment gateway integration service built with Hexagonal Architecture, enabling seamless bank transfer flows through Midtrans API.
- Features
- Architecture Overview
- Project Structure
- Tech Stack
- Getting Started
- Email Notifications
- Testing
- API Documentation
- Configuration
- License
- π¦ Multi-Bank Virtual Account Support (BCA, BNI, Mandiri, Permata, etc.)
- π§ Automated Email Notifications (payment reminders & confirmations)
- π Real-time Payment Callbacks from Midtrans
- π Secure Payment Processing with transaction validation
- π Payment History Tracking with comprehensive logging
- π§© Clean Architecture with clear separation of concerns
- π§ͺ Sandbox Testing Support for safe development
This application implements Hexagonal Architecture (Ports & Adapters), ensuring maintainability, testability, and framework independence.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INBOUND ADAPTERS β
β (REST Controllers, Messaging Handlers) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β APPLICATION LAYER β
β (Use Cases & Orchestration) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β DOMAIN LAYER β
β (Business Logic, Entities, Ports) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β OUTBOUND ADAPTERS β
β (Database, External APIs, Email Service) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Domain Layer - Core business logic and rules
- Business entities (Payment, Customer, Bank, etc.)
- Domain services with business operations
- Port definitions (interfaces) for external dependencies
- Framework and infrastructure independent
Application Layer - Use case orchestration
- Coordinates domain services and external ports
- Defines transaction boundaries
- Executes business workflows
- Input validation and error handling
Infrastructure Layer - Technical implementation
- Inbound: REST controllers, messaging consumers
- Outbound: Database adapters (JPA), external API clients (Midtrans, Email)
- Configuration management
- Framework-specific implementations
Shared Layer - Cross-cutting concerns
- Custom annotations and AOP aspects
- Common utilities (JSON, Base64, Time, Validation)
- Exception handling and error responses
- Enums and constants
app-midtrans/
βββ π± application/ # Use cases and orchestration
β βββ UseCaseExecutor.java
β βββ usecase/
β βββ VaNotifyUseCase.java
β βββ VaPaymentUseCase.java
β
βββ π§ domain/ # Core business logic
β βββ bank/
β βββ bankAccount/
β βββ callback/
β βββ customer/
β βββ email/
β βββ payment/
β
βββ π infra/ # Infrastructure & adapters
β βββ adapter/
β β βββ inbound/ # REST & Messaging
β β βββ outbound/ # DB, APIs, Email
β βββ config/ # Spring configurations
β
βββ π οΈ shared/ # Common utilities
βββ annotation/
βββ aop/
βββ enums/
βββ exception/
βββ handler/
βββ payload/
βββ utils/
- Java 17+ - Programming language
- Spring Boot 3.x - Application framework
- Spring Data JPA - Data persistence
- Hibernate - ORM framework
- PostgreSQL/MySQL - Database (configurable)
- Midtrans API - Payment gateway
- Mailtrap - Email service (development)
- SMTP - Email delivery (production)
- Maven - Dependency management
- Lombok - Code generation
- SpringDoc OpenAPI - API documentation
- SLF4J + Logback - Logging
- Java 17 or higher
- Maven 3.6+
- PostgreSQL/MySQL database
- Midtrans account (sandbox for testing)
- Email service credentials
-
Clone the repository
git clone https://github.com/yourusername/app-midtrans.git cd app-midtrans -
Configure application properties
cp src/main/resources/application.properties.example src/main/resources/application.properties
-
Set up environment variables
export MIDTRANS_SERVER_KEY=your_server_key export MIDTRANS_CLIENT_KEY=your_client_key export DATABASE_URL=jdbc:postgresql://localhost:5432/midtrans_db export EMAIL_HOST=sandbox.smtp.mailtrap.io export EMAIL_USERNAME=your_username export EMAIL_PASSWORD=your_password
-
Build the project
mvn clean install
-
Run the application
mvn spring-boot:run
The application will start on http://localhost:8080
Run the following SQL to create the database:
CREATE DATABASE midtrans_db;Tables will be auto-created by Hibernate on first run (if spring.jpa.hibernate.ddl-auto=update).
The system sends automated email notifications at key points in the payment lifecycle.
Sent when payment is pending or approaching due time, containing payment instructions and virtual account details.
Sent immediately after successful payment confirmation, including transaction summary and order details.
Customize email templates in src/main/resources/templates/email/:
reminder-email.html- Payment reminder templatesuccess-email.html- Payment confirmation template
Templates support dynamic variables like ${customerName}, ${amount}, ${vaNumber}, etc.
Midtrans provides a comprehensive sandbox environment for testing all payment scenarios without real money.
- Create a payment request via API
- Use the test VA number provided by Midtrans
- Simulate payment using Midtrans Simulator
| Bank | VA Number Format | Example |
|---|---|---|
| BCA | 5XXXX + order_id | 500012345678 |
| BNI | 8XXXX + order_id | 800012345678 |
| Mandiri | 7XXXX + order_id | 700012345678 |
| Permata | 10-digit number | 8562000001234567 |
- π Midtrans Sandbox Testing Guide
- π¦ Bank Transfer Test Scenarios
- π³ Virtual Account Simulator
Once the application is running, access the interactive API documentation:
- Swagger UI:
http://localhost:8080/swagger-ui.html - OpenAPI JSON:
http://localhost:8080/v3/api-docs
POST /api/v1.0/va/transfer
Content-Type: application/json
{
"customerId": "12345",
"bankCode": "bca",
"amount": 100000,
"orderId": "ORDER-2024-001",
"itemDetails": [...]
}POST /api/v1.0/va/notify
Content-Type: application/json
{
"transaction_id": "...",
"order_id": "...",
"transaction_status": "settlement",
...
}For complete API capabilities and integration guidelines:
- π Core API Overview
- π Authentication
- π¦ Bank Transfer API
Key configuration properties:
# Server
server.port=8080
# Database
spring.datasource.url=${DATABASE_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=update
# Midtrans
midtrans.server.key=${MIDTRANS_SERVER_KEY}
midtrans.client.key=${MIDTRANS_CLIENT_KEY}
midtrans.is.production=false
midtrans.api.url=https://api.sandbox.midtrans.com/v2
# Email
spring.mail.host=${EMAIL_HOST}
spring.mail.port=587
spring.mail.username=${EMAIL_USERNAME}
spring.mail.password=${EMAIL_PASSWORD}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true| Variable | Description | Required |
|---|---|---|
MIDTRANS_SERVER_KEY |
Midtrans server key | Yes |
MIDTRANS_CLIENT_KEY |
Midtrans client key | Yes |
DATABASE_URL |
Database connection URL | Yes |
DB_USERNAME |
Database username | Yes |
DB_PASSWORD |
Database password | Yes |
EMAIL_HOST |
SMTP host | Yes |
EMAIL_USERNAME |
SMTP username | Yes |
EMAIL_PASSWORD |
SMTP password | Yes |
sequenceDiagram
participant Client
participant Controller
participant UseCase
participant Domain
participant Midtrans
participant Database
participant Email
Client->>Controller: POST /api/v1.0/va/transfer
Controller->>UseCase: Execute VaPaymentUseCase
UseCase->>Domain: Validate Customer & Bank
Domain-->>UseCase: Validation OK
UseCase->>Midtrans: Create VA Payment
Midtrans-->>UseCase: VA Number & Details
UseCase->>Database: Save Payment Record
UseCase->>Email: Send Reminder Email
UseCase-->>Controller: Payment Response
Controller-->>Client: 200 OK + VA Details
Note over Midtrans,Database: Customer makes payment
Midtrans->>Controller: POST /api/v1.0/va/notify (callback)
Controller->>UseCase: Execute VaNotifyUseCase
UseCase->>Database: Update Payment Status
UseCase->>Email: Send Success Email
UseCase-->>Controller: Notification Processed
Controller-->>Midtrans: 200 OK
mvn testmvn verifymvn clean test jacoco:reportView coverage report at target/site/jacoco/index.html
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Email service limited to Mailtrap in development
- Single currency support (IDR only)
- No retry mechanism for failed callbacks
- Multi-currency support
- Payment retry mechanism
- Webhook signature verification
- Admin dashboard
- Payment analytics
- Refund support
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues:
- π§ Email: [email protected]
- π Issues: GitHub Issues
- π Docs: Wiki
- Midtrans for the payment gateway platform
- Spring Framework for the excellent ecosystem
- The clean architecture community for architectural patterns
Made with β€οΈ by Your Team

