public function widgetAccountInfoAction() { require_once APPPATH . "/src/externals/chargify-client/class.ChargifyConnector.php"; require_once APPPATH . "/src/externals/chargify-client/class.ChargifyCreditCard.php"; require_once APPPATH . "/src/externals/chargify-client/class.ChargifyCustomer.php"; require_once APPPATH . "/src/externals/chargify-client/class.ChargifyProduct.php"; require_once APPPATH . "/src/externals/chargify-client/class.ChargifySubscription.php"; $js_module = array(); $clientId = $this->user->getAccountId(); if ($clientId == 0) { array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Logged in as', 'value' => 'SCALR ADMIN')); } else { $client = Client::Load($clientId); array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Logged in as', 'value' => $client->Email)); // PayPal users: users without Chargify Client ID property if (!$client->GetSettingValue(CLIENT_SETTINGS::BILLING_CGF_CID)) { // Billing type array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Billing type', 'value' => 'PayPal (Legacy)')); $sid = $this->db->GetOne("SELECT subscriptionid FROM subscriptions WHERE clientid=? AND status='Active'", array($clientId)); if ($sid) { array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Subscription ID', 'value' => $sid)); } $t = strtotime($client->DueDate); if ($t) { array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Due date', 'value' => date("M j Y", $t))); } if ($this->db->GetOne("SELECT amount FROM payments WHERE clientid = ?", array($clientId)) == 50) { $package = 'Beta-legacy'; } else { $package = 'Production'; } if ($client->GetSettingValue(CLIENT_SETTINGS::BILLING_PACKAGE) == '3') { $package = 'Mission Critical'; } array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Plan', 'value' => $package)); } else { if (!$client->GetSettingValue(CLIENT_SETTINGS::BILLING_CGF_SID)) { array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Plan', 'value' => 'Development')); } else { $c = new ChargifyConnector(); try { $subs = $c->getCustomerSubscription($client->GetSettingValue(CLIENT_SETTINGS::BILLING_CGF_SID)); $color = ucfirst($subs->getState()) != 'Active' ? 'red' : 'green'; array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Status', 'value' => "<span style='color:{$color}'>" . ucfirst($subs->getState()) . "</span>")); array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Billing type', 'value' => ucfirst($subs->getCreditCard()->getCardType()) . " (" . $subs->getCreditCard()->getMaskedCardNumber() . ")")); array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Plan', 'value' => ucfirst($subs->getProduct()->getHandle()))); array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Due date', 'value' => date("M j Y", strtotime($subs->next_assessment_at)))); array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Balance', 'value' => "\$" . number_format($subs->getBalanceInCents() / 100, 2))); } catch (Exception $e) { array_push($js_module, array('xtype' => 'displayfield', 'hideLabel' => true, 'value' => "<span style='color:red;'>Billing information is not available at the moment</span>")); } } } } $this->response->data(array('module' => $js_module)); }