PHP code example of graigdev / payment

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

    

graigdev / payment example snippets


// Get a user's wallet
$wallet = \GraigDev\Payment\Models\Wallet::where('user_id', auth()->id())->first();

// If you published the models, use this instead:
// $wallet = \App\Models\Payment\Wallet::where('user_id', auth()->id())->first();

// Deposit funds
$wallet->deposit(100, 'Manual deposit');

// Withdraw funds
$wallet->withdraw(50, 'Manual withdrawal');

// Generate a payment code
$paymentCode = \GraigDev\Payment\Models\PaymentCode::create([
    'code' => 'PAY-' . strtoupper(Str::random(10)),
    'amount' => 100,
    'description' => 'Subscription payment',
    'generated_by' => auth()->id(),
]);

// Redeem a payment code
$code = 'PAY-ABCDEFGHIJ';
$paymentCode = \GraigDev\Payment\Models\PaymentCode::where('code', $code)
    ->unused()
    ->valid()
    ->first();

if ($paymentCode) {
    $paymentCode->markAsUsed(auth()->id());
    $wallet->deposit($paymentCode->amount, 'Redeemed code: ' . $code);
}

// Get all transactions for a wallet
$transactions = $wallet->transactions;

// Get transactions of a specific type
$deposits = $wallet->transactions()->ofType('DEPOSIT')->get();

return [
    // Payment code settings
    'code_prefix' => 'PAY',
    'code_length' => 10,
    
    // Wallet settings
    'currency' => 'USD',
    'min_withdrawal' => 10,
    
    // Transaction types
    'transaction_types' => [
        'deposit' => 'DEPOSIT',
        'withdrawal' => 'WITHDRAWAL',
        'transfer' => 'TRANSFER',
        'payment' => 'PAYMENT',
        'refund' => 'REFUND',
    ],
];
bash
php artisan vendor:publish --tag="payment-config"
bash
php artisan vendor:publish --tag="payment-migrations"
bash
php artisan vendor:publish --tag="payment-models"
bash
php artisan payment:publish-models
bash
php artisan payment:publish-models --force
bash
php artisan migrate