Skip to content

Commit

Permalink
Merge pull request #24 from aligent/feature/order-metafields-api
Browse files Browse the repository at this point in the history
Feature/order metafields api
  • Loading branch information
jswift authored Nov 12, 2020
2 parents c202954 + 49051cd commit dda07fd
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Running tests: `composer run-script test`

#### Orders (V3)

- ☑️ Order Metafields
- ☑️ Transactions
- ☑️ Order Refunds

Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## New Features

- Implement new Order Metafields api
- Implement V3 Payment endpoints (Create Payment Access Token, Get Accepted Payment Methods)

## Minor Update
Expand Down
39 changes: 39 additions & 0 deletions src/BigCommerce/Orders/OrderMetafieldsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace BigCommerce\ApiV3\Orders;

use BigCommerce\ApiV3\Api\ResourceApi;
use BigCommerce\ApiV3\ResponseModels\Order\OrderMetafieldResponse;
use BigCommerce\ApiV3\ResponseModels\Order\OrderMetafieldsResponse;

class OrderMetafieldsApi extends ResourceApi
{
private const RESOURCE_NAME = 'metafields';
private const METAFIELD_ENDPOINT = 'orders/{order_id}/metafields';
private const METAFIELDS_ENDPOINT = 'orders/{order_id}/metafields/%d';

protected function singleResourceEndpoint(): string
{
return self::METAFIELD_ENDPOINT;
}

protected function multipleResourcesEndpoint(): string
{
return self::METAFIELDS_ENDPOINT;
}

protected function resourceName(): string
{
return self::RESOURCE_NAME;
}

public function get(): OrderMetafieldResponse
{
return new OrderMetafieldResponse($this->getResource());
}

public function getAll(array $filters = [], int $page = 1, int $limit = 250): OrderMetafieldsResponse
{
return new OrderMetafieldsResponse($this->getAllResources($filters, $page, $limit));
}
}
10 changes: 10 additions & 0 deletions src/BigCommerce/Orders/OrdersApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ public function refund(): RefundsApi
{
return $this->refunds();
}

public function metafields(): OrderMetafieldsApi
{
return new OrderMetafieldsApi($this->getClient(), null, $this->getResourceId());
}

public function metafield(int $id): OrderMetafieldsApi
{
return new OrderMetafieldsApi($this->getClient(), $id, $this->getResourceId());
}
}
10 changes: 10 additions & 0 deletions src/BigCommerce/ResourceModels/Order/OrderMetafield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace BigCommerce\ApiV3\ResourceModels\Order;

use BigCommerce\ApiV3\ResourceModels\Metafield;

class OrderMetafield extends Metafield
{
public string $resource_type = 'order';
}
22 changes: 22 additions & 0 deletions src/BigCommerce/ResponseModels/Order/OrderMetafieldResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace BigCommerce\ApiV3\ResponseModels\Order;

use BigCommerce\ApiV3\ResourceModels\Order\OrderMetafield;
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse;
use stdClass;

class OrderMetafieldResponse extends SingleResourceResponse
{
private OrderMetafield $metafield;

public function getMetafield(): OrderMetafield
{
return $this->metafield;
}

protected function addData(stdClass $rawData): void
{
$this->metafield = new OrderMetafield($rawData);
}
}
22 changes: 22 additions & 0 deletions src/BigCommerce/ResponseModels/Order/OrderMetafieldsResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace BigCommerce\ApiV3\ResponseModels\Order;

use BigCommerce\ApiV3\ResourceModels\Order\OrderMetafield;
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse;

class OrderMetafieldsResponse extends PaginatedResponse
{
/**
* @return OrderMetafield[]
*/
public function getMetafields(): array
{
return $this->getData();
}

protected function resourceClass(): string
{
return OrderMetafield::class;
}
}
18 changes: 18 additions & 0 deletions tests/BigCommerce/Orders/OrderMetafieldsApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace BigCommerce\Tests\Orders;

use BigCommerce\Tests\BigCommerceApiTest;

class OrderMetafieldsApiTest extends BigCommerceApiTest
{
public function testCanGetOrderMetafield(): void
{
$this->markTestIncomplete();
}

public function testCanGetAllOrderMetafields(): void
{
$this->markTestIncomplete();
}
}

0 comments on commit dda07fd

Please sign in to comment.