PHP code example of zevpay / laravel

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

    

zevpay / laravel example snippets


use ZevPay\Laravel\Facades\ZevPay;

// Initialize a checkout session
$session = ZevPay::checkout()->initialize([
    'amount' => 500000, // ₦5,000 in kobo
    'email' => '[email protected]',
    'reference' => 'ORDER-123',
    'callback_url' => 'https://yoursite.com/callback',
]);

// Verify a checkout session
$result = ZevPay::checkout()->verify($sessionId);

// Create a transfer
$transfer = ZevPay::transfers()->create([
    'type' => 'bank_transfer',
    'amount' => 100000,
    'account_number' => '0123456789',
    'bank_code' => '044',
    'narration' => 'Payout',
]);

// Create an invoice
$invoice = ZevPay::invoices()->create([
    'customer_name' => 'Jane Doe',
    'customer_email' => '[email protected]',
    'due_date' => '2026-04-01',
    'line_items' => [
        ['description' => 'Web design', 'quantity' => 1, 'unit_price' => 5000000],
    ],
]);

use ZevPay\ZevPay;

class PaymentController extends Controller
{
    public function checkout(ZevPay $zevpay)
    {
        $session = $zevpay->checkout->initialize([
            'amount' => 500000,
            'email' => '[email protected]',
        ]);

        return redirect($session['checkout_url']);
    }
}

use ZevPay\Laravel\Events\ChargeSuccess;
use ZevPay\Laravel\Events\TransferSuccess;
use ZevPay\Laravel\Events\WebhookReceived;

// Listen to a specific event
class HandleChargeSuccess
{
    public function handle(ChargeSuccess $event): void
    {
        $reference = $event->payload['data']['reference'];
        $amount = $event->payload['data']['amount'];

        // Update your order, send receipt, etc.
    }
}

// Or listen to all webhook events
class LogAllWebhooks
{
    public function handle(WebhookReceived $event): void
    {
        logger()->info("ZevPay webhook: {$event->eventType}", $event->payload);
    }
}

protected $except = [
    'webhooks/zevpay',
];

// config/zevpay.php
return [
    'secret_key' => env('ZEVPAY_SECRET_KEY'),
    'public_key' => env('ZEVPAY_PUBLIC_KEY'),

    'webhook' => [
        'secret' => env('ZEVPAY_WEBHOOK_SECRET'),
        'path' => env('ZEVPAY_WEBHOOK_PATH', 'webhooks/zevpay'),
    ],

    'options' => [
        'base_url' => env('ZEVPAY_BASE_URL', 'https://api.zevpaycheckout.com'),
        'timeout' => (int) env('ZEVPAY_TIMEOUT', 30),
        'max_retries' => (int) env('ZEVPAY_MAX_RETRIES', 2),
    ],
];

use ZevPay\Exceptions\ValidationException;
use ZevPay\Exceptions\AuthenticationException;
use ZevPay\Exceptions\NotFoundException;

try {
    ZevPay::checkout()->initialize([/* ... */]);
} catch (ValidationException $e) {
    // $e->details contains field-level errors
} catch (AuthenticationException $e) {
    // Invalid API key
} catch (NotFoundException $e) {
    // Resource not found
}
bash
php artisan vendor:publish --tag=zevpay-config