shipbg/php-sdk
Composer 安装命令:
composer require shipbg/php-sdk
包简介
Portable, dependency-free PHP SDK for the ShipBG multi-carrier shipping API (generated from the OpenAPI spec).
README 文档
README
Portable, dependency-free PHP client for the ShipBG multi-carrier shipping API. Generated from the OpenAPI spec — typed request methods + DTOs, single source of truth, no drift.
- PHP 7.4+, zero Composer dependencies (just
ext-curl+ext-json). - Pluggable transport — ships a
CurlTransportdefault; inject anyTransport(e.g. a WordPresswp_remote_*adapter, Guzzle, Symfony HttpClient). Same SDK on WooCommerce, Magento, OpenCart, plain PHP. - Resource-grouped, fully typed:
$client->rates->quote($payload)returns aQuoteRatesResult.
Install
composer require shipbg/php-sdk
Usage
use ShipBG\Sdk\Client; $client = new Client('YOUR_API_TOKEN'); // default CurlTransport // or inject a platform transport: // $client = new Client($token, 'https://shipbg.com/api/v1', new MyWpRemoteTransport()); $account = $client->account->show(); // GET /account → AccountResponseData $rates = $client->rates->quote([ // POST /rates:quote → QuoteRatesResult 'from_address' => [/* ... */], 'to_address' => [/* ... */], 'parcel' => ['weight' => 1.5], 'currency' => 'BGN', ]); foreach ($rates->rates as $rate) { // typed DTO graph }
Errors raise ShipBG\Sdk\Exception\ApiException (getStatus(), getType(), getBody()).
Custom transport
Implement ShipBG\Sdk\Transport to route HTTP through your platform's stack:
final class WpRemoteTransport implements \ShipBG\Sdk\Transport { public function send(string $method, string $url, array $headers, ?string $body): array { $res = wp_remote_request($url, ['method' => $method, 'headers' => $headers, 'body' => $body]); return [(int) wp_remote_retrieve_response_code($res), (string) wp_remote_retrieve_body($res)]; } }
Regenerating
Generated from backend/docs/api/openapi.snapshot.json by tools/sdk-generator/generate-plain.php in the monorepo. Regenerate, commit, git tag vX.Y.Z && git push --tags → Packagist auto-updates.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-12