trunkrs/sdk
Composer 安装命令:
composer require trunkrs/sdk
包简介
Trunkrs Client SDK
关键字:
README 文档
README
The Trunkrs software development kit for the public client SDK. With this PHP SDK you can manage your shipments, shipment states and webhooks within our system.
Migrate from version 1
Check out our migration guide if you wish to migrate your v1 implementation of the Trunkrs SDK.
Requirements
PHP 7.0 and later.
Installation
You can install the SDK via Composer. Run the following command:
composer require trunkrs/sdk
To use the bindings, use Composer's autoload:
require_once('vendor/autoload.php');
Dependencies
The SDK requires the following extensions in order to work properly:
jsonguzzle/guzzle(optional, can be replaced)
If you use Composer, these dependencies should be handled automatically.
Getting started
Setup the SDK settings before usage by supplying your merchant credentials. If you don't have any credentials yet, please contact Trunkrs for more information.
\Trunkrs\SDK\Settings::setApiKey("your-trunkrs-api-key");
Using staging
To make use of the Trunkrs staging environment, which has been supplied to test your implementation with our system. The SDK can be switched easily.
\Trunkrs\SDK\Settings::useStaging();
Both API endpoints and the tracking URL's will point to the staging environment.
Shipments
Create a shipment
A shipment can be created through the Shipment class. It exposes a static method Shipment::create(...).
$details = new \Trunkrs\SDK\ShipmentDetails(); $parcel = new \Trunkrs\SDK\Parcel(); // Set the reference of the parcel. This is required. $parcel->reference = 'your-order-reference'; $details->parcels = [ // Define which parcels are part of this shipment $parcel, ]; $details->sender = new \Trunkrs\SDK\Address(); // Set the pickup address properties. $details->recipient = new \Trunkrs\SDK\Address(); // Set the delivery address properties. $shipments = \Trunkrs\SDK\Shipment::create($details);
International shipping
When shipping internationally we require you to define the contents of a parcel as well as the volume and weight of the parcel.
Retrieve shipment details
Details for a single shipment can be retrieved through its identifier by calling the Shipment::find($trunkrsNr) method.
$shipment = \Trunkrs\SDK\Shipment::find('4000002123');
Retrieve shipment history
Your shipment history can be listed in a paginated manner by using the Shipment::retrieve($page) method.
Every returned page contains a maximum of 50 shipments.
$shipments = \Trunkrs\SDK\Shipment::retrieve();
Cancel a shipment
Shipments can be canceled by their identifier or simply through the cancel() method on an instance of a Shipment.
The Shipment class exposes the cancelByTrunkrsNr($trunkrsNr) static method:
\Trunkrs\SDK\Shipment::cancelByTrunkrsNr('4000002123');
An instance of the Shipment class also exposes a convenience method cancel():
$shipment = \Trunkrs\SDK\Shipment::find('4000002123'); $shipment->cancel();
Shipment State
To retrieve details about the shipment's current state and the current owner of the shipment.
The ShipmentState class can be used which exposes the static forShipment($shipmentId) method.
$status = \Trunkrs\SDK\ShipmentState::forShipment('4000002123');
Web hooks
To be notified about shipment state changes, Trunkrs has created a webhook notification service. The SDK allows the registration of a callback URL for notifications through this service.
Register subscription
The Webhook class exposes a static method called register($webhook) which allows the registration of new web hooks:
$webhook = new \Trunkrs\SDK\Webhook(); $webhook->callbackUrl = "https://your.web.service/shipments/webhook"; $webhook->sessionHeaderName = 'X-SESSION-TOKEN'; $webhook->sessionToken = "your-secret-session-token"; $webhook->event = \Trunkrs\SDK\Enum\WebhookEvent::ON_STATE_UPDATE; \Trunkrs\SDK\Webhook::register($webhook);
Retrieve active subscriptions
Your active webhook subscriptions can be listed using Webhook::retrieve().
$webhooks = \Trunkrs\SDK\Webhook::retrieve();
Cancel subscription
Canceling a web hook subscription can be done using Webhook::removeById($webhookId) or the instance method on an instance of webhook.
$webhookId = 100; \Trunkrs\SDK\Webhook::removeById($webhookId);
$webhook = \Trunkrs\SDK\Webhook::find(100); $webhook->remove();
trunkrs/sdk 适用场景与选型建议
trunkrs/sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 109.93k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「logistics」 「trunkrs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 trunkrs/sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 trunkrs/sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 trunkrs/sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Miaoxing Logistics Plugin
Trunkrs Shipping Method Plugin for Magento 2
A PSR-7 compatible library for making CRUD API endpoints
Unofficial PHP SDK for Poste Delivery Business Rest API services
PHP SDK for SpediamoPro Rest API services
PHP SDK for InPost Global Rest API
统计信息
- 总下载量: 109.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-10