Powered by: Spring Boot, JPA (Hibernate), H2Database, JUnit
- Purchase prepaid data for a SIM card by getting voucher code from 3rd parties.
- The customer can check all the voucher codes that they have purchased by phone number.
- TopupService (an API gateway to process all topup requests)
- VoucherService (an Facade service to work with 3rd parties)
- Website call TopupService with data (paymentId, phoneNumber, provider, dataPlan) to get a voucher code (Assume payment has been done before)
- TopupService send an async request to VoucherService with data (phoneNumber, provider, dataPlan)
- VoucherService find a 3rd Party named by provider and send a request to get Voucher code.
3a. If 3rd Party return a voucher code in 3 seconds, then return the code to the website.
3b. Otherwise return a message that says the request is being processed within 30 seconds. Send the code later via SMS. - Store the voucher code to database.
- Website call TopupService with username and phoneNumber
- TopupService find all voucher codes that match (username, phoneNumber) (TODO: supporting pagination)
- Return the list of voucher codes to the website
- JDK 8
- Maven
- IntelliJ IDEA Community Edition [Optional]
git clone https://github.com/NathanMBui/bank-topup.git
cd bank-topup
mvn clean install
Order | Service | Running Port | Command line |
---|---|---|---|
1 |
voucher-service | 8081 | java -jar target/voucher-service-0.0.1.jar |
2 |
topup-service | 8080 | java -jar target/topup-service-0.0.1.jar |
Using below curl commands 0. Login
curl --location --request POST 'http://localhost:8080/login' \
--form 'username="admin"' \
--form 'password="admin"'
copy the Headers["Authentication"] value to use below commands
- Purchase Voucher
curl --location --request POST 'http://localhost:8080/topup' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTYyMzgzNDcwOH0.aKO-VoikdEJD1yFEVCjFD885oUjvh2JTuNWsd6XkACwW3LZHQT1eK9n5F9Am5_RpAMgmyrcMtM68nFuuhTl9TA' \
--data-raw '{"paymentId": "p123", "phoneNumber": "1234567890", "provider": "Viettel", "type": "ST90"}'
- Get list of Voucher by phone number
curl --location --request GET 'http://localhost:8080/topup?phoneNumber=1234567890' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTYyMzgzNDcwOH0.aKO-VoikdEJD1yFEVCjFD885oUjvh2JTuNWsd6XkACwW3LZHQT1eK9n5F9Am5_RpAMgmyrcMtM68nFuuhTl9TA' \
--data-raw ''
- Get voucher code (not allowed to be called directly from website in production)
curl --location --request POST 'http://localhost:8081/vouchers' \
--header 'Content-Type: application/json' \
--data-raw '{"phoneNumber": "1234567890", "provider": "Viettel", "type": "ST70"}'
Method | URI | Description | Parameters | Request JSON | Response JSON |
---|---|---|---|---|---|
POST |
/login | Login | Headers["Authorization"] | ||
GET |
/topup | List of vouchers | phoneNumber | {"phoneNumber":(string), "vouchers": [{"code":(string), "type":(string), "provider":(string), "description":(string)}]} | |
POST |
/topup | Purchase a voucher | {"paymentId":(string), "phone": (string), "provider": (string), "type": (string)} | {"message":(string), "voucherCode": (string)} |
Method | URI | Description | Parameters | Request JSON | Response JSON |
---|---|---|---|---|---|
POST |
/vouchers | Get a voucher from 3rd party | {"phoneNumber": (string), "provider": (string), "type": (string)} | {"code":(string), "type":(string), "provider":(string), "description":(string)} |
- Cache (Redis) user data, list of voucher
- Support pagination when get list of voucher
- Use Service Registry to manage 3rd parties api