Skip to content

Commit

Permalink
Added the POST /api/v1/shipment/shipwithlabel action
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Finkler committed Mar 7, 2019
1 parent 23fdadc commit 73d7447
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"authors": [
{
"name": "Julian Finkler",
"email": "julian@billbee.de"
"email": "julian@billbee.io"
}
],
"minimum-stability": "stable",
Expand Down
23 changes: 23 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions src/Model/Dimensions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* This file is part of the Billbee API package.
*
* Copyright 2017 - 2019 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*
* Created by Julian Finkler <julian@billbee.io>
*/

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;
}
}
81 changes: 81 additions & 0 deletions src/Model/ShipmentWithLabel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* This file is part of the Billbee API package.
*
* Copyright 2017 - 2019 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*
* Created by Julian Finkler <julian@mintware.de>
*/

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;
}
66 changes: 66 additions & 0 deletions src/Response/Model/ShipmentWithLabelResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* This file is part of the Billbee API package.
*
* Copyright 2017 - 2019 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*
* Created by Julian Finkler <julian@mintware.de>
*/

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;
}
24 changes: 24 additions & 0 deletions src/Response/ShipWithLabelResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* This file is part of the Billbee API package.
*
* Copyright 2017 - 2019 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*
* Created by Julian Finkler <julian@billbee.io>
*/

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;
}
6 changes: 5 additions & 1 deletion test_config.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
36 changes: 36 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 = '')
{
Expand All @@ -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'],
Expand All @@ -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'],
];
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 73d7447

Please sign in to comment.