/** * License Manager * * Allows to check plans and activate a license key */ public function postLicenseManager($method = NULL) { // Include libraries require_once app_path() . "/libraries/Curl/Curl.php"; // Validate the request if ($this->_isValidRequest()) { $code = Input::get('code') ? Input::get('code') : Input::get('amp;code'); $license_key = Input::get('license'); $guid = Input::get('guid') ? Input::get('guid') : Input::get('amp;guid'); if (!$code or !$license_key) { $this->_invalidRequest("Code and License Key parameters are required"); } // Get product code and then fetch secret key $product = Product::where('code', '=', $code)->first(); if (!$product) { $this->_invalidRequest("Product was not found, contact support."); } // Get License Data $license = License::where("license_key", "=", $license_key)->first(); if (!$license) { $this->_invalidRequest("License Key was not found"); } // Get all active plans of a buyer if (!$method) { $transaction = Transaction::where("id", "=", $license->transaction_id)->first(); $buyer_email = $transaction->purchase->buyer->email; $curl = new Curl(); $plans = $curl->simple_get($product->api_url, array("getPlans" => $buyer_email), array(CURLOPT_BUFFERSIZE => 10)); $plans = json_decode($plans); if ($plans) { $plans->created_at = $license->created_at; die(json_encode($plans)); } else { die(json_encode(array())); } } // Activate license key for a GUID if ($method == "activate") { // Check if License is already activated if (!$guid) { $this->_invalidRequest("GUID parameter is required"); } // Total Licenses Used $totalLicensesUsed = LicensesUses::where("license_id", "=", $license->id)->count(); if (!$license->status) { $response = array("success" => "false", "overusage" => "false"); } else { // If user has allowed usage if ($totalLicensesUsed >= $license->allowed_usage) { $response = array("success" => "false", "overusage" => "true"); } else { $licensesUses = LicensesUses::where("license_id", "=", $license->id)->where("guid", "=", $guid)->first(); if ($licensesUses) { // Update last checked $licensesUses->last_checked = time(); $licensesUses->save(); } else { // Add to DB $licensesUses = new LicensesUses(); $licensesUses->license_id = $license->id; $licensesUses->guid = $guid; $licensesUses->activated_at = time(); $licensesUses->last_checked = time(); $licensesUses->save(); } $response = array("success" => "true", "overusage" => "false"); } } die(json_encode($response)); } } }