The Payment App is a simple application that implements wallet management and discount code generation services. It is a testing app and is not meant for production use.
- Go version 1.21 or higher
- Docker & Docker Compose for running the program inside the docker
- PostgreSQL for running the compiled binary
The configuration is specified in the configs/config.yml file. Ensure the database connection configurations are correctly set in this file.
Before compiling & running the application, ensure that a PostgreSQL database is up and running.
- Run the migrate tool :
make migrate
- Build the application :
make build
- Running the application :
./payment
You can modify the configuration in the configs/config.yaml or pass config.yaml from another directory using the -config flag.
To run the application with Docker Compose, simply execute the following command:
docker-compose up -d
This will start the payment app, which will listen and serve on port 8080.
- POST /wallet/register: Register a new wallet.
- PUT /wallet/{phoneNumber}: Perform a transaction.
- DELETE /wallet/{phoneNumber}: Delete a wallet.
- GET /wallet/{phoneNumber}: Get wallet details by phone number.
- POST /discount: Create a new discount.
- GET /discount/usages: Get discount usages.
- GET /discount/apply: Apply a discount.
Note: To use the wallet service and creating new discount codes, ensure that the token is configured in config.yaml and included in the Authorization header of your requests.
Register a new wallet
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token" \
-d '{"phone": "PhoneNumber", "amount": 100000}' \
http://localhost:8080/wallet/register
Perform a transaction
curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: token" \
-d '{"amount": 1000, "description": "Withdrawal for groceries", "type": "withdrawal"}' \
http://localhost:8080/wallet/PhoneNumber
Delete a wallet
curl -X DELETE \
-H "Authorization: token" \
http://localhost:8080/wallet/PhoneNumber
Get wallet details by phone number
curl -H "Authorization: token" \
http://localhost:8080/wallet/PhoneNumber
Create a new discount code
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token" \
-d '{"usage_limit": 1000, "description": "Voucher for cup league", "amount": 1000000, "type": "voucher"}' \
http://localhost:8080/discount
Get discount code transactions
curl http://localhost:8080/discount/usages?code=WS9DE6CH
Apply a discount
curl http://localhost:8080/discount/apply?code=WS9DE6CH&phone=PhoneNumber
For detailed information on the available routes and request/response schemas, refer to the Swagger documentation provided in the docs/swagger.yaml file.