├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── examples └── create_shipment.php ├── src ├── Enum │ ├── AdditionalService.php │ ├── ContentType.php │ ├── EndpointHost.php │ ├── ParcelTemplate.php │ └── ServiceType.php ├── InpostApi.php ├── InpostApiInterface.php ├── Plugin │ ├── AcceptLanguagePlugin.php │ ├── AuthenticationPlugin.php │ ├── ContentTypePlugin.php │ ├── OrganizationIdPlugin.php │ ├── RequestIdPlugin.php │ ├── SandboxUriPlugin.php │ ├── UriPlugin.php │ └── UserAgentHeaderPlugin.php └── Resource │ ├── AbstractResource.php │ ├── AddressBooks.php │ ├── Batches.php │ ├── DeleteTrait.php │ ├── DispatchOrders.php │ ├── DispatchOrders │ └── Printout.php │ ├── DispatchPoints.php │ ├── GetTrait.php │ ├── Mpks.php │ ├── Organizations.php │ ├── Organizations │ ├── AddressBooks.php │ ├── Batches.php │ ├── DispatchOrders.php │ ├── DispatchOrders │ │ ├── Calculate.php │ │ ├── Comment.php │ │ └── Printouts.php │ ├── DispatchPoints.php │ ├── FileMappings.php │ ├── FileMappings │ │ └── Export.php │ ├── Mpks.php │ ├── Reports.php │ ├── Reports │ │ └── Cod.php │ ├── ShipmentTemplates.php │ ├── Shipments.php │ ├── Shipments │ │ ├── BulkBuy.php │ │ ├── Calculate.php │ │ ├── Labels.php │ │ ├── ReturnLabels.php │ │ └── SelectOffers.php │ ├── Statistics.php │ └── Users.php │ ├── Points.php │ ├── PostTrait.php │ ├── PutTrait.php │ ├── ResourceInterface.php │ ├── SendingMethods.php │ ├── Services.php │ ├── ShipmentTemplates.php │ ├── Shipments.php │ ├── Shipments │ ├── Buy.php │ ├── Label.php │ └── SelectOffer.php │ ├── Statuses.php │ ├── Tracking.php │ └── Tracking │ └── ServiceHistory.php └── version /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /.idea 3 | composer.lock -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Adrian Szuszkiewicz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Inpost ShipX PHP SDK 2 | 3 | ## Installation 4 | 5 | ```sh 6 | composer require imper86/php-inpost-api 7 | ``` 8 | 9 | ### HTTPlug note 10 | This lib uses [HTTPlug](https://github.com/php-http/httplug) 11 | so it doesn't depend on any http client. In order to use this 12 | lib you must have some [PSR-18 http client](https://www.php-fig.org/psr/psr-18) 13 | and [PSR-17 http factories](https://www.php-fig.org/psr/psr-17). 14 | If you don't know which one you shoud install you can require 15 | these: 16 | 17 | ```sh 18 | composer require php-http/guzzle6-adapter http-interop/http-factory-guzzle 19 | ``` 20 | 21 | ## Usage 22 | Using this library is very simple, fast example should be enough 23 | to understand how it works. 24 | 25 | ```php 26 | use Imper86\PhpInpostApi\InpostApi; 27 | use Imper86\PhpInpostApi\Plugin\AcceptLanguagePlugin; 28 | 29 | // if you want to use all resources you must ask Inpost for 30 | // access token via their contact form 31 | // https://inpost.pl/formularz-wsparcie 32 | $token = 'aaaa.aaaa'; 33 | 34 | // create api client 35 | $api = new InpostApi($token); 36 | 37 | // this library provides optional Plugin for localizing 38 | // error messages 39 | 40 | $api->addPlugin(new AcceptLanguagePlugin('pl_PL')); 41 | 42 | // from now you can use these api methods: 43 | $api->addressBooks()->(...); 44 | $api->batches()->(...); 45 | $api->dispatchOrders()->(...); 46 | $api->dispatchPoints()->(...); 47 | $api->mpks()->(...); 48 | $api->organizations()->(...); 49 | $api->points()->(...); 50 | $api->sendingMethods()->(...); 51 | $api->services()->(...); 52 | $api->shipments()->(...); 53 | $api->shipmentTemplates()->(...); 54 | $api->statuses()->(...); 55 | $api->tracking()->(...); 56 | 57 | // fast example: 58 | var_dump($api->organizations()->shipments()->get('1234')); 59 | ``` 60 | 61 | If you use IDE with typehinting such as PHPStorm, you'll easily 62 | figure it out. If not, please 63 | [take a look in Resource directory](src/Resource) 64 | 65 | ## Examples 66 | If you still wonder how to use this lib, checkout example 67 | php scripts: 68 | 69 | * [Create shipment and generate label](examples/create_shipment.php) 70 | 71 | ## Contributing 72 | Any help will be very appreciated :) 73 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "imper86/php-inpost-api", 3 | "description": "PHP SDK for Inpost ShipX API", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "imper", 9 | "email": "me@imper.info" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=7.1", 14 | "ext-json": "*", 15 | "imper86/php-http-cache-plugin": "^2.0", 16 | "imper86/http-client-builder": "^2.0" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Imper86\\PhpInpostApi\\": "src" 21 | } 22 | }, 23 | "require-dev": { 24 | "symfony/var-dumper": "^5.3", 25 | "php-http/guzzle6-adapter": "^2.0", 26 | "http-interop/http-factory-guzzle": "^1.0", 27 | "imper86/vbump": "^1.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/create_shipment.php: -------------------------------------------------------------------------------- 1 | organizations()->shipments()->post($organizationId, [ 15 | 'receiver' => [ 16 | 'name' => 'Name', 17 | 'company_name' => 'Company name', 18 | 'first_name' => 'Jan', 19 | 'last_name' => 'Kowalski', 20 | 'email' => 'test@inpost.pl', 21 | 'phone' => '111222333', 22 | ], 23 | 'parcels' => [ 24 | ['template' => 'small'], 25 | ], 26 | 'insurance' => [ 27 | 'amount' => 25, 28 | 'currency' => 'PLN', 29 | ], 30 | 'cod' => [ 31 | 'amount' => 12.50, 32 | 'currency' => 'PLN', 33 | ], 34 | 'custom_attributes' => [ 35 | 'sending_method' => 'dispatch_order', 36 | 'target_point' => 'KRA012', 37 | ], 38 | 'service' => ServiceType::INPOST_LOCKER_STANDARD, 39 | 'reference' => 'Test', 40 | 'external_customer_id' => '8877xxx', 41 | ]); 42 | 43 | $shipmentData = json_decode($response->getBody()->__toString(), true); 44 | 45 | while ($shipmentData['status'] !== 'confirmed') { 46 | sleep(1); 47 | $response = $api->shipments()->get($shipmentData['id']); 48 | $shipmentData = json_decode($response->getBody()->__toString(), true); 49 | } 50 | 51 | $labelResponse = $api->shipments()->label()->get($shipmentData['id'], [ 52 | 'format' => 'Pdf', 53 | 'type' => 'A6', 54 | ]); 55 | 56 | file_put_contents('/tmp/inpost_label.pdf', $labelResponse->getBody()->__toString()); 57 | -------------------------------------------------------------------------------- /src/Enum/AdditionalService.php: -------------------------------------------------------------------------------- 1 | 4 | * Github: https://github.com/imper86 5 | * Date: 25.10.2019 6 | * Time: 16:42 7 | */ 8 | 9 | namespace Imper86\PhpInpostApi; 10 | 11 | use Http\Client\Common\Plugin; 12 | use Imper86\HttpClientBuilder\Builder; 13 | use Imper86\HttpClientBuilder\BuilderInterface; 14 | use Imper86\PhpInpostApi\Plugin\AuthenticationPlugin; 15 | use Imper86\PhpInpostApi\Plugin\ContentTypePlugin; 16 | use Imper86\PhpInpostApi\Plugin\RequestIdPlugin; 17 | use Imper86\PhpInpostApi\Plugin\SandboxUriPlugin; 18 | use Imper86\PhpInpostApi\Plugin\UriPlugin; 19 | use Imper86\PhpInpostApi\Plugin\UserAgentHeaderPlugin; 20 | use Imper86\PhpInpostApi\Resource\AddressBooks; 21 | use Imper86\PhpInpostApi\Resource\Batches; 22 | use Imper86\PhpInpostApi\Resource\DispatchOrders; 23 | use Imper86\PhpInpostApi\Resource\DispatchPoints; 24 | use Imper86\PhpInpostApi\Resource\Mpks; 25 | use Imper86\PhpInpostApi\Resource\Organizations; 26 | use Imper86\PhpInpostApi\Resource\Points; 27 | use Imper86\PhpInpostApi\Resource\ResourceInterface; 28 | use Imper86\PhpInpostApi\Resource\SendingMethods; 29 | use Imper86\PhpInpostApi\Resource\Services; 30 | use Imper86\PhpInpostApi\Resource\Shipments; 31 | use Imper86\PhpInpostApi\Resource\ShipmentTemplates; 32 | use Imper86\PhpInpostApi\Resource\Statuses; 33 | use Imper86\PhpInpostApi\Resource\Tracking; 34 | use InvalidArgumentException; 35 | use Psr\Cache\CacheItemPoolInterface; 36 | 37 | /** 38 | * Class Asana 39 | * @package Imper86\InpostApi 40 | * 41 | * @method AddressBooks addressBooks() 42 | * @method Batches batches() 43 | * @method DispatchOrders dispatchOrders() 44 | * @method DispatchPoints dispatchPoints() 45 | * @method Mpks mpks() 46 | * @method Organizations organizations() 47 | * @method Points points() 48 | * @method SendingMethods sendingMethods() 49 | * @method Services services() 50 | * @method Shipments shipments() 51 | * @method ShipmentTemplates shipmentTemplates() 52 | * @method Statuses statuses() 53 | * @method Tracking tracking() 54 | */ 55 | class InpostApi implements InpostApiInterface 56 | { 57 | /** 58 | * @var BuilderInterface 59 | */ 60 | private $builder; 61 | /** 62 | * @var string 63 | */ 64 | private $token; 65 | 66 | public function __construct(?string $token = null, bool $sandbox = false, ?BuilderInterface $builder = null) 67 | { 68 | $this->token = $token; 69 | $this->builder = $builder ?: new Builder(); 70 | $this->builder->addPlugin(new UriPlugin($this->builder->getUriFactory())); 71 | $this->builder->addPlugin(new ContentTypePlugin()); 72 | $this->builder->addPlugin(new UserAgentHeaderPlugin()); 73 | $this->builder->addPlugin(new RequestIdPlugin()); 74 | 75 | if ($token) { 76 | $this->builder->addPlugin(new AuthenticationPlugin($token)); 77 | } 78 | 79 | if ($sandbox) { 80 | $this->builder->addPlugin(new SandboxUriPlugin()); 81 | } 82 | } 83 | 84 | public function __call($name, $arguments) 85 | { 86 | return $this->api($name); 87 | } 88 | 89 | public function api(string $resource): ResourceInterface 90 | { 91 | $className = 'Imper86\\PhpInpostApi\\Resource\\' . ucfirst($resource); 92 | 93 | if (class_exists($className) && is_subclass_of($className, ResourceInterface::class)) { 94 | return new $className($this); 95 | } 96 | 97 | throw new InvalidArgumentException(sprintf('%s resource not found', $resource)); 98 | } 99 | 100 | public function getBuilder(): BuilderInterface 101 | { 102 | return $this->builder; 103 | } 104 | 105 | public function addPlugin(Plugin $plugin): void 106 | { 107 | $this->builder->addPlugin($plugin); 108 | } 109 | 110 | public function removePlugin(string $fqcn): void 111 | { 112 | $this->builder->removePlugin($fqcn); 113 | } 114 | 115 | public function addCache(CacheItemPoolInterface $cacheItemPool, array $config = []): void 116 | { 117 | $this->builder->addCache($cacheItemPool, $config); 118 | } 119 | 120 | public function removeCache(): void 121 | { 122 | $this->builder->removeCache(); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/InpostApiInterface.php: -------------------------------------------------------------------------------- 1 | 4 | * Github: https://github.com/imper86 5 | * Date: 25.10.2019 6 | * Time: 16:37 7 | */ 8 | 9 | namespace Imper86\PhpInpostApi; 10 | 11 | use Http\Client\Common\Plugin; 12 | use Imper86\HttpClientBuilder\BuilderInterface; 13 | use Imper86\PhpInpostApi\Resource\AddressBooks; 14 | use Imper86\PhpInpostApi\Resource\Batches; 15 | use Imper86\PhpInpostApi\Resource\DispatchOrders; 16 | use Imper86\PhpInpostApi\Resource\DispatchPoints; 17 | use Imper86\PhpInpostApi\Resource\Mpks; 18 | use Imper86\PhpInpostApi\Resource\Organizations; 19 | use Imper86\PhpInpostApi\Resource\Points; 20 | use Imper86\PhpInpostApi\Resource\ResourceInterface; 21 | use Imper86\PhpInpostApi\Resource\SendingMethods; 22 | use Imper86\PhpInpostApi\Resource\Services; 23 | use Imper86\PhpInpostApi\Resource\Shipments; 24 | use Imper86\PhpInpostApi\Resource\ShipmentTemplates; 25 | use Imper86\PhpInpostApi\Resource\Statuses; 26 | use Imper86\PhpInpostApi\Resource\Tracking; 27 | use Psr\Cache\CacheItemPoolInterface; 28 | 29 | /** 30 | * Interface AsanaInterface 31 | * @package Imper86\AllegroApi 32 | * 33 | * @method AddressBooks addressBooks() 34 | * @method Batches batches() 35 | * @method DispatchOrders dispatchOrders() 36 | * @method DispatchPoints dispatchPoints() 37 | * @method Mpks mpks() 38 | * @method Organizations organizations() 39 | * @method Points points() 40 | * @method SendingMethods sendingMethods() 41 | * @method Services services() 42 | * @method Shipments shipments() 43 | * @method ShipmentTemplates shipmentTemplates() 44 | * @method Statuses statuses() 45 | * @method Tracking tracking() 46 | */ 47 | interface InpostApiInterface 48 | { 49 | /** 50 | * @param string $resource 51 | * @return ResourceInterface 52 | */ 53 | public function api(string $resource): ResourceInterface; 54 | 55 | /** 56 | * @return BuilderInterface 57 | */ 58 | public function getBuilder(): BuilderInterface; 59 | 60 | /** 61 | * @param Plugin $plugin 62 | */ 63 | public function addPlugin(Plugin $plugin): void; 64 | 65 | /** 66 | * Fully qualified class name of plugin 67 | * 68 | * @param string $fqcn 69 | */ 70 | public function removePlugin(string $fqcn): void; 71 | 72 | /** 73 | * @param CacheItemPoolInterface $cacheItemPool 74 | * @param array $config 75 | */ 76 | public function addCache(CacheItemPoolInterface $cacheItemPool, array $config = []): void; 77 | 78 | /** 79 | * Removes cache plugin from http client 80 | */ 81 | public function removeCache(): void; 82 | } 83 | -------------------------------------------------------------------------------- /src/Plugin/AcceptLanguagePlugin.php: -------------------------------------------------------------------------------- 1 | acceptLanguage = $acceptLanguage; 21 | } 22 | 23 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise 24 | { 25 | if (!$request->hasHeader('Accept-Language')) { 26 | $request = $request->withHeader('Accept-Language', $this->acceptLanguage); 27 | } 28 | 29 | return $next($request); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Plugin/AuthenticationPlugin.php: -------------------------------------------------------------------------------- 1 | token = $token; 21 | } 22 | 23 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise 24 | { 25 | if ($request->hasHeader('Authorization')) { 26 | return $next($request); 27 | } 28 | 29 | return $next($request->withHeader('Authorization', sprintf('Bearer %s', $this->token))); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Plugin/ContentTypePlugin.php: -------------------------------------------------------------------------------- 1 | hasHeader('Content-Type')) { 17 | $request = $request->withHeader('Content-Type', ContentType::JSON); 18 | } 19 | 20 | if (!$request->hasHeader('Accept')) { 21 | $request = $request->withHeader('Accept', ContentType::JSON); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Plugin/OrganizationIdPlugin.php: -------------------------------------------------------------------------------- 1 | placeholder = $placeholder; 25 | $this->organizationId = $organizationId; 26 | } 27 | 28 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise 29 | { 30 | $uri = $request->getUri(); 31 | 32 | if (false !== strpos($uri->getPath(), $this->placeholder)) { 33 | $uri = $uri->withPath(str_replace($this->placeholder, $this->organizationId, $uri->getPath())); 34 | $request = $request->withUri($uri); 35 | } 36 | 37 | return $next($request); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Plugin/RequestIdPlugin.php: -------------------------------------------------------------------------------- 1 | hasHeader('X-Request-ID')) { 16 | $request = $request->withHeader('X-Request-ID', uniqid('', true)); 17 | } 18 | 19 | return $next($request); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Plugin/SandboxUriPlugin.php: -------------------------------------------------------------------------------- 1 | getUri(); 17 | $uri = $uri->withHost(EndpointHost::SANDBOX); 18 | 19 | return $next($request->withUri($uri)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Plugin/UriPlugin.php: -------------------------------------------------------------------------------- 1 | 4 | * Github: https://github.com/imper86 5 | * Date: 25.10.2019 6 | * Time: 17:29 7 | */ 8 | 9 | namespace Imper86\PhpInpostApi\Plugin; 10 | 11 | use Http\Client\Common\Plugin; 12 | use Http\Promise\Promise; 13 | use Imper86\PhpInpostApi\Enum\EndpointHost; 14 | use Psr\Http\Message\RequestInterface; 15 | use Psr\Http\Message\UriFactoryInterface; 16 | 17 | class UriPlugin implements Plugin 18 | { 19 | /** 20 | * @var UriFactoryInterface 21 | */ 22 | private $uriFactory; 23 | 24 | public function __construct(UriFactoryInterface $uriFactory) 25 | { 26 | $this->uriFactory = $uriFactory; 27 | } 28 | 29 | public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise 30 | { 31 | $uri = $request->getUri(); 32 | 33 | if (empty($uri->getHost())) { 34 | $uri = $uri->withHost(EndpointHost::API); 35 | } 36 | 37 | return $next($request->withUri($uri->withScheme('https'))); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Plugin/UserAgentHeaderPlugin.php: -------------------------------------------------------------------------------- 1 | hasHeader('X-User-Agent')) { 16 | $request = $request->withHeader('X-User-Agent', 'imper86/php-inpost-api') 17 | ->withHeader('X-User-Agent-Version', trim(file_get_contents(__DIR__ . '/../../version'))); 18 | } 19 | 20 | return $next($request); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Resource/AbstractResource.php: -------------------------------------------------------------------------------- 1 | 4 | * Github: https://github.com/imper86 5 | * Date: 20.10.2019 6 | * Time: 14:40 7 | */ 8 | 9 | namespace Imper86\PhpInpostApi\Resource; 10 | 11 | use Imper86\PhpInpostApi\InpostApiInterface; 12 | use InvalidArgumentException; 13 | use Psr\Http\Client\ClientInterface as HttpClientInterface; 14 | use Psr\Http\Message\RequestFactoryInterface; 15 | use Psr\Http\Message\ResponseInterface; 16 | use Psr\Http\Message\StreamFactoryInterface; 17 | use Psr\Http\Message\UriFactoryInterface; 18 | use ReflectionClass; 19 | 20 | abstract class AbstractResource implements ResourceInterface 21 | { 22 | /** 23 | * @var InpostApiInterface 24 | */ 25 | protected $client; 26 | /** 27 | * @var RequestFactoryInterface 28 | */ 29 | protected $requestFactory; 30 | /** 31 | * @var UriFactoryInterface 32 | */ 33 | protected $uriFactory; 34 | /** 35 | * @var HttpClientInterface 36 | */ 37 | protected $httpClient; 38 | /** 39 | * @var StreamFactoryInterface 40 | */ 41 | protected $streamFactory; 42 | /** 43 | * @var ReflectionClass 44 | */ 45 | protected $reflection; 46 | 47 | 48 | public function __construct(InpostApiInterface $client) 49 | { 50 | $this->client = $client; 51 | $this->requestFactory = $client->getBuilder()->getRequestFactory(); 52 | $this->uriFactory = $client->getBuilder()->getUriFactory(); 53 | $this->streamFactory = $client->getBuilder()->getStreamFactory(); 54 | $this->httpClient = $client->getBuilder()->getHttpClient(); 55 | $this->reflection = new ReflectionClass($this); 56 | } 57 | 58 | public function __call($name, $arguments) 59 | { 60 | $className = $this->reflection->getName() . '\\' . ucfirst($name); 61 | 62 | if (class_exists($className) && is_a($className, ResourceInterface::class, true)) { 63 | return new $className($this->client); 64 | } 65 | 66 | throw new InvalidArgumentException(sprintf('%s resource not found', $name)); 67 | } 68 | 69 | protected function apiGet(string $uri, ?array $query = null): ResponseInterface 70 | { 71 | $uri = $this->uriFactory->createUri($uri); 72 | 73 | if ($query) { 74 | $queryString = http_build_query($query); 75 | $queryString = preg_replace('/%5B\d+%5D/', '[]', $queryString); 76 | 77 | $uri = $uri->withQuery($queryString); 78 | } 79 | 80 | $request = $this->requestFactory->createRequest('GET', $uri); 81 | 82 | return $this->httpClient->sendRequest($request); 83 | } 84 | 85 | protected function apiPost(string $uri, ?array $body = null): ResponseInterface 86 | { 87 | $request = $this->requestFactory->createRequest('POST', $uri); 88 | 89 | if ($body) { 90 | $stream = $this->streamFactory->createStream(json_encode($body)); 91 | $request = $request->withBody($stream); 92 | } 93 | 94 | return $this->httpClient->sendRequest($request); 95 | } 96 | 97 | protected function apiPut(string $uri, ?array $body = null): ResponseInterface 98 | { 99 | $request = $this->requestFactory->createRequest('PUT', $uri); 100 | 101 | if ($body) { 102 | $stream = $this->streamFactory->createStream(json_encode($body)); 103 | $request = $request->withBody($stream); 104 | } 105 | 106 | return $this->httpClient->sendRequest($request); 107 | } 108 | 109 | protected function apiDelete(string $uri, ?array $query = null): ResponseInterface 110 | { 111 | $uri = $this->uriFactory->createUri($uri); 112 | 113 | if ($query) { 114 | $uri = $uri->withQuery(http_build_query($query)); 115 | } 116 | 117 | $request = $this->requestFactory->createRequest('DELETE', $uri); 118 | 119 | return $this->httpClient->sendRequest($request); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/Resource/AddressBooks.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('%s/%s', $this->getBaseUri(), $id), $query); 16 | } 17 | 18 | protected function getBaseUri(): string 19 | { 20 | return '/v1/address_books'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Resource/Batches.php: -------------------------------------------------------------------------------- 1 | apiDelete(sprintf('%s/%s', $this->getBaseUri(), $id)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Resource/DispatchOrders.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/dispatch_orders/%s', $orderId), $query); 23 | } 24 | 25 | protected function getBaseUri(): string 26 | { 27 | return '/v1/dispatch_orders'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Resource/DispatchOrders/Printout.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/dispatch_orders/%s/printout', $dispatchOrderId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/DispatchPoints.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/dispatch_points/%s', $id), $query); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Resource/GetTrait.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('%s%s', $this->getBaseUri(), $id ? "/{$id}" : null), $query); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Resource/Mpks.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('%s/%s', $this->getBaseUri(), $id), $query); 16 | } 17 | 18 | protected function getBaseUri(): string 19 | { 20 | return '/v1/mpks'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Resource/Organizations.php: -------------------------------------------------------------------------------- 1 | apiGet( 15 | sprintf('/v1/organizations/%s/address_books%s', $organizationId, $addressId ? "/{$addressId}" : ''), 16 | $query 17 | ); 18 | } 19 | 20 | public function post(string $organizationId, array $body): ResponseInterface 21 | { 22 | return $this->apiPost(sprintf('/v1/organizations/%s/address_books', $organizationId), $body); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Batches.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/batches', $organizationId), $body); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/DispatchOrders.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/dispatch_orders', $organizationId), $body); 26 | } 27 | 28 | public function get(string $organizationId, ?array $query = null): ResponseInterface 29 | { 30 | return $this->apiGet(sprintf('/v1/organizations/%s/dispatch_orders', $organizationId), $query); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Resource/Organizations/DispatchOrders/Calculate.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/dispatch_orders/calculate', $organizationId), $body); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/DispatchOrders/Comment.php: -------------------------------------------------------------------------------- 1 | apiPost( 15 | sprintf('/v1/organizations/%s/dispatch_orders/%s/comment', $organizationId, $dispatchOrderId), 16 | $body 17 | ); 18 | } 19 | 20 | public function put(string $organizationId, string $dispatchOrderId, array $body): ResponseInterface 21 | { 22 | return $this->apiPut( 23 | sprintf('/v1/organizations/%s/dispatch_orders/%s/comment', $organizationId, $dispatchOrderId), 24 | $body 25 | ); 26 | } 27 | 28 | public function delete(string $organizationId, string $dispatchOrderId, array $body): ResponseInterface 29 | { 30 | $uri = $this->uriFactory->createUri( 31 | sprintf('/v1/organizations/%s/dispatch_orders/%s/comment', $organizationId, $dispatchOrderId) 32 | ); 33 | $request = $this->requestFactory->createRequest('DELETE', $uri) 34 | ->withBody($this->streamFactory->createStream(json_encode($body))); 35 | 36 | return $this->httpClient->sendRequest($request); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Resource/Organizations/DispatchOrders/Printouts.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/dispatch_orders/printouts', $organizationId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/DispatchPoints.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/dispatch_points', $organizationId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/FileMappings.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/file_mappings', $organizationId), $query); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Resource/Organizations/FileMappings/Export.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/file_mappings/export', $organizationId), $body); 15 | } 16 | 17 | public function get(string $organizationId, string $exportId, ?array $query = null): ResponseInterface 18 | { 19 | return $this->apiGet( 20 | sprintf('/v1/organizations/%s/file_mappings/export/%s', $organizationId, $exportId), 21 | $query 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Mpks.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/mpks', $organizationId), $query); 15 | } 16 | 17 | public function post(string $organizationId, array $body): ResponseInterface 18 | { 19 | return $this->apiPost(sprintf('/admin/v1/organizations/%s/mpks', $organizationId), $body); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Reports.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/reports/cod', $organizationId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/ShipmentTemplates.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/shipment_templates', $organizationId), $query); 15 | } 16 | 17 | public function post(string $organizationId, array $body): ResponseInterface 18 | { 19 | return $this->apiPost(sprintf('/v1/organizations/%s/shipment_templates', $organizationId), $body); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Shipments.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/shipments', $organizationId), $body); 30 | } 31 | 32 | public function get(string $organizationId, ?string $id = null, ?array $query = null): ResponseInterface 33 | { 34 | return $this->apiGet( 35 | sprintf('/v1/organizations/%s/shipments%s', $organizationId, $id ? "/{$id}" : ''), 36 | $query 37 | ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Shipments/BulkBuy.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/shipments/bulk_buy', $organizationId), $body); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Shipments/Calculate.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/shipments/calculate', $organizationId), $body); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Shipments/Labels.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/shipments/labels', $organizationId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Shipments/ReturnLabels.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/shipments/return_labels', $organizationId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Shipments/SelectOffers.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/organizations/%s/shipments/select_offers', $organizationId), $body); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Statistics.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/organizations/%s/statistics', $organizationId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Organizations/Users.php: -------------------------------------------------------------------------------- 1 | apiGet( 15 | sprintf('/v1/organizations/%s/users%s', $organizationId, $userId ? "/{$userId}" : ''), 16 | $query 17 | ); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Resource/Points.php: -------------------------------------------------------------------------------- 1 | apiPost($this->getBaseUri(), $body); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Resource/PutTrait.php: -------------------------------------------------------------------------------- 1 | apiPut(sprintf('%s/%s', $this->getBaseUri(), $id), $body); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Resource/ResourceInterface.php: -------------------------------------------------------------------------------- 1 | 4 | * Github: https://github.com/imper86 5 | * Date: 20.10.2019 6 | * Time: 13:30 7 | */ 8 | 9 | namespace Imper86\PhpInpostApi\Resource; 10 | 11 | interface ResourceInterface 12 | { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/Resource/SendingMethods.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/shipment_templates/%s', $id), $query); 16 | } 17 | 18 | protected function getBaseUri(): string 19 | { 20 | return '/v1/shipment_templates'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Resource/Shipments.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('%s/%s', $this->getBaseUri(), $id), $query); 26 | } 27 | 28 | protected function getBaseUri(): string 29 | { 30 | return '/v1/shipments'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Resource/Shipments/Buy.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/shipments/%s/buy', $shipmentId), $body); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Shipments/Label.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/shipments/%s/label', $shipmentId), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Shipments/SelectOffer.php: -------------------------------------------------------------------------------- 1 | apiPost(sprintf('/v1/shipments/%s/select_offer', $shipmentId), $body); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Resource/Statuses.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/tracking/%s', $trackingNumber), $query); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Resource/Tracking/ServiceHistory.php: -------------------------------------------------------------------------------- 1 | apiGet(sprintf('/v1/tracking/%s/service_history', $trackingNumber), $query); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | v1.1.2 2 | --------------------------------------------------------------------------------