From 8f859e8cb7779aa622bcd68a3c145da13c56efbb Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 31 Oct 2023 14:45:08 +0000 Subject: [PATCH 1/5] Amend Parcel.php resource to support quantity field for multicollo. Add ShippingProduct.php, AvailableShippingFunctionality.php and WeightRange.php to support Shipping Products calls. --- .../AvailableShippingFunctionality.php | 135 ++++++++++++++++++ src/Resources/Parcel.php | 2 + src/Resources/ShippingProduct.php | 27 ++++ src/Resources/WeightRange.php | 12 ++ 4 files changed, 176 insertions(+) create mode 100644 src/Resources/AvailableShippingFunctionality.php create mode 100644 src/Resources/ShippingProduct.php create mode 100644 src/Resources/WeightRange.php diff --git a/src/Resources/AvailableShippingFunctionality.php b/src/Resources/AvailableShippingFunctionality.php new file mode 100644 index 0000000..68f58e3 --- /dev/null +++ b/src/Resources/AvailableShippingFunctionality.php @@ -0,0 +1,135 @@ + Date: Tue, 31 Oct 2023 14:56:40 +0000 Subject: [PATCH 2/5] Set ApiClient version to 1.1.0. --- src/SendCloudApiClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SendCloudApiClient.php b/src/SendCloudApiClient.php index 4c04588..0d777f6 100644 --- a/src/SendCloudApiClient.php +++ b/src/SendCloudApiClient.php @@ -21,7 +21,7 @@ class SendCloudApiClient { - public const CLIENT_VERSION = '0.2.0'; + public const CLIENT_VERSION = '1.1.0'; public const API_ENDPOINT = 'https://panel.sendcloud.sc/api'; public const API_VERSION = 'v2'; From 8bf9299b8dd2eb11963c2816534ddc4c5df479e1 Mon Sep 17 00:00:00 2001 From: Ash Date: Tue, 31 Oct 2023 15:00:07 +0000 Subject: [PATCH 3/5] Add ShippingProductsEndpoint to client. --- src/Endpoints/ShippingProductsEndpoint.php | 54 +++++++++++++++++++ .../Collections/ShippingProductCollection.php | 24 +++++++++ src/SendCloudApiClient.php | 4 ++ 3 files changed, 82 insertions(+) create mode 100644 src/Endpoints/ShippingProductsEndpoint.php create mode 100644 src/Resources/Collections/ShippingProductCollection.php diff --git a/src/Endpoints/ShippingProductsEndpoint.php b/src/Endpoints/ShippingProductsEndpoint.php new file mode 100644 index 0000000..7b3ca77 --- /dev/null +++ b/src/Endpoints/ShippingProductsEndpoint.php @@ -0,0 +1,54 @@ +client); + } + + /** + * @return ShippingProductCollection + */ + protected function getResourceCollectionObject(): ShippingProductCollection + { + return new ShippingProductCollection(null, null); + } + + /** + * @param $id + * @param array $filters + * @return AbstractResource + * @throws ApiException + */ + public function get($id, array $filters = []) + { + return $this->restRead($id, $filters); + } + + /** + * @param $filters + * @return array|AbstractCollection + * @throws ApiException + */ + public function list(array $filters = []) + { + return $this->restList($filters); + } +} diff --git a/src/Resources/Collections/ShippingProductCollection.php b/src/Resources/Collections/ShippingProductCollection.php new file mode 100644 index 0000000..38241e1 --- /dev/null +++ b/src/Resources/Collections/ShippingProductCollection.php @@ -0,0 +1,24 @@ +client); + } +} diff --git a/src/SendCloudApiClient.php b/src/SendCloudApiClient.php index 0d777f6..d053b56 100644 --- a/src/SendCloudApiClient.php +++ b/src/SendCloudApiClient.php @@ -15,6 +15,7 @@ use Imbue\SendCloud\Endpoints\ParcelStatusEndpoint; use Imbue\SendCloud\Endpoints\SenderAddressEndpoint; use Imbue\SendCloud\Endpoints\ShippingMethodEndpoint; +use Imbue\SendCloud\Endpoints\ShippingProductsEndpoint; use Imbue\SendCloud\Endpoints\UserEndpoint; use Imbue\SendCloud\Exceptions\ApiException; use Psr\Http\Message\ResponseInterface; @@ -58,6 +59,8 @@ class SendCloudApiClient public $parcelStatuses; /** @var ShippingMethodEndpoint */ public $shippingMethods; + /** @var ShippingProductsEndpoint */ + public $shippingProducts; /** @var LabelEndpoint */ public $labels; /** @var InvoiceEndpoint */ @@ -97,6 +100,7 @@ public function initializeEndpoints() $this->parcels = new ParcelEndpoint($this); $this->parcelStatuses = new ParcelStatusEndpoint($this); $this->shippingMethods = new ShippingMethodEndpoint($this); + $this->shippingProducts = new ShippingProductsEndpoint($this); $this->senderAddresses = new SenderAddressEndpoint($this); $this->labels = new LabelEndpoint($this); $this->invoices = new InvoiceEndpoint($this); From 2bdc222dda298858466c12ee144bac9daa856aa0 Mon Sep 17 00:00:00 2001 From: Ash Date: Wed, 8 Nov 2023 20:29:49 +0000 Subject: [PATCH 4/5] Bugfix Products endpoint, get Product/Method/Properties implemented to allow collo assessment. --- src/Endpoints/ShippingProductsEndpoint.php | 7 +++--- src/Resources/ShippingProduct.php | 4 ++-- src/Resources/ShippingProductMethod.php | 24 +++++++++++++++++++ .../ShippingProductMethodProperties.php | 16 +++++++++++++ ...ngProductMethodPropertiesMaxDimensions.php | 18 ++++++++++++++ src/Resources/WeightRange.php | 4 ++-- 6 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/Resources/ShippingProductMethod.php create mode 100644 src/Resources/ShippingProductMethodProperties.php create mode 100644 src/Resources/ShippingProductMethodPropertiesMaxDimensions.php diff --git a/src/Endpoints/ShippingProductsEndpoint.php b/src/Endpoints/ShippingProductsEndpoint.php index 7b3ca77..7c9775b 100644 --- a/src/Endpoints/ShippingProductsEndpoint.php +++ b/src/Endpoints/ShippingProductsEndpoint.php @@ -11,7 +11,7 @@ class ShippingProductsEndpoint extends AbstractEndpoint { /** @var string */ - protected $resourcePath = 'shipping_products'; + protected $resourcePath = 'shipping-products'; /** @var string */ protected $singleResourceKey = 'shipping_product'; @@ -39,7 +39,7 @@ protected function getResourceCollectionObject(): ShippingProductCollection */ public function get($id, array $filters = []) { - return $this->restRead($id, $filters); + return $this->list($filters)->getArrayCopy()->get($id); } /** @@ -50,5 +50,4 @@ public function get($id, array $filters = []) public function list(array $filters = []) { return $this->restList($filters); - } -} + }} diff --git a/src/Resources/ShippingProduct.php b/src/Resources/ShippingProduct.php index 5db1dea..e5f74a5 100644 --- a/src/Resources/ShippingProduct.php +++ b/src/Resources/ShippingProduct.php @@ -2,7 +2,7 @@ namespace Imbue\SendCloud\Resources; -class ShippingProduct +class ShippingProduct extends AbstractResource { /** @var string */ public $name; @@ -22,6 +22,6 @@ class ShippingProduct /** @var AvailableShippingFunctionality[] */ public $available_functionalities; - /** @var ShippingMethod[] */ + /** @var ShippingProductMethod[] */ public $methods; } \ No newline at end of file diff --git a/src/Resources/ShippingProductMethod.php b/src/Resources/ShippingProductMethod.php new file mode 100644 index 0000000..76c4e88 --- /dev/null +++ b/src/Resources/ShippingProductMethod.php @@ -0,0 +1,24 @@ + Date: Wed, 15 Nov 2023 19:15:17 +0000 Subject: [PATCH 5/5] Add restCreateCollection method to enable calling a rest create method which returns a collection rather than a single result. Add ParcelMultiEndpoint to allow creating multi-collo shipments. --- src/Endpoints/AbstractEndpoint.php | 30 ++++++++++++++++++ src/Endpoints/ParcelMultiEndpoint.php | 44 +++++++++++++++++++++++++++ src/SendCloudApiClient.php | 4 +++ 3 files changed, 78 insertions(+) create mode 100644 src/Endpoints/ParcelMultiEndpoint.php diff --git a/src/Endpoints/AbstractEndpoint.php b/src/Endpoints/AbstractEndpoint.php index 1cc91b9..00b397f 100644 --- a/src/Endpoints/AbstractEndpoint.php +++ b/src/Endpoints/AbstractEndpoint.php @@ -66,6 +66,36 @@ protected function restCreate(array $body) return ResourceFactory::createFromApiResult($result, $this->getResourceObject(), $this->getSingleResourceKey()); } + /** + * @param array $body + * @return AbstractCollection + * @throws ApiException + */ + protected function restCreateCollection(array $body) + { + $result = $this->client->performHttpCall( + self::REST_CREATE, + $this->getResourcePath(), + $this->parseRequestBody($body) + ); + + /** @var AbstractCollection $collection */ + $collection = $this->getResourceCollectionObject( + null, + null + ); + + if (is_object($result)) { + $result = $result->{$collection->getCollectionResourceName()}; + } + + foreach ($result as $dataResult) { + $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject()); + } + + return $collection; + } + /** * @param $id * @param array $filters diff --git a/src/Endpoints/ParcelMultiEndpoint.php b/src/Endpoints/ParcelMultiEndpoint.php new file mode 100644 index 0000000..f959a08 --- /dev/null +++ b/src/Endpoints/ParcelMultiEndpoint.php @@ -0,0 +1,44 @@ +client); + } + + /** + * @param $previous + * @param $next + * @return ParcelCollection + */ + protected function getResourceCollectionObject($previous, $next): ParcelCollection + { + return new ParcelCollection($this->client, $previous, $next); + } + + /** + * @param array $data + * @return ParcelCollection + * @throws ApiException + */ + public function create(array $data = []): ParcelCollection + { + return $this->restCreateCollection($data); + } +} diff --git a/src/SendCloudApiClient.php b/src/SendCloudApiClient.php index d053b56..c379a4a 100644 --- a/src/SendCloudApiClient.php +++ b/src/SendCloudApiClient.php @@ -12,6 +12,7 @@ use Imbue\SendCloud\Endpoints\InvoiceEndpoint; use Imbue\SendCloud\Endpoints\LabelEndpoint; use Imbue\SendCloud\Endpoints\ParcelEndpoint; +use Imbue\SendCloud\Endpoints\ParcelMultiEndpoint; use Imbue\SendCloud\Endpoints\ParcelStatusEndpoint; use Imbue\SendCloud\Endpoints\SenderAddressEndpoint; use Imbue\SendCloud\Endpoints\ShippingMethodEndpoint; @@ -55,6 +56,8 @@ class SendCloudApiClient /** @var ParcelEndpoint */ public $parcels; + /** @var ParcelMultiEndpoint */ + public $parcelsMulti; /** @var ParcelStatusEndpoint */ public $parcelStatuses; /** @var ShippingMethodEndpoint */ @@ -98,6 +101,7 @@ public function __construct(ClientInterface $httpClient = null) public function initializeEndpoints() { $this->parcels = new ParcelEndpoint($this); + $this->parcelsMulti = new ParcelMultiEndpoint($this); $this->parcelStatuses = new ParcelStatusEndpoint($this); $this->shippingMethods = new ShippingMethodEndpoint($this); $this->shippingProducts = new ShippingProductsEndpoint($this);