forked from Adyen/adyen-php-api-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.php
208 lines (181 loc) · 5.06 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
namespace Adyen;
use Psr\Log\LoggerInterface;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class Client
{
const LIB_VERSION = "1.2.0";
const USER_AGENT_SUFFIX = "adyen-php-api-library/";
const ENDPOINT_TEST = "https://pal-test.adyen.com";
const ENDPOINT_LIVE = "https://pal-live.adyen.com";
const ENPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory.shtml";
const ENPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory.shtml";
const API_VERSION = "v18";
/**
* @var Adyen_Config $config
*/
private $_config;
private $_httpClient;
/**
* @var Adyen_Logger_Abstract $logger
*/
private $logger;
/**
* Client constructor.
* @param null $config
* @throws AdyenException
*/
public function __construct($config = null)
{
if (!$config) {
// create config
$this->_config = new \Adyen\Config();
}elseif ($config instanceof \Adyen\ConfigInterface) {
$this->_config = $config;
} else {
throw new \Adyen\AdyenException("This config object is not supported, you need to implement the ConfigInterface");
}
}
public function getConfig()
{
return $this->_config;
}
/**
* Set Username of Web Service User
*
* @param $username
*/
public function setUsername($username)
{
$this->_config->set('username', $username);
}
/**
* Set Password of Web Service User
*
* @param $password
*/
public function setPassword($password)
{
$this->_config->set('password', $password);
}
/**
* Set environment to connect to test or live platform of Adyen
*
* @param $environment
* @throws AdyenException
*/
public function setEnvironment($environment)
{
if($environment == \Adyen\Environment::TEST) {
$this->_config->set('environment', \Adyen\Environment::TEST);
$this->_config->set('endpoint', self::ENDPOINT_TEST);
$this->_config->set('endpointDirectorylookup', self::ENPOINT_TEST_DIRECTORY_LOOKUP);
} elseif($environment == \Adyen\Environment::LIVE) {
$this->_config->set('environment', \Adyen\Environment::LIVE);
$this->_config->set('endpoint', self::ENDPOINT_LIVE);
$this->_config->set('endpointDirectorylookup', self::ENPOINT_LIVE_DIRECTORY_LOOKUP);
} else {
// environment does not exists
$msg = "This environment does not exists use " . \Adyen\Environment::TEST . ' or ' . \Adyen\Environment::LIVE;
throw new \Adyen\AdyenException($msg);
}
}
/**
* Set Request URl
*
* @param $url
*/
public function setRequestUrl($url)
{
$this->_config->set('endpoint', $url);
}
public function setMerchantAccount($merchantAccount)
{
$this->_config->set('merchantAccount', $merchantAccount);
}
public function setApplicationName($applicationName) {
$this->_config->set('applicationName', $applicationName);
}
/**
* Type can be json or array
*
* @param $value
*/
public function setInputType($value)
{
$this->_config->set('inputType', $value);
}
/**
* Type can be json or array
*
* @param $value
*/
public function setOutputType($value)
{
$this->_config->set('outputType', $value);
}
/**
* Get the library version
*
* @return string
*/
public function getLibraryVersion()
{
return self::LIB_VERSION;
}
/**
* Get the version of the API endpoint
*
* @return string
*/
public function getApiVersion()
{
return self::API_VERSION;
}
/**
* @param HttpClient\ClientInterface $httpClient
*/
public function setHttpClient(\Adyen\HttpClient\ClientInterface $httpClient)
{
$this->_httpClient = $httpClient;
}
/**
* @return mixed
*/
public function getHttpClient()
{
if (is_null($this->_httpClient)) {
$this->_httpClient = $this->_createDefaultHttpClient();
}
return $this->_httpClient;
}
protected function _createDefaultHttpClient()
{
return new \Adyen\HttpClient\CurlClient();
}
/**
* Set the Logger object
* @param \Psr\Log\LoggerInterface $logger
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* @return \Psr\Log\LoggerInterface implementation
*/
public function getLogger()
{
if (!isset($this->logger)) {
$this->logger = $this->createDefaultLogger();
}
return $this->logger;
}
protected function createDefaultLogger()
{
$logger = new Logger('adyen-php-api-library');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::NOTICE));
return $logger;
}
}