Skip to content

turackangal/wallet-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wallet-API

Digital Wallet Rest API

Prerequisite

  1. Download and install maven from offical site.
  2. Download and install docker from offical site.
  3. Download and install docker-compose from offical site.

Installation

  1. Go to project directory and build appllication and create a .jar file with maven
mvn clean install 
  1. Run application with docker compose
docker-compose -f docker-compose-test.yml up

Features

  1. Spring Boot for create web service
  2. PostgreSQL store data on database
  3. Flyway update database and manage migrations
  4. Docker build and run container applications
  5. JsonWebToken generate JWT token, manage authorization and authentication
  6. Resilience4j Rate Limit for specific endpoints
  7. Actuator Application Health Check
  8. JaCoCo show test results

Important points for before the start

Application has 2 profile as test and prod. Actually they have same variables but it can changable by the profile.

All rules fallowed in case except add role column to customer(for authorization) and password column (for authentication)

Database tables

  • Role: id, role
  • Customer: id, name, surname, TCKN, password, role_id
  • Wallet: id, customer id, wallet name, currency, active for shopping, active for withdraw, balance, usable balance.
  • Transaction: id, wallet id, amount, type, opposite party type, opposite party, status.

Enums

  • Type is either DEPOSIT or WITHDRAW
  • Opposite Party Type is either IBAN or PAYMENT
  • Status is PENDING, APPROVED or DENIED
  • Role is EMPLOYEE or CUSTOMER

When application starts, application add dummy customer and role with flyway. Customer has 2 role as EMPLOYEE and CUSTOMER. If you want do operation for another customer, you should have EMPLOYEE role.

INSERT INTO role (id, role) VALUES (nextval('role_seq'), 'CUSTOMER');

INSERT INTO customer (id, name, surname, tckn, password, role_id) VALUES (nextval('customer_seq'), 'John', 'Doe', '85659108642', '1234', '1');

INSERT INTO role (id, role) VALUES (nextval('role_seq'), 'EMPLOYEE');

INSERT INTO customer (id, name, surname, tckn, password, role_id) VALUES (nextval('customer_seq'), 'Max', 'Mustermann', '22197380642', '1234', '2');

JWT token used for authentication and authorization. Token keeps customer Tckn and roles. Only login can call without JWT token, atherwise you will see Forbidden error. We have the swageer and swagger updated for this token, when you open the swagger you will see Authorize button on right top, you can paste the token and login, it will add token to header automatically.

Application has some input validation like wallet_id should be UUID, balance should be digit format(because it is bigDecimal), not null fields etc. If input fieled validation is fail, you will see BAD REQUEST error. When you open request detail on Swagger-UI, you will see input field validations.

Transaction operations can only be completed from the EMPLOYEE role. Customer has not authorization on transaction operations.

If application has error when deploy with docker, it will try again because restart-policy is active.

If you want see test result with JaCoCo, after maven build command, you can see .html file in /target/site/jacoco folder. Test coverage is %90

If you want see application health status, you can go to Spring-Actuator URL

Usage

List endpoints

Application has Swagger-UI integration, You can see endpoints on Swagger-UI. Open Swagger-UI with

  http://localhost:8080/swagger-ui/index.html#

Login

Application has JWT authentication and authorization. So we should generate JWT token, we can login with login credentials.

  POST /customers/login

It will return generated JWT token

Create wallet

  POST /wallets/customer/{customerId}

It will create a new wallet by customer Id.

Get wallets by customerId

  GET /wallets/customer/{customerId}

Get all wallets by customer id

Get wallets by customer id and wallet currency

  GET /wallets/customer/{customerId}/currency/{currency}

Get all wallets by customer id and wallet currency

Deposit to wallet

  PUT /wallets/deposit

Deposit from wallet and return updated wallet.

When update wallet, it will create transaction automatically. Amount more than 1000 should be saved with status PENDING, less than this amount should be saved with status APPROVED.

Approved deposits should be reflected to balance and usable balance of the wallet. Pending deposits should only be reflected to balance of the wallet.

Withdraw to wallet

  PUT /wallets/withdraw

Deposit from wallet and return updated wallet.

Wallet settings for shopping and withdraw will control, if settings not OK, it will return error.

Amount more than 1000 should be saved with status PENDING, less than this amount should be saved with status APPROVED.

Approved withdraws should be reflected to balance and usable balance of the wallet. Pending withdraws should only be reflected to usable balance of the wallet.

If not enough balance in wallet, application will return error.

Get Transaction By Wallet

  GET /transactions/wallet/{walletId}

Only EMPLOYEE role can do this operation. List transactions by the wallet id.

Update Transaction

  PUT /transactions

Only EMPLOYEE role can do this operation. Update transaction by transactionId and status. If transaction is not PENDING status, application will return error.

If transaction will complete, related wallet balance or useableBalance will update by transaction status and type.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors