Code Monkey home page Code Monkey logo

wallets-challenge's Introduction

Wallets challenge

Notes

  • The followed approach tries to charge first the money against the Stripe service and then update the wallet balance in the database. Another approach could be doing it the other way around and making use of the annotation @Transactional in order to rollback the database changes in case the Stripe service is down. However, there would be a small time window when the user would have the balance updated without being charged yet
  • The method 'refund' in class 'StripService' was fixed to call the refunds url (before it was calling the charges url)
  • The unit test class 'StripeServiceTest' was fixed. To avoid changing the provided implementation, the tests use Mockito and Java reflection to mock and test both the happy path and the error one
  • Hexagonal architecture is being used. Spring has been considered part of the infrastructure so there are no Spring annotations inside the 'application' folder. Use cases are being initialized inside 'infrastructure/configuration' folder

Improvements

  • The Stripe service doesn't allow charging an amount less than 10, so we could add a request validation (@Min) to do the same. This way we avoid database and service calls
  • Docker could be added to use a Postgres database instead of H2 as well as do some tests using Testcontainers
  • We could add some retry logic when trying to update the wallet in the database in case there is some database failure (@Retryable). Or we could send a Kafka event to do the database update for the same purpose

How to run

./mvnw clean install
./mvnw spring-boot:run

You can check the OpenAPI documentation:

You can test the GET endpoint like this: http://localhost:8090/api/v1/wallets/3ad80683-bc0a-483a-9e24-a7d0fff1c090

How to run tests

./mvnw clean install
./mvnw test

wallets-challenge's People

Contributors

sroigmas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.