You are here

function LingotekAccount::getAccountStatus in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.3 lib/Drupal/lingotek/LingotekAccount.php \LingotekAccount::getAccountStatus()
  2. 7.4 lib/Drupal/lingotek/LingotekAccount.php \LingotekAccount::getAccountStatus()

Get Account Status NOTE: You shouldnt need to call this directly. Its called in the constructor. Request: https://LINGOTEK_BILLING_SERVER/billing/account.json?community=B2MMD3X5&external_id=community_admin&oauth_key=28c279fa-28dc-452e-93af-68d194a2c366&oauth_secret=0e999486-3b4d-47e4-ba9a-d0f3f0bbda73 Response: {"state":"active","plan":{"trial_ends_at":0,"state":"active","activated_at":1355267936,"type":"cosmopolitan_monthly","languages_allowed":2,"language_cost_per_period_in_cents":14900}} Will return FALSE or a json decoded object.

1 call to LingotekAccount::getAccountStatus()
LingotekAccount::__construct in lib/Drupal/lingotek/LingotekAccount.php
Constructor.

File

lib/Drupal/lingotek/LingotekAccount.php, line 159
Defines LingotekAccount.

Class

LingotekAccount
A class representing a Lingotek Account

Code

function getAccountStatus() {
  $result = FALSE;
  $fields = array(
    'community' => variable_get('lingotek_community_identifier', ''),
    'external_id' => variable_get('lingotek_login_id', ''),
    'oauth_key' => variable_get('lingotek_oauth_consumer_id', ''),
    'oauth_secret' => variable_get('lingotek_oauth_consumer_secret', ''),
  );
  if (!empty($fields['community']) && !empty($fields['external_id']) && !empty($fields['oauth_key']) && !empty($fields['oauth_secret'])) {
    $ch = curl_init(LINGOTEK_BILLING_SERVER . '?' . http_build_query($fields));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    //curl_setopt( $ch, CURLINFO_HEADER_OUT, TRUE );
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    //debug( $response );

    //debug( $info );
    $json = json_decode($response);
    if (isset($json) && $info['http_code'] == 200) {

      // Did we get valid json data back?  If not, $json is NULL.

      //debug ( $json );
      $result = TRUE;

      // Not Found - {"state":"not_found"} - Account isn't setup yet.  The state after autoprovisioning a community, but before setting up your billing account.
      if ($json->state == self::LINGOTEK_ACCOUNT_STATUS_NOT_FOUND) {
        $this
          ->setStatus(self::LINGOTEK_ACCOUNT_STATUS_NOT_FOUND);
        $this
          ->setPlan(self::LINGOTEK_ACCOUNT_PLAN_NONE);
      }
      elseif ($json->state == self::LINGOTEK_ACCOUNT_STATUS_ACTIVE) {
        $this
          ->setStatus(self::LINGOTEK_ACCOUNT_STATUS_ACTIVE);
        variable_set('lingotek_account_status', self::LINGOTEK_ACCOUNT_STATUS_ACTIVE);
        if (is_object($json->plan)) {
          $this
            ->setPlan($json->plan->type);
          variable_set('lingotek_account_plan', $json->plan->type);
          if ($json->plan->type == self::LINGOTEK_ACCOUNT_ENTERPRISE) {
            $this
              ->setEnterpriseStatus(TRUE);
            variable_set('lingotek_account_enterprise', 1);

            // Store as 0/1
          }
          else {

            //$this->setEnterpriseStatus( FALSE );
            variable_set('lingotek_account_enterprise', 0);

            // Store as 0/1
          }
        }

        // END:  Plan
        menu_rebuild();
      }

      // END  Active
    }

    // END:  Got 200 Response
  }

  // END:  has credentials
  return $result;
}