From 40f2796972037b4fb7fe52477e1118f479f29be8 Mon Sep 17 00:00:00 2001 From: drigato Date: Thu, 19 Jun 2014 16:55:01 -0400 Subject: [PATCH] Created an invoice view Some refactoring Some validation --- .../controllers/BillingController.php | 111 ++++++++++++------ .../application/forms/BillingClient.php | 12 +- .../forms/BillingUpgradeDowngrade.php | 7 +- .../views/scripts/billing/invoice.phtml | 0 .../views/scripts/billing/invoices.phtml | 9 ++ 5 files changed, 94 insertions(+), 45 deletions(-) create mode 100644 airtime_mvc/application/views/scripts/billing/invoice.phtml create mode 100644 airtime_mvc/application/views/scripts/billing/invoices.phtml diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 59d8f21a0..189aa28f6 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -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×tamp=$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×tamp=$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? diff --git a/airtime_mvc/application/forms/BillingClient.php b/airtime_mvc/application/forms/BillingClient.php index c278afc23..2b889a52e 100644 --- a/airtime_mvc/application/forms/BillingClient.php +++ b/airtime_mvc/application/forms/BillingClient.php @@ -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); diff --git a/airtime_mvc/application/forms/BillingUpgradeDowngrade.php b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php index 905482943..8a7d8a084 100644 --- a/airtime_mvc/application/forms/BillingUpgradeDowngrade.php +++ b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php @@ -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'); } } diff --git a/airtime_mvc/application/views/scripts/billing/invoice.phtml b/airtime_mvc/application/views/scripts/billing/invoice.phtml new file mode 100644 index 000000000..e69de29bb diff --git a/airtime_mvc/application/views/scripts/billing/invoices.phtml b/airtime_mvc/application/views/scripts/billing/invoices.phtml new file mode 100644 index 000000000..ed1f13a74 --- /dev/null +++ b/airtime_mvc/application/views/scripts/billing/invoices.phtml @@ -0,0 +1,9 @@ +
+invoices as $invoice) {?> +
+ ">View Invoice +
+ + +
\ No newline at end of file