This is a simple backend project functioning as a payment gateway, integrated with Midtrans. It is built using Go (Golang) with a clean, production-ready architecture.
- User registration and login (JWT authentication)
- Create payment transactions (Midtrans Snap integration)
- Check transaction status
- View transaction history (for logged-in users)
- Webhook to receive payment status notifications from Midtrans
- Database schema for users, transactions, and transaction items
- Language: Go
- Web Framework: Gin
- ORM: GORM
- Database: PostgreSQL
- Payment Gateway: Midtrans
- Authentication: JWT
- Containerization: Docker
-
Clone the Repository
git clone https://github.com/bagussubagja/backend-payment-gateway-go.git cd backend-payment-gateway-go -
Configure Environment Variables Copy the
.env.examplefile to.envand fill in your credentials.cp .env.example .env
-
Install Dependencies
go mod tidy
-
Run Database Migration (Once) Temporarily uncomment the
AutoMigrateblock instorage/postgres.go, then run the server to create tables. Re-comment it afterward. -
Start the Application
go run main.go
The server will run at
http://localhost:8080.
Make sure the following variables are set in your .env file:
PORT: App server port (e.g.,8080)DB_HOST: PostgreSQL host (e.g.,localhost)DB_PORT: PostgreSQL port (e.g.,5432)DB_USER: PostgreSQL username (e.g.,postgres)DB_PASSWORD: PostgreSQL passwordDB_NAME: Database name (e.g.,payment_db)JWT_SECRET_KEY: Secret key for signing JWTJWT_EXPIRATION_HOURS: Token expiration in hours (e.g.,24h)MIDTRANS_SERVER_KEY: Midtrans server keyMIDTRANS_CLIENT_KEY: Midtrans client keyMIDTRANS_ENVIRONMENT: Midtrans environment (sandboxorproduction)
POST /api/v1/auth/register- Register a new userPOST /api/v1/auth/login- Login and get JWT tokenPOST /api/v1/payments/notification- Midtrans webhook notificationGET /api/v1/profile- Get user profilePOST /api/v1/payments/create- Create a new payment transactionPOST /api/v1/payments/qris- Create a QRIS transactionGET /api/v1/payments/status/:orderID- Get transaction status by order IDGET /api/v1/payments/history- Get user transaction history