Skip to content

Commit 91c5ea7

Browse files
authored
Merge pull request #15 from aligent/feature/orders-v3
Feature/orders v3
2 parents a3234e9 + 30accb3 commit 91c5ea7

19 files changed

+507
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ Running tests: `composer run-script test`
6262

6363
#### Orders (V3)
6464

65-
- Transactions
66-
- Order Refunds
65+
- ☑️ Transactions
66+
- ☑️ Order Refunds
6767

6868
#### Payment Methods
6969

RELEASE_NOTES.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#### New Features
22

3-
Add support for the [Themes API](https://developer.bigcommerce.com/api-reference/store-management/themes)
3+
Add support for the [Orders v3 API](https://developer.bigcommerce.com/api-reference/store-management/order-transactions)
44

55
Includes
66

7-
- Themes
8-
- Theme Actions
9-
- Theme Jobs
10-
11-
#### Code Improvements
12-
13-
- Refactor PaginatedResponse to be simpler to implement
7+
- Transactions
8+
- Order refunds

src/BigCommerce/Client.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace BigCommerce\ApiV3;
44

5+
use BigCommerce\ApiV3\Orders\OrdersApi;
56
use BigCommerce\ApiV3\Customers\CustomersApi;
67
use BigCommerce\ApiV3\PriceLists\PriceListsApi;
78
use BigCommerce\ApiV3\Themes\ThemesApi;
@@ -122,4 +123,9 @@ public function theme(string $uuid): ThemesApi
122123
$api->setUuid($uuid);
123124
return $api;
124125
}
126+
127+
public function order(int $orderId): OrdersApi
128+
{
129+
return new OrdersApi($this, $orderId);
130+
}
125131
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Orders;
4+
5+
use BigCommerce\ApiV3\Api\V3ApiBase;
6+
use BigCommerce\ApiV3\ResponseModels\Order\TransactionsResponse;
7+
8+
class OrdersApi extends V3ApiBase
9+
{
10+
private const ORDER_ENDPOINT = 'orders/%d';
11+
private const TRANSACTIONS_ENDPOINT = self::ORDER_ENDPOINT . '/transactions';
12+
13+
public function transactions(): TransactionsResponse
14+
{
15+
$response = $this->getClient()->getRestClient()->get(
16+
sprintf(self::TRANSACTIONS_ENDPOINT, $this->getResourceId())
17+
);
18+
19+
return new TransactionsResponse($response);
20+
}
21+
22+
public function refunds(): RefundsApi
23+
{
24+
return new RefundsApi($this->getClient(), null, $this->getResourceId());
25+
}
26+
27+
public function refund(): RefundsApi
28+
{
29+
return $this->refunds();
30+
}
31+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\Orders;
4+
5+
use BigCommerce\ApiV3\Api\V3ApiBase;
6+
use BigCommerce\ApiV3\ResourceModels\Order\OrderRefundItem;
7+
use BigCommerce\ApiV3\ResponseModels\Order\RefundQuoteResponse;
8+
use BigCommerce\ApiV3\ResponseModels\Order\RefundResponse;
9+
use BigCommerce\ApiV3\ResponseModels\Order\RefundsResponse;
10+
use GuzzleHttp\RequestOptions;
11+
12+
class RefundsApi extends V3ApiBase
13+
{
14+
private const ORDER_REFUNDS_ENDPOINT = 'orders/%d/payment_actions';
15+
private const REFUND_QUOTE_ENDPOINT = self::ORDER_REFUNDS_ENDPOINT . '/refund_quotes';
16+
private const REFUND_ENDPOINT = self::ORDER_REFUNDS_ENDPOINT . '/refunds';
17+
18+
/**
19+
* @param OrderRefundItem[] $items
20+
* @param string $reason
21+
* @return RefundResponse
22+
* @throws \GuzzleHttp\Exception\GuzzleException
23+
*/
24+
public function create(array $items, string $reason): RefundResponse
25+
{
26+
$response = $this->getClient()->getRestClient()->post(
27+
sprintf(self::REFUND_ENDPOINT, $this->getParentResourceId()),
28+
[
29+
RequestOptions::JSON => []
30+
]
31+
);
32+
33+
return new RefundResponse($response);
34+
}
35+
36+
public function createQuote(): RefundQuoteResponse
37+
{
38+
$response = $this->getClient()->getRestClient()->post(
39+
sprintf(self::REFUND_QUOTE_ENDPOINT, $this->getParentResourceId()),
40+
[
41+
RequestOptions::JSON => []
42+
]
43+
);
44+
45+
return new RefundQuoteResponse($response);
46+
}
47+
48+
public function getAll(): RefundsResponse
49+
{
50+
$response = $this->getClient()->getRestClient()->get(
51+
sprintf(self::REFUND_ENDPOINT, $this->getParentResourceId())
52+
);
53+
54+
return new RefundsResponse($response);
55+
}
56+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\ResourceModels\Order;
4+
5+
use BigCommerce\ApiV3\ResourceModels\ResourceModel;
6+
7+
class OrderRefundItem extends ResourceModel
8+
{
9+
public const ITEM_TYPE__SHIPPING = 'SHIPPING';
10+
public const ITEM_TYPE__HANDLING = 'HANDLING';
11+
public const ITEM_TYPE__PRODUCT = 'PRODUCT';
12+
public const ITEM_TYPE__GIFT_WRAPPING = 'GIFT_WRAPPING';
13+
14+
public string $item_type;
15+
public int $item_id;
16+
public ?float $amount;
17+
public ?float $quantity;
18+
public ?string $reason;
19+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\ResourceModels\Order;
4+
5+
use BigCommerce\ApiV3\ResourceModels\ResourceModel;
6+
use stdClass;
7+
8+
class Refund extends ResourceModel
9+
{
10+
public int $id;
11+
public int $order_id;
12+
public int $user_id;
13+
public string $created;
14+
public string $reason;
15+
public float $total_amount;
16+
public float $total_tax;
17+
/**
18+
* @var OrderRefundItem[]
19+
*/
20+
public array $items;
21+
public array $payments;
22+
23+
public function __construct(?stdClass $optionObject = null)
24+
{
25+
$this->items = array_map(fn($i) => new OrderRefundItem($i), $optionObject->items);
26+
unset($optionObject->items);
27+
parent::__construct($optionObject);
28+
}
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\ResourceModels\Order;
4+
5+
use BigCommerce\ApiV3\ResourceModels\ResourceModel;
6+
7+
class RefundQuote extends ResourceModel
8+
{
9+
public int $order_id;
10+
public float $total_refund_amount;
11+
public float $total_refund_tax_amount;
12+
public float $rounding;
13+
public float $adjustment;
14+
public bool $tax_inclusive;
15+
public array $refund_methods;
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\ResourceModels\Order;
4+
5+
use BigCommerce\ApiV3\ResourceModels\ResourceModel;
6+
7+
class Transaction extends ResourceModel
8+
{
9+
public int $id;
10+
public int $order_id;
11+
public string $event;
12+
public string $method;
13+
public int $amount;
14+
public string $currency;
15+
public string $gateway;
16+
public string $gateway_transaction_id;
17+
public string $status;
18+
public bool $test;
19+
public bool $fraud_review;
20+
public ?int $reference_transaction_id;
21+
public string $date_created;
22+
public object $avs_result;
23+
public object $cvv_result;
24+
public object $credit_card;
25+
public object $gift_certificate;
26+
public object $store_credit;
27+
public object $offline;
28+
public object $custom;
29+
public string $payment_instrument_token;
30+
public string $payment_method_id;
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace BigCommerce\ApiV3\ResponseModels\Order;
4+
5+
use BigCommerce\ApiV3\ResourceModels\Order\RefundQuote;
6+
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse;
7+
use stdClass;
8+
9+
class RefundQuoteResponse extends SingleResourceResponse
10+
{
11+
private RefundQuote $quote;
12+
13+
public function getQuote(): RefundQuote
14+
{
15+
return $this->quote;
16+
}
17+
18+
protected function addData(stdClass $rawData): void
19+
{
20+
$this->quote = new RefundQuote($rawData);
21+
}
22+
}

0 commit comments

Comments
 (0)