diff --git a/app/Actions/License/CheckResaleLicense.php b/app/Actions/License/CheckResaleLicense.php index cef4e62ee..2ce3c574a 100644 --- a/app/Actions/License/CheckResaleLicense.php +++ b/app/Actions/License/CheckResaleLicense.php @@ -4,7 +4,6 @@ namespace App\Actions\License; use App\Models\InstanceSettings; use Illuminate\Support\Facades\Http; -use Visus\Cuid2\Cuid2; class CheckResaleLicense { @@ -12,41 +11,49 @@ class CheckResaleLicense { try { $settings = InstanceSettings::get(); - $instance_id = config('app.id'); + $settings->update([ + 'is_resale_license_active' => false, + ]); if (!$settings->resale_license) { return; } - ray('Checking license key'); + $base_url = config('coolify.license_url'); + if (isDev()) { + $base_url = 'http://host.docker.internal:8787'; + } + $instance_id = config('app.id'); + + ray("Checking license key against $base_url/lemon/validate"); $data = Http::withHeaders([ 'Accept' => 'application/json', - ])->post('https://api.lemonsqueezy.com/v1/licenses/validate', [ + ])->get("$base_url/lemon/validate", [ 'license_key' => $settings->resale_license, - 'instance_name' => $instance_id, - ])->throw()->json(); - $product_id = (int)data_get($data, 'meta.product_id'); - $valid_product_id = (int)config('coolify.lemon_squeezy_product_id'); - if ($product_id !== $valid_product_id) { - throw new \Exception('Invalid product id'); - } - ray('Valid Product Id'); - - ['valid' => $valid, 'license_key' => $license_key] = $data; - - if ($valid) { - if (data_get($license_key, 'status') === 'inactive') { - Http::withHeaders([ - 'Accept' => 'application/json', - ])->post('https://api.lemonsqueezy.com/v1/licenses/activate', [ - 'license_key' => $settings->resale_license, - 'instance_name' => $instance_id, - ])->throw()->json(); - } + 'instance_id' => $instance_id, + ])->json(); + if (data_get($data, 'valid') === true && data_get($data, 'license_key.status') === 'active') { + ray('Valid & active license key'); $settings->update([ 'is_resale_license_active' => true, ]); return; } - throw new \Exception('Invalid license key'); + $data = Http::withHeaders([ + 'Accept' => 'application/json', + ])->get("$base_url/lemon/activate", [ + 'license_key' => $settings->resale_license, + 'instance_id' => $instance_id, + ])->json(); + if (data_get($data, 'activated') === true) { + ray('Activated license key'); + $settings->update([ + 'is_resale_license_active' => true, + ]); + return; + } + if (data_get($data, 'license_key.status') === 'active') { + throw new \Exception('Invalid license key.'); + } + throw new \Exception('Cannot activate license key.'); } catch (\Throwable $th) { ray($th); $settings->update([ diff --git a/app/Http/Livewire/License.php b/app/Http/Livewire/License.php deleted file mode 100644 index 14c147a87..000000000 --- a/app/Http/Livewire/License.php +++ /dev/null @@ -1,26 +0,0 @@ -validate([ - 'license' => 'required' - ]); - // Pretend we're checking the license - // if ($this->license === '123') { - // ray('license is valid'); - // Cache::put('license_key', '123'); - // return redirect()->to('/'); - // } else { - // ray('license is invalid'); - // } - } -} diff --git a/config/coolify.php b/config/coolify.php index 0a4220887..fba1087b9 100644 --- a/config/coolify.php +++ b/config/coolify.php @@ -2,8 +2,8 @@ return [ 'self_hosted' => env('SELF_HOSTED', true), + 'license_url' => 'https://license.coolify.io', 'lemon_squeezy_webhook_secret' => env('LEMON_SQUEEZY_WEBHOOK_SECRET'), - 'lemon_squeezy_product_id' => env('LEMON_SQUEEZY_PRODUCT_ID'), 'lemon_squeezy_checkout_id' => env('LEMON_SQUEEZY_CHECKOUT_ID'), 'mux_enabled' => env('MUX_ENABLED', true), 'dev_webhook' => env('SERVEO_URL'), diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index ec28418ea..0a257eb9d 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -33,7 +33,6 @@ services: - SELF_HOSTED - LEMON_SQUEEZY_WEBHOOK_SECRET - LEMON_SQUEEZY_CHECKOUT_ID - - LEMON_SQUEEZY_PRODUCT_ID ports: - "${APP_PORT:-8000}:80" expose: diff --git a/resources/views/livewire/check-license.blade.php b/resources/views/livewire/check-license.blade.php index 8f055da81..093e637fd 100644 --- a/resources/views/livewire/check-license.blade.php +++ b/resources/views/livewire/check-license.blade.php @@ -18,7 +18,7 @@ @if (session()->has('error'))
- {{ session('error') }} + {!! session('error') !!}
@endif diff --git a/resources/views/livewire/license.blade.php b/resources/views/livewire/license.blade.php deleted file mode 100644 index a367c124e..000000000 --- a/resources/views/livewire/license.blade.php +++ /dev/null @@ -1,6 +0,0 @@ -
-
- - Check - -
diff --git a/resources/views/subscription.blade.php b/resources/views/subscription.blade.php index d70c8e495..b954c165e 100644 --- a/resources/views/subscription.blade.php +++ b/resources/views/subscription.blade.php @@ -29,6 +29,6 @@ Subscription @else -
Resale license is not active. Please contact your instance admin.
+
Resale license is not active. Please contact your instance admin.
@endif