K Khay logo
K Khay
Get Started
Composer: kkhay/kkhayv1.0.4PHP 8.1+ & Laravel

PHP & Laravel SDK

The official PHP SDK for K Khay Gateway. Works smoothly in Laravel, Symfony, WordPress plugins, or standalone PHP projects. Built purely with PHP standard library extensions (ext-curl, ext-json, ext-hash) and timing-safe hash_equals().

1. Installation

Composer Package
$composer require kkhay/kkhay

2. Invoice Creation

index.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Kkhay\KkhayClient;
$kkhay = new KkhayClient([
'api_key' => getenv('KKHAY_API_KEY'),
]);
$invoice = $kkhay->createInvoice([
'amount' => 75.00,
'currency' => 'USD',
'pay_network' => 'bsc',
'pay_token' => 'USDT',
'order_id' => 'PHP-ORDER-101',
'title' => 'Hosting Renewal',
'customer_email' => 'client@company.com',
'redirect_url' => 'https://company.com/billing/success',
]);
header('Location: ' . $invoice['hosted_url']);
exit;

3. Webhook Handler (Laravel)

KkhayWebhookController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Kkhay\KkhayWebhook;
class KkhayWebhookController extends Controller
{
public function handle(Request $request)
{
$payload = $request->getContent();
$signature = $request->header('x-kkhay-signature');
$secret = config('services.kkhay.webhook_secret');
if (!KkhayWebhook::verifySignature($payload, $signature, $secret)) {
return response()->json(['error' => 'Invalid signature'], 400);
}
$event = json_decode($payload, true);
if (in_array($event['event'], ['payment.finished', 'payment.paid'])) {
// Update order status in database
// $event['order_id'], $event['tx_hash']
}
return response()->json(['status' => 'success']);
}
}