Professional Documents
Culture Documents
Authorizer
You are tasked with implementing an application that authorizes a transaction for a specific
account following a set of predefined rules.
Please read the instructions below, and feel free to ask for clarifications if needed.
Sample usage
Your program is going to be provided json lines as input in the stdin and should provide a json
line output for each one — imagine this as a stream of events arriving at the authorizer.
Input
{"account": {"id": 1, "active-card": true, "available-limit": 100}}
{"transaction": {"id": 1, "merchant": "Burger King", "amount": 20,
"time":"2019-02-13T10:00:00.000Z"}}
{"transaction": {"id": 1, "merchant": "Habbib's", "amount": 90, "time":
"2019-02-13T11:00:00.000Z"}}
Output
{"account": {"id": 1, "active-card": t
rue, " available-limit": 1 00}, "violations": []}
{"account": {"id": 1, "active-card": t rue, " available-limit": 8 0}, "violations": []}
{"account": {"id": 1, "active-card": t rue, " available-limit": 8 0}, "violations":
["insufficient-limit"]}
State
The program should not rely on any external database. The internal state should be handled
by an explicit in-memory structure. The state is to be reset at the application start.
Operations
The program handles two kinds of operations, deciding on which one according to the line that
is being processed:
1. Account creation
2. Transaction authorization
Monetary values are positive and negative integers using a currency without cents.
Account creation
Input
Output
The created account's current state plus any business logic violations.
Business rules
input
, "
{"account": {"id": 1 active-card": t rue, " available-limit": 1 00}}
{"account": {"id": 2 , " active-card": t rue, " available-limit": 3 50}}
{"account": {"id": 1 , " active-card": t rue, " available-limit": 3 50}}
output
{"account": {"active-card": true, "
available-limit": 1 00}, " violations": []}
{"account": {"active-card": true, " available-limit": 3 50}, " violations": []}
{"account": {"active-card": true, " available-limit": 1 00}, " violations":
["account-already-initialized" ]}
Transaction authorization
Input
Tries to authorize a transaction for a particular merchant, amount and time given the
account's state and last authorized transactions.
Output
Business rules
You should implement the following rules, keeping in mind new rules will appear in the future:
Input
{"transaction": {"merchant": "Burger King", "amount": 20, "time":
"2019-02-13T10:00:00.000Z"}}
Output
{"account": {"active-card": true, "available-limit": 80}, "violations":
[]}
Input
{"transaction": {"merchant": "Habbib's", "amount": 90, "time":
"2019-02-13T11:00:00.000Z"}}
Output
{"account": {"active-card": true, "available-limit": 80}, "violations":
["insufficient-limit"]}
Error handling
Please assume input parsing errors could be happened, as well data errors (as negative
amounts).
Violations of the business rules are not considered to be errors as they are expected to happen
and should be listed in the outputs' violations field as described on the output schema in the
examples. That means the program execution should continue normally after any violation.
Our expectations
We at Lulo Bank value simple, elegant, and working code. This exercise should reflect your
understanding of it.