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
|
|
|
$this->client = $client; |
35
|
|
|
$this->organizationUuid = $organizationUuid ? (string) $organizationUuid : 'self'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getLocations() |
39
|
|
|
{ |
40
|
|
|
$url = sprintf(self::GET_LOCATIONS, $this->organizationUuid); |
41
|
|
|
$json = $this->client->getJson($this->client->get($url)); |
42
|
|
|
|
43
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getLocation(UuidInterface $locationUuid) |
47
|
|
|
{ |
48
|
|
|
$url = sprintf(self::GET_LOCATION_INVENTORY, $this->organizationUuid, (string) $locationUuid); |
49
|
|
|
$json = $this->client->getJson($this->client->get($url)); |
50
|
|
|
dump($json); |
51
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getHistory(UuidInterface $locationUuid) |
55
|
|
|
{ |
56
|
|
|
$url = sprintf(self::GET_HISTORY, $this->organizationUuid, (string) $locationUuid); |
57
|
|
|
$json = $this->client->getJson($this->client->get($url, ['balanceChangeType' => 'RESTOCK'])); |
58
|
|
|
dump($json); |
59
|
|
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
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: