Created an invoice view

Some refactoring
Some validation
This commit is contained in:
drigato 2014-06-19 16:55:01 -04:00
parent 540b9167a1
commit 40f2796972
5 changed files with 94 additions and 45 deletions

View File

@ -12,49 +12,66 @@ class BillingController extends Zend_Controller_Action {
$request = $this->getRequest();
$form = new Application_Form_BillingUpgradeDowngrade();
if ($request->isPost()) {
//$formData = $form->getValues();
$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;
$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 = $_SERVER["WHMCS_AUTOAUTH_KEY"];
$timestamp = time(); //whmcs timezone?
$client = self::getClientDetails();
$email = $client["email"];
$hash = sha1($email.$timestamp.$autoauthkey);
//$goto = "viewinvoice.php?id=".$result["invoiceid"];
$goto="viewinvoice.php?id=5108";
$this->_redirect($whmcsurl."?email=$email&timestamp=$timestamp&hash=$hash&goto=$goto");
if ($form->isValid($formData)) {
$credentials = self::getAPICredentials();
$postfields = array();
$postfields["username"] = $credentials["username"];
$postfields["password"] = md5($credentials["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)."&";
//update client info
//$result = $this->makeRequest($credentials["url"], $query_string);
//self::viewInvoice($result["invoiceid"]);
self::viewInvoice(5108);
} else {
$this->view->form = $form;
}
} else {
$this->view->form = $form;
}
}
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"],
);
}
private static function viewInvoice($invoice_id)
{
$whmcsurl = "https://account.sourcefabric.com/dologin.php";
$autoauthkey = $_SERVER["WHMCS_AUTOAUTH_KEY"];
$timestamp = time(); //whmcs timezone?
$client = self::getClientDetails();
$email = $client["email"];
$hash = sha1($email.$timestamp.$autoauthkey);
$goto = "viewinvoice.php?id=".$invoice_id;
header("Location: ".$whmcsurl."?email=$email&timestamp=$timestamp&hash=$hash&goto=$goto");
}
public function clientAction()
{
$request = $this->getRequest();
@ -88,7 +105,7 @@ class BillingController extends Zend_Controller_Action {
}
}
public function invoiceAction()
public function invoicesAction()
{
$accessKey = $_SERVER["WHMCS_ACCESS_KEY"];
$username = $_SERVER["WHMCS_USERNAME"];
@ -98,7 +115,23 @@ class BillingController extends Zend_Controller_Action {
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "updateclient";
$postfields["action"] = "getinvoices";
$postfields["responsetype"] = "json";
$postfields["userid"] = 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);
$this->view->invoices = $result["invoices"]["invoice"];
}
public function invoiceAction()
{
$request = $this->getRequest();
$invoice_id = $request->getParam('invoiceid');
self::viewInvoice($invoice_id);
}
//TODO: this does not return a service id. why?

View File

@ -116,7 +116,7 @@ class Application_Form_BillingClient extends Zend_Form
->addFilter('StringTrim');
$this->addElement($phonenumber);
/*$securityqid = new Zend_Form_Element_Select('securityqid');
$securityqid = new Zend_Form_Element_Select('securityqid');
$securityqid->setLabel(_('Please choose a security question:'))
->setValue($client["securityqid"])
->setAttrib('class', 'input_text')
@ -137,7 +137,7 @@ class Application_Form_BillingClient extends Zend_Form
->setRequired(true)
->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($securityqans);*/
$this->addElement($securityqans);
foreach ($client["customfields"] as $field) {
if ($field["id"] == 7) {
@ -151,8 +151,8 @@ class Application_Form_BillingClient extends Zend_Form
$vat->setLabel(_('VAT/Tax ID (EU only)'))
->setValue($vatvalue)
->setAttrib('class', 'input_text')
->setRequired(true)
->addValidator($notEmptyValidator)
//->setRequired(true)
//->addValidator($notEmptyValidator)
->addFilter('StringTrim');
$this->addElement($vat);
@ -168,6 +168,7 @@ class Application_Form_BillingClient extends Zend_Form
$password = new Zend_Form_Element_Password('password2');
$password->setLabel(_('Password:'));
$password->setAttrib('class', 'input_text');
$password->setValue("xxxxxx");
$password->setRequired(true);
$password->addFilter('StringTrim');
$password->addValidator($notEmptyValidator);
@ -176,8 +177,11 @@ class Application_Form_BillingClient extends Zend_Form
$passwordVerify = new Zend_Form_Element_Password('password2verify');
$passwordVerify->setLabel(_('Verify Password:'));
$passwordVerify->setAttrib('class', 'input_text');
$passwordVerify->setValue("xxxxxx");
$passwordVerify->setRequired(true);
$passwordVerify->addFilter('StringTrim');
//$passwordVerify->addValidator($notEmptyValidator);
$passwordVerify->addValidator('Identical', false, array('token' => 'password2'));
$passwordVerify->addValidator($notEmptyValidator);
$this->addElement($passwordVerify);

View File

@ -41,9 +41,12 @@ class Application_Form_BillingUpgradeDowngrade extends Zend_Form
->setValue('paypal');
$this->addElement($paymentmethod);
$submit = new Zend_Form_Element_Submit("submit");
/*$submit = new Zend_Form_Element_Submit("submit");
$submit->setIgnore(true)
->setLabel(_("Save"));
$this->addElement($submit);
$this->addElement($submit);*/
$client = new Application_Form_BillingClient();
$this->addSubForm($client, 'billing_client_info');
}
}

View File

@ -0,0 +1,9 @@
<div class="ui-widget ui-widget-content block-shadow clearfix padded-strong">
<?php
foreach ($this->invoices as $invoice) {?>
<div>
<a href="invoice?invoiceid=<?php echo $invoice["id"]?>">View Invoice</a>
</div>
<?php }?>
</div>