patryk-sawicki / inpost-laravel
InPost ShipX API客户端,适用于laravel。
1.0.4
2024-03-19 07:44 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- laravel/framework: ^8.00 || ^9.00 || ^10.00 || ^11.00
Requires (Dev)
- phpunit/phpunit: ^9.5
README
InPost ShipX API客户端,适用于laravel。
基于aPaczka api 文档。
需求
- PHP 7.4或更高版本,并支持json扩展。
安装
推荐通过Composer进行安装。
composer require patryk-sawicki/inpost-laravel
用法
添加到环境变量
INPOST_API_KEY = 'your_api_key'
导入类
use PatrykSawicki\InPost\app\Classes\InPost;
组织
列表
获取组织列表。
InPost::organizations()->list(array $options = [], bool $returnJson = false);
获取
获取组织详情。
InPost::organizations()->get(int $id, bool $returnJson = false);
统计
获取组织统计。
InPost::organizations()->statistics(int $id, bool $returnJson = false);
服务
获取可用服务的列表。
InPost::services()->list(bool $returnJson = false);
网点
列表
获取可用网点的列表。
InPost::points()->list(array $options = [], bool $returnJson = false);
获取
获取网点详情。
InPost::points()->get(string $name, bool $returnJson = false);
运输
发送
发送新的运输。
use PatrykSawicki\InPost\app\Classes\InPost; use PatrykSawicki\InPost\app\Models\Cash as InPostCash; use PatrykSawicki\InPost\app\Models\Dimensions as InPostDimensions; use PatrykSawicki\InPost\app\Models\Weight as InPostWeight; use PatrykSawicki\InPost\app\Models\Address as InPostAddress; use PatrykSawicki\InPost\app\Models\Parcel as InPostParcel; use PatrykSawicki\InPost\app\Models\Parcels as InPostParcels; use PatrykSawicki\InPost\app\Models\Receiver as InPostReceiver; use PatrykSawicki\InPost\app\Models\Sender as InPostSender; $shipment = InPost::shipment(); /*Set organization*/ $shipment->setOrganizationId(123); /*Receiver*/ $receiverAddress = new InPostAddress('street', 'building_number', 'city', 'post_code', 'PL'); $receiver = new InPostReceiver('name', 'company name', 'first name', 'last name', 'e-mail', 'phone', $receiverAddress); $shipment->setReceiver($receiver); /*Sender - Optional*/ $senderAddress = new InPostAddress('street', 'building_number', 'city', 'post_code', 'PL'); $sender = new InPostSender('name', 'company name', 'first name', 'last name', 'e-mail', 'phone', $senderAddress); $shipment->setSender($sender); /*Parcels*/ $dimensions = new InPostDimensions(10, 10, 10, 'mm'); $weight = new InPostWeight(10, 'kg'); $firstParcel = new InPostParcel($dimensions, $weight, 'parcel 1'); /*Second parcel is optional.*/ $dimensions = new InPostDimensions(20, 20, 20, 'mm'); $weight = new InPostWeight(5, 'kg'); $secondParcel = new InPostParcel($dimensions, $weight, 'parcel 2'); $shipment->setParcels(new InPostParcels($firstParcel, $secondParcel)); /*Insurance - Optional*/ $insurance = new InPostCash(100, 'PLN'); $shipment->setInsurance($insurance); /*Cod - Optional*/ $cod = new InPostCash(100, 'PLN'); $shipment->setCod($cod); /*Additional Services - Optional*/ $shipment->setAdditionalServices(['sms', 'email']); /*Reference - Optional*/ $shipment->setReference('reference'); /*Comments - Optional*/ $shipment->setComments('comments'); /*External customer id - Optional*/ $shipment->setExternalCustomerId('external customer id'); /*MPK - Optional*/ $shipment->setMpk('mpk'); /*Is return - Optional*/ $shipment->setIsReturn(false); /*Service*/ $shipment->setService('inpost_locker_standard'); /*Custom attributes - Optional*/ $shipment->setCustomAttributes(['target_point' => 'xxx']); /*Only choice of offer - Optional*/ $shipment->setOnlyChoiceOfOffer(true); /*Send shipment*/ $shipment->send(bool $returnJson = false);
取消
取消运输。
InPost::shipment()->cancel(int $id, bool $returnJson = false);
标签
获取运输标签。
return InPost::shipment()->label(int $id, string $format = 'pdf', string $type = 'normal');
跟踪
获取跟踪详情。
InPost::tracking()->get(string $tracking_number, bool $returnJson = false);
状态
获取可用状态的列表。
InPost::statuses()->list(bool $returnJson = false);
发货订单
创建
创建新的发货订单。
use PatrykSawicki\InPost\app\Classes\InPost; use PatrykSawicki\InPost\app\Models\Address as InPostAddress; $dispatchOrders = InPost::dispatchOrders(); /*Set organization*/ $dispatchOrders->setOrganizationId(2324); /*Set shipments*/ $dispatchOrders->setShipments(1, 2, 3, 4); /*Set comments - Optional*/ $dispatchOrders->setComments('Test'); /*Set address*/ $dispatchOrders->setAddress(new InPostAddress('street', 'building_number', 'city', 'post_code', 'PL')); /*Set office hours - Optional*/ $dispatchOrders->setOfficeHours('09:00 - 18:00'); /*Set name*/ $dispatchOrders->setName('Patryk Sawicki'); /*Set phone*/ $dispatchOrders->setPhone('+48793202257'); /*Set email - Optional*/ $dispatchOrders->setEmail('patryk@patryksawicki.pl'); /*Create a new dispatch orders.*/ $dispatchOrders->create(bool $returnJson = false);
取消
取消发货订单
InPost::dispatchOrders()->cancel(int $id, bool $returnJson = false);
列表
获取发货订单列表。
$dispatchOrders = InPost::dispatchOrders(); /*Set organization*/ $dispatchOrders->setOrganizationId(2324); $dispatchOrders->list(bool $returnJson = false);
获取
获取发货订单详情。
$dispatchOrders->get(int $id, bool $returnJson = false);
添加评论
向发货订单添加评论。
$dispatchOrders = InPost::dispatchOrders(); /*Set organization*/ $dispatchOrders->setOrganizationId(123456); $dispatchOrders->addComment(int $dispatch_order_id, string $comment, bool $returnJson = false);
更新评论
更新发货订单中的评论。
$dispatchOrders = InPost::dispatchOrders(); /*Set organization*/ $dispatchOrders->setOrganizationId(123456); $dispatchOrders->updateComment(int $dispatch_order_id, int $comment_id, string $comment, bool $returnJson = false);
更新评论
更新发货订单中的评论。
$dispatchOrders = InPost::dispatchOrders(); /*Set organization*/ $dispatchOrders->setOrganizationId(123456); $dispatchOrders->removeComment(int $dispatch_order_id, int $comment_id, bool $returnJson = false);
变更日志
变更日志可在此处找到。