_config = $config; $this->_regionSpecificProperties = $regionSpecificProperties; $this->_utils = new OffAmazonPaymentsServiceUtils(); if (empty($this->_config['merchantId'])) { throw new InvalidArgumentException("merchantId not set in the properties file"); } if (empty($this->_config['accessKey'])) { throw new InvalidArgumentException("accessKey not set in the properties file"); } if (empty($this->_config['secretKey'])) { throw new InvalidArgumentException("secretKey not set in the properties file"); } if (empty($this->_config['cnName'])) { throw new InvalidArgumentException("cnName not set in the properties file"); } if (empty($this->_config['applicationName'])) { throw new InvalidArgumentException( "applicationName not set in the properties file" ); } if (empty($this->_config['applicationVersion'])) { throw new InvalidArgumentException( "applicationVersion not set in the properties file" ); } if (empty($this->_config['region'])) { throw new InvalidArgumentException("region not set in the properties file"); } $this->_config['region'] = $this->_validateRegion($this->_config['region']); if (empty($this->_config['environment'])) { throw new InvalidArgumentException("environment not set in the properties file"); } $this->_config['environment'] = $this->_validateEnvironment($this->_config['environment']); if (empty($this->_config['caBundleFile'])) { $this->_config['caBundleFile'] = null; } if (empty($this->_config['serviceUrl'])) { $this->_config['serviceUrl'] = null; } if (empty($this->_config['widgetUrl'])) { $this->_config['widgetUrl'] = null; } if (empty($this->_config['proxyHost'])) { $this->_config['proxyHost'] = null; } if (empty($this->_config['proxyPort'])) { $this->_config['proxyPort'] = null; } if (empty($this->_config['proxyUsername'])) { $this->_config['proxyUsername'] = null; } if (empty($this->_config['proxyPassword'])) { $this->_config['proxyPassword'] = null; } } public function getMerchantId() { return $this->_config['merchantId']; } public function getAccessKey() { return $this->_config['accessKey']; } public function getSecretKey() { return $this->_config['secretKey']; } public function getServiceUrl() { return $this->_regionSpecificProperties->getServiceUrlFor( $this->getRegion(), $this->getEnvironment(), $this->_config['serviceUrl'] ); } public function getWidgetUrl() { return $this->_regionSpecificProperties->getWidgetUrlFor( $this->getRegion(), $this->getEnvironment(), $this->getMerchantId(), $this->_config['widgetUrl'] ); } public function getCurrency() { return $this->_regionSpecificProperties->getCurrencyFor($this->getRegion()); } public function getApplicationName() { return $this->_config['applicationName']; } public function getApplicationVersion() { return $this->_config['applicationVersion']; } public function getRegion() { return $this->_config['region']; } public function getEnvironment() { return $this->_config['environment']; } public function getCaBundleFile() { return $this->_config['caBundleFile']; } public function getClientId() { return $this->_config['clientId']; } public function getProxyUsername() { return $this->_config['proxyUsername']; } public function getProxyPassword() { return $this->_config['proxyPassword']; } public function getProxyHost() { return $this->_config['proxyHost']; } public function getProxyPort() { return $this->_config['proxyPort']; } public function getCnName() { return $this->_config['cnName']; } public function isProxyConfigured() { $host = $this->getProxyHost(); $port = $this->getProxyPort(); return !empty($host) && !empty($port); } public function isProxyAuthenticationConfigured() { $user = $this->getProxyUsername(); $pw = $this->getProxyPassword(); return $this->isProxyConfigured() && !empty($user) && !empty($pw); } public function isCaBundleConfigured() { $file = $this->getCaBundleFile(); return !empty($file); } public function getUserAgentString() { return $this->_utils->buildUserAgentString( $this->getApplicationName(), $this->getApplicationVersion() ); } private function _validateRegion($region) { include_once 'Regions.php'; return self::_getValueForConstant($region, new OffAmazonPaymentsService_Regions()); } private static function _validateEnvironment($environment) { include_once 'Environments.php'; return self::_getValueForConstant($environment, new OffAmazonPaymentsService_Environments()); } private static function _getValueForConstant($constant, $valuesClass) { $rc = new ReflectionClass($valuesClass); $value = $rc->getConstant(strtoupper($constant)); if ($value == null) { $allowedValues = implode(",", array_keys($rc->getConstants())); throw new InvalidArgumentException( "check your property file: " . $constant . " is not a valid option. Available options are: " . $allowedValues ); } return $value; } }