承接 mitigoa/kra-php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mitigoa/kra-php-sdk

最新稳定版本:1.0.0

Composer 安装命令:

composer require mitigoa/kra-php-sdk

包简介

KRA GavaConnect PHP SDK - Unofficial PHP client for Kenya Revenue Authority GavaConnect APIs

README 文档

README

Unofficial PHP SDK for Kenya Revenue Authority (KRA) GavaConnect APIs

PHP License Version

Overview

The KRA GavaConnect PHP SDK is a comprehensive, PSR-compliant PHP library for interacting with the Kenya Revenue Authority's GavaConnect APIs. It provides a clean, type-safe interface for:

  • PIN Validation
  • Tax Compliance Certificate (TCC) Verification
  • Taxpayer Obligations & Liabilities
  • NIL Return Filing
  • eTIMS Invoice Submission
  • e-Slip Verification
  • Excise License Checks

Features

  • Framework-agnostic core - Zero Laravel/Symfony dependencies
  • PSR compliance - PSR-4 autoloading, PSR-7 HTTP messages, PSR-18 HTTP client, PSR-6 caching
  • Auto token management - OAuth2 client credentials with silent refresh
  • Typed responses - Every API returns strongly-typed DTOs
  • Granular exceptions - AuthException, ApiException, RateLimitException
  • Offline testable - Full sandbox mode + Mockery-ready interfaces
  • Plugin ecosystem - Laravel, WordPress, WooCommerce, Symfony, Filament

Requirements

  • PHP 8.1+
  • Composer

Installation

composer require kra-php/sdk

Quick Start

use KraPHP\KraClient;

$kra = new KraClient([
    'client_id'     => getenv('KRA_CLIENT_ID'),
    'client_secret' => getenv('KRA_CLIENT_SECRET'),
    'environment'   => 'sandbox', // or 'production'
]);

// Validate a PIN
$pin = $kra->pin()->validate('A000000010');
echo $pin->taxpayerName;    // "ACME KENYA LIMITED"
echo $pin->pinStatus;       // "ACTIVE"

// Validate TCC
$tcc = $kra->tcc()->validate('A000000010', 'TCC-2024-XXXXX');
echo $tcc->isValid;         // true
echo $tcc->expiryDate;     // "2024-12-31"

// Get tax obligations
$obligations = $kra->taxpayer()->getObligations('A000000010');

// File NIL return
$result = $kra->returns()->fileNil([
    'pin'         => 'A000000010',
    'obligation'  => 'VAT',
    'period'      => '2024-10',
    'reason'      => 'No taxable supplies',
]);

// Submit eTIMS invoice
$invoice = new EtimsInvoice([
    'invoiceNumber' => 'INV-2024-001',
    'buyerPin'      => 'A000000020',
    'buyerName'     => 'BUYER COMPANY LTD',
    'invoiceDate'   => '2024-11-01',
    'currency'      => 'KES',
    'items'         => [
        [
            'description' => 'Web Development Services',
            'quantity'    => 1,
            'unitPrice'   => 50000.00,
            'vatRate'     => 16,
            'vatAmount'   => 8000.00,
        ],
    ],
    'totalExclVat'  => 50000.00,
    'totalVat'      => 8000.00,
    'totalInclVat'  => 58000.00,
]);

$response = $kra->etims()->submitInvoice($invoice);
echo $response->invoiceId;
echo $response->controlUnit;
echo $response->qrCode;

Configuration

$config = [
    // Required
    'client_id'     => 'your-client-id',
    'client_secret' => 'your-client-secret',

    // Environment
    'environment'   => 'sandbox', // 'sandbox' | 'production'

    // Base URLs (optional - defaults provided)
    'sandbox_base_url' => 'https://api-sandbox.developer.go.ke',
    'prod_base_url'    => 'https://api.developer.go.ke',
    'etims_sandbox_url' => 'https://etims-api-sbx.kra.go.ke',
    'etims_prod_url'   => 'https://etims-api.kra.go.ke/etims-api',

    // Cache (optional)
    'cache_driver'  => 'file', // 'file' | 'redis' | 'memcached' | 'array'
    'cache_ttl'     => 3300,  // seconds

    // HTTP (optional)
    'timeout'       => 30,    // seconds
    'retry_attempts' => 3,

    // eTIMS mTLS (optional)
    'etims_cert_path' => '/path/to/client.crt',
    'etims_key_path'  => '/path/to/client.key',
];

$kra = new KraClient($config);

Environment Variables

# OAuth2 Credentials
KRA_CLIENT_ID=your-client-id
KRA_CLIENT_SECRET=your-client-secret

# Environment
KRA_ENVIRONMENT=sandbox

# Cache
KRA_CACHE_DRIVER=redis
KRA_CACHE_TTL=3300

# HTTP
KRA_TIMEOUT=30
KRA_RETRY_ATTEMPTS=3

# eTIMS
KRA_ETIMS_CERT_PATH=/path/to/client.crt
KRA_ETIMS_KEY_PATH=/path/to/client.key

Error Handling

use KraPHP\Exceptions\AuthException;
use KraPHP\Exceptions\ApiException;
use KraPHP\Exceptions\RateLimitException;

try {
    $pin = $kra->pin()->validate('A000000010');
} catch (AuthException $e) {
    // Authentication failed
    echo $e->getMessage();
    echo $e->getKraErrorCode(); // e.g., 'INVALID_CREDENTIALS'
} catch (ApiException $e) {
    // API error response
    echo $e->getHttpStatusCode(); // e.g., 404
    echo $e->getKraErrorCode();   // e.g., 'PIN_NOT_FOUND'
} catch (RateLimitException $e) {
    // Rate limit exceeded
    echo $e->getRetryAfter(); // seconds until retry
}

Testing

# Install dependencies
composer install

# Run unit tests
vendor/bin/phpunit --testsuite unit

# Run with coverage
vendor/bin/phpunit --coverage-html coverage/

# Run static analysis
vendor/bin/phpstan analyse

# Fix code style
vendor/bin/php-cs-fixer fix

API Coverage

API Endpoint Method
PIN Validator /pin/validate GET
PIN by ID /pin/check-by-id GET
TCC Checker /tcc/validate GET
Taxpayer Obligations /taxpayer/obligations GET
Taxpayer Liabilities /taxpayer/liabilities GET
NIL Return /returns/nil POST
e-Slip Verify /eslip/verify GET
Excise License /excise/check GET
eTIMS Invoice /etims/invoice POST
eTIMS Stock IO /etims/stock POST
eTIMS Purchase /etims/purchase POST

Documentation

License

MIT License - see LICENSE file.

Support

Built for Kenya. Open to the world.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固