PHP code example of klump / laravel-klump

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

    

klump / laravel-klump example snippets


<livewire:klump-checkout 
    :order="$order" 
    :items="$items" 
    :customer="$customer" 
/>

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class CheckoutController extends Controller
{
    public function checkout()
    {
        $order = [
            'id' => 'ORD-' . uniqid(),
            'amount' => 50000, // Amount in kobo/cents
            'currency' => 'NGN',
            'redirect_url' => route('payment.success'),
        ];
        
        $items = [
            [
                'name' => 'Product Name',
                'unit_price' => 50000, // Price in kobo/cents
                'quantity' => 1,
                'description' => 'Product description',
            ],
        ];
        
        $customer = [
            'name' => 'John Doe',
            'email' => '[email protected]',
            'phone' => '08012345678',
        ];
        
        return view('checkout', compact('order', 'items', 'customer'));
    }
    
    public function success(Request $request)
    {
        // Handle successful payment
        return view('payment.success');
    }
}



namespace App\Http\Livewire;

use Klump\LaravelKlump\Http\Livewire\KlumpCheckout;

class CustomKlumpCheckout extends KlumpCheckout
{
    public function checkout()
    {
        // Custom logic before checkout
        
        parent::checkout();
        
        // Custom logic after checkout
    }
}

Livewire::component('custom-klump-checkout', CustomKlumpCheckout::class);



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Klump\LaravelKlump\Services\KlumpService;

class KlumpWebhookController extends Controller
{
    protected $klumpService;
    
    public function __construct(KlumpService $klumpService)
    {
        $this->klumpService = $klumpService;
    }
    
    public function handle(Request $request)
    {
        // Verify webhook signature
        if (!$this->klumpService->verifyWebhook($request)) {
            return response()->json(['error' => 'Invalid signature'], 400);
        }
        
        $payload = $request->all();
        $event = $payload['event'];
        
        // Handle different webhook events
        switch ($event) {
            case 'payment.successful':
                // Handle successful payment
                break;
            case 'payment.failed':
                // Handle failed payment
                break;
            // Add more event handlers as needed
        }
        
        return response()->json(['status' => 'success']);
    }
}

Route::post('webhooks/klump', [KlumpWebhookController::class, 'handle']);
bash
php artisan vendor:publish --provider="Klump\LaravelKlump\KlumpServiceProvider"