mitigoa/kra-php-sdk
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
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
- Email: apisupport@kra.go.ke
- GitHub Issues: https://github.com/kra-php/sdk/issues
Built for Kenya. Open to the world.
mitigoa/kra-php-sdk 适用场景与选型建议
mitigoa/kra-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 5, 最近一次更新时间为 2026 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth2」 「tax」 「pin」 「kenya」 「tcc」 「kra」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mitigoa/kra-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mitigoa/kra-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mitigoa/kra-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Aktive-Merchant provides a common interface to process payments using multiple gateways.
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
API client for validating Tax Identification Number.
Validate the format of EU vat numbers.
Laravel Token Builder
Module allowing creation of tax rates and categories in the CMS via SiteConfig
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-22