A production-ready wallet service backend built with Go, featuring Paystack integration, Google OAuth authentication, JWT tokens, and API key management.
- Google OAuth Authentication - Sign in with Google to generate JWT tokens
- Wallet Management - Create wallets, check balance, view transaction history
- Paystack Integration - Deposit funds using Paystack payment gateway
- Wallet Transfers - Transfer funds between users
- API Key System - Service-to-service authentication with permission-based access
- Webhook Support - Real-time transaction updates from Paystack
- SQLite Database - Lightweight, embedded database with WAL mode for concurrency
/wallet-service
├── cmd/server/main.go # Application entry point
├── internal/
│ ├── config/ # Configuration management
│ ├── database/ # Database connection & migrations
│ ├── domain/ # Business logic
│ │ ├── auth/ # API key & JWT logic
│ │ ├── user/ # User models
│ │ └── wallet/ # Wallet & transaction logic
│ ├── repository/ # Database operations
│ ├── paystack/ # Paystack client & webhooks
│ ├── api/ # HTTP handlers & routing
│ │ ├── handlers/ # Request handlers
│ │ └── middleware/ # Authentication middleware
│ ├── security/ # JWT & hashing utilities
│ └── utils/ # Helper functions
├── go.mod
└── README.md
- Go 1.21 or higher
- Paystack account (test or live keys)
- Google OAuth credentials
git clone <repository-url>
cd wallet-service
go mod downloadCopy .env.example to .env and fill in your credentials:
cp .env.example .env- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Go to "Credentials" → "Create Credentials" → "OAuth 2.0 Client ID"
- Add authorized redirect URI:
http://localhost:8080/auth/google/callback - Copy Client ID and Client Secret to
.env
- Sign up at Paystack
- Go to Settings → API Keys & Webhooks
- Copy your test keys to
.env
go run cmd/server/main.goThe server will start on http://localhost:8080
GET /auth/google
Redirects to Google OAuth consent screen.
GET /auth/google/callback
Handles OAuth callback and returns JWT token.
Response:
{
"data": {
"token": "eyJhbGciOiJIUzI1NiIs...",
"user": {
"id": "user_id",
"email": "user@example.com",
"name": "John Doe"
}
}
}All API key endpoints require JWT authentication.
POST /keys/create
Authorization: Bearer <jwt_token>
{
"name": "wallet-service",
"permissions": ["deposit", "transfer", "read"],
"expiry": "1D"
}
Expiry Options: 1H, 1D, 1M, 1Y
Permissions:
deposit- Can initiate depositstransfer- Can transfer fundsread- Can view balance and transactions
Response:
{
"data": {
"api_key": "sk_live_abc123...",
"expires_at": "2025-12-10T10:00:00Z"
}
}POST /keys/rollover
Authorization: Bearer <jwt_token>
{
"expired_key_id": "key_id",
"expiry": "1M"
}
Creates a new API key with same permissions as an expired key.
Wallet endpoints accept either JWT or API Key authentication:
- JWT:
Authorization: Bearer <token> - API Key:
x-api-key: <api_key>
POST /wallet/deposit
Authorization: Bearer <jwt_token>
# OR
x-api-key: <api_key>
{
"amount": 5000
}
Response:
{
"data": {
"reference": "DEP_user_id_5000",
"authorization_url": "https://checkout.paystack.com/..."
}
}User completes payment at authorization_url. Paystack sends webhook to credit wallet.
GET /wallet/balance
Authorization: Bearer <jwt_token>
# OR
x-api-key: <api_key>
Requires: read permission for API keys
Response:
{
"data": {
"balance": 15000
}
}POST /wallet/transfer
Authorization: Bearer <jwt_token>
# OR
x-api-key: <api_key>
{
"wallet_number": "4566678954356",
"amount": 3000
}
Requires: transfer permission for API keys
Response:
{
"data": {
"status": "success",
"message": "Transfer completed"
}
}GET /wallet/transactions
Authorization: Bearer <jwt_token>
# OR
x-api-key: <api_key>
Requires: read permission for API keys
Response:
{
"data": [
{
"id": "txn_id",
"type": "deposit",
"amount": 5000,
"status": "success",
"reference": "DEP_...",
"created_at": "2025-12-09T10:00:00Z"
},
{
"id": "txn_id_2",
"type": "transfer",
"amount": -3000,
"status": "success",
"recipient_wallet": "4566678954356",
"created_at": "2025-12-09T11:00:00Z"
}
]
}POST /wallet/paystack/webhook
Receives payment notifications from Paystack. Validates signature and credits wallet on successful payment.
Configure in Paystack Dashboard:
- Go to Settings → API Keys & Webhooks
- Add webhook URL:
https://your-domain.com/wallet/paystack/webhook - Select events:
charge.success
GET /wallet/deposit/{reference}/status?reference=DEP_...
Manual verification endpoint (for debugging). Does NOT credit wallet - only webhook credits wallets.
-
Sign in with Google
# Open in browser http://localhost:8080/auth/google -
Create API Key
curl -X POST http://localhost:8080/keys/create \ -H "Authorization: Bearer <your_jwt>" \ -H "Content-Type: application/json" \ -d '{ "name": "test-key", "permissions": ["deposit", "transfer", "read"], "expiry": "1D" }'
-
Initiate Deposit
curl -X POST http://localhost:8080/wallet/deposit \ -H "x-api-key: <your_api_key>" \ -H "Content-Type: application/json" \ -d '{"amount": 10000}'
-
Check Balance
curl http://localhost:8080/wallet/balance \ -H "x-api-key: <your_api_key>" -
Transfer Funds
curl -X POST http://localhost:8080/wallet/transfer \ -H "x-api-key: <your_api_key>" \ -H "Content-Type: application/json" \ -d '{ "wallet_number": "recipient_wallet_number", "amount": 5000 }'
Use ngrok to expose your local server:
ngrok http 8080Add the ngrok URL to Paystack webhook settings:
https://your-ngrok-url.ngrok.io/wallet/paystack/webhook