/** * Get the information regarding to the user's eBay store * @return array Return a result of eBay API calls */ public function getEbayStoreAction() { // Check if the eBay keys are exist for API connection if (!ISC_ADMIN_EBAY::checkEbayConfig()) { ISC_JSON::output(GetLang('EbayStoreKeysMissing'), false); } try { $xml = ISC_ADMIN_EBAY_OPERATIONS::getStore(); } catch (ISC_EBAY_API_EXCEPTION $ex) { ISC_JSON::output(GetLang('NoEbayStoreFound'), false, array('noStore' => true)); } // otherwise, save the eBay store $GLOBALS['ISC_NEW_CFG']['EbayStore'] = (string)$xml->Store->Name; $settings = GetClass('ISC_ADMIN_SETTINGS'); // if something goes wrong when we saving the configuration, return error message to caller if(!$settings->CommitSettings()) { ISC_JSON::output(GetLang('EbaySettingsNotSaved'), false); } // Log this action if we are in the control panel if (defined('ISC_ADMIN_CP')) { $GLOBALS['ISC_CLASS_LOG']->LogAdminAction(); } ISC_JSON::output(GetLang('EbayGetStoreSuccess'), true, array('storeName' => (string)$xml->Store->Name)); }
/** * To save the eBay settings on Unreal Shopping Cart */ public function SaveEbay() { $devId = trim($_POST['EbayDevId']); $appId = trim($_POST['EbayAppId']); $certId = trim($_POST['EbayCertId']); $userToken = trim($_POST['EbayUserToken']); $defaultSite = (int)$_POST['EbayDefaultSite']; $testMode = $_POST['EbayTestMode']; if (!$this->isProductionSiteAllowed()) { $testMode = 'sandbox'; } ISC_ADMIN_EBAY_OPERATIONS::setSiteId($defaultSite); // the events that we're subscribing to $ebayEvents = array( 'AuctionCheckoutComplete', 'BestOffer', 'BestOfferPlaced', 'BidPlaced', 'BidReceived', 'CheckoutBuyerRequestsTotal', 'EndOfAuction', 'Feedback', 'FeedbackLeft', 'FeedbackReceived', 'FixedPriceEndOfTransaction', 'FixedPriceTransaction', 'ItemClosed', 'ItemExtended', 'ItemListed', 'ItemRevised', 'ItemRevisedAddCharity', 'ItemSold', 'ItemSuspended', 'ItemUnsold', ); $getStoreAndSubscribe = false; $settingsValid = true; // was the keys changed? we should unsubscribe from the old notifications first if (self::checkEbayConfig('', false)) { $currentDevId = GetConfig('EbayDevId'); $currentAppId = GetConfig('EbayAppId'); $currentCertId = GetConfig('EbayCertId'); $currentUserToken = GetConfig('EbayUserToken'); $currentTestMode = GetConfig('EbayTestMode'); if ($currentDevId != $devId || $currentAppId != $appId || $currentCertId != $certId || $currentUserToken != $userToken || $currentTestMode != $testMode ) { try { ISC_ADMIN_EBAY_OPERATIONS::setApplicationNotificationsEnabled(false); $disableArray = array_fill(0, count($ebayEvents), false); $unsubscribeEvents = array_combine($ebayEvents, $disableArray); ISC_ADMIN_EBAY_OPERATIONS::setApplicationNotificationEvents($unsubscribeEvents); } catch (ISC_EBAY_API_EXCEPTION $ex) { } $getStoreAndSubscribe = true; } } else { $getStoreAndSubscribe = true; } // Save the Ebay Settings to config file $GLOBALS['ISC_NEW_CFG']['EbayDevId'] = $devId; $GLOBALS['ISC_NEW_CFG']['EbayAppId'] = $appId; $GLOBALS['ISC_NEW_CFG']['EbayCertId'] = $certId; $GLOBALS['ISC_NEW_CFG']['EbayUserToken'] = $userToken; $GLOBALS['ISC_NEW_CFG']['EbayDefaultSite'] = $defaultSite; $GLOBALS['ISC_NEW_CFG']['EbayTestMode'] = $testMode; $settings = GetClass('ISC_ADMIN_SETTINGS'); // if we save the configuration successfully if(!$settings->CommitSettings()) { // otherwise display the error message FlashMessage(GetLang('EbaySettingsNotSaved'), MSG_ERROR, 'index.php?ToDo=viewEbay¤tTab=2'); } try { // attempt to get ebay details for US to validate settings ISC_ADMIN_EBAY_OPERATIONS::setSiteId(0); ISC_ADMIN_EBAY_OPERATIONS::geteBayOfficialTime(); } catch (ISC_EBAY_API_EXCEPTION $ex) { $settingsValid = false; } $GLOBALS['ISC_NEW_CFG']['EbaySettingsValid'] = $settingsValid; if(!$settings->CommitSettings()) { FlashMessage(GetLang('EbaySettingsNotSaved'), MSG_ERROR, 'index.php?ToDo=viewEbay¤tTab=2'); } if (empty ($devId) && empty ($appId) && empty ($certId) && empty ($userToken)) { FlashMessage(GetLang('EbayKeysRemovedSuccessfully'), MSG_SUCCESS, 'index.php?ToDo=viewEbay¤tTab=2', 'EbayConfig'); } if ($settingsValid) { if ($getStoreAndSubscribe) { // above settings need to be committed first before we can check for the ebay store correctly $ebayStore = ''; try { $xml = ISC_ADMIN_EBAY_OPERATIONS::getStore(); $ebayStore = (string)$xml->Store->Name; } catch (ISC_EBAY_API_EXCEPTION $ex) { // if we can't retrieve a store name then we don't want to produce an error, silently continue } // save ebay store setting $GLOBALS['ISC_NEW_CFG']['EbayStore'] = $ebayStore; if(!$settings->CommitSettings()) { // otherwise display the error message FlashMessage(GetLang('EbaySettingsNotSaved'), MSG_ERROR, 'index.php?ToDo=viewEbay¤tTab=2', 'EbayConfig'); } // ensure our application is subscribed to ebay notifications try { ISC_ADMIN_EBAY_OPERATIONS::setApplicationNotificationsEnabled(true); $enableArray = array_fill(0, count($ebayEvents), true); $subscribeEvents = array_combine($ebayEvents, $enableArray); ISC_ADMIN_EBAY_OPERATIONS::setApplicationNotificationEvents($subscribeEvents); } catch (ISC_EBAY_API_EXCEPTION $ex) { FlashMessage(GetLang('EbayNotificationsNotSubscribed', array('message' => $ex->getMessage())), MSG_ERROR, 'index.php?ToDo=viewEbay¤tTab=2', 'EbayConfig'); } } } else { FlashMessage(GetLang('EbaySettingsNotValid'), MSG_ERROR, 'index.php?ToDo=viewEbay¤tTab=2', 'EbayConfig'); } // log the action if (defined('ISC_ADMIN_CP')) { $GLOBALS['ISC_CLASS_LOG']->LogAdminAction(); } // display the success message FlashMessage(GetLang('EbaySettingsSavedSuccessfully'), MSG_SUCCESS, 'index.php?ToDo=viewEbay¤tTab=2', 'EbayConfig'); }