PHP code example of yemeni-open-source / laravel-wallet

1. Go to this page and download the library: Download yemeni-open-source/laravel-wallet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yemeni-open-source / laravel-wallet example snippets


use YemeniOpenSource\LaravelWallet\Traits\HasWallet;

class User extends Model
{
    use HasWallet;

    //...
}


// The wallet balance initially will be [0]
$user = User::first();
$user->wallet->balance; // 0

// This will add to the wallet balance as passed amount.
$user->wallet->deposit(643.646);
$user->wallet->balance; // 643.6460

// This will subtract from the wallet balance as passed amount.
$user->wallet->withdraw(168.545);
$user->wallet->balance; // 475.1010

// It will throw [UnacceptedTransactionException] exception if passed amount greater wallet balance 
$user->wallet->withdraw(500);
$user->wallet->balance; // UnacceptedTransactionException

// If you want to force withdraw, use [forceWithdraw]
$user->wallet->forceWithdraw(500);
$user->wallet->balance; // -24.8990

$user = User::first();
$user->wallet->deposit(100, ['currency' => 'USD', 'bank' => 'TEST BANK']);
$user->wallet->withdraw(64, ['currency' => 'USD', 'description' => 'Purchase of Item #101']);
$user->wallet->withdraw(64, ['currency' => 'USD', 'transfer' => 'Western union tracking number #101']);
sh
php artisan vendor:publish --provider="YemeniOpenSource\LaravelWallet\WalletServiceProvider" --tag=config
config/wallet.php
sh
php artisan migrate
sh
php artisan vendor:publish --provider="YemeniOpenSource\LaravelWallet\WalletServiceProvider" --tag=migrations