_merchantId = $merchantId; $this->_accessKey = $accessKey; $this->_secretKey = $secretKey; $this->_applicationName = $applicationName; $this->_applicationVersion = $applicationVersion; $this->_region = strtoupper($region); $this->_environment = strtoupper($environment); $this->_caBundleFile = $caBundleFile; $this->_serviceUrl = $serviceUrl; $this->_widgetUrl = $widgetUrl; $this->_regionSpecificProperties = new OffAmazonPaymentsService_RegionSpecificProperties(); $this->_clientId = $clientId; if ($this->_merchantId == "") { throw new InvalidArgumentException("merchantId not set in the properties file"); } if ($this->_accessKey == "") { throw new InvalidArgumentException("accessKey not set in the properties file"); } if ($this->_secretKey == "") { throw new InvalidArgumentException("secretKey not set in the properties file"); } if ($this->_applicationName == "") { throw new InvalidArgumentException( "applicationName not set in the properties file" ); } if ($this->_applicationVersion == "") { throw new InvalidArgumentException( "applicationVersion not set in the properties file" ); } if ($this->_region == "") { throw new InvalidArgumentException("region not set in the properties file"); } $this->_region = $this->_validateRegion($this->_region); if ($this->_environment == "") { throw new InvalidArgumentException("environment not set in the properties file"); } $this->_environment = $this->_validateEnvironment($this->_environment); if ($this->_caBundleFile == "") { $this->_caBundleFile = null; } } public function getMerchantId() { return $this->_merchantId; } public function getAccessKey() { return $this->_accessKey; } public function getSecretKey() { return $this->_secretKey; } public function getServiceUrl() { return $this->_regionSpecificProperties->getServiceUrlFor($this->_region, $this->_environment, $this->_serviceUrl); } public function getWidgetUrl() { return $this->_regionSpecificProperties->getWidgetUrlFor($this->_region, $this->_environment, $this->_merchantId, $this->_widgetUrl); } public function getCurrency() { return $this->_regionSpecificProperties->getCurrencyFor($this->_region); } public function getApplicationName() { return $this->_applicationName; } public function getApplicationVersion() { return $this->_applicationVersion; } public function getRegion() { return $this->_region; } public function getEnvironment() { return $this->_environment; } public function getCaBundleFile() { return $this->_caBundleFile; } public function getClientId() { return $this->_clientId; } 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($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; } public static function withRegionSpecificProperties( $merchantId, $accessKey, $secretKey, $applicationName, $applicationVersion, $region, $environment, $serviceUrl, $widgetUrl, $caBundleFile, $regionSpecificProperties, $clientId) { $instance = new self($merchantId, $accessKey, $secretKey, $applicationName, $applicationVersion, $region, $environment, $serviceUrl, $widgetUrl, $caBundleFile, $clientId); $instance->_regionSpecificProperties = $regionSpecificProperties; return $instance; } } ?>