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