41 lines
1.3 KiB
PHP
Executable File
41 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Services\Licensing;
|
|
|
|
use App\Models\LicenseDeliveryOutbox;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
final class LicenseDeliveryService
|
|
{
|
|
public function deliverPending(int $limit = 20): int
|
|
{
|
|
$delivered = 0;
|
|
$pending = LicenseDeliveryOutbox::query()
|
|
->whereNull('delivered_at')
|
|
->whereNotNull('recipient_email')
|
|
->where('recipient_email', '!=', '')
|
|
->oldest()
|
|
->limit(max(1, min($limit, 100)))
|
|
->get();
|
|
|
|
foreach ($pending as $outbox) {
|
|
$plain = Crypt::decryptString($outbox->encrypted_license_key);
|
|
$recipient = strtolower(trim((string) $outbox->recipient_email));
|
|
if ($recipient === '') {
|
|
continue;
|
|
}
|
|
|
|
Mail::raw(
|
|
"Thank you for choosing Rsync Studio.\n\nYour licence key is:\n\n{$plain}\n\nOpen Rsync Studio → Settings → Licence and enter this key to activate your Mac.\n\nKeep this key private. You can manage activations from the Rsync Studio licence portal.",
|
|
fn ($message) => $message->to($recipient)->subject('Your Rsync Studio licence key')
|
|
);
|
|
|
|
$outbox->update(['delivered_at' => now()]);
|
|
$delivered++;
|
|
}
|
|
|
|
return $delivered;
|
|
}
|
|
}
|