{"id":23110514,"url":"https://github.com/shrink/interviews-chip-interest","last_synced_at":"2025-04-03T23:28:46.455Z","repository":{"id":67764056,"uuid":"303995148","full_name":"shrink/interviews-chip-interest","owner":"shrink","description":"Manage user interest accounts.","archived":false,"fork":false,"pushed_at":"2020-10-16T11:36:47.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-09T11:26:59.313Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shrink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-14T11:33:56.000Z","updated_at":"2020-12-23T12:32:35.000Z","dependencies_parsed_at":"2023-02-21T01:16:11.118Z","dependency_job_id":null,"html_url":"https://github.com/shrink/interviews-chip-interest","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrink%2Finterviews-chip-interest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrink%2Finterviews-chip-interest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrink%2Finterviews-chip-interest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shrink%2Finterviews-chip-interest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shrink","download_url":"https://codeload.github.com/shrink/interviews-chip-interest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247096461,"owners_count":20882943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-17T01:49:18.308Z","updated_at":"2025-04-03T23:28:46.450Z","avatar_url":"https://github.com/shrink.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Interest Accounts\n\nManage user interest accounts.\n\n## Usage\n\n```php\n$userId = new UserId('88224979-406e-4e32-9458-55836e4e1f95');\n\nOpensInterestAccounts::class-\u003eopenInterestAccount($userId);\n\n$account = OpensInterestAccounts::class-\u003einterestAccountByUserId($userId);\n\nAwardsInterest::class-\u003eawardEarnedInterest($account);\n\n$account-\u003ebalance();\n```\n\n| Contract | Implementations |\n| -------- | -------------- |\n| [`AwardsInterest`][awards-interest] | [`MemoryInterestCalculator`][memory-interest-calculator] Awards interest to account earned during a period of days |\n| [`CalculatesInterestRates`][calculates-interest-rates] | [`IncomeBasedRate`][income-based-rate] Calculates new Interest Account interest rate using User monthly income |\n| [`OpensInterestAccounts`][opens-interest-accounts] | [`MemoryAccountManager`][memory-account-manager]  Opens Interest Account using calculated interest rate |\n| [`ProvidesInterestAccounts`][provides-interest-accounts] | [`MemoryAccountManager`][memory-account-manager] Provides Interest Accounts from memory |\n| [`ProvidesUserInformation`][provides-users-information] | [`ChipUserApi`][chip-user-api] Provides user information from the Chip HTTP API |\n\n### Notes\n\n* All numeric values are used as integers to avoid floating point math errors\nthat are possible with PHP. A percentage value should be passed as an integer\nrepresenting the number of 1/100ths. For example, `1` is equivalent to `0.01%`,\n`450` is equivalent to `4.50%` and `10000` is equivalent to `100.00%`.\n\n### Income Based Rates\n\nIncome based rates are calculated using a minimum required amount, with a\ndefault rate for any user that does not provide income information or does not\nmeet any minimum requirements.\n\n```php\nnew IncomeBasedRate(\n    $default = 50,\n    $rates = [\n      $minimum = 0 =\u003e $rate = 093,\n      5000 =\u003e 102,\n    ]\n);\n```\n\n### Memory Interest Calculator\n\nInterest is calculated based on the Account balance, Account interest rate and\nthe award frequency -- for example, an award frequency of `3` will award 3 days\nof interest on the balance. Any awards less than 1 penny (`\u003e0 \u003c1`) will be held\nuntil the total pending awards is at least 1 penny.\n\n```php\nnew MemoryInterestCalculator(\n    $awardFrequency = 3,\n    Lcobucci\\Clock\\Clock\n);\n```\n\n### Chip User API\n\nThe Chip User API provides user data over an http interface. You will need one\nor many packages that\n[provide implementations of `psr/http-{client,message,factory}`][http-clients]\nto use this user information provider, such as [`guzzle`][guzzle].\n\n```php\nnew ChipUserApi(\n    Psr\\Http\\Client\\ClientInterface,\n    Psr\\Http\\Message\\ServerRequestFactoryInterface,\n    'https://stats.dev.chip.test/'\n);\n```\n\n## Development\n\nDocker is used to provide a development environment, which is available during\nthe development lifecycle via the following `make` commands:\n\n```console\ndev:~$ make help\n\n  check             Run the library's code quality checks (test, analysis)\n  help              List supported commands\n  shell             Log in to the development container\n  test              Run the library's tests\n```\n\n### Code Quality\n\nStrict code quality requirements are enforced for each commit,\n[`vimeo/psalm`][psalm] provides Static Analysis and code analysis is provided by\n[`nunomaduro/phpinsights`][php-insights] -- these tools are configured in\n[`psalm.xml`](psalm.xml) and [`insights.php`](insights.php) respectively.\n\n### CI\n\nA GitHub Workflow ([`test`][workflows-test]) automatically tests the library\nagainst all PHP versions included in `strategy.matrix.php`.\n\n### Hooks\n\nA pre-commit Git Hook is included for ensuring compliance with code\nrequirements on commit, enable the Git Hook by running the following command:\n\n```console\ndev:~$ git config core.hooksPath .github/hooks\n```\n\n[workflows-test]: .github/workflows/test.yml\n[psalm]: https://psalm.dev\n[php-insights]: https://phpinsights.com\n[http-clients]: https://packagist.org/providers/psr/http-client-implementation\n[guzzle]: https://github.com/guzzle/guzzle\n[awards-interest]: src/Interest/AwardsInterest.php\n[memory-interest-calculator]: src/Interest/MemoryInterestCalculator.php\n[calculates-interest-rates]: src/Interest/CalculatesInterestRates.php\n[income-based-rate]: src/Interest/IncomeBasedRate.php\n[opens-interest-accounts]: src/Interest/OpensInterestAccounts.php\n[memory-account-manager]: src/Interest/MemoryAccountManager.php\n[provides-interest-accounts]: src/Interest/ProvidesInterestAccounts.php\n[provides-users-information]: src/Interest/ProvidesUserInformation.php\n[chip-user-api]: src/Interest/ChipUserApi.php\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshrink%2Finterviews-chip-interest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshrink%2Finterviews-chip-interest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshrink%2Finterviews-chip-interest/lists"}