Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the layouts endpoint #20

Merged
merged 1 commit into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@
New features:
- `GET /api/v1/cloudstorages` added. (`Client::getCloudStorages()`)
- `GET /api/v1/products/category` added. (`Client::getCategories()`)
- `GET /api/v1/layouts` added. (`Client::getLayouts()`)
- Added `$templateId` and `$sendToCloudId` to `Client::createInvoice()`

## 1.6.2 (16 Sep 2019)

Expand Down
35 changes: 34 additions & 1 deletion src/Client.php
Expand Up @@ -614,15 +614,23 @@ public function createDeliveryNote($orderId, $includePdf)
*
* @param int $orderId The internal id of the order
* @param bool $includePdf If true, the PDF is included in the response as base64 encoded string
* @param int|null $templateId The internal id of a template
* @param int|null $sendToCloudId The internal id of an cloud storage where the invoice is uploaded to
*
* @return Response\CreateDeliveryNoteResponse The response
*
* @throws QuotaExceededException If the maximum number of calls per second exceeded
* @throws Exception If the response cannot be parsed
*/
public function createInvoice($orderId, $includePdf)
public function createInvoice($orderId, $includePdf, $templateId = null, $sendToCloudId = null)
{
$node = 'orders/CreateInvoice/' . $orderId . '?includeInvoicePdf=' . ($includePdf ? 'True' : 'False');
if ($templateId != null && is_numeric($templateId)) {
$node .= '&templateId=' . $templateId;
}
if ($sendToCloudId != null && is_numeric($sendToCloudId)) {
$node .= '&sendToCloudId=' . $sendToCloudId;
}
return $this->requestPOST(
$node,
[],
Expand Down Expand Up @@ -1346,6 +1354,31 @@ public function getCloudStorages()

#endregion

#region LAYOUTS

#region GET

/**
* Get a list of all layouts
*
* @return Response\GetLayoutsResponse The Response
*
* @throws QuotaExceededException If the maximum number of calls per second exceeded
* @throws Exception If the response cannot be parsed
*/
public function getLayouts()
{
return $this->requestGET(
'layouts',
[],
Response\GetLayoutsResponse::class
);
}

#endregion

#endregion

/**
* Execute all requests in the pool
*
Expand Down
39 changes: 39 additions & 0 deletions src/Model/Layout.php
@@ -0,0 +1,39 @@
<?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 BillbeeDe\BillbeeAPI\Type\LayoutType;
use MintWare\DMM\DataField;

class Layout
{
/**
* @var int
* @DataField(name="Id", type="int")
*/
public $id;

/**
* @var string
* @DataField(name="Name", type="string")
*/
public $name = '';

/**
* @var int
* @DataField(name="Type", type="int")
*
* @see LayoutType
*/
public $type = LayoutType::INVOICE;
}
24 changes: 24 additions & 0 deletions src/Response/GetLayoutsResponse.php
@@ -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 GetLayoutsResponse extends BaseResponse
{
/**
* @var \BillbeeDe\BillbeeAPI\Model\Layout[]
* @DataField(name="Data", type="\BillbeeDe\BillbeeAPI\Model\Layout[]")
*/
public $data = null;
}
23 changes: 23 additions & 0 deletions src/Type/LayoutType.php
@@ -0,0 +1,23 @@
<?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\Type;

class LayoutType
{
const INVOICE = 0;
const LABEL = 1;
const DELIVERY_NOTE = 2;
const ORDER_COMMIT = 3;
const OFFER = 4;
const CANCELLATION_INVOICE = 5;
}
3 changes: 2 additions & 1 deletion test_config.dist.yml
Expand Up @@ -15,7 +15,8 @@ test_delete_web_hooks: false # If true, the delete all web hooks call will be te
customer_id: '' # Id of a customer
address_id: '' # Id of an address
cloud_storage_id: 0 # Id of an cloud storage
category_id: 0 # Id of c category
category_id: 0 # Id of a category
layout_id: 0 # Id of a layout
# Test Shipping:
shippable_order_id: '' # Id of an order which can be shipped
shipping_provider_id: '' # The Id of a shipping provider
Expand Down
26 changes: 26 additions & 0 deletions tests/ClientTest.php
Expand Up @@ -89,6 +89,7 @@ class ClientTest extends TestCase
protected $shippingProviderProduct;
protected $cloudStorageId = 0;
protected $categoryId = 0;
protected $layoutId = 0;

public function __construct($name = null, array $data = [], $dataName = '')
{
Expand Down Expand Up @@ -116,6 +117,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
$this->shippingProviderProduct,
$this->cloudStorageId,
$this->categoryId,
$this->layoutId,
) = [
$data['username'],
$data['password'],
Expand All @@ -137,6 +139,7 @@ public function __construct($name = null, array $data = [], $dataName = '')
$data['shipping_provider_product'],
$data['cloud_storage_id'],
$data['category_id'],
$data['layout_id'],
];
}

Expand Down Expand Up @@ -1197,6 +1200,29 @@ public function testGetCategories()
$this->assertTrue($containsCategory);
}

/** @throws Exception */
public function testGetLayouts()
{
if ($this->layoutId == 0) {
return;
}

$client = $this->getClient();
sleep(1);
$layouts = $client->getLayouts();
$this->assertGreaterThanOrEqual(1, count($layouts->data));

$containsLayout = false;
foreach ($layouts->data as $layout) {
if ($layout->id == $this->layoutId) {
$containsLayout = true;
break;
}
}

$this->assertTrue($containsLayout);
}

/** @throws Exception */
public function getClient()
{
Expand Down