moffhub/connector-sdk
Composer 安装命令:
composer require moffhub/connector-sdk
包简介
SDK for building MPS-compliant payment and service connectors. Base classes, HTTP client, webhook verification, and a sandbox connector.
README 文档
README
Base classes and helpers for building MPS-compliant payment and service connectors. Extend BaseConnector, declare your manifest, implement the capabilities you support, and you're done — config validation, lifecycle, and HTTP plumbing are handled for you.
This package implements the contracts defined in moffhub/mps-spec.
Installation
composer require moffhub/connector-sdk
Requires PHP 8.3+. Pulls in moffhub/mps-spec and guzzlehttp/guzzle.
What you get
BaseConnector— abstract base for payment connectors. ImplementsConnectorInterface(initialize/healthCheck/destroy) and validates config against the manifest.BaseServiceConnector— abstract base for service connectors (domain logic providers).SandboxConnector— in-memory connector for tests and local development. Use it as a stand-in when you don't want to hit a real provider.Support\HttpClient— thin Guzzle wrapper with sensible defaults (timeouts, JSON, retries) for talking to provider APIs.Support\WebhookVerifier— HMAC signature verification helper for webhook endpoints.
Quick start: a payment connector
use Moffhub\ConnectorSdk\BaseConnector; use Moffhub\MpsSpec\Contracts\HasChargeCapability; use Moffhub\MpsSpec\Data\{ChargeRequest, ChargeResponse, ConfigField, ConnectorManifest}; use Moffhub\MpsSpec\Enums\{Capability, Channel, ChargeStatus, SettlementModel}; final class AcmeConnector extends BaseConnector implements HasChargeCapability { public function manifest(): ConnectorManifest { return new ConnectorManifest( connectorId: 'acme', displayName: 'Acme Payments', version: '1.0.0', specVersion: '0.1', vendorName: 'Acme Inc.', vendorWebsite: 'https://acme.example', vendorSupportEmail: 'support@acme.example', supportedChannels: [Channel::Card], supportedCurrencies: ['USD'], capabilities: [Capability::Payment], settlementModel: SettlementModel::T1, requiredConfig: [ new ConfigField(key: 'api_key', label: 'API Key', required: true, secret: true), new ConfigField(key: 'environment', label: 'Environment', required: true), ], ); } public function createCharge(ChargeRequest $request): ChargeResponse { $this->ensureInitialized(); // requireConfig() throws if the key is missing $apiKey = $this->requireConfig('api_key'); // ... call provider API, return ChargeResponse return new ChargeResponse(/* ... */); } public function queryCharge(string $chargeId): ChargeResponse { $this->ensureInitialized(); // ... } }
Wiring it up
$connector = new AcmeConnector(); $connector->initialize([ 'api_key' => $_ENV['ACME_KEY'], 'environment' => 'live', ]); $response = $connector->createCharge(new ChargeRequest(/* ... */));
initialize() validates the supplied config against requiredConfig from your manifest and throws InvalidArgumentException if anything required is missing.
Helpers
HttpClient — talking to providers
use Moffhub\ConnectorSdk\Support\HttpClient; $client = new HttpClient(baseUri: 'https://api.acme.example', timeout: 10); $response = $client->post('/charges', [ 'headers' => ['Authorization' => "Bearer {$apiKey}"], 'json' => $payload, ]);
WebhookVerifier — verifying inbound webhooks
use Moffhub\ConnectorSdk\Support\WebhookVerifier; $verifier = new WebhookVerifier(secret: $this->requireConfig('webhook_secret')); $verifier->verify(rawBody: $request->getContent(), signature: $request->header('X-Signature')); // Throws WebhookVerificationFailedException on mismatch
SandboxConnector — in-memory connector for tests
use Moffhub\ConnectorSdk\SandboxConnector; $connector = new SandboxConnector(); $connector->initialize([]); $response = $connector->createCharge($request); // returns deterministic fake data
Service connectors
Use BaseServiceConnector instead of BaseConnector for service connectors (domain logic providers — utility lookups, ticketing, etc.). The lifecycle is the same; the contract is ServiceConnectorInterface from moffhub/mps-spec.
Testing your connector
The Moffhub CLI (moffhub/cli) ships a certification suite that exercises your connector against the spec — manifest validation, capability conformance, lifecycle, and contract tests. See its README for usage.
License
MIT. See LICENSE.
moffhub/connector-sdk 适用场景与选型建议
moffhub/connector-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payments」 「sdk」 「connector」 「kenya」 「africa」 「payment-gateway」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moffhub/connector-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moffhub/connector-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moffhub/connector-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
Redshift Connector for Laravel with AWS Secret Manager
Import and export products with specific columns names. Map them with the Akeneo attributes and integrate or generate the CSV you need.
Facebook Connector Symfony Bundle for Contao - Basic Version.
PHP library that provides an object-oriented wrapper to connect to SSH and run shell commands with the php ssh2 extension.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-25