@@ -4,105 +4,105 @@ |
||
| 4 | 4 | |
| 5 | 5 | class EnvatoApi |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Envanto API bearer token. |
|
| 9 | - * |
|
| 10 | - * @var string |
|
| 11 | - **/ |
|
| 12 | - private $bearer; |
|
| 13 | - |
|
| 14 | - /** |
|
| 15 | - * Purchase verification endpoint. |
|
| 16 | - * |
|
| 17 | - * @var string |
|
| 18 | - **/ |
|
| 19 | - protected $url = 'https://api.envato.com/v3/market/author/sale?code='; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Request headers. |
|
| 23 | - * |
|
| 24 | - * @var array |
|
| 25 | - **/ |
|
| 26 | - private $headers; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Create EnvantoApi Instance. |
|
| 30 | - **/ |
|
| 31 | - public function __construct($bearer) |
|
| 32 | - { |
|
| 33 | - $this->bearer = $bearer; |
|
| 34 | - $this->buildHeaders(); |
|
| 35 | - } |
|
| 7 | + /** |
|
| 8 | + * Envanto API bearer token. |
|
| 9 | + * |
|
| 10 | + * @var string |
|
| 11 | + **/ |
|
| 12 | + private $bearer; |
|
| 13 | + |
|
| 14 | + /** |
|
| 15 | + * Purchase verification endpoint. |
|
| 16 | + * |
|
| 17 | + * @var string |
|
| 18 | + **/ |
|
| 19 | + protected $url = 'https://api.envato.com/v3/market/author/sale?code='; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Request headers. |
|
| 23 | + * |
|
| 24 | + * @var array |
|
| 25 | + **/ |
|
| 26 | + private $headers; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Create EnvantoApi Instance. |
|
| 30 | + **/ |
|
| 31 | + public function __construct($bearer) |
|
| 32 | + { |
|
| 33 | + $this->bearer = $bearer; |
|
| 34 | + $this->buildHeaders(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | //end __construct() |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Make a call to the Envato API to verify purchase. |
|
| 41 | - * |
|
| 42 | - * @return mixed Guzzle\Response::getBody() |
|
| 43 | - * |
|
| 44 | - * @param string $code |
|
| 45 | - **/ |
|
| 46 | - public function getPurchaseData($code) |
|
| 47 | - { |
|
| 48 | - $ch_verify = curl_init($this->url . $code); |
|
| 49 | - curl_setopt($ch_verify, CURLOPT_HTTPHEADER, $this->headers); |
|
| 50 | - curl_setopt($ch_verify, CURLOPT_SSL_VERIFYPEER, false); |
|
| 51 | - curl_setopt($ch_verify, CURLOPT_RETURNTRANSFER, 1); |
|
| 52 | - curl_setopt($ch_verify, CURLOPT_CONNECTTIMEOUT, 5); |
|
| 53 | - curl_setopt($ch_verify, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); |
|
| 54 | - |
|
| 55 | - $cinit_verify_data = curl_exec($ch_verify); |
|
| 56 | - curl_close($ch_verify); |
|
| 57 | - |
|
| 58 | - if ($cinit_verify_data != '') { |
|
| 59 | - return json_decode($cinit_verify_data, true); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return [ |
|
| 63 | - 'error' => 'exception', |
|
| 64 | - 'description' => 'A server error was encountered please notify us if you see this', |
|
| 65 | - ]; |
|
| 66 | - } |
|
| 39 | + /** |
|
| 40 | + * Make a call to the Envato API to verify purchase. |
|
| 41 | + * |
|
| 42 | + * @return mixed Guzzle\Response::getBody() |
|
| 43 | + * |
|
| 44 | + * @param string $code |
|
| 45 | + **/ |
|
| 46 | + public function getPurchaseData($code) |
|
| 47 | + { |
|
| 48 | + $ch_verify = curl_init($this->url . $code); |
|
| 49 | + curl_setopt($ch_verify, CURLOPT_HTTPHEADER, $this->headers); |
|
| 50 | + curl_setopt($ch_verify, CURLOPT_SSL_VERIFYPEER, false); |
|
| 51 | + curl_setopt($ch_verify, CURLOPT_RETURNTRANSFER, 1); |
|
| 52 | + curl_setopt($ch_verify, CURLOPT_CONNECTTIMEOUT, 5); |
|
| 53 | + curl_setopt($ch_verify, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); |
|
| 54 | + |
|
| 55 | + $cinit_verify_data = curl_exec($ch_verify); |
|
| 56 | + curl_close($ch_verify); |
|
| 57 | + |
|
| 58 | + if ($cinit_verify_data != '') { |
|
| 59 | + return json_decode($cinit_verify_data, true); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return [ |
|
| 63 | + 'error' => 'exception', |
|
| 64 | + 'description' => 'A server error was encountered please notify us if you see this', |
|
| 65 | + ]; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | //end getPurchaseData() |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Verify purchase. |
|
| 72 | - * |
|
| 73 | - * @return string Array |
|
| 74 | - * |
|
| 75 | - * @param string $code Purchase Code |
|
| 76 | - **/ |
|
| 77 | - public function verifyPurchase(string $code) |
|
| 78 | - { |
|
| 79 | - $purchase = []; |
|
| 80 | - $purchase['response'] = (object) $this->getPurchaseData($code); |
|
| 81 | - if ($purchase->error) { |
|
| 82 | - return $purchase['status'] = 'error'; |
|
| 83 | - } else { |
|
| 84 | - return $purchase['status'] = 'success'; |
|
| 85 | - } |
|
| 86 | - } |
|
| 70 | + /** |
|
| 71 | + * Verify purchase. |
|
| 72 | + * |
|
| 73 | + * @return string Array |
|
| 74 | + * |
|
| 75 | + * @param string $code Purchase Code |
|
| 76 | + **/ |
|
| 77 | + public function verifyPurchase(string $code) |
|
| 78 | + { |
|
| 79 | + $purchase = []; |
|
| 80 | + $purchase['response'] = (object) $this->getPurchaseData($code); |
|
| 81 | + if ($purchase->error) { |
|
| 82 | + return $purchase['status'] = 'error'; |
|
| 83 | + } else { |
|
| 84 | + return $purchase['status'] = 'success'; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | //end verifyPurchase() |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * setting the header for the rest of the api. |
|
| 92 | - **/ |
|
| 93 | - protected function buildHeaders() |
|
| 94 | - { |
|
| 95 | - $headers = [ |
|
| 96 | - 'Content-type' => 'application/json', |
|
| 97 | - 'Authorization' => 'Bearer ' . $this->bearer, |
|
| 98 | - ]; |
|
| 99 | - $h = []; |
|
| 100 | - foreach ($headers as $key => $value) { |
|
| 101 | - $h[] = $key . ':' . $value; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $this->headers = $h; |
|
| 105 | - } |
|
| 90 | + /** |
|
| 91 | + * setting the header for the rest of the api. |
|
| 92 | + **/ |
|
| 93 | + protected function buildHeaders() |
|
| 94 | + { |
|
| 95 | + $headers = [ |
|
| 96 | + 'Content-type' => 'application/json', |
|
| 97 | + 'Authorization' => 'Bearer ' . $this->bearer, |
|
| 98 | + ]; |
|
| 99 | + $h = []; |
|
| 100 | + foreach ($headers as $key => $value) { |
|
| 101 | + $h[] = $key . ':' . $value; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $this->headers = $h; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | //end buildHeaders() |
| 108 | 108 | }//end class |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | **/ |
| 46 | 46 | public function getPurchaseData($code) |
| 47 | 47 | { |
| 48 | - $ch_verify = curl_init($this->url . $code); |
|
| 48 | + $ch_verify = curl_init($this->url.$code); |
|
| 49 | 49 | curl_setopt($ch_verify, CURLOPT_HTTPHEADER, $this->headers); |
| 50 | 50 | curl_setopt($ch_verify, CURLOPT_SSL_VERIFYPEER, false); |
| 51 | 51 | curl_setopt($ch_verify, CURLOPT_RETURNTRANSFER, 1); |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $headers = [ |
| 96 | 96 | 'Content-type' => 'application/json', |
| 97 | - 'Authorization' => 'Bearer ' . $this->bearer, |
|
| 97 | + 'Authorization' => 'Bearer '.$this->bearer, |
|
| 98 | 98 | ]; |
| 99 | 99 | $h = []; |
| 100 | 100 | foreach ($headers as $key => $value) { |
| 101 | - $h[] = $key . ':' . $value; |
|
| 101 | + $h[] = $key.':'.$value; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $this->headers = $h; |
@@ -6,35 +6,35 @@ |
||
| 6 | 6 | |
| 7 | 7 | class LicenseChecker |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Handle an incoming request. |
|
| 11 | - * |
|
| 12 | - * @param \Illuminate\Http\Request $request |
|
| 13 | - * @param \Closure $next |
|
| 14 | - * |
|
| 15 | - * @return mixed |
|
| 16 | - */ |
|
| 17 | - public function handle($request, Closure $next, $licenseKey = null) |
|
| 18 | - { |
|
| 19 | - if ($this->validLicense($licenseKey)) { |
|
| 20 | - return $next($request); |
|
| 21 | - } else { |
|
| 22 | - return response()->json(['UnAuthorized' => 'Invalid Purchase Key'], 403); |
|
| 23 | - } |
|
| 24 | - } |
|
| 9 | + /** |
|
| 10 | + * Handle an incoming request. |
|
| 11 | + * |
|
| 12 | + * @param \Illuminate\Http\Request $request |
|
| 13 | + * @param \Closure $next |
|
| 14 | + * |
|
| 15 | + * @return mixed |
|
| 16 | + */ |
|
| 17 | + public function handle($request, Closure $next, $licenseKey = null) |
|
| 18 | + { |
|
| 19 | + if ($this->validLicense($licenseKey)) { |
|
| 20 | + return $next($request); |
|
| 21 | + } else { |
|
| 22 | + return response()->json(['UnAuthorized' => 'Invalid Purchase Key'], 403); |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Check if license key is valid. |
|
| 28 | - * |
|
| 29 | - * @return bool |
|
| 30 | - **/ |
|
| 31 | - private function validLicense($licenseKey) |
|
| 32 | - { |
|
| 33 | - $purchase = app()->envatoapi->verifyPurchase($licenseKey); |
|
| 34 | - if (is_array($purchase) and $purchase['status'] == 'success') { |
|
| 35 | - return true; |
|
| 36 | - } |
|
| 26 | + /** |
|
| 27 | + * Check if license key is valid. |
|
| 28 | + * |
|
| 29 | + * @return bool |
|
| 30 | + **/ |
|
| 31 | + private function validLicense($licenseKey) |
|
| 32 | + { |
|
| 33 | + $purchase = app()->envatoapi->verifyPurchase($licenseKey); |
|
| 34 | + if (is_array($purchase) and $purchase['status'] == 'success') { |
|
| 35 | + return true; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return false; |
|
| 39 | - } |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -11,10 +11,10 @@ |
||
| 11 | 11 | **/ |
| 12 | 12 | class Update extends Model |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Array of all fillable attributes on the model. |
|
| 16 | - * |
|
| 17 | - * @var array |
|
| 18 | - **/ |
|
| 19 | - protected $fillable = []; |
|
| 14 | + /** |
|
| 15 | + * Array of all fillable attributes on the model. |
|
| 16 | + * |
|
| 17 | + * @var array |
|
| 18 | + **/ |
|
| 19 | + protected $fillable = []; |
|
| 20 | 20 | } // END class |
@@ -9,47 +9,47 @@ |
||
| 9 | 9 | |
| 10 | 10 | class UpdateManagerController extends Controller |
| 11 | 11 | { |
| 12 | - // When including ths trait make sure you inject RepositoryContract as $repository and |
|
| 13 | - // CustomersRepository as $customers to the constructor |
|
| 14 | - use VerifiesPurchase; |
|
| 12 | + // When including ths trait make sure you inject RepositoryContract as $repository and |
|
| 13 | + // CustomersRepository as $customers to the constructor |
|
| 14 | + use VerifiesPurchase; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Update Repository. |
|
| 18 | - * |
|
| 19 | - * @var mixed |
|
| 20 | - **/ |
|
| 21 | - public $repository; |
|
| 16 | + /** |
|
| 17 | + * Update Repository. |
|
| 18 | + * |
|
| 19 | + * @var mixed |
|
| 20 | + **/ |
|
| 21 | + public $repository; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Customers Repository. |
|
| 25 | - * |
|
| 26 | - * @var mixed |
|
| 27 | - **/ |
|
| 28 | - public $customers; |
|
| 23 | + /** |
|
| 24 | + * Customers Repository. |
|
| 25 | + * |
|
| 26 | + * @var mixed |
|
| 27 | + **/ |
|
| 28 | + public $customers; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Create a new instance of the UpdatesManagerController::class. |
|
| 32 | - **/ |
|
| 33 | - public function __construct(RepositoryContract $repository, CustomersRepository $customers) |
|
| 34 | - { |
|
| 35 | - $this->repository = $repository; |
|
| 36 | - $this->customers = $customers; |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * Create a new instance of the UpdatesManagerController::class. |
|
| 32 | + **/ |
|
| 33 | + public function __construct(RepositoryContract $repository, CustomersRepository $customers) |
|
| 34 | + { |
|
| 35 | + $this->repository = $repository; |
|
| 36 | + $this->customers = $customers; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return mixed Illuminate\Http\Response |
|
| 41 | - * |
|
| 42 | - * @param $version Version to fetch |
|
| 43 | - **/ |
|
| 44 | - public function fetchUpdate($version) |
|
| 45 | - { |
|
| 46 | - $this->getCustomer(); |
|
| 47 | - if (null == $this->customer) { |
|
| 48 | - return $this->invalidKeyResponse(); |
|
| 49 | - } |
|
| 50 | - $update = $this->repository->config('updates.updatesPath') . "/update_{$version}.zip"; |
|
| 51 | - if (file_exists($update)) { |
|
| 52 | - return response()->download($update); |
|
| 53 | - } |
|
| 54 | - } |
|
| 39 | + /** |
|
| 40 | + * @return mixed Illuminate\Http\Response |
|
| 41 | + * |
|
| 42 | + * @param $version Version to fetch |
|
| 43 | + **/ |
|
| 44 | + public function fetchUpdate($version) |
|
| 45 | + { |
|
| 46 | + $this->getCustomer(); |
|
| 47 | + if (null == $this->customer) { |
|
| 48 | + return $this->invalidKeyResponse(); |
|
| 49 | + } |
|
| 50 | + $update = $this->repository->config('updates.updatesPath') . "/update_{$version}.zip"; |
|
| 51 | + if (file_exists($update)) { |
|
| 52 | + return response()->download($update); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | if (null == $this->customer) { |
| 48 | 48 | return $this->invalidKeyResponse(); |
| 49 | 49 | } |
| 50 | - $update = $this->repository->config('updates.updatesPath') . "/update_{$version}.zip"; |
|
| 50 | + $update = $this->repository->config('updates.updatesPath')."/update_{$version}.zip"; |
|
| 51 | 51 | if (file_exists($update)) { |
| 52 | 52 | return response()->download($update); |
| 53 | 53 | } |
@@ -9,52 +9,52 @@ |
||
| 9 | 9 | |
| 10 | 10 | class InstallManagerController extends Controller |
| 11 | 11 | { |
| 12 | - /* |
|
| 12 | + /* |
|
| 13 | 13 | * When including this trait make sure you inject RepositoryContract as $repository |
| 14 | 14 | * and CustomersRepository as $customers to the constructor |
| 15 | 15 | */ |
| 16 | - use VerifiesPurchase; |
|
| 16 | + use VerifiesPurchase; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Update Repository. |
|
| 20 | - * |
|
| 21 | - * @var mixed |
|
| 22 | - **/ |
|
| 23 | - public $repository; |
|
| 18 | + /** |
|
| 19 | + * Update Repository. |
|
| 20 | + * |
|
| 21 | + * @var mixed |
|
| 22 | + **/ |
|
| 23 | + public $repository; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Customers Repository. |
|
| 27 | - * |
|
| 28 | - * @var mixed |
|
| 29 | - **/ |
|
| 30 | - public $customers; |
|
| 25 | + /** |
|
| 26 | + * Customers Repository. |
|
| 27 | + * |
|
| 28 | + * @var mixed |
|
| 29 | + **/ |
|
| 30 | + public $customers; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Create a new instance of the UpdatesManagerController::class. |
|
| 34 | - **/ |
|
| 35 | - public function __construct(RepositoryContract $repository, CustomersRepository $customers) |
|
| 36 | - { |
|
| 37 | - $this->repository = $repository; |
|
| 38 | - $this->customers = $customers; |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * Create a new instance of the UpdatesManagerController::class. |
|
| 34 | + **/ |
|
| 35 | + public function __construct(RepositoryContract $repository, CustomersRepository $customers) |
|
| 36 | + { |
|
| 37 | + $this->repository = $repository; |
|
| 38 | + $this->customers = $customers; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Get the installer zip file for the version specified |
|
| 43 | - * NOTE: The purchase key must be passed in the request for verification. |
|
| 44 | - * |
|
| 45 | - * @return mixed Illuminate\Http\Response |
|
| 46 | - * |
|
| 47 | - * @param $version Version to fetch |
|
| 48 | - **/ |
|
| 49 | - public function getInstaller($version) |
|
| 50 | - { |
|
| 51 | - $response = $this->verifyPurchase(); |
|
| 52 | - if (null == $this->customer) { |
|
| 53 | - return $this->invalidKeyResponse(); |
|
| 54 | - } |
|
| 55 | - $install = $this->repository->config('install.resourcePath') . "/install_{$version}.zip"; |
|
| 56 | - if (file_exists($install)) { |
|
| 57 | - return response()->download($install); |
|
| 58 | - } |
|
| 59 | - } |
|
| 41 | + /** |
|
| 42 | + * Get the installer zip file for the version specified |
|
| 43 | + * NOTE: The purchase key must be passed in the request for verification. |
|
| 44 | + * |
|
| 45 | + * @return mixed Illuminate\Http\Response |
|
| 46 | + * |
|
| 47 | + * @param $version Version to fetch |
|
| 48 | + **/ |
|
| 49 | + public function getInstaller($version) |
|
| 50 | + { |
|
| 51 | + $response = $this->verifyPurchase(); |
|
| 52 | + if (null == $this->customer) { |
|
| 53 | + return $this->invalidKeyResponse(); |
|
| 54 | + } |
|
| 55 | + $install = $this->repository->config('install.resourcePath') . "/install_{$version}.zip"; |
|
| 56 | + if (file_exists($install)) { |
|
| 57 | + return response()->download($install); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | if (null == $this->customer) { |
| 53 | 53 | return $this->invalidKeyResponse(); |
| 54 | 54 | } |
| 55 | - $install = $this->repository->config('install.resourcePath') . "/install_{$version}.zip"; |
|
| 55 | + $install = $this->repository->config('install.resourcePath')."/install_{$version}.zip"; |
|
| 56 | 56 | if (file_exists($install)) { |
| 57 | 57 | return response()->download($install); |
| 58 | 58 | } |