1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LauLamanApps\IzettleApi\Client; |
6
|
|
|
|
7
|
|
|
use LauLamanApps\IzettleApi\API\Purchase\Purchase; |
8
|
|
|
use LauLamanApps\IzettleApi\API\Purchase\PurchaseHistory; |
9
|
|
|
use LauLamanApps\IzettleApi\Client\Purchase\PurchaseBuilderInterface; |
10
|
|
|
use LauLamanApps\IzettleApi\Client\Purchase\PurchaseHistoryBuilderInterface; |
11
|
|
|
use LauLamanApps\IzettleApi\IzettleClientInterface; |
12
|
|
|
use Ramsey\Uuid\UuidInterface; |
13
|
|
|
|
14
|
|
|
final class PurchaseClient |
15
|
|
|
{ |
16
|
|
|
const BASE_URL = 'https://purchase.izettle.com'; |
17
|
|
|
|
18
|
|
|
const GET_PURCHASE = self::BASE_URL . '/purchases/v2/%s'; |
19
|
|
|
const GET_PURCHASES = self::BASE_URL . '/purchases/v2'; |
20
|
|
|
|
21
|
|
|
private $client; |
22
|
|
|
private $purchaseHistoryBuilder; |
23
|
|
|
private $purchaseBuilder; |
24
|
|
|
|
25
|
2 |
|
public function __construct( |
26
|
|
|
IzettleClientInterface $client, |
27
|
|
|
PurchaseHistoryBuilderInterface $purchaseHistoryBuilder, |
28
|
|
|
PurchaseBuilderInterface $purchaseBuilder |
29
|
|
|
) { |
30
|
2 |
|
$this->client = $client; |
31
|
2 |
|
$this->purchaseHistoryBuilder = $purchaseHistoryBuilder; |
32
|
2 |
|
$this->purchaseBuilder = $purchaseBuilder; |
33
|
2 |
|
} |
34
|
|
|
|
35
|
1 |
|
public function getPurchaseHistory(): PurchaseHistory |
36
|
|
|
{ |
37
|
1 |
|
$json = $this->client->getJson($this->client->get(self::GET_PURCHASES)); |
38
|
|
|
|
39
|
1 |
|
return $this->purchaseHistoryBuilder->buildFromJson($json); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function getPurchase(UuidInterface $uuid): Purchase |
43
|
|
|
{ |
44
|
1 |
|
$json = $this->client->getJson($this->client->get(sprintf(self::GET_PURCHASE, (string) $uuid))); |
45
|
|
|
|
46
|
1 |
|
return $this->purchaseBuilder->buildFromJson($json); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|