rrcatto/ikhokha-php-sdk
最新稳定版本:v0.1.0
Composer 安装命令:
composer require rrcatto/ikhokha-php-sdk
包简介
Lightweight PHP SDK for the iKhokha iK Pay API using file_get_contents, with optional Fat-Free Framework helper.
README 文档
README
Lightweight PHP SDK for the iKhokha iK Pay API using file_get_contents, with an optional helper for the Fat-Free Framework.
- Framework-agnostic core client (
Ikhokha\Client) - No cURL; uses
file_get_contents+stream_context_create - Simple exception types
- Optional F3 helper (
Ikhokha\F3\Service)
Installation
Via Composer (once published on Packagist):
composer require rrcatto/ikhokha-php-sdk
For local development, clone this repository and run:
composer install
Quick Start (Vanilla PHP)
<?php require __DIR__ . '/vendor/autoload.php'; use Ikhokha\Client; use Ikhokha\Exception\HttpException; use Ikhokha\Exception\IkhokhaException; $client = new Client( 'YourAppIDHere', // IK-APPID 'YourAppSecretHere', // AppSecret 'APPID123' // entityID / Application key ID ); $payload = [ 'amount' => 10000, // R100.00 'currency' => 'ZAR', 'requesterUrl' => 'https://example.com/requester', 'mode' => 'live', 'description' => 'Cape Motorcycle Adventures – Suzuki DS250 rental', 'externalTransactionID' => 'CMA-2025-0001', 'urls' => [ 'callbackUrl' => 'https://yourdomain/api/ikhokha/webhook', 'successPageUrl' => 'https://yourdomain/payment/success', 'failurePageUrl' => 'https://yourdomain/payment/failure', 'cancelUrl' => 'https://yourdomain/payment/cancel', ], ]; try { $response = $client->createPaymentLink($payload); $paylinkUrl = $response['paylinkUrl'] ?? null; // Redirect or show link/button to $paylinkUrl } catch (HttpException $e) { // Handle HTTP errors from Ikhokha } catch (IkhokhaException $e) { // Handle client-side errors }
Fat-Free Framework Helper
Configure your credentials in your F3 bootstrap (e.g. index.php):
$f3->set('IKHOKHA.APP_ID', 'YourAppIDHere'); $f3->set('IKHOKHA.APP_SECRET', 'YourAppSecretHere'); $f3->set('IKHOKHA.ENTITY_ID', 'APPID123'); $f3->set('IKHOKHA.BASE_URL', 'https://api.ikhokha.com'); // optional
Route example:
$f3->route('POST /api/paylink', function($f3) { $svc = \Ikhokha\F3\Service::instance(); $payload = json_decode($f3->get('BODY'), true) ?: []; $result = $svc->createPaymentLink($payload); header('Content-Type: application/json'); echo json_encode($result); });
A simple webhook handler example:
$f3->route('POST /api/ikhokha/webhook', function($f3) { $rawBody = $f3->get('BODY'); $headers = getallheaders(); // Here you could verify ik-sign if you want, reusing the same signing logic. $payload = json_decode($rawBody, true) ?: []; // TODO: store $payload['status'], $payload['paylinkID'], $payload['externalTransactionID'], etc. http_response_code(200); echo 'OK'; });
Examples
See the examples/ directory for:
quickstart.php– minimal CLI examplecreate_payment_link.php– creating a paylinktransaction_history.php– listing paymentsstatus_lookup.php– checking payment statusf3_config.php– sample F3 configurationf3_route_create_payment_link.php– F3 route for creating paylinksf3_route_webhook.php– F3 route for handling webhooks
Requirements
- PHP 7.4+
allow_url_fopenenabled (for HTTP viafile_get_contents)
License
MIT – see LICENSE.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-20