Created a separate view for upgrades and client info

This commit is contained in:
drigato 2014-06-17 12:47:08 -04:00
parent d39f7548cd
commit 1f4c8b755d
6 changed files with 224 additions and 21 deletions
airtime_mvc/application

View File

@ -7,32 +7,172 @@ class BillingController extends Zend_Controller_Action {
}
public function purchaseAction()
public function upgradeAction()
{
$form = new Application_Form_BillingPurchase();
$this->view->form = $form;
//$this->view->html = $this->view->render('billing/purchase.phtml');
$request = $this->getRequest();
$form = new Application_Form_BillingUpgradeDowngrade();
if ($request->isPost()) {
$formData = $request->getPost();
/*$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;*/
$url = "https://account.sourcefabric.com/includes/api.php";
$username = "api_access";
$password = "raditional69203";
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "upgradeproduct";
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
$postfields["clientid"] = 1846;
//TODO: do not hardcode
//$postfields["serviceid"] = self::getClientInstanceId();
$postfields["serviceid"] = "1678";
$postfields["type"] = "product";
$postfields["newproductid"] = $formData["newproductid"];
$postfields["newproductbillingcycle"] = $formData["newproductbillingcycle"];
$postfields["paymentmethod"] = $formData["paymentmethod"];
$postfields["responsetype"] = "json";
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
//$result = $this->makeRequest($url, $query_string);
//$invoiceUrl = "https://account.sourcefabric.com/viewinvoice.php?id=".$result["invoiceid"];
$whmcsurl = "https://account.sourcefabric.com/dologin.php";
$autoauthkey = "MabIttEtkac2";
$timestamp = time(); //whmcs timezone?
$client = self::getClientDetails();
$email = $client["email"];
$hash = sha1($email.$timestamp.$autoauthkey);
$goto="viewinvoice.php?id=5108";
$this->_redirect($whmcsurl."?email=$email&timestamp=$timestamp&hash=$hash&goto=$goto");
} else {
$this->view->form = $form;
}
}
public function clientAction()
{
$request = $this->getRequest();
$form = new Application_Form_BillingClient();
if ($request->isPost()) {
$formData = $request->getPost();
/*$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;*/
$url = "https://account.sourcefabric.com/includes/api.php";
$username = "api_access";
$password = "raditional69203";
$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);
Logging::info($result);
} else {
$this->view->form = $form;
}
}
//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;*/
$url = "https://account.sourcefabric.com/includes/api.php";
$username = "api_access";
$password = "raditional69203";
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "getclientsproducts";
$postfields["responsetype"] = "json";
$postfields["clientid"] = 1846;
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($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;*/
$url = "https://account.sourcefabric.com/includes/api.php";
$username = "api_access";
$password = "raditional69203";
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "getproducts";
$postfields["responsetype"] = "json";
$postfields["gid"] = "15";
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$result = self::makeRequest($url, $query_string);
return $result["products"]["product"];
}
public static function getClientDetails()
{
try {
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
/*$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
$password = $_SERVER["WHMCS_PASSWORD"];
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;
$url = "https://account.sourcefabric.com/includes/api.php?accesskey=" . $accessKey;*/
$url = "https://account.sourcefabric.com/includes/api.php";
$username = "api_access";
$password = "raditional69203";
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "getclientsdetails";
$postfields["stats"] = true;
$postfields["clientid"] = Application_Model_Preference::GetClientId();
//$postfields["clientid"] = Application_Model_Preference::GetClientId();
$postfields["clientid"] = 1846;
$postfields["responsetype"] = "json";
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$arr = self::makeRequest($url, $query_string);
return $arr["client"];
} catch (Exception $e) {
Logging::info($e->getMessage());
}
}
private static function makeRequest($url, $query_string) {
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
@ -48,8 +188,7 @@ class BillingController extends Zend_Controller_Action {
}
curl_close($ch);
$arr = json_decode($jsondata, true);
return $arr["client"];
return json_decode($jsondata, true);
} catch (Exception $e) {
Logging::info($e->getMessage());
}

View File

