statum/statum-php-sdk
Composer 安装命令:
composer require statum/statum-php-sdk
包简介
Official PHP SDK for Statum APIs (SMS, Airtime, Account)
README 文档
README
Official PHP SDK for Statum APIs. Built for secure, production-grade enterprise usage with strict typing, immutable DTOs, and framework-agnostic Guzzle HTTP integrations. Easily send SMS alerts, automate airtime disbursements, and query real-time account balances.
Table of Contents
- Features
- Getting Started
- Installation
- Quick Start in 2 Minutes
- Core Integration Examples
- Error & Exception Handling
- API JSON Payload Specifications
- Integration Guidelines & Gotchas
- Running Tests
- License
Features
- Type-Safe Constructors: Parameter validation happens locally inside the SDK before outgoing HTTP calls.
- Service-Oriented Design: Clean division between SMS, Airtime, and Account APIs.
- Framework Agnostic: Works out of the box in plain scripts, Symfony, or Laravel.
- Extensive Exception Handling: Maps specific HTTP status codes (e.g. 401, 402, 422) to concrete PHP exception classes.
- Strict Typing: Full compatibility with PHP 8.1+ strict mode.
Getting Started
- Sign up for a Statum account: app.statum.co.ke
- Get your API credentials: Retrieve your Consumer Key and Consumer Secret from the Statum Dashboard.
- Read the full API documentation: docs.statum.co.ke
- Install the SDK: Follow the Installation guidelines below.
Installation
Install the package via Composer:
composer require statum/statum-php-sdk
Quick Start in 2 Minutes
Ensure your credentials are saved in your .env or system environment:
STATUM_CONSUMER_KEY=your-consumer-key STATUM_CONSUMER_SECRET=your-consumer-secret
1. Plain PHP Setup
use Statum\Sdk\StatumClient; $client = StatumClient::create( consumerKey: $_ENV['STATUM_CONSUMER_KEY'], consumerSecret: $_ENV['STATUM_CONSUMER_SECRET'] );
2. Laravel Setup
The SDK supports package auto-discovery in Laravel. To configure it, publish the configuration file:
php artisan vendor:publish --tag=statum-config
This will create a config/statum.php file. You can configure your credentials via your .env file:
STATUM_CONSUMER_KEY=your-consumer-key STATUM_CONSUMER_SECRET=your-consumer-secret STATUM_BASE_URL=https://api.statum.co.ke/api/v2 STATUM_TIMEOUT=30.0
Now type-hint StatumClient in any controller or job to inject the initialized client:
use Statum\Sdk\StatumClient; class SmsController extends Controller { public function __construct(private readonly StatumClient $client) {} public function send() { // Ready to make type-safe calls! } }
Core Integration Examples
Account Details
Fetch organization profile, available balances, and service configuration:
$response = $client->account()->getAccountDetails(); echo "Status Code: " . $response->statusCode . "\n"; echo "Organization: " . $response->organization->name . "\n"; echo "Available Balance: KES " . $response->organization->details->availableBalance . "\n"; // List registered services and account codes foreach ($response->organization->accounts as $account) { echo "Service: " . $account->serviceName . " | Code: " . $account->account . "\n"; }
Sending SMS
Send transactional or promotional SMS alerts to a recipient phone number:
$response = $client->sms()->sendSms( phoneNumber: '254721553678', // Recipient phone number in international format senderId: 'STATUM', // Your approved Sender ID message: 'Hello! This is a secure notification from Statum SDK.' ); echo "Status Code: " . $response->statusCode . "\n"; echo "Description: " . $response->description . "\n"; echo "Request ID: " . $response->requestId . "\n";
Disbursing Airtime
Disburse airtime rewards or incentives (supports amounts from KES 5 to KES 10,000):
$response = $client->airtime()->sendAirtime( phoneNumber: '254721553678', amount: '100' // Amount must be passed as a string representation ); echo "Status Code: " . $response->statusCode . "\n"; echo "Description: " . $response->description . "\n"; echo "Request ID: " . $response->requestId . "\n";
Error & Exception Handling
The SDK maps HTTP responses to concrete exception classes that inherit from Statum\Sdk\Exceptions\ApiException.
use Statum\Sdk\Exceptions\AuthenticationException; use Statum\Sdk\Exceptions\ValidationException; use Statum\Sdk\Exceptions\NetworkException; use Statum\Sdk\Exceptions\ApiException; try { $response = $client->sms()->sendSms('2547XXXXXXXX', 'SENDERID', 'Message'); } catch (AuthenticationException $e) { // Credentials failed validation (HTTP 401) echo "Auth Failure: Check Consumer Key and Secret."; } catch (ValidationException $e) { // API-side validation parameters failed (HTTP 422) echo "Request ID: " . $e->getRequestId() . "\n"; foreach ($e->getValidationErrors() as $field => $errors) { echo "Field '$field' errors: " . implode(', ', $errors) . "\n"; } } catch (NetworkException $e) { // DNS, timeouts, or connection failures echo "Connection error: " . $e->getMessage(); } catch (ApiException $e) { // General API errors (e.g. 402 Insufficient Funds, 500 Server Error) echo "HTTP Status Code: " . $e->getCode() . "\n"; echo "Error Body: " . $e->getResponseBody() . "\n"; }
API JSON Payload Specifications
Here are the wire-level JSON schemas transmitted and returned by the APIs under the hood:
1. SMS API
- Endpoint:
POST /sms - Headers:
Authorization: Basic <base64(key:secret)>
JSON Request
{
"phone_number": "254721553678",
"sender_id": "STATUM",
"message": "Hello from Statum SDK!"
}
JSON Response (Success - 200)
{
"status_code": 200,
"description": "Operation successful.",
"request_id": "d173a8b3-0f3a-463f-8a03-29826b9a2d78"
}
2. Airtime API
- Endpoint:
POST /airtime
JSON Request
{
"phone_number": "254721553678",
"amount": "100"
}
JSON Response (Success - 200)
{
"status_code": 200,
"description": "Operation successful.",
"request_id": "6e0213d5-6df9-47bf-ba2d-9b9470d96854"
}
3. Account Details API
- Endpoint:
GET /account-details
JSON Response (Success - 200)
{
"status_code": 200,
"description": "Operation successful.",
"request_id": "5a45bc7b-bf99-49ae-b089-9daf5f4adbb0",
"organization": {
"name": "Statum Test",
"details": {
"available_balance": 695.15,
"location": "Nairobi - Westlands",
"website": "www.statum.co.ke",
"office_email": "admin@statum.co.ke",
"office_mobile": "+254722199199",
"mpesa_account_top_up_code": "B9E573"
},
"accounts": [
{ "account": "Statum", "service_name": "sms" },
{ "account": "CONNECT", "service_name": "sms" }
]
}
}
Integration Guidelines & Gotchas
- Sender ID Approval: SMS requests will throw an HTTP 422
ValidationExceptionif thesenderIdis not registered and approved under your Statum account profile. - Phone Number Formatting: Ensure phone numbers are passed in the international format (with or without
+prefix), e.g.254721553678or+254721553678. - Airtime Limits: Airtime amounts must be passed as strings (e.g.
'100') and must fall strictly within the KES 5 to KES 10,000 range per transaction.
Running Tests
Ensure PHPUnit is configured and run:
composer install
composer test
License
This project is licensed under the MIT License. See LICENSE for details.
statum/statum-php-sdk 适用场景与选型建议
statum/statum-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「payments」 「kenya」 「mpesa」 「airtime」 「statum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 statum/statum-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 statum/statum-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 statum/statum-php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dealing with payments through the Egyptian payment gateway PayMob
Librería para la gestión sencilla de pagos mediante TPV Redsys y Paypal
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
A fork of simplesoftwareio/simple-sms with Verimor driver.
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-18