/payment-authorization-module

Payment authorization module in nodejs

Primary LanguageTypeScript

Payment authorization module in nodejs

Small library that can understand json calls one per line and throw an answer after processing the lines

How to run it

  • npm i
  • npm run dev

Production run

npm start

How to use it

  • Multiple lines can be send at once
  • The program runs on console
  • After all json are send you start processing typing end

Rules allowed

  • max-limit

Business rules implemented

  • max-limit not set
  • payment-id already existed
  • insufficient-limit

Input examples

Set max limit. Always set the last one and reset the limit

{"payment-rules": {"max-limit": 100}}
{"payment-rules": {"max-limit": 200}}

Payment session already initialized

{"payment-rules": {"max-limit": 100}}
{"payment-session": {"payment-id": 89087653}}
{"payment-session": {"payment-id": 89087653}}

Payment rules not initialized

{"payment-session": {"payment-id": 89087653}}

Insufficient limit

{"payment-rules": {"max-limit": 100}}
{"payment-session": {"payment-id": 89087654, "cc": "visa", "amount": 120, "time": "2022-02-13T10:00:00.000Z"}}

More than three (3) transactions in two minutes

{"payment-rules": {"max-limit": 100}}
{"payment-session": {"payment-id": 89087654, "cc": "visa", "time": "2022-02-13T10:00:00.000Z"}}
{"payment-session": {"payment-id": 89087655, "cc": "visa", "time": "2022-02-13T10:01:00.000Z"}}
{"payment-session": {"payment-id": 89087656, "cc": "visa", "time": "2022-02-13T10:01:00.000Z"}}

Output example

{"payment-session": {"payment-id":89087652,"cc":"visa","amount":30,"time":"2022-02-13T10:00:00.000Z","available-limit":70,"violations":[]}}

Error Handling

  • There is no error handling in the app for json parsing. We assume the inputs are correct. Be aware of that
  • All errors that have a rule are considered violations and are returned in the output

References