@ -1,13 +1,14 @@
<?php
require_once 'Zend/Locale.php';
class Application_Form_BillingPurchase extends Zend_Form
class Application_Form_BillingClient extends Zend_Form
{
public function init()
{
/*$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/billing-purchase.phtml'))));*/
$client = BillingController::getClientDetails();
Logging::info($client);
$notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
$emailValidator = Application_Form_Helper_ValidationTypes::overrideEmailAddressValidator();
@ -116,14 +117,18 @@ class Application_Form_BillingPurchase extends Zend_Form
->addFilter('StringTrim');
$this->addElement($phonenumber);
//TODO: get list from whmcs
$securityqid = new Zend_Form_Element_Text('securityqid');
/*$securityqid = new Zend_Form_Element_Select('securityqid');
$securityqid->setLabel(_('Please choose a security question:'))
->setValue($client["securityqid"])
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
->setMultiOptions(array(
"1" => _("What is the name of your favorite childhood friend?"),
"3" => _("What school did you attend for sixth grade?"),
"4" => _("In what city did you meet your spouse/significant other?"),
"5" => _("What street did you live on in third grade?"),
"6" => _("What is the first name of the boy or girl that you first kissed?"),
"7" => _("In what city or town was your first job?")));
$this->addElement($securityqid);
$securityqans = new Zend_Form_Element_Text('securityqans');
@ -133,7 +138,7 @@ class Application_Form_BillingPurchase extends Zend_Form
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($securityqans);
$this->addElement($securityqans);*/
foreach ($client["customfields"] as $field) {
if ($field["id"] == 7) {
@ -143,7 +148,7 @@ class Application_Form_BillingPurchase extends Zend_Form
}
}
$vat = new Zend_Form_Element_Text('vat');
$vat = new Zend_Form_Element_Text('customfield7');
$vat->setLabel(_('VAT/Tax ID (EU only)'))
->setValue($vatvalue)
->setAttrib('class', 'input_text')
@ -152,7 +157,7 @@ class Application_Form_BillingPurchase extends Zend_Form
->addFilter('StringTrim');
$this->addElement($vat);
$subscribe = new Zend_Form_Element_Checkbox('subscribe');
$subscribe = new Zend_Form_Element_Checkbox('customfield71');
$subscribe->setLabel(_('Subscribe to Sourcefabric newsletter'))
->setValue($subscribevalue)
->setAttrib('class', 'input_text')
@ -161,7 +166,7 @@ class Application_Form_BillingPurchase extends Zend_Form
->addFilter('StringTrim');
$this->addElement($subscribe);
$password = new Zend_Form_Element_Password('whmcspassword');
$password = new Zend_Form_Element_Password('password2');
$password->setLabel(_('Password:'));
$password->setAttrib('class', 'input_text');
$password->setRequired(true);
@ -169,12 +174,17 @@ class Application_Form_BillingPurchase extends Zend_Form
$password->addValidator($notEmptyValidator);
$this->addElement($password);
$passwordVerify = new Zend_Form_Element_Password('whmcspasswordVerify');
$passwordVerify = new Zend_Form_Element_Password('password2verify');
$passwordVerify->setLabel(_('Verify Password:'));
$passwordVerify->setAttrib('class', 'input_text');
$passwordVerify->setRequired(true);
$passwordVerify->addFilter('StringTrim');
$passwordVerify->addValidator($notEmptyValidator);
$this->addElement($passwordVerify);
$submit = new Zend_Form_Element_Submit("submit");
$submit->setIgnore(true)
->setLabel(_("Save"));
$this->addElement($submit);
}
}

View File

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

View File

@ -24,7 +24,7 @@
<div class="personal-block solo">
<ul>
<li>
<span class="trial-box-button"><a title="Billing" href=<?php echo $baseUrl . 'billing/purchase'?>>Buy Now</a></span>&nbsp;
<span class="trial-box-button"><a title="Billing" href=<?php echo $baseUrl . 'billing/upgrade'?>>Upgrade</a></span>&nbsp;
<a id="current-user" href=<?php echo $baseUrl . "User/edit-user"?>><span class="name"><?php echo $this->escape($this->loggedInAs()); ?></span></a>
| <a href=<?php echo $baseUrl . "Login/logout"?>><?php echo _("Logout")?></a>
</li>

View File

@ -1,4 +1,3 @@
<div class="ui-widget ui-widget-content block-shadow clearfix padded-strong">
<?php //echo $this->successMessage ?>
<?php echo $this->form ?>
</div>

View File

@ -0,0 +1,6 @@
<div class="ui-widget ui-widget-content block-shadow clearfix padded-strong">
<?php //echo $this->successMessage ?>
<div>Plan Level: <?php echo Application_Model_Preference::GetPlanLevel();?></div>
<?php echo $this->form ?>
<br><br><br><br>
</div>