Overview
The Wallet & Transactions feature provides a comprehensive digital wallet system for managing investor funds. Each user automatically receives a wallet (Cartera) upon registration, allowing them to deposit funds from bank accounts, withdraw to bank accounts, and track their complete transaction history.Key Capabilities
Automatic Wallets
Every user gets a wallet automatically created during registration with zero initial balance
Deposit & Withdraw
Transfer funds between bank accounts and wallet with real-time balance updates
Transaction History
Complete audit trail of all deposits and withdrawals with timestamps
Balance Tracking
Real-time balance calculation across wallet and linked bank accounts
Data Models
Cartera (Wallet) Entity
| Field | Type | Description |
|---|---|---|
idCartera | int | Unique wallet identifier (auto-generated) |
saldo | double | Current wallet balance |
idUsu | long | User ID (foreign key to Usuario) |
usuario | Usuario | Associated user entity |
Each user has exactly one wallet, created automatically during registration with
saldo initialized to 0.Transacciones Entity
| Field | Type | Description |
|---|---|---|
idTransaccion | long | Unique transaction identifier (auto-generated) |
monto | double | Transaction amount |
fecha | Date | Transaction date and time |
idCuentaBancaria | int | Bank account ID involved in transaction |
cuentaBancaria | CuentaBancaria | Bank account entity |
idTipoTransaccion | long | Transaction type: 1 = Deposito, 2 = Retiro |
tipoTransaccion | TipoTransaccion | Transaction type entity |
TipoTransaccion Entity
Defines transaction types:| ID | Type | Description |
|---|---|---|
| 1 | Deposito | Transfer from bank account to wallet |
| 2 | Retiro | Transfer from wallet to bank account |
Wallet System Architecture
Wallet Lifecycle
Wallet Creation
When a user registers via See implementation in
POST /api/registrar, the system automatically creates a wallet:UsuarioController.java:131-138Balance Management
Wallet balance is updated atomically during deposits, withdrawals, and investment transactions.
Transaction Workflows
Deposit Workflow (Bank Account → Wallet)
The deposit process transfers funds from a user’s bank account to their wallet:Validate Bank Account
System verifies:
- Bank account exists
- Bank account belongs to current user
- Bank account has sufficient balance
See Code Example: Deposit Transaction
See Code Example: Deposit Transaction
TransaccionController.java:92-136Withdrawal Workflow (Wallet → Bank Account)
The withdrawal process transfers funds from wallet to a bank account:Validate Wallet Balance
System verifies:
- Bank account exists
- Bank account belongs to current user
- Wallet has sufficient balance
See Code Example: Withdrawal Transaction
See Code Example: Withdrawal Transaction
TransaccionController.java:138-182Main API Endpoints
Wallet Endpoints
- Get User Wallet
- List All Wallets (Admin)
CarteraController.java:28-44Transaction Endpoints
- Make Deposit
- Make Withdrawal
- Bank account must belong to current user
- Bank account must have sufficient balance
400 BAD_REQUEST: “No cuenta con saldo suficiente en su cuenta Bancaria!”400 BAD_REQUEST: “La cuenta bancaria con Id: X no existe”
TransaccionController.java:92-136Transaction History Endpoints
- User Transactions
- Paginated Transactions
- Transactions by Bank Account
- All Transactions (Admin)
TransaccionController.java:63-69Utility Endpoints
List Transaction Types
List Transaction Types
TransaccionController.java:49-54Use Cases
Use Case 1: Investor Funding Their Wallet
Scenario: An investor wants to add funds to their wallet to invest in opportunities.-
Investor checks wallet balance:
GET /api/detalleCartera- Response shows:
saldo: 1000.0
- Response shows:
- Investor decides to deposit $5,000 from bank account #3
-
Investor calls
POST /api/deposito: -
System:
- Verifies bank account #3 belongs to investor
- Checks bank account has at least $5,000
- Deducts $5,000 from bank account
- Adds 6,000)
- Records transaction with
idTipoTransaccion: 1(Deposito)
- Investor can now use the $6,000 wallet balance to invest
Use Case 2: Cashing Out Profits
Scenario: An investor received returns from investments and wants to withdraw to their bank.-
Investor checks wallet:
GET /api/detalleCartera- Response shows:
saldo: 12000.0(original 6,000 returns)
- Response shows:
- Investor decides to withdraw $8,000 to bank account #3
-
Investor calls
POST /api/retiro: -
System:
- Verifies bank account #3 belongs to investor
- Checks wallet has at least $8,000
- Adds $8,000 to bank account
- Deducts 4,000)
- Records transaction with
idTipoTransaccion: 2(Retiro)
- Investor retains $4,000 in wallet for future investments
Use Case 3: Reviewing Transaction History
Scenario: An investor wants to review their deposit and withdrawal history.-
Investor calls
GET /api/user/listTransacciones/page/0 -
System returns first 8 transactions showing:
- Transaction IDs
- Amounts
- Dates
- Types (Deposito or Retiro)
- Associated bank accounts
-
Investor can:
- Calculate total deposits
- Calculate total withdrawals
- Reconcile with bank statements
- Track account activity patterns
Use Case 4: Admin Monitoring Platform Liquidity
Scenario: Admin wants to monitor total funds in the platform.-
Admin calls
GET /api/admin/listarCarteras - System returns all user wallets with balances
-
Admin calculates:
- Total platform liquidity: sum of all
saldovalues - Distribution of funds across users
- Identify high-value investors
- Total platform liquidity: sum of all
-
Admin calls
GET /api/admin/listaTransacciones -
Admin analyzes:
- Total deposits vs withdrawals
- Platform cash flow trends
- Most active investors
Balance Validation
The system implements strict balance validation to prevent overdrafts:Deposit Validation
Before deposit:Ensures bank account has sufficient funds.
Withdrawal Validation
Before withdrawal:Ensures wallet has sufficient funds.
Transaction Integrity
Atomic Operations
Each transaction involves multiple database updates that must all succeed or all fail:- Update source balance (bank account or wallet)
- Update destination balance (wallet or bank account)
- Create transaction record
Best Practices
Validate Ownership
Always verify bank accounts belong to the current user before processing transactions.
Check Balances
Validate sufficient funds before attempting any balance update to prevent overdrafts.
Audit Trail
Record every transaction with complete details (amount, date, type, account) for compliance.
Error Handling
Provide clear error messages distinguishing between insufficient funds, invalid accounts, etc.
Error Handling
Common error scenarios:| Scenario | HTTP Status | Response |
|---|---|---|
| Insufficient wallet balance | 400 BAD_REQUEST | {"mensaje": "No cuenta con saldo suficiente en su cartera!"} |
| Insufficient bank balance | 400 BAD_REQUEST | {"mensaje": "No cuenta con saldo suficiente en su cuenta Bancaria!"} |
| Bank account not owned | 400 BAD_REQUEST | {"mensaje": "La cuenta bancaria con Id: X no existe"} |
| Wallet not found | 404 NOT_FOUND | {"mensaje": "El no se encontro la cartera..."} |
Related Features
- User Management - Automatic wallet creation during user registration
- Investment Opportunities - Use wallet funds to invest in opportunities