1 | <?php |
||
22 | final class ProductClient |
||
23 | { |
||
24 | const BASE_URL = 'https://products.izettle.com/organizations/%s'; |
||
25 | |||
26 | const POST_CATEGORY = self::BASE_URL . '/categories'; |
||
27 | const GET_CATEGORY = self::BASE_URL . '/categories/%s'; |
||
28 | const GET_CATEGORIES = self::BASE_URL . '/categories'; |
||
29 | |||
30 | const POST_DISCOUNT = self::BASE_URL . '/discounts'; |
||
31 | const GET_DISCOUNT = self::BASE_URL . '/discounts/%s'; |
||
32 | const PUT_DISCOUNT = self::BASE_URL . '/discounts/%s'; |
||
33 | const DELETE_DISCOUNT = self::BASE_URL . '/discounts/%s'; |
||
34 | const GET_DISCOUNTS = self::BASE_URL . '/discounts'; |
||
35 | |||
36 | const GET_EXPORT = self::BASE_URL . '/products/%s'; |
||
37 | const GET_EXPORT_TEMPLATE = self::BASE_URL . '/products/%s/template'; |
||
38 | |||
39 | const GET_LIBRARY = self::BASE_URL . '/library'; |
||
40 | |||
41 | const POST_PRODUCT = self::BASE_URL . '/products'; |
||
42 | const GET_PRODUCT = self::BASE_URL . '/products/%s'; |
||
43 | const PUT_PRODUCT = self::BASE_URL . '/products/v2/%s'; |
||
44 | const DELETE_PRODUCT = self::BASE_URL . '/products/%s'; |
||
45 | const POST_PRODUCT_VARIANT = self::BASE_URL . '/products/%s/variants'; |
||
46 | const PUT_PRODUCT_VARIANT = self::BASE_URL . '/products/%s/variants/%s'; |
||
47 | const DELETE_PRODUCT_VARIANT = self::BASE_URL . '/products/%s/variants/%s'; |
||
48 | const GET_PRODUCTS = self::BASE_URL . '/products'; |
||
49 | const DELETE_PRODUCTS = self::BASE_URL . '/products'; |
||
50 | |||
51 | private $client; |
||
52 | private $organizationUuid; |
||
53 | private $categoryBuilder; |
||
54 | private $discountBuilder; |
||
55 | private $libraryBuilder; |
||
56 | private $productBuilder; |
||
57 | |||
58 | 9 | public function __construct( |
|
59 | IzettleClientInterface $client, |
||
60 | ?UuidInterface $organizationUuid = null, |
||
61 | CategoryBuilderInterface $categoryBuilder, |
||
62 | DiscountBuilderInterface $discountBuilder, |
||
63 | LibraryBuilderInterface $libraryBuilder, |
||
64 | ProductBuilderInterface $productBuilder |
||
65 | ) { |
||
66 | 9 | $this->client = $client; |
|
67 | 9 | $this->organizationUuid = $organizationUuid ? (string) $organizationUuid : 'self'; |
|
68 | 9 | $this->categoryBuilder = $categoryBuilder; |
|
69 | 9 | $this->discountBuilder = $discountBuilder; |
|
70 | 9 | $this->libraryBuilder = $libraryBuilder; |
|
71 | 9 | $this->productBuilder = $productBuilder; |
|
72 | 9 | } |
|
73 | |||
74 | 1 | public function getCategories(): array |
|
75 | { |
||
76 | 1 | $url = sprintf(self::GET_CATEGORIES, $this->organizationUuid); |
|
77 | 1 | $json = $this->client->getJson($this->client->get($url)); |
|
78 | |||
79 | 1 | return $this->categoryBuilder->buildFromJson($json); |
|
80 | } |
||
81 | |||
82 | 1 | public function createCategory(Category $category): void |
|
87 | |||
88 | 1 | public function getDiscounts(): array |
|
89 | { |
||
90 | 1 | $url = sprintf(self::GET_DISCOUNTS, $this->organizationUuid); |
|
91 | 1 | $json = $this->client->getJson($this->client->get($url)); |
|
92 | |||
93 | 1 | return $this->discountBuilder->buildFromJson($json); |
|
94 | } |
||
95 | |||
96 | 1 | public function createDiscount(Discount $discount): void |
|
102 | |||
103 | 1 | public function deleteDiscount(Discount $discount): void |
|
109 | |||
110 | 1 | public function getLibrary(): Library |
|
111 | { |
||
112 | 1 | $url = sprintf(self::GET_LIBRARY, $this->organizationUuid); |
|
113 | 1 | $json = $this->client->getJson($this->client->get($url)); |
|
114 | |||
115 | 1 | return $this->libraryBuilder->buildFromJson($json); |
|
116 | } |
||
117 | |||
118 | 1 | public function getProducts(): array |
|
119 | { |
||
120 | 1 | $url = sprintf(self::GET_PRODUCTS, $this->organizationUuid); |
|
121 | 1 | $json = $this->client->getJson($this->client->get($url)); |
|
122 | |||
123 | 1 | return $this->productBuilder->buildFromJson($json); |
|
124 | } |
||
125 | |||
126 | 1 | public function createProduct(Product $product): void |
|
132 | |||
133 | 1 | public function deleteProduct(Product $product): void |
|
139 | } |
||
140 |