{"id":37000620,"url":"https://github.com/roboticsexpert/balance-manager","last_synced_at":"2026-01-14T00:04:08.639Z","repository":{"id":43580089,"uuid":"462300093","full_name":"roboticsexpert/balance-manager","owner":"roboticsexpert","description":"Balance manager system for laravel","archived":false,"fork":false,"pushed_at":"2023-01-05T11:38:27.000Z","size":18,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-17T05:13:42.946Z","etag":null,"topics":["balance","credit","cryptocurrency","decimal","double-spending","laravel","php","race-conditions"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/roboticsexpert.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-22T13:02:20.000Z","updated_at":"2022-02-26T14:30:11.000Z","dependencies_parsed_at":"2022-07-22T18:33:04.572Z","dependency_job_id":null,"html_url":"https://github.com/roboticsexpert/balance-manager","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/roboticsexpert/balance-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboticsexpert%2Fbalance-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboticsexpert%2Fbalance-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboticsexpert%2Fbalance-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboticsexpert%2Fbalance-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/roboticsexpert","download_url":"https://codeload.github.com/roboticsexpert/balance-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/roboticsexpert%2Fbalance-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["balance","credit","cryptocurrency","decimal","double-spending","laravel","php","race-conditions"],"created_at":"2026-01-14T00:04:08.202Z","updated_at":"2026-01-14T00:04:08.632Z","avatar_url":"https://github.com/roboticsexpert.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Balance manager\n\nin many projects, you need to have credit (balance) concept for your user that make you distract from your main business\nlogic.\n\nwith this package you will have balance for your users easily without being worry about `Race Condition`\nand `Double Spending`.\n\nthis project mainly designed for exchange systems, but you can use it in any project.\n\n## Installation\n\n```php\ncomposer require roboticsexpert/balance-manager\n```\n\nafter instaling composer package, if you use auto discovery for service providers, everything ok, but if you blocked\nthat just add this line to `config/app.php` in `providers` section:\n\n```php\nRoboticsexpert\\BalanceManager\\BalanceManagerServiceProvider::class\n```\n\nafter that you should run\n\n```bash \nphp artisan migrate\n```\n\nand this:\n\n```bash \nphp artisan vendor:publish --provider=\"Roboticsexpert\\BalanceManager\\BalanceManagerServiceProvider\"\n```\n\nit will create `balance.php` file in your config file.\n\n## Usage\n\nFirst of all, you should decide with currencies you want to have in your system, and consider a KEY for each currency\nand add those keys in balance.php config file\n\n```php\nreturn [\n\n    // add symbols of your currencies\n    // symbols must be lower than 16 char\n\n    'currencies'=\u003e[\n        'BTC',\n        'TMN',\n        'DOGE',\n    ]\n];\n```\n\nyou can use this project with 2 strategy,Facade or Dependency injection!\n\nI suggest to you to use it with dependecy injection for IDE auto complete feature but use it as you prefer!\n\nafter that you can get `BalanceManager` from with these to methods:\n\n### Facade\n\nyou can get BalanceManager service like this:\n\n```php\nuse Roboticsexpert\\BalanceManager\\BalanceManagerFacade as BalanceManager;\n\n\nBalanceManager::getAllBalancesByUserId(1)\n```\n\n### Dependency Injection\n\nyou can get BalanceManager service from `app()` like this:\n\n```php\nuse Roboticsexpert\\BalanceManager\\Services\\BalanceManager;\n\n$balanceManager=app(BalanceManager::class); \n\n$balanceManager-\u003egetAllBalancesByUserId(1);\n```\n\nor get from laravel automatic dependency injection\n\n```php\nuse Roboticsexpert\\BalanceManager\\Services\\BalanceManager;\nclass Controller extends BaseController\n{\n    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;\n\n    public function index(BalanceManager $balanceManager){\n        dd($balanceManager-\u003egetAllBalancesByUserId(1));\n    }\n}\n\n```\n\n## Methods\n\n### Get all balance for user\n\nit will return array of `Balance` model\n\n```php\n$balances= $balanceManager-\u003egetAllBalancesByUserId(\"USER_ID\");\ndd($balances);\n```\n\n### Change balance of user\n\n```php\n$balanceChangeResult= $balanceManager-\u003echangeBalanceByUserIdAndCurrency(\n        int $userId, //user id\n        string $currency, // like USDT, TMN\n        string $reason, // a unique string for each action\n        IBalanceHistoryRelated $model, // a model that is author of change balance\n        Decimal $valueChange, // value you want to add or sub from user balance\n        Decimal $lockedValueChange // in general usage it should be new \\Decimal\\Decimal(0)\n);\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froboticsexpert%2Fbalance-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froboticsexpert%2Fbalance-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froboticsexpert%2Fbalance-manager/lists"}