Implement a function that authorizes a transaction for a specific account, following some predefined rules.
You'll receive as input:
-
The account data
- Card status (
active
orblocked
) - Current available limit, i.e., the amount available for purchases for the account.
- Card status (
-
Transaction to be authorized
- Merchant (the name is enough)
- Amount
- Time of the transaction
-
List of approved transactions (using the same data model of the transaction to be authorized)
The output should consist of:
- Whether the purchase was authorized or not
- The updated available limit for the account
- All of the reasons why the transaction was denied, when relevant.
- The transaction amount should not be above the account limit
- No transaction should be approved when the card is blocked
- The first transaction shouldn't be above 90% of the limit
- There should not be more than 10 transactions for the same merchant
- Transactions from a list of denied merchants should not be approved
- There should not be more than 3 approved transactions on a 2 minutes interval
- There should not be more than 2 similar transactions (same amount and merchant) in a 2 minutes interval
Here are some tips that might help you think about the problem and implement the solution:
- Consider starting by implementing few rules and then expanding your solution to support the rest.
- Consider designing the solution as if you were implementing the business logic layer of a service/application.
- The examples below (in Clojure) suggest how the data structures and function signatures could look like. These are just suggestions; you can use modified versions of the schemas.