定制 klump/laravel-klump 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

klump/laravel-klump

最新稳定版本:1.0.0

Composer 安装命令:

composer require klump/laravel-klump

包简介

Klump Buy Now Pay Later integration for Laravel

README 文档

README

A Laravel package for integrating Klump's Buy Now Pay Later (BNPL) payment solution into your Laravel applications.

Requirements

  • PHP 8.0 or higher
  • Laravel 10.0 or higher
  • Livewire 3.0 or higher

Installation

You can install the package via composer:

composer require klump/laravel-klump

After installing the package, publish the configuration file:

php artisan vendor:publish --provider="Klump\LaravelKlump\KlumpServiceProvider"

Configuration

After publishing the configuration, you can find the config file at config/klump.php. You need to set your Klump API credentials in your .env file:

KLUMP_PUBLIC_KEY=your_public_key
KLUMP_SECRET_KEY=your_secret_key
KLUMP_ENVIRONMENT=sandbox # or production

Basic Usage

Setting Up the Checkout Component

The package provides a Livewire component for handling Klump checkout. To use it, you need to include the Klump JavaScript SDK in your layout or view:

<!-- Add this in your layout file or view -->
<script src="https://js.useklump.com/klump.js" defer></script>

Then, you can use the Livewire component in your blade files:

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

Where:

  • $order is an array containing order information (id, amount, currency, etc.)
  • $items is an array of items in the order
  • $customer is an array with customer details

Example Controller

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' => 'john@example.com',
            'phone' => '08012345678',
        ];
        
        return view('checkout', compact('order', 'items', 'customer'));
    }
    
    public function success(Request $request)
    {
        // Handle successful payment
        return view('payment.success');
    }
}

Handling Checkout Events

The Klump checkout component dispatches several events that you can listen for:

  • onSuccess: Called when payment is successful
  • onError: Called when payment fails
  • onClose: Called when the checkout modal is closed

These events are already configured in the Livewire component, but you can customize them by extending the component.

Advanced Usage

Custom Checkout Component

If you need to customize the checkout process, you can extend the KlumpCheckout component:

<?php

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
    }
}

Then register your custom component in your AppServiceProvider:

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

Webhook Handling

To handle Klump webhooks, you can create a webhook controller:

<?php

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']);
    }
}

Then register the webhook route in your routes/web.php or routes/api.php:

Route::post('webhooks/klump', [KlumpWebhookController::class, 'handle']);

Testing

composer test

Security

If you discover any security related issues, please email richienabuk@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-19