shrink / interviews-chip-interest

Manage user interest accounts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interest Accounts

Manage user interest accounts.

Usage

$userId = new UserId('88224979-406e-4e32-9458-55836e4e1f95');

OpensInterestAccounts::class->openInterestAccount($userId);

$account = OpensInterestAccounts::class->interestAccountByUserId($userId);

AwardsInterest::class->awardEarnedInterest($account);

$account->balance();
Contract Implementations
AwardsInterest MemoryInterestCalculator Awards interest to account earned during a period of days
CalculatesInterestRates IncomeBasedRate Calculates new Interest Account interest rate using User monthly income
OpensInterestAccounts MemoryAccountManager Opens Interest Account using calculated interest rate
ProvidesInterestAccounts MemoryAccountManager Provides Interest Accounts from memory
ProvidesUserInformation ChipUserApi Provides user information from the Chip HTTP API

Notes

  • All numeric values are used as integers to avoid floating point math errors that are possible with PHP. A percentage value should be passed as an integer representing the number of 1/100ths. For example, 1 is equivalent to 0.01%, 450 is equivalent to 4.50% and 10000 is equivalent to 100.00%.

Income Based Rates

Income based rates are calculated using a minimum required amount, with a default rate for any user that does not provide income information or does not meet any minimum requirements.

new IncomeBasedRate(
    $default = 50,
    $rates = [
      $minimum = 0 => $rate = 093,
      5000 => 102,
    ]
);

Memory Interest Calculator

Interest is calculated based on the Account balance, Account interest rate and the award frequency -- for example, an award frequency of 3 will award 3 days of interest on the balance. Any awards less than 1 penny (>0 <1) will be held until the total pending awards is at least 1 penny.

new MemoryInterestCalculator(
    $awardFrequency = 3,
    Lcobucci\Clock\Clock
);

Chip User API

The Chip User API provides user data over an http interface. You will need one or many packages that provide implementations of psr/http-{client,message,factory} to use this user information provider, such as guzzle.

new ChipUserApi(
    Psr\Http\Client\ClientInterface,
    Psr\Http\Message\ServerRequestFactoryInterface,
    'https://stats.dev.chip.test/'
);

Development

Docker is used to provide a development environment, which is available during the development lifecycle via the following make commands:

dev:~$ make help

  check             Run the library's code quality checks (test, analysis)
  help              List supported commands
  shell             Log in to the development container
  test              Run the library's tests

Code Quality

Strict code quality requirements are enforced for each commit, vimeo/psalm provides Static Analysis and code analysis is provided by nunomaduro/phpinsights -- these tools are configured in psalm.xml and insights.php respectively.

CI

A GitHub Workflow (test) automatically tests the library against all PHP versions included in strategy.matrix.php.

Hooks

A pre-commit Git Hook is included for ensuring compliance with code requirements on commit, enable the Git Hook by running the following command:

dev:~$ git config core.hooksPath .github/hooks

About

Manage user interest accounts.

License:MIT License


Languages

Language:PHP 96.5%Language:Makefile 1.9%Language:Dockerfile 1.3%Language:Shell 0.4%