rhaima/larakonnect 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

rhaima/larakonnect

Composer 安装命令:

composer require rhaima/larakonnect

包简介

Laravel package for Konnect.network payment gateway integration - Accept online payments in Tunisia (bank cards, e-DINAR, wallet)

README 文档

README

Latest Version on Packagist Total Downloads License

A Laravel package for integrating Konnect.network payment gateway. Accept online payments in Tunisia via bank cards, e-DINAR, and Konnect wallet.

Features

  • 🚀 Easy integration with Laravel 10, 11, and 12
  • 💳 Support for bank cards, e-DINAR, and Konnect wallet
  • 🔒 Secure payment processing with PCI-DSS compliance
  • 📦 Eloquent model with polymorphic relations
  • 🎯 Event-driven architecture for payment lifecycle
  • 🛠 Artisan commands for installation and debugging
  • 🧪 Sandbox mode for testing

Installation

composer require rhaima/larakonnect

Run the installation command:

php artisan larakonnect:install

This will:

  • Publish the configuration file
  • Publish and run migrations (optional)
  • Add environment variables to your .env file

Configuration

Add your Konnect credentials to .env:

KONNECT_SANDBOX=true
KONNECT_API_KEY=your_wallet_id:your_api_secret
KONNECT_WALLET_ID=your_wallet_id

Get your credentials from:

Exclude Webhook from CSRF

Add the webhook route to your CSRF exceptions in app/Http/Middleware/VerifyCsrfToken.php:

protected $except = [
    'konnect/webhook',
];

Usage

Basic Usage with Facade

use Rhaima\LaraKonnect\Facades\LaraKonnect;

// Create a payment link (amount in TND)
$result = LaraKonnect::createPaymentLink(
    amountTND: 150.500,
    orderId: 'ORDER-2024-001',
    description: 'iPhone repair service',
    customer: [
        'first_name' => 'Mohamed',
        'last_name' => 'Rhaima',
        'email' => 'client@example.com',
        'phone' => '22123456',
    ]
);

if ($result->success) {
    return redirect($result->payUrl);
}

// Handle error
return back()->with('error', $result->error);

Advanced Usage

use Rhaima\LaraKonnect\Facades\LaraKonnect;
use Rhaima\LaraKonnect\Services\KonnectClient;

// Convert TND to millimes (1 TND = 1000 millimes)
$amountMillimes = KonnectClient::toMillimes(150.500); // 150500

// Initialize payment with full options
$result = LaraKonnect::initPayment($amountMillimes, 'ORDER-123', [
    'description' => 'Payment description',
    'acceptedPaymentMethods' => ['bank_card', 'e-DINAR'],
    'lifespan' => 30, // minutes
    'theme' => 'dark',
    'firstName' => 'Mohamed',
    'lastName' => 'Rhaima',
    'email' => 'client@example.com',
    'phoneNumber' => '22123456',
    'successUrl' => 'https://yoursite.com/payment/success',
    'failUrl' => 'https://yoursite.com/payment/fail',
]);

// Check payment status
$payment = LaraKonnect::getPayment($paymentRef);

if ($payment->isCompleted()) {
    // Payment successful
}

// Quick status check
if (LaraKonnect::isCompleted($paymentRef)) {
    // ...
}

Using the Model

use Rhaima\LaraKonnect\Models\KonnectPayment;

// Create and initiate payment with tracking
$result = KonnectPayment::createAndInitiate(
    amountTnd: 150.500,
    orderId: 'ORDER-123',
    payable: $order, // Your model (Order, Intervention, etc.)
    customerInfo: [
        'first_name' => 'Mohamed',
        'email' => 'client@example.com',
    ]
);

if ($result['success']) {
    return redirect($result['payUrl']);
}

// Query payments
$pendingPayments = KonnectPayment::pending()->get();
$completedPayments = KonnectPayment::completed()->get();
$orderPayments = KonnectPayment::forOrder('ORDER-123')->get();

Using the Trait

Add the trait to any model that can have payments:

use Rhaima\LaraKonnect\Traits\HasKonnectPayments;

class Intervention extends Model
{
    use HasKonnectPayments;

    // Optional: customize the order ID
    public function getKonnectOrderId(): string
    {
        return 'INT-' . $this->reference;
    }

    // Optional: auto-fill customer info
    public function getKonnectCustomerInfo(): array
    {
        return [
            'first_name' => $this->client->prenom,
            'last_name' => $this->client->nom,
            'phone' => $this->client->telephone,
        ];
    }
}

Then use it:

$intervention = Intervention::find(1);

// Initiate payment
$result = $intervention->initiateKonnectPayment(150.500);

// Check payment status
if ($intervention->isPaidViaKonnect()) {
    // Already paid
}

// Get payment history
$payments = $intervention->konnectPayments;
$latestPayment = $intervention->latestKonnectPayment;

Handling Events

Listen to payment events in your EventServiceProvider:

use Rhaima\LaraKonnect\Events\PaymentInitiated;
use Rhaima\LaraKonnect\Events\PaymentCompleted;
use Rhaima\LaraKonnect\Events\PaymentFailed;

protected $listen = [
    PaymentCompleted::class => [
        UpdateOrderStatus::class,
        SendPaymentConfirmation::class,
    ],
    PaymentFailed::class => [
        NotifyAdminOfFailedPayment::class,
    ],
];

Example listener:

class UpdateOrderStatus
{
    public function handle(PaymentCompleted $event): void
    {
        $order = Order::where('reference', $event->orderId)->first();
        
        if ($order) {
            $order->update([
                'payment_status' => 'paid',
                'paid_at' => now(),
            ]);
            
            // Send notification
            $order->client->notify(new PaymentReceived($order));
        }
    }
}

Available Methods

Facade Methods

Method Description
createPaymentLink($amount, $orderId, $description?, $customer?) Quick payment link creation
initPayment($amountMillimes, $orderId, $options?) Full payment initialization
getPayment($paymentRef) Get payment details
isCompleted($paymentRef) Check if payment is completed
getStatus($paymentRef) Get payment status enum
toMillimes($amountTND) Convert TND to millimes
toTND($millimes) Convert millimes to TND

Model Methods

Method Description
createAndInitiate(...) Create record and initiate payment
markAsCompleted() Mark payment as completed
markAsFailed() Mark payment as failed
refreshFromKonnect() Sync status from Konnect API
isCompleted() Check if completed
isPending() Check if pending

Artisan Commands

# Install the package
php artisan larakonnect:install

# Check configuration status
php artisan larakonnect:status

# Check specific payment
php artisan larakonnect:status PAYMENT_REF

Testing

Use sandbox mode and test cards:

Card Type Number CVV
Visa 4000000000000002 Any 3 digits
Mastercard 5100000000000008 Any 3 digits
KONNECT_SANDBOX=true

Customization

Views

Publish and customize the views:

php artisan vendor:publish --tag=larakonnect-views

Views will be published to resources/views/vendor/larakonnect/.

Configuration

Publish the configuration:

php artisan vendor:publish --tag=larakonnect-config

Security

If you discover any security vulnerabilities, please email mohamed.rhaima96@gmail.com.

Credits

License

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

rhaima/larakonnect 适用场景与选型建议

rhaima/larakonnect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「payment」 「gateway」 「laravel」 「paiement」 「fintech」 「tunisia」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rhaima/larakonnect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rhaima/larakonnect 我们能提供哪些服务?
定制开发 / 二次开发

基于 rhaima/larakonnect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-20