Task description: Payment System Task.pdf
- Merchant Microservice to manage Users
- Transaction Microservice to manage Transactions
- Web UI
- Postgres 15 as DB
- Keycloak 22 for handling authorization
- Kafka 3.5 for messaging
- Java 17, spring boot 3.1.3, gradle, checkstyle
- JUnit 5 and cucumber
- React 18, react router 6, redux, axios, bootstrap, vite, eslint
- Docker and docker-compose
- Tools: Idea Ultimate, Docker Desktop, Keycloak UI, Kafka UI, Swagger.
Run docker compose and ensure that all containers are running:
- docker-compose.exe -f docker-compose-stage.yml -p emerchantpay up -d
In Intellij Idea you can right-click on the compose file and run.
- Run Postgres, Keycloak, Kafka using docker-compose:
- docker-compose.exe -f docker-compose-dev.yml -p emerchantpay up -d
- Run Microservices as spring boot application
- com.vvkozlov.emerchantpay.merchant.MerchantApplication (Merchant folder)
- com.vvkozlov.emerchantpay.transaction.TransactionApplication (Transaction folder)
- Run Web UI
- execute "yarn install" ("npm install") from the web-ui folder
- execute "yarn start" ("npm start") from the web-ui folder
- Ensure that all applications are running
- Open http://localhost:8080/
Login as emp_admin / emp_admin_password - Import Merchants
- You can check other features: View, Edit, Delete a Merchant. You can also import other admins.
Users are imported both to the merchant service DB and the keycloak. - After importing merchants, you can use the Transaction UI.
- Log out from merchant ui and press login button. Enter credentials:
Name = <merchant_email>
password = password - When Merchant is logged in, he can see a list of transactions. Initially it is empty.
- Click "New Transaction" at the top menu. Start with Authorize transaction.
Notes:
- Merchants are not intended to use the merchant management service.
Admins are not intended to use the transaction management service. - Each transaction belongs to a merchant that creates it (the "sub" JWT claim is scanned).
- For Merchants, the main id used across microservices is located in the "sub" claim of their JWT
This id is generated in keycloak when a Merchant is created there. This id is declared as String (not UUID) to avoid tight coupling with implementation. - Admins are not stored in Merchant DB, they are stored in keycloak and its DB.
Default password for imported Admins is "password". - Kafka handles the following Events:
5.1. Amount is charged (transaction topic)
5.2. Amount is refunded (transaction topic)
5.3. Merchant Status is changed (merchant topic)
You can check these events in backend service container logs (consume) or Kafka UI
Useful links:
- Keycloak Admin UI:
http://localhost:5451/admin/master/console/
dev_kc_admin
dev_kc_password
(or use "stage_" prefix for stage)
- You can switch to emerchantpay realm in top left corner.
-
Kafka UI
http://localhost:5453/ui/
No Authorization -
Postgres:
jdbc:postgresql://localhost:5450/dev_emerchantpay
dev_db_admin
dev_db_password
(or "stage_") -
Merchant service Swagger UI:
http://localhost:8081/swagger-ui/index.html#
Offline doc:swagger.html -
Transaction Microservice Swagger UI:
http://localhost:8082/swagger-ui/index.html#
Offline doc:swagger.html
To generate docs, execute from microservice root:
npm install -g @redocly/openapi-cli
./gradlew clean generateOpenApiDocs
./gradlew generateHtmlDocs
All tests are checked and working.
For keycloak test, run docker-compose-dev to get dev keycloak instance
In IntelliJ idea, tests can be run by clicking on test folder and choosing "Run tests"
-
Get Merchant Admin JWT from keycloak:
curl --location 'http://localhost:5451/realms/emerchantpay/protocol/openid-connect/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=emerchantpay-test-client' \
--data-urlencode 'client_secret=emerchantpay_test_client_secret' \
--data-urlencode 'username=emp_admin' \
--data-urlencode 'password=emp_admin_password' \
--data-urlencode 'grant_type=password' -
Get Merchant JWT (import merchants first):
curl --location 'http://localhost:5451/realms/emerchantpay/protocol/openid-connect/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=emerchantpay-test-client' \
--data-urlencode 'client_secret=emerchantpay_test_client_secret' \
--data-urlencode 'username=vasil@store.com' \
--data-urlencode 'password=password' \
--data-urlencode 'grant_type=password'