示例#1
0
文件: apis.php 项目: buttasg/cowgirlk
 /**
  * @param ShopgateConfigInterface $config
  */
 public function setup(ShopgateConfigInterface $config)
 {
     // needs to check if an old config is present without any access token
     if ($config->getCustomerNumber() && $config->getShopNumber() && $config->getApiKey() && !$config->getOauthAccessToken()) {
         // needs to load the non-oauth-url since the new access token needs to be generated using the classic shopgate merchant api authentication
         $apiUrls = $config->getApiUrls();
         $apiUrl = $config->getServer() == 'custom' ? str_replace('/api/merchant2', '/api/merchant', $config->getApiUrl()) : $apiUrls[$config->getServer()][ShopgateConfigInterface::SHOPGATE_AUTH_SERVICE_CLASS_NAME_SHOPGATE];
         $smaAuthServiceShopgate = new ShopgateAuthenticationServiceShopgate($config->getCustomerNumber(), $config->getApiKey());
         $smaAuthServiceShopgate->setup($config);
         $classicSma = new ShopgateMerchantApi($smaAuthServiceShopgate, $config->getShopNumber(), $apiUrl);
         // the "get_shop_info" returns an oauth access token
         $shopInfo = $classicSma->getShopInfo()->getData();
         // set newly generated access token
         $this->accessToken = $shopInfo['oauth_access_token'];
         // create a new settings array
         $shopgateSettingsNew = array($field = 'oauth_access_token' => $shopInfo[$field], $field = 'customer_number' => $shopInfo[$field], $field = 'shop_number' => $shopInfo[$field], $field = 'apikey' => $shopInfo[$field], $field = 'alias' => $shopInfo[$field], $field = 'cname' => $shopInfo[$field]);
         // save all shop config data to plugin-config using the configs save method
         $config->load($shopgateSettingsNew);
         $config->save(array_keys($shopgateSettingsNew), true);
     } elseif (!$this->accessToken && $config->getOauthAccessToken()) {
         // this would mean the data was somehow not in sync (should no be happening by default)
         $this->accessToken = $config->getOauthAccessToken();
     } else {
         // skip this since the connection is fully functional or there has not been made any connection at all, yet
         // -> missing data (except the oauth access token) is treated as "no valid connection available"
         // -> in either case there is nothing to do here
     }
 }
示例#2
0
文件: core.php 项目: buttasg/cowgirlk
 /**
  * Builds the Shopgate Library object graph for ShopgateMerchantApi and returns the instance.
  *
  * @return ShopgateMerchantApi
  */
 public function buildMerchantApi()
 {
     $merchantApi = null;
     switch ($smaAuthServiceClassName = $this->config->getSmaAuthServiceClassName()) {
         case ShopgateConfigInterface::SHOPGATE_AUTH_SERVICE_CLASS_NAME_SHOPGATE:
             $smaAuthService = new ShopgateAuthenticationServiceShopgate($this->config->getCustomerNumber(), $this->config->getApikey());
             $smaAuthService->setup($this->config);
             $merchantApi = new ShopgateMerchantApi($smaAuthService, $this->config->getShopNumber(), $this->config->getApiUrl());
             break;
         case ShopgateConfigInterface::SHOPGATE_AUTH_SERVICE_CLASS_NAME_OAUTH:
             $smaAuthService = new ShopgateAuthenticationServiceOAuth($this->config->getOauthAccessToken());
             $smaAuthService->setup($this->config);
             $merchantApi = new ShopgateMerchantApi($smaAuthService, null, $this->config->getApiUrl());
             break;
         default:
             // undefined auth service
             trigger_error('Invalid SMA-Auth-Service defined - this should not happen with valid plugin code', E_USER_ERROR);
             break;
     }
     return $merchantApi;
 }