Start of form customization for billing

This commit is contained in:
Albert Santoni 2014-06-24 15:52:43 -04:00
parent 5d69ba5f91
commit 8c20592423
5 changed files with 144 additions and 54 deletions

View file

@ -9,6 +9,10 @@ class BillingController extends Zend_Controller_Action {
public function upgradeAction() 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(); $request = $this->getRequest();
$form = new Application_Form_BillingUpgradeDowngrade(); $form = new Application_Form_BillingUpgradeDowngrade();
if ($request->isPost()) { if ($request->isPost()) {
@ -21,12 +25,11 @@ class BillingController extends Zend_Controller_Action {
$postfields["username"] = $credentials["username"]; $postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]); $postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "upgradeproduct"; $postfields["action"] = "upgradeproduct";
//$postfields["clientid"] = Application_Model_Preference::GetClientId(); //$postfields["clientid"] = Application_Model_Preference::GetClientId();
$postfields["clientid"] = 1846; $postfields["clientid"] = 1846;
//TODO: do not hardcode
$postfields["serviceid"] = self::getClientServiceId(); //$postfields["serviceid"] = self::getClientInstanceId();
$postfields["serviceid"] = "1678";
$postfields["type"] = "product"; $postfields["type"] = "product";
$postfields["newproductid"] = $formData["newproductid"]; $postfields["newproductid"] = $formData["newproductid"];
$postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"]; $postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"];
@ -34,20 +37,15 @@ class BillingController extends Zend_Controller_Action {
$postfields["responsetype"] = "json"; $postfields["responsetype"] = "json";
$upgrade_query_string = ""; $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 //update client info
$clientfields = array(); $clientfields = array();
$clientfields["username"] = $credentials["username"]; $clientfields["username"] = $credentials["username"];
$clientfields["password"] = md5($credentials["password"]); $clientfields["password"] = md5($credentials["password"]);
$clientfields["action"] = "updateclient"; $clientfields["action"] = "updateclient";
//$clientfields["clientid"] = Application_Model_Preference::GetClientId(); //$clientfields["clientid"] = Application_Model_Preference::GetClientId();
$clientfields["clientid"] = 1846; $clientfields["clientid"] = 1846;
$clientfields["customfields"] = base64_encode(serialize($formData["customfields"]));
unset($formData["customfields"]);
$clientfields["responsetype"] = "json"; $clientfields["responsetype"] = "json";
unset($formData["newproductid"]); unset($formData["newproductid"]);
unset($formData["newproductbillingcycle"]); unset($formData["newproductbillingcycle"]);
@ -57,22 +55,17 @@ class BillingController extends Zend_Controller_Action {
unset($clientfields["password2verify"]); unset($clientfields["password2verify"]);
unset($clientfields["submit"]); unset($clientfields["submit"]);
$client_query_string = ""; $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); $result = $this->makeRequest($credentials["url"], $client_query_string);
Logging::info($result);
if ($result["result"] == "error") { if ($result["result"] == "error") {
$this->setErrorMessage(); $this->setErrorMessage();
$this->view->form = $form; $this->view->form = $form;
} else { } else {
$result = $this->makeRequest($credentials["url"], $upgrade_query_string); //$result = $this->makeRequest($credentials["url"], $upgrade_query_string);
if ($result["result"] == "error") { //self::viewInvoice($result["invoiceid"]);
Logging::info($_SERVER['HTTP_HOST']." - Account upgrade failed. - ".$result["message"]); self::viewInvoice(5108);
$this->setErrorMessage();
$this->view->form = $form;
} else {
self::viewInvoice($result["invoiceid"]);
}
} }
} else { } else {
$this->view->form = $form; $this->view->form = $form;
@ -113,7 +106,7 @@ class BillingController extends Zend_Controller_Action {
{ {
$whmcsurl = "https://account.sourcefabric.com/dologin.php"; $whmcsurl = "https://account.sourcefabric.com/dologin.php";
$autoauthkey = $_SERVER["WHMCS_AUTOAUTH_KEY"]; $autoauthkey = $_SERVER["WHMCS_AUTOAUTH_KEY"];
$timestamp = time(); $timestamp = time(); //whmcs timezone?
$client = self::getClientDetails(); $client = self::getClientDetails();
$email = $client["email"]; $email = $client["email"];
$hash = sha1($email.$timestamp.$autoauthkey); $hash = sha1($email.$timestamp.$autoauthkey);
@ -128,27 +121,22 @@ class BillingController extends Zend_Controller_Action {
if ($request->isPost()) { if ($request->isPost()) {
$formData = $request->getPost(); $formData = $request->getPost();
if ($form->isValid($formData)) { if ($form->isValid($formData)) {
$credentials = self::getAPICredentials(); $credentials = self::getAPICredentials();
$postfields = array(); $postfields = array();
$postfields["username"] = $credentials["username"]; $postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["password"]); $postfields["password"] = md5($credentials["password"]);
$postfields["action"] = "updateclient"; $postfields["action"] = "updateclient";
$postfields["customfields"] = base64_encode(serialize($formData["customfields"]));
unset($formData["customfields"]);
//$postfields["clientid"] = Application_Model_Preference::GetClientId(); //$postfields["clientid"] = Application_Model_Preference::GetClientId();
$postfields["clientid"] = 1846; $postfields["clientid"] = 1846;
$postfields["responsetype"] = "json"; $postfields["responsetype"] = "json";
$postfields = array_merge($postfields, $formData); $postfields = array_merge($postfields, $formData);
unset($postfields["password2verify"]); unset($postfields["password2verify"]);
unset($postfields["submit"]); unset($postfields["submit"]);
$query_string = ""; $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); $result = $this->makeRequest($credentials["url"], $query_string);
@ -181,7 +169,7 @@ class BillingController extends Zend_Controller_Action {
//$postfields["clientid"] = Application_Model_Preference::GetClientId(); //$postfields["clientid"] = Application_Model_Preference::GetClientId();
$query_string = ""; $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); $result = self::makeRequest($credentials["url"], $query_string);
$this->view->invoices = $result["invoices"]["invoice"]; $this->view->invoices = $result["invoices"]["invoice"];
@ -194,10 +182,9 @@ class BillingController extends Zend_Controller_Action {
self::viewInvoice($invoice_id); 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(); $credentials = self::getAPICredentials();
$postfields = array(); $postfields = array();
@ -209,21 +196,10 @@ class BillingController extends Zend_Controller_Action {
//$postfields["clientid"] = Application_Model_Preference::GetClientId(); //$postfields["clientid"] = Application_Model_Preference::GetClientId();
$query_string = ""; $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); $result = self::makeRequest($credentials["url"], $query_string);
if (empty($result["products"])) { Logging::info($result);
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;
} }
public static function getProducts() public static function getProducts()
@ -239,7 +215,7 @@ class BillingController extends Zend_Controller_Action {
$postfields["gid"] = "15"; $postfields["gid"] = "15";
$query_string = ""; $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); $result = self::makeRequest($credentials["url"], $query_string);
return $result["products"]["product"]; return $result["products"]["product"];
@ -260,7 +236,7 @@ class BillingController extends Zend_Controller_Action {
$postfields["responsetype"] = "json"; $postfields["responsetype"] = "json";
$query_string = ""; $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); $arr = self::makeRequest($credentials["url"], $query_string);
return $arr["client"]; return $arr["client"];

View file

@ -4,7 +4,7 @@ require_once 'Zend/Locale.php';
class Application_Form_BillingClient extends Zend_Form class Application_Form_BillingClient extends Zend_Form
{ {
public function init() public function init()
{ {
/*$this->setDecorators(array( /*$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/billing-purchase.phtml'))));*/ array('ViewScript', array('viewScript' => 'form/billing-purchase.phtml'))));*/
$client = BillingController::getClientDetails(); $client = BillingController::getClientDetails();

View file

@ -6,7 +6,7 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form
$productPrices = array(); $productPrices = array();
$productTypes = array(); $productTypes = array();
$products = BillingController::getProducts(); $products = BillingController::getProducts();
foreach ($products as $k => $p) { foreach ($products as $k => $p) {
$productPrices[$p["name"]] = array( $productPrices[$p["name"]] = array(
"monthly" => $p["pricing"]["USD"]["monthly"], "monthly" => $p["pricing"]["USD"]["monthly"],
@ -18,23 +18,26 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form
//$currentPlanType = ucfirst(Application_Model_Preference::GetPlanLevel()); //$currentPlanType = ucfirst(Application_Model_Preference::GetPlanLevel());
$currentPlanType = "Hobbyist"; $currentPlanType = "Hobbyist";
if (($key = array_search($currentPlanType, $productTypes)) !== false) { if (($key = array_search($currentPlanType, $productTypes)) !== false) {
unset($productTypes[$key]); //unset($productTypes[$key]);
} }
$pid = new Zend_Form_Element_Radio('newproductid'); $pid = new Zend_Form_Element_Radio('newproductid');
$pid->setLabel(_('Plan type:')) $pid->setLabel(_('Plan type:'))
->setMultiOptions($productTypes) ->setMultiOptions($productTypes)
->setRequired(true)
->setValue(26); ->setValue(26);
$this->addElement($pid); $this->addElement($pid);
$billingcycle = new Zend_Form_Element_Radio('newproductbillingcycle'); $billingcycle = new Zend_Form_Element_Radio('newproductbillingcycle');
$billingcycle->setLabel(_('Billing cycle:')) $billingcycle->setLabel(_('Billing cycle:'))
->setMultiOptions(array('monthly' => 'monthly', 'annually' => 'annually')) ->setMultiOptions(array('monthly' => 'monthly', 'annually' => 'annually'))
->setRequired(true)
->setValue('monthly'); ->setValue('monthly');
$this->addElement($billingcycle); $this->addElement($billingcycle);
$paymentmethod = new Zend_Form_Element_Radio('paymentmethod'); $paymentmethod = new Zend_Form_Element_Radio('paymentmethod');
$paymentmethod->setLabel(_('Payment method:')) $paymentmethod->setLabel(_('Payment method:'))
->setRequired(true)
->setMultiOptions(array( ->setMultiOptions(array(
'paypal' => _('PayPal'), 'paypal' => _('PayPal'),
'tco' => _('Credit Card via 2Checkout'))) 'tco' => _('Credit Card via 2Checkout')))

View file

@ -1,8 +1,86 @@
<?php
$form = $this->form;
$form->setAttrib('id', 'upgrade-downgrade');
?>
<div class="ui-widget ui-widget-content block-shadow clearfix padded-strong"> <div class="ui-widget ui-widget-content block-shadow clearfix padded-strong">
<H2>Account Plans</H2>
<div class="pricing-grid">
pricing grid here
</div>
<?php if (isset($this->errorMessage)) {?> <?php if (isset($this->errorMessage)) {?>
<div class="errors"><?php echo $this->errorMessage ?></div> <div class="errors"><?php echo $this->errorMessage ?></div>
<?php }?> <?php }?>
<div>Plan Level: <?php echo Application_Model_Preference::GetPlanLevel();?></div> <div>Plan Level: <?php echo Application_Model_Preference::GetPlanLevel();?></div>
<?php echo $this->form ?> <?php //echo $form ?>
<form id="<?php echo $form->getId(); ?>" method="<?php echo $form->getMethod() ?>" action="<?php echo
$form->getAction()?>" enctype="<?php echo $form->getEncType();?>">
<div id="plantype">
<?php echo $form->newproductid ?>
</div>
<div id="billingcycle">
<?php echo $form->newproductbillingcycle ?>
</div>
<div id="paymentmethod">
<?php echo $form->paymentmethod ?>
</div>
<div class="clearfix"></div>
<?php $billingForm = $form->getSubform("billing_client_info") ?>
<div>
<?=$billingForm->firstname?>
</div>
<div>
<?=$billingForm->lastname?>
</div>
<div>
<?=$billingForm->companyname?>
</div>
<div>
<?=$billingForm->email?>
</div>
<div>
<?=$billingForm->address1?>
</div>
<div>
<?=$billingForm->address2?>
</div>
<div>
<?=$billingForm->city?>
</div>
<div>
<?=$billingForm->state?>
</div>
<div>
<?=$billingForm->postcode?>
</div>
<div>
<?=$billingForm->country?>
</div>
<div>
<?=$billingForm->phonenumber?>
</div>
<div>
<?=$billingForm->securityqid?>
</div>
<div>
<?=$billingForm->securityqans?>
</div>
<div>
<?=$billingForm->getElement("7"); ?>
</div>
<div>
<?=$billingForm->getElement("71"); ?>
</div>
<div>
<?=$billingForm->password2?>
</div>
<div>
<?=$billingForm->password2verify?>
</div>
<input type="submit" val="Submit">
</form>
<br><br><br><br> <br><br><br><br>
</div> </div>

View file

@ -0,0 +1,33 @@
@CHARSET "UTF-8";
#upgrade-downgrade dl
{
width: 300px;
}
#upgrade-downgrade dt, #upgrade-downgrade dd
{
margin: 0px;
}
#upgrade-downgrade dd
{
margin-bottom: 10px;
}
#plantype
{
float: left;
}
#billingcycle
{
float: left;
}
#paymentmethod
{
float: left;
}