1: <?php
2: namespace Worldline\Acquiring\Sdk;
3:
4: use UnexpectedValueException;
5: use Worldline\Acquiring\Sdk\Domain\ShoppingCartExtension;
6:
7: /**
8: * Class CommunicatorConfiguration
9: *
10: * @package Worldline\Acquiring\Sdk
11: */
12: class CommunicatorConfiguration
13: {
14: /**
15: * @var string
16: */
17: private $authorizationId;
18:
19: /**
20: * @var string
21: */
22: private $authorizationSecret;
23:
24: /**
25: * @var string
26: */
27: private $apiEndpoint;
28:
29: /**
30: * @var int
31: */
32: private $connectTimeout;
33:
34: /**
35: * @var int
36: */
37: private $readTimeout;
38:
39: /**
40: * @var ProxyConfiguration|null
41: */
42: private $proxyConfiguration;
43:
44: /**
45: * @var string
46: */
47: private $integrator;
48:
49: /**
50: * @var ShoppingCartExtension|null
51: */
52: private $shoppingCartExtension = null;
53:
54: /**
55: * @param string $authorizationId
56: * @param string $authorizationSecret
57: * @param string $apiEndpoint
58: * @param string $integrator
59: * @param ProxyConfiguration|null $proxyConfiguration
60: * @param int $connectTimeout
61: * @param int $readTimeout
62: */
63: public function __construct(
64: $authorizationId,
65: $authorizationSecret,
66: $apiEndpoint,
67: $integrator,
68: ProxyConfiguration $proxyConfiguration = null,
69: $connectTimeout = -1,
70: $readTimeout = -1)
71: {
72: $this->validateApiEndpoint($apiEndpoint);
73: $this->validateIntegrator($integrator);
74: $this->authorizationId = $authorizationId;
75: $this->authorizationSecret = $authorizationSecret;
76: $this->apiEndpoint = $apiEndpoint;
77: $this->integrator = $integrator;
78: $this->proxyConfiguration = $proxyConfiguration;
79: $this->connectTimeout = $connectTimeout;
80: $this->readTimeout = $readTimeout;
81: }
82:
83: private function validateApiEndpoint($apiEndpoint)
84: {
85: $url = parse_url($apiEndpoint);
86: if ($url === FALSE) {
87: throw new UnexpectedValueException('apiEndpoint is not a valid URL');
88: } else if (isset($url['path']) && $url['path'] !== '') {
89: throw new UnexpectedValueException('apiEndpoint should not contain a path');
90: } else if (isset($url['user']) || isset($url['query']) || isset($url['fragment'])) {
91: throw new UnexpectedValueException('apiEndpoint should not contain user info, query or fragment');
92: }
93: }
94:
95: private function validateIntegrator($integrator)
96: {
97: if (is_null($integrator) || strlen(trim($integrator)) == 0) {
98: throw new UnexpectedValueException("integrator is required");
99: }
100: }
101:
102: /**
103: * @return string An id used for authorization. This can be an OAuth2 client id, or something else.
104: */
105: public function getAuthorizationId()
106: {
107: return $this->authorizationId;
108: }
109:
110: /**
111: * @param string $authorizationId
112: */
113: public function setAuthorizationId($authorizationId)
114: {
115: $this->authorizationId = $authorizationId;
116: }
117:
118: /**
119: * @return string A secret used for authorization. This can be an OAuth2 client secret, or something else.
120: */
121: public function getAuthorizationSecret()
122: {
123: return $this->authorizationSecret;
124: }
125:
126: /**
127: * @param string $authorizationSecret
128: */
129: public function setAuthorizationSecret($authorizationSecret)
130: {
131: $this->authorizationSecret = $authorizationSecret;
132: }
133:
134: /**
135: * This method is an alias for getAuthorizationId.
136: * @return string
137: */
138: public function getOAuth2ClientId()
139: {
140: return $this->getAuthorizationId();
141: }
142:
143: /**
144: * This method is an alias for setAuthorizationId.
145: * @param string $oauth2ClientId
146: */
147: public function setOAuth2ClientId($oauth2ClientId)
148: {
149: $this->setAuthorizationId($oauth2ClientId);
150: }
151:
152: /**
153: * This method is an alias for getAuthorizationSecret.
154: * @return string
155: */
156: public function getOAuth2ClientSecret()
157: {
158: return $this->getAuthorizationSecret();
159: }
160:
161: /**
162: * This method is an alias for setAuthorizationSecret.
163: * @param string $oauth2ClientSecret
164: */
165: public function setOAuth2ClientSecret($oauth2ClientSecret)
166: {
167: $this->setAuthorizationSecret($oauth2ClientSecret);
168: }
169:
170: /**
171: * @return string
172: */
173: public function getApiEndpoint()
174: {
175: return $this->apiEndpoint;
176: }
177:
178: /**
179: * @param string $apiEndpoint
180: */
181: public function setApiEndpoint($apiEndpoint)
182: {
183: $this->validateApiEndpoint($apiEndpoint);
184: $this->apiEndpoint = $apiEndpoint;
185: }
186:
187: /**
188: * @return ProxyConfiguration|null
189: */
190: public function getProxyConfiguration()
191: {
192: return $this->proxyConfiguration;
193: }
194:
195: /**
196: * @param ProxyConfiguration|null $proxyConfiguration
197: */
198: public function setProxyConfiguration(ProxyConfiguration $proxyConfiguration = null)
199: {
200: $this->proxyConfiguration = $proxyConfiguration;
201: }
202:
203: /**
204: * @return int
205: */
206: public function getConnectTimeout()
207: {
208: return $this->connectTimeout;
209: }
210:
211: /**
212: * @param int $connectTimeout
213: */
214: public function setConnectTimeout($connectTimeout)
215: {
216: $this->connectTimeout = $connectTimeout;
217: }
218:
219: /**
220: * @return int
221: */
222: public function getReadTimeout()
223: {
224: return $this->readTimeout;
225: }
226:
227: /**
228: * @param int $readTimeout
229: */
230: public function setReadTimeout($readTimeout)
231: {
232: $this->readTimeout = $readTimeout;
233: }
234:
235: /**
236: * @return string
237: */
238: public function getIntegrator()
239: {
240: return $this->integrator;
241: }
242:
243: /**
244: * @param string $integrator
245: */
246: public function setIntegrator($integrator)
247: {
248: $this->validateIntegrator($integrator);
249: $this->integrator = $integrator;
250: }
251:
252: /**
253: * @return ShoppingCartExtension|null
254: */
255: public function getShoppingCartExtension()
256: {
257: return $this->shoppingCartExtension;
258: }
259:
260: /**
261: * @param ShoppingCartExtension|null $shoppingCartExtension
262: */
263: public function setShoppingCartExtension(ShoppingCartExtension $shoppingCartExtension = null)
264: {
265: $this->shoppingCartExtension = $shoppingCartExtension;
266: }
267: }
268: