Merge branch 'cc-5709-airtime-analyzer-buy-now' into cc-5709-airtime-analyzer-buy-now-saas

This commit is contained in:
Albert Santoni 2014-06-27 15:50:51 -04:00
commit e9cca4c441
4 changed files with 73 additions and 55 deletions

View File

@ -394,60 +394,11 @@ class BillingController extends Zend_Controller_Action {
self::viewInvoice($invoice_id);
}
/** Get the Airtime instance ID of the instance the customer is currently viewing. */
private static function getClientInstanceId()
{
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "getclientsproducts";
$postfields["responsetype"] = "json";
$postfields["clientid"] = Application_Model_Preference::GetClientId();
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($credentials["url"], $query_string);
Logging::info($result);
//XXX: Debugging / local testing
if ($_SERVER['SERVER_NAME'] == "airtime.localhost") {
return "1384";
}
//This code must run on airtime.pro for it to work... it's trying to match
//the server's hostname with the client subdomain. Once it finds a match
//between the product and the server's hostname/subdomain, then it
//returns the ID of that product (aka. the service ID of an Airtime instance)
foreach ($result["products"] as $product)
{
if (strpos($product[0]["groupname"], "Airtime") === FALSE)
{
//Ignore non-Airtime products
continue;
}
else
{
if ($product[0]["status"] === "Active") {
$airtimeProduct = $product[0];
$subdomain = '';
foreach ($airtimeProduct['customfields']['customfield'] as $customField)
{
if ($customField['name'] === SUBDOMAIN_WHMCS_CUSTOM_FIELD_NAME)
{
$subdomain = $customField['value'];
if (($subdomain . ".airtime.pro") === $_SERVER['SERVER_NAME'])
{
return $airtimeProduct['id'];
}
}
}
}
}
}
throw new Exception("Unable to match subdomain to a service ID");
$currentProduct = BillingController::getClientCurrentAirtimeProduct();
return $currentProduct["id"];
}
public static function getProducts()
@ -491,6 +442,65 @@ class BillingController extends Zend_Controller_Action {
return array($productPrices, $productTypes);
}
/** Get the plan (or product in WHMCS lingo) that the customer is currently on.
* @return An associative array containing the fields for the product
* */
public static function getClientCurrentAirtimeProduct()
{
static $airtimeProduct = null;
//Ghetto caching to avoid multiple round trips to WHMCS
if ($airtimeProduct) {
return $airtimeProduct;
}
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "getclientsproducts";
$postfields["responsetype"] = "json";
$postfields["clientid"] = Application_Model_Preference::GetClientId();
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($credentials["url"], $query_string);
//XXX: Debugging / local testing
if ($_SERVER['SERVER_NAME'] == "airtime.localhost") {
$_SERVER['SERVER_NAME'] = "bananas.airtime.pro";
}
//This code must run on airtime.pro for it to work... it's trying to match
//the server's hostname with the client subdomain. Once it finds a match
//between the product and the server's hostname/subdomain, then it
//returns the ID of that product (aka. the service ID of an Airtime instance)
foreach ($result["products"] as $product)
{
if (strpos($product[0]["groupname"], "Airtime") === FALSE)
{
//Ignore non-Airtime products
continue;
}
else
{
if ($product[0]["status"] === "Active") {
$airtimeProduct = $product[0];
$subdomain = '';
foreach ($airtimeProduct['customfields']['customfield'] as $customField) {
if ($customField['name'] === SUBDOMAIN_WHMCS_CUSTOM_FIELD_NAME) {
$subdomain = $customField['value'];
if (($subdomain . ".airtime.pro") === $_SERVER['SERVER_NAME']) {
return $airtimeProduct;
}
}
}
}
}
}
throw new Exception("Unable to match subdomain to a service ID");
}
public static function getClientDetails()
{

View File

@ -17,14 +17,16 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form
$pid->setLabel(_('Plan type:'))
->setMultiOptions($productTypes)
->setRequired(true)
->setValue(26);
->setValue(BillingController::getClientCurrentAirtimeProduct()["pid"]);
$this->addElement($pid);
Logging::info(BillingController::getClientCurrentAirtimeProduct());
$billingcycle = new Zend_Form_Element_Radio('newproductbillingcycle');
$billingcycle->setLabel(_('Billing cycle:'))
->setMultiOptions(array('monthly' => 'Monthly', 'annually' => 'Annually'))
->setRequired(true)
->setValue('monthly');
->setValue(BillingController::getClientCurrentAirtimeProduct()["billingcycle"]);
$this->addElement($billingcycle);
$paymentmethod = new Zend_Form_Element_Radio('paymentmethod');

View File

@ -10,5 +10,6 @@ $this->form->getElement("securityqid")->setAttrib("class", "right-align");
<?php } else if (isset($this->successMessage)) {?>
<div class="success"><?php echo $this->successMessage ?></div>
<?php }?>
<?php echo $this->form ?>
</div>

View File

@ -138,6 +138,8 @@ $(document).ready(function() {
vatFieldChangeTimer = null;
$(vatFieldId).change(function() {
$("#vaterror").text("Please wait, checking VAT number...");
if (vatFieldChangeTimer) {
clearTimeout(vatFieldChangeTimer);
}
@ -246,7 +248,10 @@ $(document).ready(function() {
<!--
<p> <a target="_blank" href="https://www.airtime.pro/pricing"><?=_("View Plans")?></a> (Opens in a new window)</p>
-->
<p id="current_plan"><b>Current Plan:</b> <?php echo Application_Model_Preference::GetPlanLevel();?>
<p id="current_plan"><b>Current Plan:</b>
<?php echo(BillingController::getClientCurrentAirtimeProduct()["name"]);
//echo Application_Model_Preference::GetPlanLevel();
?>
</p>
<h3>Choose a plan:</h3>