Wallet API is a Dockerized Laravel application for managing user wallets and transactions.
- Docker installed on your local machine.
-
Clone the repository:
git clone https://github.com/daalvand/wallet-api.git cd wallet-api
-
Create a Configuration File:
Create a
.env
file by duplicating the provided.env.example
file (cp .env.example .env
). Customize the environment variables according to your preferences. -
Start the Docker Containers:
docker-compose up -d
This command will launch the MySQL database and the application containers.
-
Install Application Dependencies:
docker-compose exec app composer install
-
Generate Application Key:
docker-compose exec app php artisan key:generate
-
Migrate the Database and Seed Initial Data:
docker-compose exec app php artisan migrate --seed
-
Set Up Scheduled Tasks:
Add the following Cron entry to your server to start the Laravel scheduler:
***** cd /project-path && docker-compose exec app php artisan schedule:run >> /path/logs/scheduled-jobs.log 2>&1
-
Access the Application:
Visit http://localhost:8000 in your web browser to access the Wallet API application.
To run the application tests, execute the following command:
touch database/database.sqlite
docker-compose exec app php artisan test
The application offers two API endpoints:
-
Endpoint:
GET /api/wallet/balance/{user}
- This endpoint returns the current balance of a user's wallet.
- The
{user}
parameter should be replaced with the ID of the user.
-
Endpoint:
POST /api/wallet/deposit/{user}
- This endpoint deposits money into a user's wallet and returns a transaction reference ID.
- The
{user}
parameter should be replaced with the ID of the user. - The request body should be a JSON object containing an
amount
field.
-
GetTotalAmount: To get the total amount, run this command:
docker-compose exec app php artisan transactions:total
For complete documentation of the API, please refer to the swagger.
The project incorporates GitHub Actions for Continuous Integration. The workflow encompasses:
- Building and pushing Docker images to Docker Hub.
- Executing tests for the application.
The CI workflow triggers automatically with every push to the main
branch.