52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?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'));
|
|
}
|
|
}
|