
- Set up project structure with FastAPI - Implement user and account management - Add send and receive money functionality - Set up transaction processing system - Add JWT authentication - Configure SQLAlchemy with SQLite - Set up Alembic for database migrations - Create comprehensive API documentation
4.1 KiB
4.1 KiB
Fintech Payment Service
A FastAPI backend for fintech payment services, providing APIs for users, accounts, and money transfer operations.
Features
- User Management: Create and manage user accounts
- Account Management: Create and manage financial accounts
- Transaction Processing:
- Send money to external accounts
- Receive money from external sources
- Make internal transfers between accounts
- View transaction history
- Security: JWT authentication for secure API access
Tech Stack
- Framework: FastAPI
- Database: SQLite
- ORM: SQLAlchemy
- Migrations: Alembic
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: Bcrypt
API Endpoints
Authentication
POST /api/v1/login/access-token
- Get access token
Users
POST /api/v1/users/
- Create a new userGET /api/v1/users/me
- Get current user infoPUT /api/v1/users/me
- Update current user infoGET /api/v1/users/{user_id}
- Get user by ID
Accounts
GET /api/v1/accounts/
- List user accountsPOST /api/v1/accounts/
- Create a new accountGET /api/v1/accounts/{account_id}
- Get account detailsPUT /api/v1/accounts/{account_id}
- Update account detailsDELETE /api/v1/accounts/{account_id}
- Delete an account
Transactions
GET /api/v1/transactions/
- List user transactionsGET /api/v1/transactions/account/{account_id}
- List account transactionsPOST /api/v1/transactions/deposit
- Create a depositPOST /api/v1/transactions/withdrawal
- Create a withdrawalPOST /api/v1/transactions/transfer
- Transfer between accountsPOST /api/v1/transactions/receive
- Receive money from external sourcePOST /api/v1/transactions/send
- Send money to external destinationGET /api/v1/transactions/{transaction_id}
- Get transaction details
Health Check
GET /api/v1/health
- Check API health
Setup Instructions
Prerequisites
- Python 3.8+
- pip
Installation
-
Clone the repository:
git clone <repository-url> cd fintechpaymentservice
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
# Create a .env file with the following variables SECRET_KEY=your_secret_key_here ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30
-
Run database migrations:
alembic upgrade head
-
Start the server:
uvicorn main:app --reload
-
Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Usage Examples
Create a User
curl -X POST "http://localhost:8000/api/v1/users/" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"password": "securepassword"
}'
Get Access Token
curl -X POST "http://localhost:8000/api/v1/login/access-token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=user@example.com&password=securepassword"
Create an Account
curl -X POST "http://localhost:8000/api/v1/accounts/" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"account_type": "savings",
"currency": "USD"
}'
Receive Money
curl -X POST "http://localhost:8000/api/v1/transactions/receive" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"receiver_account_id": 1,
"external_sender_info": "Bank XYZ - Account 12345",
"amount": 500.00,
"currency": "USD",
"description": "Salary payment"
}'
Send Money
curl -X POST "http://localhost:8000/api/v1/transactions/send" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"sender_account_id": 1,
"external_receiver_info": "Bank ABC - Account 67890",
"amount": 100.00,
"currency": "USD",
"description": "Utility bill payment"
}'
Development
Running Tests
pytest
Code Linting
ruff check .
Code Formatting
ruff format .