This is my first project in my Golang learning journey. It implements a simple payment system where you can create and process payments using QR codes.
The API exposes the following endpoints:
- GET
/→ Returns all users.
- GET
/:id→ Returns user filtered by parameterid. - POST
/→ Creates a new user.- Body:
{ "name": "string(required)", "cpf": "string(required)", "balance": "float,(required)", "city": "string(required)" } - PUT
/:id/balance→ Updates user's balance.- Body:
{ "diff": "float(required)" }- A positive value deposits money into the account, and a negative value withdraws from it.
- DELETE
/:id→ Deletes user by the given parameterid.
- GET
/→ Returns all payments. - GET
/:user_id/:user_type→ Returns all payments for the givenuser_idanduser_type(receiver_idorpayer_id)- Passing
receiver_idreturns received payments (deposits). - Passing
payer_idreturns sent payments (withdrawals).
- Passing
- GET
/:id→ Returns a specific payment filtered byid. - POST
/→ Creates a new payment with a QR code.- Body:
{ "receiver_id": "string(required)", "amount": "float(optional)`" }- If you don't provide
amount, it creates a QR code payment without a fixed value. In that case, you must provide anamountwhen processing the payment (see endpoint below). - To make it simple, it uses the user's cpf as pix key.
- POST
/:user_id/pay→ Processes a payment by transferring money from one account to another and marking it aspaid.- Body:
{ "qr_code_data": "string(required)", "amount": "float(optional)`" }- In
user_id, you must provide the ID of the user who is making the payment (payer_id). - If the 15-minute processing time limit has elapsed, the payment will not be processed and will be marked as
expired. - If something goes wrong, it will be marked as
failed. - The program will get
TransactionAmountfrom the QR code. If the QR code has no predefined value, you must provide anamountin the request body for the payment to be processed.
- DELETE
/:id→ Deletes payment by the given parameterid.
- Database: SQLite
- Backend: Go (Golang)
- Frontend: Vanila Javascript
Make sure you have Go installed. Then run:
go run main.goBy default, the server will start on port 8080 and will create database in the project repository.
You can interact with the project in two ways:
-
Frontend: The frontend part is very simple and was created only to make testing the API easier. Access http://localhost:8080 in your browser to interact with it.
-
API: Use Postman,
curl, or any HTTP client to test the API directly. Example:curl http://localhost:8080/payments
This project includes automated tests. Make sure the server is running on port 8080, then run:
go test tests/payment_test.goNote: You must delete any pre-created database file for the tests to run correctly.