fix: licensing
This commit is contained in:
parent
e7d019028a
commit
97e2a5d30b
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\InstanceSettings;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
class CheckResaleLicense
|
||||
{
|
||||
@ -12,41 +11,49 @@ public function __invoke()
|
||||
{
|
||||
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([
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Livewire\Component;
|
||||
|
||||
class License extends Component
|
||||
{
|
||||
public string $license;
|
||||
public function submit()
|
||||
{
|
||||
ray('checking license');
|
||||
$this->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');
|
||||
// }
|
||||
}
|
||||
}
|
@ -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'),
|
||||
|
@ -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:
|
||||
|
@ -18,7 +18,7 @@
|
||||
</div>
|
||||
@if (session()->has('error'))
|
||||
<div class="text-error">
|
||||
{{ session('error') }}
|
||||
{!! session('error') !!}
|
||||
</div>
|
||||
@endif
|
||||
</form>
|
||||
|
@ -1,6 +0,0 @@
|
||||
<div>
|
||||
<form wire:submit.prevent='submit'>
|
||||
<x-forms.input id="license" label="License Key" />
|
||||
<x-forms.button type='submit'>Check</x-forms.button>
|
||||
</form>
|
||||
</div>
|
@ -29,6 +29,6 @@
|
||||
Subscription</a>
|
||||
</x-forms.button>
|
||||
@else
|
||||
<div>Resale license is not active. Please contact your instance admin.</div>
|
||||
<div class="px-10">Resale license is not active. Please contact your instance admin.</div>
|
||||
@endif
|
||||
</x-layout-subscription>
|
||||
|
Loading…
Reference in New Issue
Block a user