Getting Started β’ API Endpoints β’ Requirements β’ Contribute
Simple solution for this challenger using Bun and Elysia.
The goal of this project is implement a simplified version of a payment service. It should be possible to make transfers between ordinary customers and merchants, and the merchant only receive transfers. Ordinary customers can make and receive transfers from any other customer.
You need to have this two main global dependencies installed:
- Bun Latest (or NVM, but ensure that bun is installed as a node global dependency)
- Docker/Docker Engine with Docker Compose (both latest)
-
Clone the repository:
git clone https://github.com/patricks-js/payment-api.git
-
Install dependencies running
bun install
-
Up containers with
bun services:up
-
Run migrations with
bun migrations:run
-
Seed database with
bun migrations:seed
-
(Optional) For contributing, run
bun prepare
to sync git hooks
- Start the application running
bun start # or dev for development mode
- The API will be accessible at http://localhost:3333
- The API documentation (swagger) will be accessible at http://localhost:3333/api/swagger
To run tests, run the following command
bun test
To run tests with watch mode, run the following command
bun test:dev
Here you can list the main routes of your API, and what are their expected request bodies.
GET CUSTOMERS
GET /api/customers - Retrieve a list of all customers.
[
{
"customerId": "ab40cb90-21df-46f2-8eff-7f4fe41f823",
"fullName": "Bernado Silva",
"document": "123456787",
"email": "bernado@example.com",
"balance": 20.0,
"type": "MERCHANT"
},
{
"customerId": "821216ac-d2ac-4907-afe1-47f8a91e0dc6",
"fullName": "Phill Foden",
"document": "123456783",
"email": "foden@example.com",
"balance": 0.0,
"type": "COMMON"
}
]
POST CUSTOMER
POST /api/customers - Register a new customer into the App
POST /api/transactions
Content-Type: application/json
{
"fullName": "Phill Foden",
"password": "senha",
"document": "123456783",
"email": "foden@example.com",
"type": "CUSTOMER",
"balance": 10
}
POST TRANSACTIONS
POST /api/transactions - Register a new Transaction between customers (CUSTOMER to CUSTOMER or CUSTOMER to MERCHANT)
POST /api/transactions
Content-Type: application/json
Authorization: Bearer {{token}}
{
"senderId": "821216ac-d2ac-4907-afe1-47f8a91e0dc6",
"receiverId": "ab40cb90-21df-46f2-8eff-7f4fe41f823",
"amount": 2000
}
Payload
{
"transactionId": "1234",
"amount": 100.0,
"sender": {
"id": "821216ac-d2ac-4907-afe1-47f8a91e0dc6",
"fullName": "Phill Foden"
},
"receiver": {
"id": "ab40cb90-21df-46f2-8eff-7f4fe41f823",
"fullName": "Bernado Silva"
}
}
Main specification about this challenger.
- Customers can receive and make transfers
- Merchant only receive transfers
- Email and CPF/CNPJ must be uniques
- Customers must have sufficient balance to make transfers
- Transfers must be authorized with an external service
- All transfers are transactions, if any error occurs, the operations is reverted
- Customers should receive a message when a transfer is completed. Check this mock
- Customer can create an account
- Customer can login to their own account
- Customer can be a Customer or a merchant
- Customer can view transaction history
- Customer can update account information
- Customers can make a transfer to other customers
- Customers can receive transfers from other customers
- Login with email & password
- Login with third-part service
- Notification service with email
- Customer's password must be encrypted
- Only refresh tokens must be stored in the database
- Request must have an access token
The API uses Spring Security for authentication control. The following roles are available:
COMMON -> Standard role for logged-in customers.
MERCHANT -> Standard role for receive transfers (registering new partners).
To access protected endpoints as an ADMIN customer, provide the appropriate authentication credentials in the request header.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request to the repository.
git clone https://github.com/patricks-js/payment-api.git
git checkout -b feature/NAME
- Follow commit conventions
- Open a Pull Request explaining the problem solved or feature made, if exists, append screenshot of visual modifications and wait for the review!