| 1: | <?php |
| 2: | namespace Worldline\Acquiring\Sdk; |
| 3: | |
| 4: | use UnexpectedValueException; |
| 5: | use Worldline\Acquiring\Sdk\Domain\ShoppingCartExtension; |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | class CommunicatorConfiguration |
| 13: | { |
| 14: | |
| 15: | |
| 16: | |
| 17: | private string $authorizationId; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | private string $authorizationSecret; |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | private ?string $oauth2Scopes = null; |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | private string $apiEndpoint; |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | private int $connectTimeout; |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | private int $readTimeout; |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | private ?ProxyConfiguration $proxyConfiguration; |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | private string $integrator; |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | private ?ShoppingCartExtension $shoppingCartExtension = null; |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | public function __construct( |
| 69: | string $authorizationId, |
| 70: | string $authorizationSecret, |
| 71: | string $apiEndpoint, |
| 72: | string $integrator, |
| 73: | ProxyConfiguration $proxyConfiguration = null, |
| 74: | int $connectTimeout = -1, |
| 75: | int $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(string $apiEndpoint): void |
| 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(string $integrator): void |
| 101: | { |
| 102: | if (strlen(trim($integrator)) == 0) { |
| 103: | throw new UnexpectedValueException("integrator is required"); |
| 104: | } |
| 105: | } |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | public function getAuthorizationId(): string |
| 111: | { |
| 112: | return $this->authorizationId; |
| 113: | } |
| 114: | |
| 115: | |
| 116: | |
| 117: | |
| 118: | public function setAuthorizationId(string $authorizationId): void |
| 119: | { |
| 120: | $this->authorizationId = $authorizationId; |
| 121: | } |
| 122: | |
| 123: | |
| 124: | |
| 125: | |
| 126: | public function getAuthorizationSecret(): string |
| 127: | { |
| 128: | return $this->authorizationSecret; |
| 129: | } |
| 130: | |
| 131: | |
| 132: | |
| 133: | |
| 134: | public function setAuthorizationSecret(string $authorizationSecret): void |
| 135: | { |
| 136: | $this->authorizationSecret = $authorizationSecret; |
| 137: | } |
| 138: | |
| 139: | |
| 140: | |
| 141: | |
| 142: | |
| 143: | public function getOAuth2ClientId(): string |
| 144: | { |
| 145: | return $this->getAuthorizationId(); |
| 146: | } |
| 147: | |
| 148: | |
| 149: | |
| 150: | |
| 151: | |
| 152: | public function setOAuth2ClientId(string $oauth2ClientId): void |
| 153: | { |
| 154: | $this->setAuthorizationId($oauth2ClientId); |
| 155: | } |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | public function getOAuth2ClientSecret(): string |
| 162: | { |
| 163: | return $this->getAuthorizationSecret(); |
| 164: | } |
| 165: | |
| 166: | |
| 167: | |
| 168: | |
| 169: | |
| 170: | public function setOAuth2ClientSecret(string $oauth2ClientSecret): void |
| 171: | { |
| 172: | $this->setAuthorizationSecret($oauth2ClientSecret); |
| 173: | } |
| 174: | |
| 175: | |
| 176: | |
| 177: | |
| 178: | public function getOAuth2Scopes(): ?string |
| 179: | { |
| 180: | return $this->oauth2Scopes; |
| 181: | } |
| 182: | |
| 183: | |
| 184: | |
| 185: | |
| 186: | public function setOAuth2Scopes(?string $oauth2Scopes): void |
| 187: | { |
| 188: | $this->oauth2Scopes = $oauth2Scopes; |
| 189: | } |
| 190: | |
| 191: | |
| 192: | |
| 193: | |
| 194: | public function getApiEndpoint(): string |
| 195: | { |
| 196: | return $this->apiEndpoint; |
| 197: | } |
| 198: | |
| 199: | |
| 200: | |
| 201: | |
| 202: | public function setApiEndpoint(string $apiEndpoint): void |
| 203: | { |
| 204: | $this->validateApiEndpoint($apiEndpoint); |
| 205: | $this->apiEndpoint = $apiEndpoint; |
| 206: | } |
| 207: | |
| 208: | |
| 209: | |
| 210: | |
| 211: | public function getProxyConfiguration(): ?ProxyConfiguration |
| 212: | { |
| 213: | return $this->proxyConfiguration; |
| 214: | } |
| 215: | |
| 216: | |
| 217: | |
| 218: | |
| 219: | public function setProxyConfiguration(ProxyConfiguration $proxyConfiguration = null): void |
| 220: | { |
| 221: | $this->proxyConfiguration = $proxyConfiguration; |
| 222: | } |
| 223: | |
| 224: | |
| 225: | |
| 226: | |
| 227: | public function getConnectTimeout(): int |
| 228: | { |
| 229: | return $this->connectTimeout; |
| 230: | } |
| 231: | |
| 232: | |
| 233: | |
| 234: | |
| 235: | public function setConnectTimeout(int $connectTimeout): void |
| 236: | { |
| 237: | $this->connectTimeout = $connectTimeout; |
| 238: | } |
| 239: | |
| 240: | |
| 241: | |
| 242: | |
| 243: | public function getReadTimeout(): int |
| 244: | { |
| 245: | return $this->readTimeout; |
| 246: | } |
| 247: | |
| 248: | |
| 249: | |
| 250: | |
| 251: | public function setReadTimeout(int $readTimeout): void |
| 252: | { |
| 253: | $this->readTimeout = $readTimeout; |
| 254: | } |
| 255: | |
| 256: | |
| 257: | |
| 258: | |
| 259: | public function getIntegrator(): string |
| 260: | { |
| 261: | return $this->integrator; |
| 262: | } |
| 263: | |
| 264: | |
| 265: | |
| 266: | |
| 267: | public function setIntegrator(string $integrator): void |
| 268: | { |
| 269: | $this->validateIntegrator($integrator); |
| 270: | $this->integrator = $integrator; |
| 271: | } |
| 272: | |
| 273: | |
| 274: | |
| 275: | |
| 276: | public function getShoppingCartExtension(): ?ShoppingCartExtension |
| 277: | { |
| 278: | return $this->shoppingCartExtension; |
| 279: | } |
| 280: | |
| 281: | |
| 282: | |
| 283: | |
| 284: | public function setShoppingCartExtension(ShoppingCartExtension $shoppingCartExtension = null): void |
| 285: | { |
| 286: | $this->shoppingCartExtension = $shoppingCartExtension; |
| 287: | } |
| 288: | } |
| 289: | |