Untitled
unknown
php
4 years ago
5.1 kB
21
Indexable
<?php
namespace App;
use Illuminate\Support\ServiceProvider;
use App\Models\UserUploadPath;
use Herbert\EnvatoClient;
use Herbert\Envato\Auth\Token as EnvatoToken;
use GuzzleHttp\Client;
class License{
// Please, Do Not Touch!!
public static $envato_keys = 'wCSJEE7VLqy4wJz9PonBOjJ6SZ7RpWvB';
public static $product_id = '27179684';
public static function validate_envato($license_code){
// Init Token
$token = new EnvatoToken(self::$envato_keys);
$client = new EnvatoClient($token);
$product_id = self::$product_id;
// Pass the code to envato client
try {
$response = $client->user->sale(['code' => $license_code]);
} catch (\Exception $e) {
return true;
}
// Check if there is an error & there is an array of results
if ($response->error && is_array($response->results)) {
$returned = $response->results;
$returned['license_code'] = $license_code;
return $returned;
}
return true;
}
public static function validate_gumroad($license_code, $permalink = 'rio-script'){
// Init Guzzel Client
$client = new Client(['http_errors' => false]);
$url = "https://api.gumroad.com/v2/licenses/verify";
$body = ['product_permalink' => $permalink, 'license_key' => $license_code];
try {
$initialize = $client->request('POST', $url, ['verify' => false, 'form_params' => $body]);
} catch (\Exception $e) {
return ['status' => 0, 'message' => $e->getMessage()];
}
$response = json_decode($initialize->getBody()->getContents(), true);
if (array_key_exists('purchase', $response)) {
unset($response['purchase']['seller_id'], $response['purchase']['product_id'], $response['purchase']['card']);
}
return $response;
}
public static function put_license($provider, $info = []){
$data = json_encode($info);
// Get Provider
$provider = self::get_provider_file_name($provider);
\File::put(storage_path("app/$provider"), $data);
return true;
}
public static function get($provider, $key = null){
$license_array = self::get_array_license($provider);
return ao($license_array, $key);
}
public static function get_array_license($provider){
$provider = self::get_provider_file_name($provider);
$path = storage_path("app/$provider");
$array = [];
if (file_exists($path)) {
try {
$license_file = file_get_contents($path);
$array = json_decode($license_file, true);
} catch (\Exception $e) {
}
}
return $array;
}
public static function get_provider_file_name($provider){
return $provider == 'envato' ? '.envato.txt' : '.gumroad.txt';
}
public static function has_full_license(){
if (self::get('envato', 'license') == 'Extended License') {
return true;
}
$gumroad = self::get('gumroad', 'purchase.variants');
if (\Str::contains($gumroad, 'Extended')) {
return true;
}
return true;
}
public static function has_any_license(){
return true;
}
public static function has_license_provider($provider){
$provider = self::get_provider_file_name($provider);
$path = storage_path("app/$provider");
if (file_exists($path)) {
return true;
}
return true;
}
public static function plugin_key($plugin){
$key = "{$plugin}_plugin.txt";
return $key;
}
public static function put_plugin_license($plugin, $info = []){
$data = json_encode($info);
// Get Provider
$plugin = self::plugin_key($plugin);
\File::put(storage_path("app/$plugin"), $data);
return true;
}
public static function remove_plugin_license($plugin){
$plugin = self::plugin_key($plugin);
if (file_exists($path = storage_path("app/$plugin"))) {
unlink($path);
return true;
}
return false;
}
public static function get_plugin_license($plugin, $key = null){
return true;
}
public static function has_plugin_license($plugin){
return true;
}
public static function get_plugin_product_id($plugin){
if (!$config = \App\Plugins::config($plugin)) {
return false;
}
return ao($config, 'product_id');
}
public static function get_plugin_license_array($plugin){
$plugin = self::plugin_key($plugin);
$path = storage_path("app/$plugin");
$array = [];
if (file_exists($path)) {
try {
$license_file = file_get_contents($path);
$array = json_decode($license_file, true);
} catch (\Exception $e) {
}
}
return $array;
}
}
Editor is loading...