From 73d744717d9935eb94acd1d7dc533450ec9058db Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Thu, 7 Mar 2019 12:27:17 +0100 Subject: [PATCH] Added the `POST /api/v1/shipment/shipwithlabel` action --- CHANGELOG.md | 5 ++ composer.json | 2 +- src/Client.php | 23 ++++++ src/Model/Dimensions.php | 48 +++++++++++ src/Model/ShipmentWithLabel.php | 81 +++++++++++++++++++ .../Model/ShipmentWithLabelResult.php | 66 +++++++++++++++ src/Response/ShipWithLabelResponse.php | 24 ++++++ test_config.dist.yml | 6 +- tests/ClientTest.php | 36 +++++++++ 9 files changed, 289 insertions(+), 2 deletions(-) create mode 100644 src/Model/Dimensions.php create mode 100644 src/Model/ShipmentWithLabel.php create mode 100644 src/Response/Model/ShipmentWithLabelResult.php create mode 100644 src/Response/ShipWithLabelResponse.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f48f55..d0eacbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v1.5.0 (7 Mar 2019) + +New features: +- `POST /api/v1/shipment/shipwithlabel` added. (`Client::shipWithLabel(Model\ShipmentWithLabel)`) + ## v1.4.1 (7 Jan 2019) Bug Fixes: diff --git a/composer.json b/composer.json index 958cd01..d75df48 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "authors": [ { "name": "Julian Finkler", - "email": "julian@billbee.de" + "email": "julian@billbee.io" } ], "minimum-stability": "stable", diff --git a/src/Client.php b/src/Client.php index 8da1725..53e03d2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -854,6 +854,29 @@ public function getShippingProviders() #endregion + #region POST + + /** + * Creates a shipment for an order in billbee + * + * @return Response\ShipWithLabelResponse The response + * + * @throws QuotaExceededException If the maximum number of calls per second exceeded + * @throws \Exception If the response cannot be parsed + */ + public function shipWithLabel(Model\ShipmentWithLabel $shipment) + { + $result = $this->requestPOST( + 'shipment/shipwithlabel', + $this->jom->serialize($shipment), + Response\ShipWithLabelResponse::class + ); + + return $result; + } + + #endregion + #endregion #region PRODUCT CUSTOM FIELDS diff --git a/src/Model/Dimensions.php b/src/Model/Dimensions.php new file mode 100644 index 0000000..6a87c5e --- /dev/null +++ b/src/Model/Dimensions.php @@ -0,0 +1,48 @@ + + */ + +namespace BillbeeDe\BillbeeAPI\Model; + +use MintWare\DMM\DataField; + +class Dimensions +{ + /** + * @var float + * @DataField(name="width", type="float") + */ + public $width; + + /** + * @var float + * @DataField(name="height", type="float") + */ + public $height; + + /** + * @var float + * @DataField(name="length", type="float") + */ + public $length; + + /** + * @param float $width The width + * @param float $height The height + * @param float $length The length + */ + public function __construct($width = 0.0, $height = 0.0, $length = 0.0) + { + $this->width = (float)$width; + $this->height = (float)$height; + $this->length = (float)$length; + } +} diff --git a/src/Model/ShipmentWithLabel.php b/src/Model/ShipmentWithLabel.php new file mode 100644 index 0000000..28c9a1d --- /dev/null +++ b/src/Model/ShipmentWithLabel.php @@ -0,0 +1,81 @@ + + */ + +namespace BillbeeDe\BillbeeAPI\Model; + +use MintWare\DMM\DataField; + +class ShipmentWithLabel +{ + /** + * The Billbee internal id of the order to ship + * @var int + * @DataField(name="OrderId", type="int") + */ + public $orderId; + + /** + * The id of the provider. You can query all providers with the shippingproviders endpoint + * @var int + * @DataField(name="ProviderId", type="int") + */ + public $providerId; + + /** + * The id of the shipping provider product to be used + * @var int + * @DataField(name="ProductId", type="int") + */ + public $productId; + + /** + * Optional parameter to automatically change the orderstate to sent after creating the shipment + * @var bool + * @DataField(name="ChangeStateToSend", type="bool") + */ + public $changeStateToSend; + + /** + * Optional the name of a connected cloudprinter to send the label to + * @var string + * @DataField(name="PrinterName", type="string") + */ + public $printerName; + + /** + * Optional the shipments weight in gram to override the calculated weight + * @var int + * @DataField(name="WeightInGram", type="int") + */ + public $weightInGram; + + /** + * Optional specify the shipdate to be transmitted to the carrier + * @var \DateTime + * @DataField(name="ShipDate", type="datetime") + */ + public $shipDate; + + /** + * Optional specify a reference text to be included on the label. Not all carriers support this option. + * @var string + * @DataField(name="ClientReference", type="string") + */ + public $clientReference; + + /** + * Option specify the dimensions of the package in cm + * @var Dimensions + * @DataField(name="Dimension", type="BillbeeDe\BillbeeAPI\Model\Dimensions") + */ + public $dimension; +} diff --git a/src/Response/Model/ShipmentWithLabelResult.php b/src/Response/Model/ShipmentWithLabelResult.php new file mode 100644 index 0000000..f1683c4 --- /dev/null +++ b/src/Response/Model/ShipmentWithLabelResult.php @@ -0,0 +1,66 @@ + + */ + +namespace BillbeeDe\BillbeeAPI\Response\Model; + +use MintWare\DMM\DataField; + +class ShipmentWithLabelResult +{ + /** + * @var int + * @DataField(name="OrderId", type="int") + */ + public $orderId; + + /** + * @var string + * @DataField(name="OrderReference", type="string") + */ + public $orderReference; + + /** + * @var string + * @DataField(name="ShippingId", type="string") + */ + public $shippingId; + + /** + * @var string + * @DataField(name="TrackingUrl", type="string") + */ + public $trackingUrl; + + /** + * @var string + * @DataField(name="LabelDataPdf", type="string") + */ + public $labelDataPdf; + + /** + * @var string + * @DataField(name="ExportDocsPdf", type="string") + */ + public $exportDocsPdf; + + /** + * @var string + * @DataField(name="Carrier", type="string") + */ + public $carrier; + + /** + * @var string + * @DataField(name="ShippingDate", type="string") + */ + public $shippingDate; +} diff --git a/src/Response/ShipWithLabelResponse.php b/src/Response/ShipWithLabelResponse.php new file mode 100644 index 0000000..0e5cdd6 --- /dev/null +++ b/src/Response/ShipWithLabelResponse.php @@ -0,0 +1,24 @@ + + */ + +namespace BillbeeDe\BillbeeAPI\Response; + +use MintWare\DMM\DataField; + +class ShipWithLabelResponse extends BaseResponse +{ + /** + * @var \BillbeeDe\BillbeeAPI\Response\Model\ShipmentWithLabelResult + * @DataField(name="Data", type="\BillbeeDe\BillbeeAPI\Response\Model\ShipmentWithLabelResult") + */ + public $data = null; +} diff --git a/test_config.dist.yml b/test_config.dist.yml index 055422c..47b09ca 100644 --- a/test_config.dist.yml +++ b/test_config.dist.yml @@ -13,4 +13,8 @@ custom_field_definition_id: '' # The id of a custom field definition web_hook_uri: '' # The uri for testing webhooks test_delete_web_hooks: false # If true, the delete all web hooks call will be tested customer_id: '' # Id of a customer -address_id: '' # Id of an address \ No newline at end of file +address_id: '' # Id of an address +# Test Shipping: +shippable_order_id: '' # Id of an order which can be shipped +shipping_provider_id: '' # The Id of a shipping provider +shipping_provider_product: '' # The Id of a shipping provider product \ No newline at end of file diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 4c4b9e0..98fb8ef 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -19,6 +19,7 @@ use BillbeeDe\BillbeeAPI\Model\CustomerAddress; use BillbeeDe\BillbeeAPI\Model\CustomFieldDefinition; use BillbeeDe\BillbeeAPI\Model\DeliveryNoteDocument; +use BillbeeDe\BillbeeAPI\Model\Dimensions; use BillbeeDe\BillbeeAPI\Model\Event; use BillbeeDe\BillbeeAPI\Model\Invoice; use BillbeeDe\BillbeeAPI\Model\InvoiceDocument; @@ -29,6 +30,7 @@ use BillbeeDe\BillbeeAPI\Model\PartnerOrder; use BillbeeDe\BillbeeAPI\Model\Product; use BillbeeDe\BillbeeAPI\Model\Shipment; +use BillbeeDe\BillbeeAPI\Model\ShipmentWithLabel; use BillbeeDe\BillbeeAPI\Model\ShippingProvider; use BillbeeDe\BillbeeAPI\Model\Stock; use BillbeeDe\BillbeeAPI\Model\StockCode; @@ -79,6 +81,9 @@ class ClientTest extends TestCase protected $testDeleteWebHooks = false; protected $customerId = ''; protected $addressId; + protected $shippableOrderId; + protected $shippingProviderId; + protected $shippingProviderProduct; public function __construct($name = null, array $data = [], $dataName = '') { @@ -101,6 +106,9 @@ public function __construct($name = null, array $data = [], $dataName = '') $this->testDeleteWebHooks, $this->customerId, $this->addressId, + $this->shippableOrderId, + $this->shippingProviderId, + $this->shippingProviderProduct, ) = [ $data['username'], $data['password'], @@ -117,6 +125,9 @@ public function __construct($name = null, array $data = [], $dataName = '') $data['test_delete_web_hooks'], $data['customer_id'], $data['address_id'], + $data['shippable_order_id'], + $data['shipping_provider_id'], + $data['shipping_provider_product'], ]; } @@ -1095,6 +1106,31 @@ public function testUpdateCustomer() $client->updateCustomer($customer2); } + /** @throws \Exception */ + public function testShipOrderWithLabel() + { + if (empty($this->shippableOrderId) + || empty($this->shippingProviderId) + || empty($this->shippingProviderProduct)) { + return; + } + + $client = $this->getClient(); + sleep(1); + $shipment = new ShipmentWithLabel(); + $shipment->changeStateToSend = true; + $shipment->clientReference = 'Hallo Welt'; + $shipment->dimension = new Dimensions(15, 15, 10); + $shipment->orderId = $this->shippableOrderId; + $shipment->providerId = $this->shippingProviderId; + $shipment->productId = $this->shippingProviderProduct; + $shipment->shipDate = new \DateTime('now'); + $shipment->weightInGram = 130; + + $res = $client->shipWithLabel($shipment); + print_r($res); + } + public function getClient() { static $client = null;