Start of form customization for billing
This commit is contained in:
parent
5d69ba5f91
commit
8c20592423
5 changed files with 144 additions and 54 deletions
|
@ -9,6 +9,10 @@ class BillingController extends Zend_Controller_Action {
|
|||
|
||||
public function upgradeAction()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
$this->view->headLink()->appendStylesheet($baseUrl.'css/billing.css?'.$CC_CONFIG['airtime_version']);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$form = new Application_Form_BillingUpgradeDowngrade();
|
||||
if ($request->isPost()) {
|
||||
|
@ -21,12 +25,11 @@ class BillingController extends Zend_Controller_Action {
|
|||
$postfields["username"] = $credentials["username"];
|
||||
$postfields["password"] = md5($credentials["password"]);
|
||||
$postfields["action"] = "upgradeproduct";
|
||||
|
||||
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
$postfields["clientid"] = 1846;
|
||||
|
||||
$postfields["serviceid"] = self::getClientServiceId();
|
||||
|
||||
//TODO: do not hardcode
|
||||
//$postfields["serviceid"] = self::getClientInstanceId();
|
||||
$postfields["serviceid"] = "1678";
|
||||
$postfields["type"] = "product";
|
||||
$postfields["newproductid"] = $formData["newproductid"];
|
||||
$postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"];
|
||||
|
@ -34,20 +37,15 @@ class BillingController extends Zend_Controller_Action {
|
|||
$postfields["responsetype"] = "json";
|
||||
|
||||
$upgrade_query_string = "";
|
||||
foreach ($postfields as $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&";
|
||||
foreach ($postfields AS $k=>$v) $upgrade_query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
//update client info
|
||||
$clientfields = array();
|
||||
$clientfields["username"] = $credentials["username"];
|
||||
$clientfields["password"] = md5($credentials["password"]);
|
||||
$clientfields["action"] = "updateclient";
|
||||
|
||||
//$clientfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
$clientfields["clientid"] = 1846;
|
||||
|
||||
$clientfields["customfields"] = base64_encode(serialize($formData["customfields"]));
|
||||
unset($formData["customfields"]);
|
||||
|
||||
$clientfields["responsetype"] = "json";
|
||||
unset($formData["newproductid"]);
|
||||
unset($formData["newproductbillingcycle"]);
|
||||
|
@ -57,22 +55,17 @@ class BillingController extends Zend_Controller_Action {
|
|||
unset($clientfields["password2verify"]);
|
||||
unset($clientfields["submit"]);
|
||||
$client_query_string = "";
|
||||
foreach ($clientfields as $k=>$v) $client_query_string .= "$k=".urlencode($v)."&";
|
||||
foreach ($clientfields AS $k=>$v) $client_query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$result = $this->makeRequest($credentials["url"], $client_query_string);
|
||||
|
||||
Logging::info($result);
|
||||
if ($result["result"] == "error") {
|
||||
$this->setErrorMessage();
|
||||
$this->view->form = $form;
|
||||
} else {
|
||||
$result = $this->makeRequest($credentials["url"], $upgrade_query_string);
|
||||
if ($result["result"] == "error") {
|
||||
Logging::info($_SERVER['HTTP_HOST']." - Account upgrade failed. - ".$result["message"]);
|
||||
$this->setErrorMessage();
|
||||
$this->view->form = $form;
|
||||
} else {
|
||||
self::viewInvoice($result["invoiceid"]);
|
||||
}
|
||||
//$result = $this->makeRequest($credentials["url"], $upgrade_query_string);
|
||||
//self::viewInvoice($result["invoiceid"]);
|
||||
self::viewInvoice(5108);
|
||||
}
|
||||
} else {
|
||||
$this->view->form = $form;
|
||||
|
@ -113,7 +106,7 @@ class BillingController extends Zend_Controller_Action {
|
|||
{
|
||||
$whmcsurl = "https://account.sourcefabric.com/dologin.php";
|
||||
$autoauthkey = $_SERVER["WHMCS_AUTOAUTH_KEY"];
|
||||
$timestamp = time();
|
||||
$timestamp = time(); //whmcs timezone?
|
||||
$client = self::getClientDetails();
|
||||
$email = $client["email"];
|
||||
$hash = sha1($email.$timestamp.$autoauthkey);
|
||||
|
@ -128,27 +121,22 @@ class BillingController extends Zend_Controller_Action {
|
|||
if ($request->isPost()) {
|
||||
$formData = $request->getPost();
|
||||
if ($form->isValid($formData)) {
|
||||
|
||||
|
||||
$credentials = self::getAPICredentials();
|
||||
|
||||
$postfields = array();
|
||||
$postfields["username"] = $credentials["username"];
|
||||
$postfields["password"] = md5($credentials["password"]);
|
||||
$postfields["action"] = "updateclient";
|
||||
|
||||
$postfields["customfields"] = base64_encode(serialize($formData["customfields"]));
|
||||
unset($formData["customfields"]);
|
||||
|
||||
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
$postfields["clientid"] = 1846;
|
||||
|
||||
$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)."&";
|
||||
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$result = $this->makeRequest($credentials["url"], $query_string);
|
||||
|
||||
|
@ -181,7 +169,7 @@ class BillingController extends Zend_Controller_Action {
|
|||
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
|
||||
$query_string = "";
|
||||
foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$result = self::makeRequest($credentials["url"], $query_string);
|
||||
$this->view->invoices = $result["invoices"]["invoice"];
|
||||
|
@ -194,10 +182,9 @@ class BillingController extends Zend_Controller_Action {
|
|||
self::viewInvoice($invoice_id);
|
||||
}
|
||||
|
||||
private static function getClientServiceId()
|
||||
//TODO: this does not return a service id. why?
|
||||
private static function getClientInstanceId()
|
||||
{
|
||||
$service_id = null;
|
||||
|
||||
$credentials = self::getAPICredentials();
|
||||
|
||||
$postfields = array();
|
||||
|
@ -209,21 +196,10 @@ class BillingController extends Zend_Controller_Action {
|
|||
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
|
||||
|
||||
$query_string = "";
|
||||
foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$result = self::makeRequest($credentials["url"], $query_string);
|
||||
if (empty($result["products"])) {
|
||||
Logging::info($_SERVER['HTTP_HOST']." - Account upgrade failed - Could not find service id");
|
||||
} else {
|
||||
foreach ($result["products"]["product"] as $product) {
|
||||
if (array_key_exists("groupname", $product) && $product["groupname"] == "Airtime") {
|
||||
$service_id = $product["id"];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $service_id;
|
||||
Logging::info($result);
|
||||
}
|
||||
|
||||
public static function getProducts()
|
||||
|
@ -239,7 +215,7 @@ class BillingController extends Zend_Controller_Action {
|
|||
$postfields["gid"] = "15";
|
||||
|
||||
$query_string = "";
|
||||
foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$result = self::makeRequest($credentials["url"], $query_string);
|
||||
return $result["products"]["product"];
|
||||
|
@ -260,7 +236,7 @@ class BillingController extends Zend_Controller_Action {
|
|||
$postfields["responsetype"] = "json";
|
||||
|
||||
$query_string = "";
|
||||
foreach ($postfields as $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
|
||||
|
||||
$arr = self::makeRequest($credentials["url"], $query_string);
|
||||
return $arr["client"];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue