- Introduction
- Database Schema
- API Endpoints
- Web Routes
- Design Patterns
- Authentication
- Postman Collection
- Requirements
- Getting Started
- Testing
- Running the Application
This project provides a set of APIs for managing a wallet system. Users can top-up, withdraw, and transfer funds between wallets. The API also supports real-time balance updates and transaction tracking.
- users: id, name, email, password, email_verified_at
- wallets: id, user_id, balance, created_at, updated_at
- transactions: id, wallet_id, type (topup, withdraw, transfer, fee), amount, recipient_wallet_id, fee, created_at, updated_at
Endpoint: /api/wallet/topup
Method: POST
Description: Add funds to the wallet.
Headers:
- Content-Type: "application/json"
- Accept: "application/json"
- Authorization: "Bearer {{token}}"
Request Body:
{
"amount": 500
}
Response Example:
{
"status": "success",
"message": "Top-up successful",
"data": {
"balance": {
"wallet_number": 1,
"balance": "500.00",
"user": {
"name": "John Doe",
"email": "[email protected]"
}
}
}
}
Endpoint: /api/wallet/withdraw
Method: POST
Description: Withdraw funds from the wallet.
Request Body:
{
"amount": 200
}
Endpoint: /api/wallet/transfer
Method: POST
Description: Transfer funds to another user's wallet.
Request Body:
{
"recipient_id": 2,
"amount": 100
}
Endpoint: /api/wallet/balance
Method: GET
Description: Retrieve the current balance.
Endpoint: /api/wallet/transactions
Method: GET
Description: Retrieve the list of all transactions for the authenticated user.
These routes define the user-facing pages for managing wallet functionalities through the UI.
Endpoint: /
Method: GET
Description: Displays the landing page.
Route Name: landing-page
Endpoint: /login
Method: GET
Description: Displays the login form.
Route Name: login
Endpoint: /register
Method: GET
Description: Displays the registration form.
Route Name: register
Endpoint: /home
Method: GET
Description: Displays the home page with user’s balance and links to wallet functionalities.
Route Name: home
Endpoint: /wallet/topup
Method: GET
Description: Displays the form to top-up the user’s wallet.
Route Name: wallet.topUp
Endpoint: /wallet/withdraw
Method: GET
Description: Displays the form to withdraw from the user’s wallet.
Route Name: wallet.withdraw
Endpoint: /wallet/transfer
Method: GET
Description: Displays the form to transfer funds to another user.
Route Name: wallet.transfer
Endpoint: /transactions
Method: GET
Description: Displays the user’s transaction history.
Route Name: transactions
This pattern is used to calculate fees for transactions like withdrawals and transfers. Depending on the amount, a different fee strategy is applied to ensure a flexible and scalable system.
- For amounts greater than $25, a higher fee percentage is applied using the
HighAmountFeeStrategy
. - For smaller amounts,
LowAmountFeeStrategy
is used.
All data interactions are handled using repositories to ensure loose coupling and better separation of concerns.
Authentication is handled via Laravel Sanctum. You must pass the Bearer token
in the request headers to access protected routes.
A Postman collection is available with all the API endpoints for easy testing and integration. It includes example requests and expected responses.
Link to Postman Collection: Postman Collection Please update the environment variables in Postman:
app_url
: Your app linktoken
: Retrieved after login.
- PHP 8.2
- MySQL 5.7+
- Laravel 10.x
- Clone this repository:
git clone https://github.com/salmazz/fin-tech-app.git cd fin-tech-app
- Set up the environment:
cp .env.example .env composer install composer dumpautoload
- Set up the database:
php artisan migrate --seed
To run the tests:
php artisan test
- Home Page Test: Ensures the home page displays the correct user balance and wallet information.
- Top Up Test: Verifies that a user can successfully top-up their wallet through the UI.
- Withdraw Test: Verifies that a user can withdraw funds from their wallet via the web interface.
- Transaction History Test: Ensures that the transaction history page correctly paginates and displays transactions.
- Top Up API Test: Ensures that the
/api/wallet/topup
endpoint works correctly and updates the wallet balance. - Withdraw API Test: Verifies that the
/api/wallet/withdraw
endpoint successfully processes withdrawals. - Transfer API Test: Ensures that the
/api/wallet/transfer
endpoint transfers funds between users. - Transaction API Test: Verifies that the
/api/wallet/transactions
endpoint retrieves the user's transactions with proper pagination.
Feel free to adjust any details to better suit your project setup!