Files
fotospiel-app/app/Filament/Resources/GiftVoucherResource/Pages/ListGiftVouchers.php
Codex Agent 10c99de1e2
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Migrate billing from Paddle to Lemon Squeezy
2026-02-03 10:59:54 +01:00

88 lines
3.6 KiB
PHP

<?php
namespace App\Filament\Resources\GiftVoucherResource\Pages;
use App\Filament\Resources\GiftVoucherResource;
use App\Services\Audit\SuperAdminAuditLogger;
use App\Services\GiftVouchers\GiftVoucherService;
use Filament\Actions\Action;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Support\Str;
class ListGiftVouchers extends ListRecords
{
protected static string $resource = GiftVoucherResource::class;
protected function getHeaderActions(): array
{
return [
Action::make('issue')
->label('Gutschein ausstellen')
->icon('heroicon-o-plus')
->form([
TextInput::make('amount')
->label('Betrag')
->numeric()
->required(),
TextInput::make('currency')
->label('Währung')
->default('EUR')
->maxLength(3)
->required(),
TextInput::make('purchaser_email')->label('E-Mail Käufer')->required(),
TextInput::make('recipient_email')->label('E-Mail Empfänger'),
TextInput::make('recipient_name')->label('Name Empfänger'),
TextInput::make('message')
->label('Nachricht')
->maxLength(500),
TextInput::make('code')
->label('Code (optional)')
->placeholder('GIFT-'.Str::upper(Str::random(8))),
Placeholder::make('code_hint')
->label('')
->content('Wenn kein Code eingetragen wird, erzeugen wir automatisch einen eindeutigen Gutscheincode.'),
])
->action(function (array $data, GiftVoucherService $service): void {
$payload = [
'meta' => [
'custom_data' => [
'type' => 'gift_voucher',
'purchaser_email' => $data['purchaser_email'],
'recipient_email' => $data['recipient_email'] ?? null,
'recipient_name' => $data['recipient_name'] ?? null,
'message' => $data['message'] ?? null,
'gift_code' => $data['code'] ?? null,
],
],
'data' => [
'id' => 'manual_'.Str::uuid(),
'attributes' => [
'currency' => $data['currency'] ?? 'EUR',
'total' => (float) $data['amount'] * 100,
'user_email' => $data['purchaser_email'],
],
],
];
$voucher = $service->issueFromLemonSqueezy($payload);
app(SuperAdminAuditLogger::class)->recordModelMutation(
'issued',
$voucher,
SuperAdminAuditLogger::fieldsMetadata([
'amount',
'currency',
'status',
'expires_at',
'coupon_id',
]),
source: static::class
);
})
->modalHeading('Geschenkgutschein ausstellen'),
];
}
}