PHP code example of hpwebdeveloper / laravel-pay-pocket

1. Go to this page and download the library: Download hpwebdeveloper/laravel-pay-pocket 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/ */

    

hpwebdeveloper / laravel-pay-pocket example snippets



use HPWebdeveloper\LaravelPayPocket\Interfaces\WalletOperations;
use HPWebdeveloper\LaravelPayPocket\Traits\ManagesWallet;

class User extends Authenticatable implements WalletOperations
{
    use ManagesWallet;
}

namespace App\Enums;

enum WalletEnums: string
{
    case WALLET1 = 'wallet_1';
    case WALLET2 = 'wallet_2';
}


deposit(type: 'wallet_1', amount: 123.45, notes: null)

$user = auth()->user();
$user->deposit('wallet_1', 123.45);

$user = auth()->user();
$user->deposit('wallet_2', 67.89);

use HPWebdeveloper\LaravelPayPocket\Facades\LaravelPayPocket;

$user = auth()->user();
LaravelPayPocket::deposit($user, 'wallet_1', 123.45);


$user = auth()->user();
$user->deposit('wallet_1', 67.89, 'You ordered pizza.');

pay(amount: 12.34, notes: null)

$user = auth()->user();
$user->pay(12.34);

use HPWebdeveloper\LaravelPayPocket\Facades\LaravelPayPocket;

$user = auth()->user();
LaravelPayPocket::pay($user, 12.34);

@return \Illuminate\Database\Eloquent\Collection<WalletsLog>

$user = auth()->user();
$logs = $user->pay(120.00, 'Order #1234');

// Access transaction details
foreach ($logs as $log) {
    echo "Wallet: {$log->wallet_name}, Amount: {$log->value}";
}

// Get the number of wallets used in the payment
$walletCount = $logs->count();

// Calculate total amount deducted (verification)
$totalDeducted = $logs->sum('value');

// Get all wallet names used in the transaction
$walletsUsed = $logs->pluck('wallet_name');

// Access specific log details
$firstLog = $logs->first();
echo "From: {$firstLog->from}, To: {$firstLog->to}";
echo "Reference: {$firstLog->reference}";

$user = auth()->user();

// User has: wallet_1 = $100, wallet_2 = $50
$logs = $user->pay(120.00, 'Premium subscription');

// Returns collection with 2 logs:
// Log 1: wallet_1 deducted $100 (100.00 -> 0.00)
// Log 2: wallet_2 deducted $20 (50.00 -> 30.00)

echo "Payment completed using {$logs->count()} wallet(s)";
// Output: Payment completed using 2 wallet(s)

$user->walletBalance // Total combined balance available across all wallets

// Or using provided facade

LaravelPayPocket::checkBalance($user);

$user->getWalletBalanceByType('wallet_1') // Balance available in wallet_1
$user->getWalletBalanceByType('wallet_2') // Balance available in wallet_2

// Or using provided facade

LaravelPayPocket::walletBalanceByType($user, 'wallet_1');
bash
php artisan vendor:publish --tag="pay-pocket-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="pay-pocket-wallets"
php artisan vendor:publish --tag="config"
bash
php artisan vendor:publish --tag="pay-pocket-migrations"
php artisan migrate
php artisan vendor:publish --tag="pay-pocket-wallets"
php artisan vendor:publish --tag="config"