rrcatto/ikhokha-php-sdk 问题修复 & 功能扩展

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

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

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 example
  • create_payment_link.php – creating a paylink
  • transaction_history.php – listing payments
  • status_lookup.php – checking payment status
  • f3_config.php – sample F3 configuration
  • f3_route_create_payment_link.php – F3 route for creating paylinks
  • f3_route_webhook.php – F3 route for handling webhooks

Requirements

  • PHP 7.4+
  • allow_url_fopen enabled (for HTTP via file_get_contents)

License

MIT – see LICENSE.

统计信息

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

GitHub 信息

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

其他信息

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