diff --git a/composer.json b/composer.json index 387f7f9..2132a5d 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "jouwweb/sendcloud", + "name": "retrobak/sendcloud", "description": "Provides a client to interact with the Sendcloud API in an object-oriented way.", "keywords": [ "sendcloud", diff --git a/src/Client.php b/src/Client.php index 5e6a568..05719ff 100644 --- a/src/Client.php +++ b/src/Client.php @@ -203,6 +203,61 @@ public function createParcel( } } + /** + * @param Address $shippingAddress + * @param int|null $servicePointId + * @param string|null $orderNumber + * @param int|null $weight + * @param string|null $customsInvoiceNumber + * @param int|null $customsShipmentType + * @param array|null $items + * @param string|null $postNumber + * @param ShippingMethod|int $shippingMethod + * @param SenderAddress|int|Address|null $senderAddress Passing null will pick Sendcloud's default. An Address will + * @return Parcel + * @throws SendCloudRequestException + */ + public function createParcelWithLabel( + Address $shippingAddress, + ?int $servicePointId, + ?string $orderNumber = null, + ?int $weight = null, + ?string $customsInvoiceNumber = null, + ?int $customsShipmentType = null, + ?array $items = null, + ?string $postNumber = null, + $shippingMethod, + $senderAddress + ) + { + $parcelData = $this->getParcelData( + null, + $shippingAddress, + $servicePointId, + $orderNumber, + $weight, + true, + $shippingMethod, + $senderAddress, + $customsInvoiceNumber, + $customsShipmentType, + $items, + $postNumber + ); + + try { + $response = $this->guzzleClient->post('parcels', [ + 'json' => [ + 'parcel' => $parcelData, + ], + ]); + + return new Parcel(json_decode((string)$response->getBody(), true)['parcel']); + } catch (TransferException $exception) { + throw $this->parseGuzzleException($exception, 'Could not create parcel in Sendcloud.'); + } + } + /** * Update details of an existing parcel. *