|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Client; |
|
6
|
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\IzettleClientInterface; |
|
8
|
|
|
use Ramsey\Uuid\UuidInterface; |
|
9
|
|
|
|
|
10
|
|
|
final class InventoryClient |
|
11
|
|
|
{ |
|
12
|
|
|
const BASE_URL = 'https://inventory.izettle.com/organizations/%s'; |
|
13
|
|
|
|
|
14
|
|
|
const GET_HISTORY = self::BASE_URL . '/history/locations/%s'; |
|
15
|
|
|
|
|
16
|
|
|
const GET_PRODUCT_INVENTORY = self::BASE_URL . '/inventory/locations/%s/products/%s'; |
|
17
|
|
|
const GET_LOCATION_INVENTORY = self::BASE_URL . '/inventory/locations/%s'; |
|
18
|
|
|
const POST_INVENTORY = self::BASE_URL . '/inventory'; |
|
19
|
|
|
const POST_INVENTORY_BULK = self::BASE_URL . '/inventory/bulk'; |
|
20
|
|
|
const PUT_INVENTORY = self::BASE_URL . '/inventory'; |
|
21
|
|
|
const DELETE_PRODUCT_INVENTORY = self::BASE_URL . '/inventory/products/%s'; |
|
22
|
|
|
|
|
23
|
|
|
const GET_LOCATIONS = self::BASE_URL . '/locations'; |
|
24
|
|
|
const PUT_LOCATIONS = self::BASE_URL . '/locations/%s'; |
|
25
|
|
|
|
|
26
|
|
|
const GET_SETTINGS = self::BASE_URL . '/settings'; |
|
27
|
|
|
const POST_SETTINGS = self::BASE_URL . '/settings'; |
|
28
|
|
|
const PUT_SETTINGS = self::BASE_URL . '/settings'; |
|
29
|
|
|
|
|
30
|
|
|
private $client; |
|
31
|
|
|
private $organizationUuid; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(IzettleClientInterface $client, ?UuidInterface $organizationUuid = null) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->client = $client; |
|
36
|
|
|
$this->organizationUuid = $organizationUuid ? (string) $organizationUuid : 'self'; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getLocations() |
|
40
|
|
|
{ |
|
41
|
|
|
$url = sprintf(self::GET_LOCATIONS, $this->organizationUuid); |
|
42
|
|
|
$json = $this->client->getJson($this->client->get($url)); |
|
43
|
|
|
|
|
44
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getLocation(UuidInterface $locationUuid) |
|
48
|
|
|
{ |
|
49
|
|
|
$url = sprintf(self::GET_LOCATION_INVENTORY, $this->organizationUuid, (string) $locationUuid); |
|
50
|
|
|
$json = $this->client->getJson($this->client->get($url)); |
|
51
|
|
|
|
|
52
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getProduct(UuidInterface $locationUuid, UuidInterface $productUuid) |
|
56
|
|
|
{ |
|
57
|
|
|
$url = sprintf(self::GET_PRODUCT_INVENTORY, $this->organizationUuid, (string) $locationUuid, (string) $productUuid); |
|
58
|
|
|
$json = $this->client->getJson($this->client->get($url)); |
|
59
|
|
|
|
|
60
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getHistory(UuidInterface $locationUuid) |
|
64
|
|
|
{ |
|
65
|
|
|
$url = sprintf(self::GET_HISTORY, $this->organizationUuid, (string) $locationUuid); |
|
66
|
|
|
$json = $this->client->getJson($this->client->get($url, ['balanceChangeType' => 'RESTOCK'])); |
|
67
|
|
|
|
|
68
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getSettings() |
|
72
|
|
|
{ |
|
73
|
|
|
$url = sprintf(self::GET_SETTINGS, $this->organizationUuid); |
|
74
|
|
|
$json = $this->client->getJson($this->client->get($url)); |
|
75
|
|
|
|
|
76
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: