/** * Provision a new account with SmartBear's AlertSite API and return any response * * @param $parameters * @throws Exception - error message encountered when provisioning * @return bool - was the account successfully provisioned? */ public function provisionAccount(Varien_Object $parameters) { //get the provisioning URL $url = self::ALERTSITE_PROVISION_API_URL; $apiFriendlyParams = array(); $apiFriendlyParams['fname'] = urlencode($parameters->getFirstName()); $apiFriendlyParams['lname'] = urlencode($parameters->getLastName()); $apiFriendlyParams['phone'] = urlencode($parameters->getPhone()); $apiFriendlyParams['company'] = urlencode($parameters->getCompanyName()); $apiFriendlyParams['api_version'] = urlencode('1.0'); $apiFriendlyParams['order_type'] = urlencode('magento'); $apiFriendlyParams['response_type'] = urlencode('xml'); $apiFriendlyParams['login_email'] = urlencode(strtolower($parameters->getLoginEmail())); $apiFriendlyParams['monitor_url'] = urlencode($parameters->getMonitorUrl()); $this->setPhone($parameters->getPhone()); $this->setCompany($apiFriendlyParams['company']); $this->setFName($apiFriendlyParams['fname']); $this->setLName($apiFriendlyParams['lname']); $response = $this->getCurlResponse($url, $apiFriendlyParams, 'POST', false); if (!$response) { throw new Exception("There was a problem provisioning your new account. Please try again or contact AlertSite support."); return false; } $status = (string) $response["status"]; if ($status == 'failed') { $error = $response->Error; $errorMessage = (string) $error['description']; if ((string) $error['code'] == "0001") { if ($error->missing_fields) { $count = count($error->missing_fields); $missingFields = ""; if ($count > 1) { foreach ($error->missing_fields as $missingField) { if ((string) $missingField['name'] == 'monitor_url') { $missingFields .= " - Monitor URL Required"; } else { if ((string) $missingField['name'] == 'login_email') { $missingFields .= " - Login Email Required"; } } } } else { if ((string) $error->missing_fields['name'] == 'monitor_url') { $missingFields .= " - Monitor URL Required"; } else { if ((string) $error->missing_fields['name'] == 'login_email') { $missingFields .= " - Login Email Required"; } } } $errorMessage .= $missingFields; } } throw new Exception($errorMessage); } else { if ($status == 'success') { $this->_newAlertSiteConfig($response->AccountCreated); return true; } } return false; }