productMetaData = $productMetadata; $this->scopeConfig = $scopeConfig; $this->http = $http; $this->storeManager = $storeManager; } /** * Get Onboarding URL * * @param string $moduleKey * @param string $moduleVersion * @return string * @throws \Magento\Framework\Exception\LocalizedException */ public function getUrl($moduleKey, $moduleVersion) { $platform = 'magento'; $platformVersion = $this->productMetaData->getVersion(); $queryParameter = sprintf( '?plugin=%s&pluginVersion=%s&platform=%s&platformVersion=%sproducts=%s', $moduleKey, $moduleVersion, $platform, $platformVersion, $moduleKey ); $websiteId = $this->http->getParam('website', 0); $website = $this->storeManager->getWebsite($websiteId); $scope = $this->getScope($website); $country = $this->scopeConfig->getValue('general/store_information/country_id', $scope, $website); if (!empty($country)) { $queryParameter .= '&country=' . $country; } $url = 'https://eu.portal.klarna.com/signup' . $queryParameter; if ($country === 'US') { $url = 'https://us.portal.klarna.com/signup' . $queryParameter; } return $url; } /** * Return either website scope or default scope depending on value of $website * * @param \Magento\Store\Api\Data\WebsiteInterface $website * @return string */ private function getScope($website = null) { if ($website === null) { return ScopeConfigInterface::SCOPE_TYPE_DEFAULT; } return ScopeInterface::SCOPE_WEBSITES; } }