Validation

Refactoring
This commit is contained in:
drigato 2014-06-20 16:31:26 -04:00
parent 01bf2883e5
commit 1e1dc1dd03
2 changed files with 71 additions and 51 deletions

View File

@ -55,7 +55,7 @@ class BillingController extends Zend_Controller_Action {
$result = $this->makeRequest($credentials["url"], $client_query_string);
if ($result["result"] == "error") {
$this->view->errorMessage = "An error occurred and we could not upgrade your account. Please contact support for help";
$this->setErrorMessage();
$this->view->form = $form;
} else {
//$result = $this->makeRequest($credentials["url"], $upgrade_query_string);
@ -70,10 +70,27 @@ class BillingController extends Zend_Controller_Action {
}
}
private function setErrorMessage($msg=null)
{
if (!is_null($msg)) {
$this->view->errorMessage = $msg;
} else {
$this->view->errorMessage = "An error occurred and we could not update your account. Please contact support for help.";
}
}
private function setSuccessMessage($msg=null)
{
if (!is_null($msg)) {
$this->view->successMessage = $msg;
} else {
$this->view->successMessage = "Your account has been updated.";
}
}
private static function getAPICredentials()
{
return array(
"access_key" => $_SERVER["WHMCS_ACCESS_KEY"],
"username" => $_SERVER["WHMCS_USERNAME"],
"password" => $_SERVER["WHMCS_PASSWORD"],
"url" => "https://account.sourcefabric.com/includes/api.php?accesskey=".$_SERVER["WHMCS_ACCESS_KEY"],
@ -98,28 +115,37 @@ class BillingController extends Zend_Controller_Action {
$form = new Application_Form_BillingClient();
if ($request->isPost()) {
$formData = $request->getPost();
if ($form->isValid($formData)) {
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "updateclient";
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
$postfields["clientid"] = 1846;
$postfields = array_merge($postfields, $formData);
unset($postfields["password2verify"]);
unset($postfields["submit"]);
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = $this->makeRequest($url, $query_string);
$form = new Application_Form_BillingClient();
$this->view->form = $form;
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "updateclient";
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
$postfields["clientid"] = 18460000000;
$postfields["responsetype"] = "json";
$postfields = array_merge($postfields, $formData);
unset($postfields["password2verify"]);
unset($postfields["submit"]);
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = $this->makeRequest($credentials["url"], $query_string);
if ($result["result"] == "error") {
$this->setErrorMessage();
} else {
$form = new Application_Form_BillingClient();
$this->setSuccessMessage();
}
$this->view->form = $form;
} else {
$this->view->form = $form;
}
} else {
$this->view->form = $form;
}
@ -127,14 +153,11 @@ class BillingController extends Zend_Controller_Action {
public function invoicesAction()
{
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "getinvoices";
$postfields["responsetype"] = "json";
$postfields["userid"] = 1846;
@ -143,7 +166,7 @@ class BillingController extends Zend_Controller_Action {
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($url, $query_string);
$result = self::makeRequest($credentials["url"], $query_string);
$this->view->invoices = $result["invoices"]["invoice"];
}
@ -157,14 +180,11 @@ class BillingController extends Zend_Controller_Action {
//TODO: this does not return a service id. why?
private static function getClientInstanceId()
{
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "getclientsproducts";
$postfields["responsetype"] = "json";
$postfields["clientid"] = 1846;
@ -173,42 +193,37 @@ class BillingController extends Zend_Controller_Action {
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($url, $query_string);
$result = self::makeRequest($credentials["url"], $query_string);
Logging::info($result);
}
public static function getProducts()
{
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "getproducts";
$postfields["responsetype"] = "json";
//gid is the Airtime product group id on whmcs
$postfields["gid"] = "15";
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($url, $query_string);
$result = self::makeRequest($credentials["url"], $query_string);
return $result["products"]["product"];
}
public static function getClientDetails()
{
try {
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "getclientsdetails";
$postfields["stats"] = true;
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
@ -218,7 +233,7 @@ class BillingController extends Zend_Controller_Action {
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$arr = self::makeRequest($url, $query_string);
$arr = self::makeRequest($credentials["url"], $query_string);
return $arr["client"];
} catch (Exception $e) {
Logging::info($e->getMessage());

View File

@ -1,3 +1,8 @@
<div class="ui-widget ui-widget-content block-shadow clearfix padded-strong">
<?php if (isset($this->errorMessage)) {?>
<div class="errors"><?php echo $this->errorMessage ?></div>
<?php } else if (isset($this->successMessage)) {?>
<div class="success"><?php echo $this->successMessage ?></div>
<?php }?>
<?php echo $this->form ?>
</div>