Files
pos-system/services/wallet-service-net/docs/en
Ho Ngoc Hai 71a5d8d4ed feat(deployments): Update local environment configuration for IAM service and Redis integration
- Modified local `.env` and `.env.local` files to include external Redis configuration and IAM service database connection details.
- Updated `docker-compose.yml` to disable local Redis service in favor of an external Redis instance.
- Added JWT configuration parameters for the IAM service, enhancing security and token management.
- Revised example environment file to reflect new configuration options for external services.
- Enhanced documentation to clarify setup instructions for local development with external dependencies.
2026-01-13 01:03:33 +07:00
..

Wallet Service .NET

EN: Wallet and Point Account management service for GoodGo Platform.
VI: Dịch vụ quản lý Ví và Tài khoản Điểm cho GoodGo Platform.

Overview

The Wallet Service provides comprehensive wallet and loyalty points management with:

  • Wallet Management - Create, deposit, withdraw, transfer funds
  • Point Account - Earn, spend, and track loyalty points
  • Transaction History - Full audit trail of all transactions
  • Multi-Currency Support - Default VND with currency support
  • Domain-Driven Design - Clean Architecture with CQRS pattern

Tech Stack

Component Technology
Framework .NET 10
Database PostgreSQL (EF Core)
CQRS MediatR
Validation FluentValidation
API Docs Swagger/OpenAPI
Logging Serilog

Prerequisites

# Check .NET version
dotnet --version  # Should be 10.0.x

Quick Start

1. Configure Environment

cp .env.example .env
# Edit .env with your database connection

2. Run with Docker

cd deployments/local
docker-compose up wallet-service -d

3. Run Locally

cd services/wallet-service-net
dotnet restore
dotnet build
dotnet run --project src/WalletService.API

API Endpoints

Wallet APIs

Method Endpoint Description
POST /api/v1/wallets Create new wallet
GET /api/v1/wallets/me Get current user's wallet
GET /api/v1/wallets/{id} Get wallet by ID
POST /api/v1/wallets/deposit Deposit funds
POST /api/v1/wallets/withdraw Withdraw funds
POST /api/v1/wallets/transfer Transfer between wallets
POST /api/v1/wallets/{id}/freeze Freeze wallet
POST /api/v1/wallets/{id}/unfreeze Unfreeze wallet
GET /api/v1/wallets/transactions Get transaction history

Points APIs

Method Endpoint Description
GET /api/v1/points/me Get current user's points
POST /api/v1/points/earn Earn points
POST /api/v1/points/spend Spend points
GET /api/v1/points/transactions Get point transactions

Health Endpoints

Endpoint Purpose
/health Full health status
/health/live Liveness probe (K8s)
/health/ready Readiness probe (K8s)

Project Structure

wallet-service-net/
├── src/
│   ├── WalletService.API/           # API Layer
│   │   ├── Controllers/             # REST endpoints
│   │   └── Application/             # Commands & Queries
│   │       ├── Commands/            # Write operations
│   │       └── Queries/             # Read operations
│   │
│   ├── WalletService.Domain/        # Domain Layer 
│   │   ├── AggregatesModel/
│   │   │   ├── WalletAggregate/     # Wallet, Transaction, Money
│   │   │   └── PointAccountAggregate/  # Points, PointTransaction
│   │   ├── Events/                  # Domain events
│   │   └── Exceptions/              # Domain exceptions
│   │
│   └── WalletService.Infrastructure/  # Infrastructure Layer
│       ├── EntityConfigurations/    # EF Core mappings
│       ├── Repositories/            # Data access
│       └── WalletServiceContext.cs  # DbContext
│
├── tests/
│   ├── WalletService.UnitTests/     # Domain & Logic tests
│   └── WalletService.FunctionalTests/  # API integration tests
│
├── docs/
│   ├── en/                          # English docs
│   └── vi/                          # Vietnamese docs
│
└── Dockerfile

Domain Model

Wallet Aggregate

// Create wallet
var wallet = new Wallet(userId, "VND");

// Deposit funds
wallet.Deposit(new Money(1000000m, "VND"), "Salary", "REF001");

// Withdraw funds  
wallet.Withdraw(new Money(500000m, "VND"), "Shopping", "REF002");

// Freeze/Unfreeze
wallet.Freeze();
wallet.Unfreeze();

Point Account Aggregate

// Create account
var account = new PointAccount(userId);

// Earn points
account.EarnPoints(100, "ORDER001", "Purchase reward", expiresAt);

// Spend points
account.SpendPoints(50, "ORDER002", "Redeem discount");

// Adjust points (admin)
account.AdjustPoints(10, "ADMIN", "Bonus adjustment");

Testing

# Run all tests
dotnet test

# Run with coverage
dotnet test /p:CollectCoverage=true

# Unit tests only
dotnet test tests/WalletService.UnitTests

# Functional tests only
dotnet test tests/WalletService.FunctionalTests

Test Results

  • 23 tests total
  • 20 unit tests (Wallet, PointAccount domain)
  • 3 functional tests (Health endpoints)

Configuration

Environment Variables

Variable Description Required
DATABASE_URL PostgreSQL connection Yes
ASPNETCORE_ENVIRONMENT Environment No (default: Development)
JWT_AUTHORITY JWT issuer URL Yes (for auth)

appsettings.json

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=wallet_db;Username=postgres;Password=postgres"
  },
  "Jwt": {
    "Authority": "http://localhost:5001",
    "Issuer": "http://localhost:5001"
  }
}

Database Migrations

# Create migration
dotnet ef migrations add InitialCreate \
  --project src/WalletService.Infrastructure \
  --startup-project src/WalletService.API

# Apply migration
dotnet ef database update \
  --project src/WalletService.Infrastructure \
  --startup-project src/WalletService.API

Deployment

Docker Build

docker build -t goodgo/wallet-service:latest .

Docker Compose

Service is registered in deployments/local/docker-compose.yml with Traefik routing.

Resources

License

Proprietary - GoodGo Platform