diff --git a/airtime_mvc/application/controllers/BillingController.php b/airtime_mvc/application/controllers/BillingController.php index 106f475aa..29048f543 100644 --- a/airtime_mvc/application/controllers/BillingController.php +++ b/airtime_mvc/application/controllers/BillingController.php @@ -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×tamp=$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()); } diff --git a/airtime_mvc/application/forms/BillingPurchase.php b/airtime_mvc/application/forms/BillingClient.php similarity index 85% rename from airtime_mvc/application/forms/BillingPurchase.php rename to airtime_mvc/application/forms/BillingClient.php index dfb0c1201..a56086c9a 100644 --- a/airtime_mvc/application/forms/BillingPurchase.php +++ b/airtime_mvc/application/forms/BillingClient.php @@ -1,13 +1,14 @@ 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); } } \ No newline at end of file diff --git a/airtime_mvc/application/forms/BillingUpgradeDowngrade.php b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php new file mode 100644 index 000000000..905482943 --- /dev/null +++ b/airtime_mvc/application/forms/BillingUpgradeDowngrade.php @@ -0,0 +1,49 @@ + $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); + } +} diff --git a/airtime_mvc/application/layouts/scripts/layout.phtml b/airtime_mvc/application/layouts/scripts/layout.phtml index ec5008736..6fef87157 100644 --- a/airtime_mvc/application/layouts/scripts/layout.phtml +++ b/airtime_mvc/application/layouts/scripts/layout.phtml @@ -24,7 +24,7 @@