PHP code example of hamadou / fundry

1. Go to this page and download the library: Download hamadou/fundry 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/ */

    

hamadou / fundry example snippets




namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Hamadou\Fundry\Traits\HasWallets;

class User extends Authenticatable
{
    use HasWallets;
}

use Hamadou\Fundry\Facades\Fundry;
use Hamadou\Fundry\Enums\WalletType;
use Hamadou\Fundry\Models\Currency;

$usd = Currency::findByIsoCode('USD');

$wallet = Fundry::createWallet($user, [
    'currency_id'       => $usd->id,
    'name'              => 'Portefeuille Principal USD',
    'type'              => WalletType::PERSONAL,
    'balance'           => 0,
    'max_balance'       => 100000.00,
    'min_balance'       => 10.00,
    'transaction_limit' => 5000.00,
    'is_default'        => true,
]);

use Hamadou\Fundry\Facades\Fundry;
use Hamadou\Fundry\DTOs\DepositDTO;

// Dépôt simple sans frais
$tx = Fundry::deposit($wallet, 1000.00, 'Rechargement par carte');

// Dépôt avec DTO et commission de 2.5%
$dto = new DepositDTO(
    userId: $user->id,
    walletId: $wallet->id,
    amount: 1000.00,
    description: 'Paiement client #INV-2026',
    commissionPercentage: 2.5,
    metadata: ['gateway' => 'stripe', 'order_id' => 42]
);

$tx = Fundry::depositWithDTO($dto);
// Montant brut : 1000.00 | Commission (2.5%) : 25.00 | Crédité sur le wallet : 975.00

use Hamadou\Fundry\DTOs\WithdrawalDTO;

$dto = new WithdrawalDTO(
    userId: $user->id,
    walletId: $wallet->id,
    amount: 500.00,              // Montant net demandé
    description: 'Retrait vers compte bancaire',
    commissionPercentage: 1.0    // 1% de frais (5.00)
);

$tx = Fundry::withdrawWithDTO($dto);
// Montant net retiré : 500.00 | Commission : 5.00 | Total débité du wallet : 505.00

use Hamadou\Fundry\DTOs\TransferDTO;

$dto = new TransferDTO(
    userId: $sender->id,
    fromWalletId: $senderWallet->id,
    toWalletId: $receiverWallet->id,
    amount: 1000.00,
    description: 'Virement P2P',
    commissionPercentage: 1.5,   // 1.5% de frais à la charge de l'expéditeur
    allowCrossCurrency: true     // Optionnel : force l'Option A (true) ou l'Option B (false)
);

$tx = Fundry::transferWithDTO($dto);
// Débité chez l'expéditeur : 1015.00 (1000 + 15 de commission)
// Crédité chez le destinataire : 1000.00 (ou montant converti si devises différentes)

$defaultWallet = $user->getDefaultWallet();
$eurWallet     = $user->getWalletByCurrency('EUR');
$eurBalance    = $user->getWalletBalance('EUR');
$totalInUsd    = $user->getTotalBalanceInUsd();

if ($user->hasSufficientBalance(250.00, 'EUR')) {
    // L'utilisateur peut retirer 250 EUR en respectant min_balance et transaction_limit
}

$fundryInstance = fundry();
echo format_currency(1250.5, 'EUR'); // "1,250.50 EUR"
$allowed = can_withdraw($wallet, 100.00);
bash
php artisan fundry:install
bash
php artisan migrate
php artisan fundry:currencies seed