PHP code example of amreljako / laravel-ledger-guard

1. Go to this page and download the library: Download amreljako/laravel-ledger-guard 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/ */

    

amreljako / laravel-ledger-guard example snippets


return [

    /*
    |--------------------------------------------------------------------------
    | Default Currency
    |--------------------------------------------------------------------------
    | The default ISO currency code used when creating a new ledger wallet.
    */
    'default_currency' => 'EGP',

    /*
    |--------------------------------------------------------------------------
    | Auto-Freeze on Tamper
    |--------------------------------------------------------------------------
    | When enabled, the package will instantly freeze the ledger if any
    | cryptographic chain misalignment or direct database manipulation
    | is detected.
    */
    'auto_freeze_on_tamper' => true,

];

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Amreljako\LedgerGuard\Traits\HasLedger;

class User extends Authenticatable
{
    use HasLedger;
}

use Amreljako\LedgerGuard\Facades\LedgerGuard;

// Fetch or create user ledger for a specific currency
$ledger = $user->ledger()->firstOrCreate(['currency' => 'EGP']);

// Safely credit funds with encrypted tracking metadata
LedgerGuard::credit($ledger, 1500.50, [
    'reference_id' => 'TXN_99821',
    'gateway'      => 'Paymob',
    'description'  => 'Wallet Top up via Credit Card',
]);

use Amreljako\LedgerGuard\Facades\LedgerGuard;
use Illuminate\Support\Facades\Log;

try {
    $ledger = $user->ledger()->where('currency', 'EGP')->first();

    LedgerGuard::debit($ledger, 250.00, [
        'order_id' => 'ORD_5541',
        'item'     => 'Cyberpunk Minimalist Hooded Jacket',
    ]);

    echo "Payment successful! Balance securely updated.";

} catch (\Exception $e) {
    // Automatically catches Insufficient Funds, Frozen Accounts,
    // or Tampered Chains
    Log::alert("Transaction blocked: " . $e->getMessage());
}

// Returns a float representing the absolute safe balance
$secureBalance = $user->walletBalance('EGP');
bash
php artisan vendor:publish \
  --provider="Amreljako\LedgerGuard\LedgerGuardServiceProvider" \
  --tag="ledger-guard-migrations"

php artisan migrate
bash
php artisan vendor:publish \
  --provider="Amreljako\LedgerGuard\LedgerGuardServiceProvider" \
  --tag="ledger-guard-config"