Manage user interest accounts.
$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 |
- 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 to0.01%
,450
is equivalent to4.50%
and10000
is equivalent to100.00%
.
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,
]
);
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
);
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/'
);
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
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.
A GitHub Workflow (test
) automatically tests the library
against all PHP versions included in strategy.matrix.php
.
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