https://github.com/stephenjude/laravel-wallet
A simple wallet implementation for Laravel.
https://github.com/stephenjude/laravel-wallet
laravel wallet
Last synced: 7 months ago
JSON representation
A simple wallet implementation for Laravel.
- Host: GitHub
- URL: https://github.com/stephenjude/laravel-wallet
- Owner: stephenjude
- License: mit
- Created: 2022-05-10T15:53:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-04T07:51:24.000Z (over 1 year ago)
- Last Synced: 2024-04-13T22:49:51.956Z (over 1 year ago)
- Topics: laravel, wallet
- Language: PHP
- Homepage:
- Size: 60.5 KB
- Stars: 251
- Watchers: 8
- Forks: 21
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Laravel Wallet
[](https://packagist.org/packages/stephenjude/laravel-wallet)
[](https://github.com/stephenjude/laravel-wallet/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/stephenjude/laravel-wallet/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[](https://packagist.org/packages/stephenjude/laravel-wallet)
A simple wallet implementation for Laravel.
## Learn More
- [A Simple Wallet Implementation for Laravel - Laravel News](https://laravel-news.com/laravel-wallet)
- [Interfaces and Traits: How to Use Them in Laravel Packages - Laravel Daily](https://www.youtube.com/watch?v=s2vF84rSaEA)
- [Laravel Virtual Wallet with Coupons: 3 Packages Demo - Laravel Daily](https://www.youtube.com/watch?v=Rgu7iEpXRFM&t=44s)
## Installation
You can install the package via composer:
```bash
composer require stephenjude/laravel-wallet
```
You can publish and run the migrations with:
```bash
php artisan vendor:publish --tag="wallet-migrations"
php artisan migrate
```
[//]: # ()
[//]: # (```bash)
[//]: # (php artisan vendor:publish --tag="wallet-config")
[//]: # (```)
## Usage
### Prepare User Model
```php
use Stephenjude\Wallet\Interfaces\Wallet;
use Stephenjude\Wallet\Traits\HasWallet;
class User extends Authenticatable implements Wallet
{
use HasWallet;
}
```
### Deposit
```php
$user = User::first();
$user->deposit(200.22); // returns the wallet balance: 200.22
$user->deposit(200); // returns the wallet balance: 400.22
```
### Withdraw
```php
$user->withdraw(200); // returns the wallet balance: 200.22
$user->withdraw(0.22); // returns the wallet balance: 200
```
### Balance
```php
$user->balance
$user->wallet_balance
```
### Exceptions
#### InvalidAmountException
The `InvalidAmountException` is thrown whenever the deposit or withdrawal amount is a negative numeric value or zero.
#### InsufficientFundException
The `InsufficientFundException` is thrown whenever the withdrawal amount is less than the user's wallet balance.
### Alternative Package
If you are looking for somthing much bigger and elaborate checkout [Bavix Laravel Wallet](https://bavix.github.io/laravel-wallet/#/).
## Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [stephenjude](https://github.com/stephenjude)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.