move into sonardesk

This commit is contained in:
Mark Gregory
2026-10-12 15:18:07 +01:00
parent ef9903b7b7
commit a88d336991
14 changed files with 254 additions and 0 deletions
@@ -0,0 +1,51 @@
<?php
namespace Modules\Licensing\Http\Controllers\Admin;
use Illuminate\Contracts\View\View;
use Illuminate\Routing\Controller;
use Modules\Licensing\Models\License;
use Modules\Licensing\Services\PaddleReadOnlyClient;
use Throwable;
final class PaddleReconciliationController extends Controller
{
public function index(PaddleReadOnlyClient $paddle): View
{
$configured = trim((string) config('sonardesk-paddle.api_key')) !== '';
$environment = config('sonardesk-paddle.environment', 'sandbox');
$rows = [];
// A bounded, explicit read-only comparison; no local changes or Paddle writes.
$licenses = License::query()
->where('payment_provider', 'paddle')
->whereNotNull('external_subscription_id')
->orderByDesc('created_at')
->limit(20)
->get();
foreach ($licenses as $license) {
$result = [
'license' => $license,
'remote_status' => null,
'result' => $configured ? 'unknown' : 'not configured',
'detail' => null,
];
if ($configured) {
try {
$subscription = $paddle->subscription((string) $license->external_subscription_id);
$result['remote_status'] = (string) ($subscription['status'] ?? 'unknown');
$result['result'] = $result['remote_status'] === (string) $license->subscription_status
? 'matched' : 'different';
} catch (Throwable $e) {
report($e);
$result['result'] = 'lookup failed';
$result['detail'] = $e->getMessage();
}
}
$rows[] = $result;
}
return view('licensing::admin.paddle-reconciliation', compact('rows', 'configured', 'environment'));
}
}
@@ -0,0 +1,40 @@
<?php
namespace Modules\Licensing\Http\Controllers\Customer;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Licensing\Models\License;
final class CustomerLicensingController extends Controller
{
public function index(Request $request): View
{
$email = mb_strtolower(trim((string) $request->user()->email));
$licenses = License::query()
->with('product')
->whereRaw('LOWER(customer_email) = ?', [$email])
->latest()
->paginate(15);
return view('licensing::customer.index', compact('licenses'));
}
public function show(Request $request, License $license): View
{
// Return 404, not 403, to avoid disclosing whether a licence exists.
abort_unless(
hash_equals(
mb_strtolower(trim((string) $license->customer_email)),
mb_strtolower(trim((string) $request->user()->email))
),
404
);
$license->load(['product', 'activations']);
return view('licensing::customer.show', compact('license'));
}
}