Skip to content

Simplified payment API made with Bun 🍞 and Elysia 🦊.

License

Notifications You must be signed in to change notification settings

patricks-js/payment-api

Repository files navigation

Simplified Payment API - Back-End challenge

JAVASCRIPT__BADGE TypeScript Bun Vitest Postgres Docker JWT

Getting Started β€’ API Endpoints β€’ Requirements β€’ Contribute

Simple solution for this challenger using Bun and Elysia.

πŸš€ Getting started

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.

Installation

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)
  1. Clone the repository:

    git clone https://github.com/patricks-js/payment-api.git
  2. Install dependencies running bun install

  3. Up containers with bun services:up

  4. Run migrations with bun migrations:run

  5. Seed database with bun migrations:seed

  6. (Optional) For contributing, run bun prepare to sync git hooks

Usage

  1. Start the application running bun start # or dev for development mode
  2. The API will be accessible at http://localhost:3333
  3. The API documentation (swagger) will be accessible at http://localhost:3333/api/swagger

Running Tests

To run tests, run the following command

bun test

To run tests with watch mode, run the following command

bun test:dev

πŸ“ API Endpoints

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"
  }
}

πŸ“ Requirements

Main specification about this challenger.

Business Rules

  • 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

Functional Requirements

  • 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

Non-functional Requirements

  • 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

Authentication

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.

πŸ“« Contribute

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.

Steps

  1. git clone https://github.com/patricks-js/payment-api.git
  2. git checkout -b feature/NAME
  3. Follow commit conventions
  4. Open a Pull Request explaining the problem solved or feature made, if exists, append screenshot of visual modifications and wait for the review!

Documentations that might help

πŸ“ How to create a Pull Request

πŸ’Ύ Commit conventions

About

Simplified payment API made with Bun 🍞 and Elysia 🦊.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published