{"id":13563899,"url":"https://github.com/bavix/laravel-wallet","last_synced_at":"2025-05-13T18:09:13.505Z","repository":{"id":37663250,"uuid":"156552715","full_name":"bavix/laravel-wallet","owner":"bavix","description":"It's easy to work with a virtual wallet","archived":false,"fork":false,"pushed_at":"2025-04-24T21:20:30.000Z","size":5410,"stargazers_count":1207,"open_issues_count":4,"forks_count":240,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-05-02T22:35:32.198Z","etag":null,"topics":["balance","composer","eloquent","laravel","laravel-wallet","multi-wallet","php","purchase","virtual","wallet"],"latest_commit_sha":null,"homepage":"https://bavix.github.io/laravel-wallet/","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/bavix.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"open_collective":"laravel-wallet","custom":["https://www.tinkoff.ru/cf/1OkIPwTvTLf"]}},"created_at":"2018-11-07T13:45:32.000Z","updated_at":"2025-04-27T14:35:56.000Z","dependencies_parsed_at":"2023-12-28T07:41:35.314Z","dependency_job_id":"307b805d-efcf-4245-b4ae-e93d6c76a978","html_url":"https://github.com/bavix/laravel-wallet","commit_stats":{"total_commits":1748,"total_committers":29,"mean_commits":"60.275862068965516","dds":"0.37471395881006864","last_synced_commit":"771566015bfc6335ef8dfff28acf5a11606dbe6b"},"previous_names":[],"tags_count":157,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bavix%2Flaravel-wallet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bavix%2Flaravel-wallet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bavix%2Flaravel-wallet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bavix%2Flaravel-wallet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bavix","download_url":"https://codeload.github.com/bavix/laravel-wallet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000850,"owners_count":21997441,"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":["balance","composer","eloquent","laravel","laravel-wallet","multi-wallet","php","purchase","virtual","wallet"],"created_at":"2024-08-01T13:01:24.378Z","updated_at":"2025-05-13T18:09:13.479Z","avatar_url":"https://github.com/bavix.png","language":"PHP","funding_links":["https://opencollective.com/laravel-wallet","https://www.tinkoff.ru/cf/1OkIPwTvTLf","https://opencollective.com/laravel-wallet/contribute"],"categories":["PHP"],"sub_categories":[],"readme":"![Laravel Wallet](https://github.com/bavix/laravel-wallet/assets/5111255/95e7877c-a950-4b04-9414-de62216d31c2)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/588400f5f40cbbf3a8ab/maintainability)](https://codeclimate.com/github/bavix/laravel-wallet/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/588400f5f40cbbf3a8ab/test_coverage)](https://codeclimate.com/github/bavix/laravel-wallet/test_coverage) [![Financial Contributors on Open Collective](https://opencollective.com/laravel-wallet/all/badge.svg?label=financial+contributors)](https://opencollective.com/laravel-wallet) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fbavix%2Flaravel-wallet%2Fmaster)](https://packagist.org/packages/bavix/laravel-wallet)\n\n[![Latest Stable Version](https://poser.pugx.org/bavix/laravel-wallet/v)](https://packagist.org/packages/bavix/laravel-wallet) [![Latest Unstable Version](https://poser.pugx.org/bavix/laravel-wallet/v/unstable)](https://packagist.org/packages/bavix/laravel-wallet) [![License](https://poser.pugx.org/bavix/laravel-wallet/license)](https://packagist.org/packages/bavix/laravel-wallet) [![composer.lock](https://poser.pugx.org/bavix/laravel-wallet/composerlock)](https://packagist.org/packages/bavix/laravel-wallet)\n\n[![Sparkline](https://stars.medv.io/bavix/laravel-wallet.svg)](https://stars.medv.io/bavix/laravel-wallet)\n\nlaravel-wallet - It's easy to work with a virtual wallet.\n\n[[Benchmark](https://github.com/bavix/laravel-wallet-benchmark/)] \n[[Documentation](https://bavix.github.io/laravel-wallet/)] \n[[Get Started](https://bavix.github.io/laravel-wallet/guide/introduction/)] \n\n* **Vendor**: bavix\n* **Package**: laravel-wallet\n* **[Composer](https://getcomposer.org/):** `composer require bavix/laravel-wallet`\n\n### Support Policy\n\n| Version    | Laravel        | PHP             | Release date | End of improvements | End of support |\n|------------|----------------|-----------------|--------------|---------------------|----------------|\n| 11.x [LTS] | ^11.0, ^12.0   | 8.2,8.3,8.4     | Mar 14, 2024 | May 1, 2026         | Sep 6, 2026    |\n\n### Upgrade Guide\n\nTo perform the migration, you will be [helped by the instruction](https://bavix.github.io/laravel-wallet/#/upgrade-guide).\n\n### Community\n\nI want to create a cozy place for developers using the wallet package. This will help you find bugs faster, get feedback and discuss ideas.\n\n![telegram](https://github.com/bavix/laravel-wallet/assets/5111255/ed2b1193-c0c6-41af-83cb-0fe61ae8df21)\n\n\nTelegram: [@laravel_wallet](https://t.me/laravel_wallet)\n\n### Extensions\n\n| Extension                                                 | Description                                                                |\n|-----------------------------------------------------------|----------------------------------------------------------------------------|\n| [Swap](https://github.com/bavix/laravel-wallet-swap)      | Addition to the laravel-wallet library for quick setting of exchange rates |\n| [uuid](https://github.com/bavix/laravel-wallet-uuid)      | Addition to laravel-wallet to support model uuid keys                      | \n| [Warm Up](https://github.com/bavix/laravel-wallet-warmup) | Addition to the laravel-wallet library for refresh balance wallets         | \n\n### Usage\nAdd the `HasWallet` trait and `Wallet` interface to model.\n```php\nuse Bavix\\Wallet\\Traits\\HasWallet;\nuse Bavix\\Wallet\\Interfaces\\Wallet;\n\nclass User extends Model implements Wallet\n{\n    use HasWallet;\n}\n```\n\nNow we make transactions.\n\n```php\n$user = User::first();\n$user-\u003ebalanceInt; // 0\n\n$user-\u003edeposit(10);\n$user-\u003ebalance; // 10\n$user-\u003ebalanceInt; // int(10)\n\n$user-\u003ewithdraw(1);\n$user-\u003ebalance; // 9\n\n$user-\u003eforceWithdraw(200, ['description' =\u003e 'payment of taxes']);\n$user-\u003ebalance; // -191\n```\n\n### Purchases\n\nAdd the `CanPay` trait and `Customer` interface to your `User` model.\n```php\nuse Bavix\\Wallet\\Traits\\CanPay;\nuse Bavix\\Wallet\\Interfaces\\Customer;\n\nclass User extends Model implements Customer\n{\n    use CanPay;\n}\n```\n\nAdd the `HasWallet` trait and interface to `Item` model.\n\nStarting from version 9.x there are two product interfaces:\n- For an unlimited number of products (`ProductInterface`);\n- For a limited number of products (`ProductLimitedInterface`);\n\nAn example with an unlimited number of products:\n```php\nuse Bavix\\Wallet\\Traits\\HasWallet;\nuse Bavix\\Wallet\\Interfaces\\Customer;\nuse Bavix\\Wallet\\Interfaces\\ProductInterface;\n\nclass Item extends Model implements ProductInterface\n{\n    use HasWallet;\n\n    public function getAmountProduct(Customer $customer): int|string\n    {\n        return 100;\n    }\n\n    public function getMetaProduct(): ?array\n    {\n        return [\n            'title' =\u003e $this-\u003etitle, \n            'description' =\u003e 'Purchase of Product #' . $this-\u003eid,\n        ];\n    }\n}\n```\n\nExample with a limited number of products:\n```php\nuse Bavix\\Wallet\\Traits\\HasWallet;\nuse Bavix\\Wallet\\Interfaces\\Customer;\nuse Bavix\\Wallet\\Interfaces\\ProductLimitedInterface;\n\nclass Item extends Model implements ProductLimitedInterface\n{\n    use HasWallet;\n\n    public function canBuy(Customer $customer, int $quantity = 1, bool $force = false): bool\n    {\n        /**\n         * This is where you implement the constraint logic. \n         * \n         * If the service can be purchased once, then\n         *  return !$customer-\u003epaid($this);\n         */\n        return true; \n    }\n    \n    public function getAmountProduct(Customer $customer): int|string\n    {\n        return 100;\n    }\n\n    public function getMetaProduct(): ?array\n    {\n        return [\n            'title' =\u003e $this-\u003etitle, \n            'description' =\u003e 'Purchase of Product #' . $this-\u003eid,\n        ];\n    }\n}\n```\n\nI do not recommend using the limited interface when working with a shopping cart. \nIf you are working with a shopping cart, then you should override the `PurchaseServiceInterface` interface. \nWith it, you can check the availability of all products with one request, there will be no N-queries in the database.\n\nProceed to purchase.\n\n```php\n$user = User::first();\n$user-\u003ebalance; // 100\n\n$item = Item::first();\n$user-\u003epay($item); // If you do not have enough money, throw an exception\nvar_dump($user-\u003ebalance); // 0\n\nif ($user-\u003esafePay($item)) {\n  // try to buy again\n}\n\nvar_dump((bool)$user-\u003epaid($item)); // bool(true)\n\nvar_dump($user-\u003erefund($item)); // bool(true)\nvar_dump((bool)$user-\u003epaid($item)); // bool(false)\n```\n\n### Eager Loading\n\n```php\n// When working with one wallet\nUser::with('wallet');\n\n// When using the multi-wallet functionality\nUser::with('wallets');\n```\n\n### How to work with fractional numbers?\nAdd the `HasWalletFloat` trait and `WalletFloat` interface to model.\n```php\nuse Bavix\\Wallet\\Traits\\HasWalletFloat;\nuse Bavix\\Wallet\\Interfaces\\WalletFloat;\nuse Bavix\\Wallet\\Interfaces\\Wallet;\n\nclass User extends Model implements Wallet, WalletFloat\n{\n    use HasWalletFloat;\n}\n```\n\nNow we make transactions.\n\n```php\n$user = User::first();\n$user-\u003ebalance; // 100\n$user-\u003ebalanceFloat; // 1.00\n\n$user-\u003edepositFloat(1.37);\n$user-\u003ebalance; // 237\n$user-\u003ebalanceFloat; // 2.37\n```\n\n### Performance Comparison\n\nAll versions:\n|            Name            |  7.3   |  8.4   |  9.6   |  10.1  |  11.0  |\n|----------------------------|--------|--------|--------|--------|--------|\n| Atomic:Blocks              | -      | -      | 484ms  | 493ms  | 493ms  |\n| Cart:EagerLoaderPay        | 22s    | 679ms  | 493ms  | 530ms  | 652ms  |\n| Cart:Pay                   | 1.36s  | 472ms  | 288ms  | 298ms  | 336ms  |\n| Cart:PayFree               | 1.3s   | 415ms  | 281ms  | 291ms  | 287ms  |\n| Cart:PayOneItemXPieces     | 565ms  | 118ms  | 59.1ms | 64.6ms | 66.2ms |\n| Gift:Gift                  | 44.8ms | 53.5ms | 54.3ms | 58.4ms | 64.3ms |\n| Gift:Refund                | 106ms  | 112ms  | 108ms  | 111ms  | 139ms  |\n| Solo:Deposit               | 27.4ms | 31.8ms | 31ms   | 33.3ms | 30.1ms |\n| Solo:EagerLoading          | 904ms  | 1.09s  | 876ms  | 927ms  | 1.02s  |\n| Solo:ForceWithdraw         | 27.6ms | 31.8ms | 30.7ms | 32.9ms | 30ms   |\n| Solo:GetBalance            | 20.8ms | 24ms   | 23.7ms | 23.4ms | 20ms   |\n| Solo:Transfer              | 39.4ms | 45.7ms | 42ms   | 44.9ms | 46.6ms |\n| Solo:Withdraw              | 31.1ms | 36.3ms | 34.9ms | 37.3ms | 37.8ms |\n| State:InTransaction        | 570ms  | 566ms  | 419ms  | 425ms  | 427ms  |\n| State:RefreshInTransaction | 32.3ms | 41.2ms | 41.2ms | 45.6ms | 47.2ms |\n| State:TransactionRollback  | 29.7ms | 34.1ms | 32.9ms | 37.2ms | 36.9ms |\n\nTable generated using [benchmark](https://github.com/bavix/laravel-wallet-benchmark/). [Pull Request](https://github.com/bavix/laravel-wallet-benchmark/pull/51).\n\n## Contributors\n\n### Code Contributors\n\nThis project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].\n\u003ca href=\"https://github.com/bavix/laravel-wallet/graphs/contributors\"\u003e\u003cimg src=\"https://opencollective.com/laravel-wallet/contributors.svg?width=890\u0026button=false\" /\u003e\u003c/a\u003e\n\n### Financial Contributors\n\nBecome a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/laravel-wallet/contribute)]\n\n#### Individuals\n\n\u003ca href=\"https://opencollective.com/laravel-wallet\"\u003e\u003cimg src=\"https://opencollective.com/laravel-wallet/individuals.svg?width=890\"\u003e\u003c/a\u003e\n\n#### Organizations\n\nSupport this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/laravel-wallet/contribute)]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbavix%2Flaravel-wallet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbavix%2Flaravel-wallet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbavix%2Flaravel-wallet/lists"}