Skip to main content

Overview

The Wallets API enables management of financial wallets (money sources) for users. Each wallet tracks a balance and can represent cash, bank accounts, or other payment methods. Base Path: /api/wallets Authentication: Required (@api_login_required decorator)

Get All Wallets

Retrieve all wallets belonging to the authenticated user.
GET
method
/api/wallets

Authentication

Required. User must be logged in with valid session.

Response

wallets
array
Array of wallet objects

Example Request

curl -X GET https://api.finai.com/api/wallets \
  -H "Cookie: session=your-session-cookie"

Example Response

[
  {
    "MaNguonTien": "w9876543",
    "TenNguonTien": "Tiền mặt",
    "LoaiNguonTien": "Tiền mặt",
    "SoDu": 2500000
  },
  {
    "MaNguonTien": "w1234567",
    "TenNguonTien": "Ngân hàng ACB",
    "LoaiNguonTien": "Ngân hàng",
    "SoDu": 15000000
  },
  {
    "MaNguonTien": "w5555555",
    "TenNguonTien": "MoMo",
    "LoaiNguonTien": "Ví điện tử",
    "SoDu": 500000
  }
]

Create Wallet

Add a new wallet to the user’s account.
POST
method
/api/wallets

Request Body

name
string
required
Wallet name (e.g., “Tiền mặt”, “Ngân hàng Vietcombank”)
type
string
required
Wallet type. Common values:
  • Tiền mặt - Cash
  • Ngân hàng - Bank account
  • Ví điện tử - E-wallet
  • Thẻ tín dụng - Credit card
balance
number
Initial balance (defaults to 0)

Example Request

curl -X POST https://api.finai.com/api/wallets \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your-session-cookie" \
  -d '{
    "name": "Ngân hàng Techcombank",
    "type": "Ngân hàng",
    "balance": 10000000
  }'

Response

status
string
success or error
message
string
Error message (only present on error)
Success
{
  "status": "success"
}
Error
{
  "status": "error",
  "message": "Invalid balance value"
}

Error Codes

Status CodeDescription
200Wallet created successfully
401Unauthorized (not logged in)
500Database or validation error

Update Wallet

Modify an existing wallet’s details.
PUT
method
/api/wallets/:wallet_id

Path Parameters

wallet_id
string
required
Wallet ID to update

Request Body

name
string
required
Updated wallet name
type
string
required
Updated wallet type
balance
number
required
Updated wallet balance

Example Request

curl -X PUT https://api.finai.com/api/wallets/w1234567 \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your-session-cookie" \
  -d '{
    "name": "Ngân hàng ACB - Chính",
    "type": "Ngân hàng",
    "balance": 18000000
  }'

Response

Success
{
  "status": "success"
}
Error - Not Found
{
  "status": "error"
}

Error Codes

Status CodeDescription
200Wallet updated successfully
401Unauthorized
404Wallet not found or doesn’t belong to user
500Database error

Delete Wallet

Remove a wallet from the user’s account.
DELETE
method
/api/wallets/:wallet_id

Path Parameters

wallet_id
string
required
Wallet ID to delete

Example Request

curl -X DELETE https://api.finai.com/api/wallets/w1234567 \
  -H "Cookie: session=your-session-cookie"

Response

Success
{
  "status": "success"
}
Error
{
  "status": "error",
  "message": "Cannot delete wallet with existing transactions"
}

Error Codes

Status CodeDescription
200Wallet deleted successfully
401Unauthorized
404Wallet not found
500Database error or constraint violation

Database Schema

Reference from app/models.py:
class Wallet(db.Model):
    __tablename__ = 'nguontien'

    id = db.Column('MaNguonTien', db.String(8), primary_key=True)
    user_id = db.Column('MaNguoiDung', db.String(8), 
                        db.ForeignKey('nguoidung.MaNguoiDung', ondelete='CASCADE'), 
                        nullable=False)
    name = db.Column('TenNguonTien', db.String(100), nullable=False)
    type = db.Column('LoaiNguonTien', db.String(50))
    balance = db.Column('SoDu', db.Float, default=0.0)
    created_at = db.Column('NgayTao', db.DateTime, default=datetime.now)

Implementation Reference

Source: app/routes/foundation.py:10-47

Build docs developers (and LLMs) love