mirror of
https://github.com/wahyd4/afterpay-creditcard.git
synced 2026-08-08 21:06:52 +10:00
master
Credit card fraud check
How to run the application
I don't have an demo application to run the method because I think the unit tests are enough to show how to run it already.
How to run the tests
With Docker
docker-compose run app
If you have JAVA 8+ installed
./gradlew clean test
Jacoco test coverage
docker-compose run app gradle jacocoTestReport
Then go to build/reports/jacoco/test/html/index.html to see the result.
How the method works
The fraudulentCreditCards method in com.github.wahyd4.creditcard.service.FraudChecker receives list of transactions string and threshold to calculate all the credit cards which exceed the money threshold.
- First, all the transaction string records will be parsed into a TransactionEntry object.
- Then loops the entries, it groups all the transactions by hashed credit card id, the value of the key is all the records for that hashed id.
- During this time, the program analyses all the records for the specific card comes from the current entry. If the records overs one
24hours windows, then only keep the most recent24hours records. If the card has been marked as fraudulent, then it will skipped. - Calculates the total amount against the most recent
24hours records, if the value greater than the threshold then mark the card asfraudulentand put it into themap. - Returns all the matched hashed credit cards as a list.
Assumptions
a sequence of transactions in chronological ordermeans the first item in the list is the oldest record.
Highlights
- Wrote code with TDD
- Docker-compose to make run the code in local much easier
Languages
Java
100%