1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
namespace CommerceLeague\ActiveCampaign\Gateway; |
6
|
|
|
|
7
|
|
|
use CommerceLeague\ActiveCampaign\Helper\Config as ConfigHelper; |
8
|
|
|
use CommerceLeague\ActiveCampaignApi\Api\AbandonedCartApiResourceInterface; |
9
|
|
|
use CommerceLeague\ActiveCampaignApi\Api\ConnectionApiResourceInterface; |
10
|
|
|
use CommerceLeague\ActiveCampaignApi\Api\ContactApiResourceInterface; |
11
|
|
|
use CommerceLeague\ActiveCampaignApi\Api\CustomerApiResourceInterface; |
12
|
|
|
use CommerceLeague\ActiveCampaignApi\Api\OrderApiResourceInterface; |
13
|
|
|
use CommerceLeague\ActiveCampaignApi\ClientBuilder; |
14
|
|
|
use CommerceLeague\ActiveCampaignApi\CommonClientInterface; |
15
|
|
|
use Http\Adapter\Guzzle6\Client as GuzzleClient; |
16
|
|
|
use Http\Factory\Guzzle\RequestFactory as GuzzleRequestFactory; |
17
|
|
|
use Http\Factory\Guzzle\StreamFactory as GuzzleStreamFactory; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Client |
21
|
|
|
*/ |
22
|
|
|
class Client |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ConfigHelper |
26
|
|
|
*/ |
27
|
|
|
private $configHelper; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param ConfigHelper $configHelper |
31
|
|
|
*/ |
32
|
|
|
public function __construct(ConfigHelper $configHelper) |
33
|
|
|
{ |
34
|
|
|
$this->configHelper = $configHelper; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return CommonClientInterface |
39
|
|
|
*/ |
40
|
|
|
private function getCommonClient(): CommonClientInterface |
41
|
|
|
{ |
42
|
|
|
$url = $this->configHelper->getApiUrl(); |
43
|
|
|
$token = $this->configHelper->getApiToken(); |
44
|
|
|
|
45
|
|
|
$clientBuilder = new ClientBuilder(); |
46
|
|
|
$clientBuilder->setHttpClient(new GuzzleClient()); |
47
|
|
|
$clientBuilder->setRequestFactory(new GuzzleRequestFactory()); |
48
|
|
|
$clientBuilder->setStreamFactory(new GuzzleStreamFactory()); |
49
|
|
|
|
50
|
|
|
return $clientBuilder->buildCommonClient($url, $token); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return AbandonedCartApiResourceInterface |
55
|
|
|
*/ |
56
|
|
|
public function getAbandonedCartApi(): AbandonedCartApiResourceInterface |
57
|
|
|
{ |
58
|
|
|
return $this->getCommonClient()->getAbandonedCartApi(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return ConnectionApiResourceInterface |
63
|
|
|
*/ |
64
|
|
|
public function getConnectionApi(): ConnectionApiResourceInterface |
65
|
|
|
{ |
66
|
|
|
return $this->getCommonClient()->getConnectionApi(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return ContactApiResourceInterface |
71
|
|
|
*/ |
72
|
|
|
public function getContactApi(): ContactApiResourceInterface |
73
|
|
|
{ |
74
|
|
|
return $this->getCommonClient()->getContactApi(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return CustomerApiResourceInterface |
79
|
|
|
*/ |
80
|
|
|
public function getCustomerApi(): CustomerApiResourceInterface |
81
|
|
|
{ |
82
|
|
|
return $this->getCommonClient()->getCustomerApi(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return OrderApiResourceInterface |
87
|
|
|
*/ |
88
|
|
|
public function getOrderApi(): OrderApiResourceInterface |
89
|
|
|
{ |
90
|
|
|
return $this->getCommonClient()->getOrderApi(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|