1. Go to this page and download the library: Download vergatan10/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/ */
vergatan10 / laravel-wallet example snippets
// App/Models/User.php
use Vergatan10\Wallet\Models\Wallet;
// relasi ke wallet
public function wallet()
{
return $this->hasOne(Wallet::class);
}
// UserController.php
use Illuminate\Auth\Events\Registered;
use Illuminate\Support\Facades\Event;
// create user
$user = User::create([...]);
// tambahkan kode ini untuk menjalankan event
event(new Registered($user));
use Vergatan10\Wallet\Facades\Wallet;
use Vergatan10\Wallet\Models\Wallet as WalletModel;
$wallet = WalletModel::find(1);
// Deposit
Wallet::deposit($wallet, 10000, 'Topup manual');
// Withdraw
Wallet::withdraw($wallet, 5000, 'Penarikan');
// Transfer
Wallet::transfer($fromWallet, $toWallet, 2500, 'Transfer antar user');
// Refund transaksi
Wallet::refund($transaction);
// Lock / Unlock
$wallet->update(['is_locked' => true]);
public function test_user_can_deposit()
{
$wallet = Wallet::factory()->create();
Wallet::deposit($wallet, 10000, 'Test deposit');
$this->assertEquals(10000, $wallet->fresh()->balance);
}