mvdnbrk / myparcel-php-api
PHP的MyParcel API客户端
v2.3.0
2020-12-18 10:20 UTC
Requires
- php: ^7.3 || ^8.0
- ext-json: *
- composer/ca-bundle: ^1.2
- guzzlehttp/guzzle: ^6.4 || ^7.1
- illuminate/collections: ^8.0
Requires (Dev)
- phpunit/phpunit: ^8.5 || ^9.4
- symfony/var-dumper: ^5.0
- vlucas/phpdotenv: ^5.0
README
MyParcel使发送包裹变得简单。
要求
要使用MyParcel API客户端,需要以下条件
- 获取一个免费的MyParcel账户
- 生成你的API密钥
- 现在你可以使用MyParcel API客户端了
安装
您可以通过composer安装此包
composer require mvdnbrk/myparcel-php-api
入门
初始化MyParcel客户端并设置API密钥
$myparcel = new \Mvdnbrk\MyParcel\Client(); $myparcel->setApiKey('your-api-key');
创建包裹
$parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ 'reference' => 'your own reference for the parcel', 'recipient' => [ 'first_name' => 'John', 'last_name' => 'Doe' 'street' => 'Poststraat', 'number' => '1', 'number_suffix' => 'A', 'postal_code' => '1234AA', 'city' => 'Amsterdam', 'cc' => 'NL', ] ]);
创建运输
$shipment = $myparcel->shipments->create($parcel); // Get the `id` of the shipment. You may save this value for later reference. $shipment->id;
你已经创建了你的第一个运输!
获取标签
可以通过使用$shipment->id
来获取标签。这将返回一个A6格式的字符串。
$myparcel->labels->get($shipment->id);
或者,您可以将Shipment
实例直接传递给此方法
$myparcel->labels->get($shipment);
默认标签格式为A6,您可以通过调用setFormatA4
方法来更改它
$myparcel->labels->setFormatA4()->get($shipment);
为包裹设置投递选项
您可以通过在创建包裹时直接传递选项来设置包裹的投递选项
$parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ ... 'recipient' => [ ... ], 'options' => [ 'description' => 'Description on the label', 'signature' => true, ... ], ]);
或者,您可以使用类似signature
、onlyRecipient
、returnToSender
、ageCheck
和labelDescription
的方法。您可以在构建包裹后调用这些方法中的任何一项
$parcel->labelDescription('Your description.') ->ageCheck() ->onlyRecipient() ->returnToSender() ->signature();
邮箱包裹
此包装类型仅适用于适合标准邮箱的荷兰运输
$parcel->mailboxpackage();
将包裹发送到服务点
您可以将包裹发送到PostNL服务点,客户可以在那里取包裹
$parcel = new \Mvdnbrk\MyParcel\Resources\Parcel([ 'recipient' => [ ... ], 'pickup' => [ 'name' => 'Name of the location', 'street' => 'Poststraat', 'number' => '1', 'postal_code' => '1234AA', 'city' => 'Amsterdam', 'cc' => 'NL, ] ]);
检索服务点
$servicepoints = $myparcel->servicePoints->setPostalcode('1234AA')->setHousenumber('1')->get();
这将返回一组ServicePoint
对象
$servicepoints->each(function ($item) { $item->id; $item->name; $item->latitude; $item->longitude; $item->distance; $item->distanceForHumans(); $item->opening_hours; });
获取运输
您可以通过id
或您自己的引用来获取运输
$shipment = $myparcel->shipments->get($id); $shipment = $myparcel->shipments->getByReference('your own reference'); // Get the barcode for the shipment: $shipment->barcode; // Get the current status: $shipment->status;
跟踪运输
您可以为运输获取详细的跟踪和溯源信息。
$tracktrace = $myparcel->tracktrace->get($id); // Links: $tracktrace->link; $tracktrace->link_portal; // Check if the shipment is delivered: $tracktrace->isDelivered; // Get current state of the shipment: $tracktrace->code; $tracktrace->description; $tracktrace->datetime; // Get all traces for the shipment, this will return a collection with // all traces in descending order, including the current state: $tracktrace->items; // Convert all items to an array: $tracktrace->items->all()
与Laravel一起使用
您可以通过使用此包将此包集成到您的Laravel应用程序中。
变更日志
请参阅CHANGELOG以获取有关最近更改的更多信息。
测试
$ composer test
贡献
请参阅CONTRIBUTING以获取详细信息。
安全漏洞
请查阅我们的安全策略,了解如何报告安全漏洞。
致谢
许可
MIT许可(MIT)。请参阅许可文件以获取更多信息。