Recht: Online-Widerruf ohne Login (gesetzlicher Widerrufsbutton) - Backend
POST /widerruf (host-agnostisch, throttled, Honeypot, eigener withdrawal-Error-Bag): persistiert nur Zuordnungsdaten (Name, E-Mail, optionale Bestellnummer - KEIN Grund, darf nicht verlangt werden) und versendet sofort die gesetzlich vorgeschriebene automatische Eingangsbestaetigung mit Zeitstempel an den Verbraucher plus eine interne Benachrichtigung an die Brand-Kontaktadresse des Hosts. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
47d03ec777
commit
8c0bf00604
9 changed files with 429 additions and 0 deletions
93
app/Http/Controllers/Web/WithdrawalController.php
Normal file
93
app/Http/Controllers/Web/WithdrawalController.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\WithdrawalRequestReceived;
|
||||
use App\Mail\WithdrawalRequestSubmitted;
|
||||
use App\Models\WithdrawalRequest;
|
||||
use App\Support\WebPortalContext;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Online-Widerruf über den gesetzlichen Widerrufsbutton: ohne Login, nur
|
||||
* Zuordnungsdaten (Name, E-Mail, optional Bestellnummer) — ein Widerrufsgrund
|
||||
* darf nicht verlangt werden. Der Eingang wird sofort automatisch per E-Mail
|
||||
* bestätigt (dauerhafter Datenträger inkl. Zeitstempel) und persistiert.
|
||||
*/
|
||||
class WithdrawalController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): RedirectResponse
|
||||
{
|
||||
// Bot: ein ausgefülltes Honeypot-Feld → still und neutral abnicken,
|
||||
// bewusst VOR der Validierung (sonst verrät die Regel die Falle).
|
||||
if (filled($request->input('website')) || filled($request->input('homepage'))) {
|
||||
return $this->done();
|
||||
}
|
||||
|
||||
// Eigener Error-Bag, damit sich Widerrufs- und Kontakt-Modal auf
|
||||
// derselben Seite nicht gegenseitig öffnen.
|
||||
$validated = $request->validateWithBag('withdrawal', [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'order_reference' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$this->ensureNotRateLimited($request);
|
||||
RateLimiter::hit($this->throttleKey($request), 3600);
|
||||
|
||||
$withdrawalRequest = WithdrawalRequest::query()->create([
|
||||
'name' => $validated['name'],
|
||||
'email' => $validated['email'],
|
||||
'order_reference' => $validated['order_reference'] ?? null,
|
||||
'host' => $request->getHost(),
|
||||
'requester_ip' => $request->ip(),
|
||||
]);
|
||||
|
||||
// Gesetzlich vorgeschrieben: sofortige automatische Eingangsbestätigung.
|
||||
Mail::to($withdrawalRequest->email)->send(new WithdrawalRequestReceived($withdrawalRequest));
|
||||
Mail::to($this->operatorRecipient())->send(new WithdrawalRequestSubmitted($withdrawalRequest));
|
||||
|
||||
return $this->done();
|
||||
}
|
||||
|
||||
private function done(): RedirectResponse
|
||||
{
|
||||
return back()->with('withdrawal-status', __('Ihr Widerruf ist bei uns eingegangen. Sie erhalten umgehend eine automatische Eingangsbestätigung per E-Mail.'));
|
||||
}
|
||||
|
||||
private function operatorRecipient(): string
|
||||
{
|
||||
if (str_contains(request()->getHost(), 'pressekonto')) {
|
||||
$brand = config('domains.domains.pressekonto.brand', []);
|
||||
} else {
|
||||
$brand = WebPortalContext::fromRequest()->domainConfig['brand'] ?? [];
|
||||
}
|
||||
|
||||
return $brand['contact_email'] ?? config('mail.from.address');
|
||||
}
|
||||
|
||||
private function ensureNotRateLimited(Request $request): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey($request), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey($request));
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('Zu viele Anfragen. Bitte versuchen Sie es in :minutes Minuten erneut.', [
|
||||
'minutes' => max(1, (int) ceil($seconds / 60)),
|
||||
]),
|
||||
])->errorBag('withdrawal');
|
||||
}
|
||||
|
||||
private function throttleKey(Request $request): string
|
||||
{
|
||||
return 'withdrawal-form|'.$request->ip();
|
||||
}
|
||||
}
|
||||
35
app/Mail/WithdrawalRequestReceived.php
Normal file
35
app/Mail/WithdrawalRequestReceived.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\WithdrawalRequest;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Sofortige automatische Eingangsbestätigung an den Verbraucher — gesetzlich
|
||||
* vorgeschrieben beim Online-Widerruf (Widerrufsbutton).
|
||||
*/
|
||||
class WithdrawalRequestReceived extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public readonly WithdrawalRequest $withdrawalRequest,
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Eingangsbestätigung: Ihr Widerruf vom '.$this->withdrawalRequest->created_at->format('d.m.Y'),
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(view: 'emails.withdrawal.received');
|
||||
}
|
||||
}
|
||||
34
app/Mail/WithdrawalRequestSubmitted.php
Normal file
34
app/Mail/WithdrawalRequestSubmitted.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\WithdrawalRequest;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Interne Benachrichtigung an den Betreiber über einen neuen Online-Widerruf.
|
||||
*/
|
||||
class WithdrawalRequestSubmitted extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public readonly WithdrawalRequest $withdrawalRequest,
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Neuer Online-Widerruf #'.$this->withdrawalRequest->id.' über '.$this->withdrawalRequest->host,
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(view: 'emails.withdrawal.submitted');
|
||||
}
|
||||
}
|
||||
35
app/Models/WithdrawalRequest.php
Normal file
35
app/Models/WithdrawalRequest.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Online-Widerruf über den gesetzlichen Widerrufsbutton (ohne Login).
|
||||
* Enthält nur Zuordnungsdaten — ein Widerrufsgrund darf nicht erhoben werden.
|
||||
*/
|
||||
class WithdrawalRequest extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'order_reference',
|
||||
'host',
|
||||
'requester_ip',
|
||||
'status',
|
||||
'resolved_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'resolved_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function scopeOpen(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'open');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Online-Widerruf (gesetzlicher Widerrufsbutton): Verbraucher können Verträge
|
||||
* ohne Login widerrufen. Nur Zuordnungsdaten (Name, E-Mail, optional
|
||||
* Bestell-/Rechnungsnummer) — ein Widerrufsgrund darf nicht verlangt werden.
|
||||
* Der Eingang wird sofort automatisch per E-Mail bestätigt; die Bearbeitung
|
||||
* erfolgt manuell.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('withdrawal_requests', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('name');
|
||||
$table->string('email');
|
||||
$table->string('order_reference')->nullable();
|
||||
|
||||
$table->string('host')->nullable();
|
||||
$table->string('requester_ip', 45)->nullable();
|
||||
|
||||
$table->string('status', 40)->default('open');
|
||||
$table->timestamp('resolved_at')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['status', 'created_at']);
|
||||
$table->index('email');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('withdrawal_requests');
|
||||
}
|
||||
};
|
||||
46
resources/views/emails/withdrawal/received.blade.php
Normal file
46
resources/views/emails/withdrawal/received.blade.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Eingangsbestätigung Ihres Widerrufs</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px; }
|
||||
.meta { background: #f8fafc; border-left: 4px solid #2563eb; padding: 12px 16px; margin: 16px 0; }
|
||||
.meta dt { font-weight: bold; color: #111; }
|
||||
.meta dd { margin: 0 0 8px; }
|
||||
.note { font-size: 13px; color: #666; border-top: 1px solid #eee; padding-top: 12px; margin-top: 24px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>Guten Tag {{ $withdrawalRequest->name }},</p>
|
||||
|
||||
<p>
|
||||
hiermit bestätigen wir den Eingang Ihres Widerrufs. Ihre Erklärung ist bei uns
|
||||
am <strong>{{ $withdrawalRequest->created_at->format('d.m.Y') }}
|
||||
um {{ $withdrawalRequest->created_at->format('H:i') }} Uhr</strong> eingegangen.
|
||||
</p>
|
||||
|
||||
<dl class="meta">
|
||||
<dt>Name</dt>
|
||||
<dd>{{ $withdrawalRequest->name }}</dd>
|
||||
<dt>E-Mail</dt>
|
||||
<dd>{{ $withdrawalRequest->email }}</dd>
|
||||
@if ($withdrawalRequest->order_reference)
|
||||
<dt>Bestell-/Rechnungsnummer</dt>
|
||||
<dd>{{ $withdrawalRequest->order_reference }}</dd>
|
||||
@endif
|
||||
<dt>Vorgangsnummer</dt>
|
||||
<dd>W-{{ $withdrawalRequest->id }}</dd>
|
||||
</dl>
|
||||
|
||||
<p>
|
||||
Wir ordnen Ihren Widerruf dem zugehörigen Vertrag zu und melden uns
|
||||
schnellstmöglich mit den weiteren Schritten (z. B. zur Rückabwicklung) bei Ihnen.
|
||||
</p>
|
||||
|
||||
<p class="note">
|
||||
Diese Bestätigung wurde automatisch erstellt und dokumentiert den Zeitpunkt
|
||||
des Eingangs Ihrer Widerrufserklärung. Bitte bewahren Sie sie auf.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
36
resources/views/emails/withdrawal/submitted.blade.php
Normal file
36
resources/views/emails/withdrawal/submitted.blade.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Neuer Online-Widerruf</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; max-width: 600px; margin: 0 auto; padding: 20px; }
|
||||
.meta { background: #fef2f2; border-left: 4px solid #dc2626; padding: 12px 16px; margin: 16px 0; }
|
||||
.meta dt { font-weight: bold; color: #111; }
|
||||
.meta dd { margin: 0 0 8px; }
|
||||
.note { font-size: 13px; color: #666; border-top: 1px solid #eee; padding-top: 12px; margin-top: 24px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p>Über den Widerrufsbutton auf <strong>{{ $withdrawalRequest->host }}</strong> ist ein neuer Widerruf eingegangen:</p>
|
||||
|
||||
<dl class="meta">
|
||||
<dt>Vorgangsnummer</dt>
|
||||
<dd>W-{{ $withdrawalRequest->id }}</dd>
|
||||
<dt>Name</dt>
|
||||
<dd>{{ $withdrawalRequest->name }}</dd>
|
||||
<dt>E-Mail</dt>
|
||||
<dd><a href="mailto:{{ $withdrawalRequest->email }}">{{ $withdrawalRequest->email }}</a></dd>
|
||||
<dt>Bestell-/Rechnungsnummer</dt>
|
||||
<dd>{{ $withdrawalRequest->order_reference ?: '— nicht angegeben —' }}</dd>
|
||||
<dt>Eingegangen</dt>
|
||||
<dd>{{ $withdrawalRequest->created_at->format('d.m.Y H:i') }} Uhr</dd>
|
||||
</dl>
|
||||
|
||||
<p class="note">
|
||||
Die Eingangsbestätigung an den Verbraucher wurde automatisch versendet.
|
||||
Bitte den Vorgang dem Vertrag zuordnen und die Rückabwicklung anstoßen
|
||||
(gesetzliche Frist beachten).
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\LegalRequestController;
|
||||
use App\Http\Controllers\Web\WithdrawalController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
|
|
@ -23,3 +24,10 @@ Route::get('/release/{slug}/rechtliches', [LegalRequestController::class, 'creat
|
|||
Route::post('/release/{slug}/rechtliches', [LegalRequestController::class, 'store'])
|
||||
->middleware('throttle:10,1')
|
||||
->name('legal-request.store');
|
||||
|
||||
// Gesetzlicher Widerrufsbutton: Online-Widerruf ohne Login (zweistufig im
|
||||
// Frontend). Host-agnostisch — der Controller ordnet den Betreiber-Empfänger
|
||||
// über den Host zu.
|
||||
Route::post('/widerruf', WithdrawalController::class)
|
||||
->middleware('throttle:10,1')
|
||||
->name('widerruf.store');
|
||||
|
|
|
|||
100
tests/Feature/Web/WithdrawalRequestTest.php
Normal file
100
tests/Feature/Web/WithdrawalRequestTest.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
use App\Mail\WithdrawalRequestReceived;
|
||||
use App\Mail\WithdrawalRequestSubmitted;
|
||||
use App\Models\WithdrawalRequest;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
test('the hub shows the legally required withdrawal button and two-step modal', function () {
|
||||
/** @var TestCase $this */
|
||||
$response = $this->get('https://pressekonto.test/')->assertSuccessful();
|
||||
$content = $response->getContent();
|
||||
|
||||
expect($content)
|
||||
->toContain('Vertrag widerrufen')
|
||||
->toContain('open-withdrawal-modal')
|
||||
->toContain('action="'.route('widerruf.store').'"')
|
||||
->toContain('Jetzt widerrufen')
|
||||
// Kein Widerrufsgrund-Feld — darf gesetzlich nicht verlangt werden.
|
||||
->not->toContain('name="reason"');
|
||||
});
|
||||
|
||||
test('a withdrawal is persisted and both mails are sent immediately', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
config()->set('domains.domains.pressekonto.brand.contact_email', 'kontakt@pressekonto.de');
|
||||
|
||||
$this->from('https://pressekonto.test/')
|
||||
->post('https://pressekonto.test/widerruf', [
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
'order_reference' => 'STR-2026-0042',
|
||||
])
|
||||
->assertRedirect('https://pressekonto.test/')
|
||||
->assertSessionHas('withdrawal-status');
|
||||
|
||||
$request = WithdrawalRequest::query()->firstOrFail();
|
||||
|
||||
expect($request->name)->toBe('Paula Presse');
|
||||
expect($request->email)->toBe('paula@example.test');
|
||||
expect($request->order_reference)->toBe('STR-2026-0042');
|
||||
expect($request->host)->toBe('pressekonto.test');
|
||||
expect($request->status)->toBe('open');
|
||||
|
||||
// Gesetzlich vorgeschrieben: sofortige automatische Eingangsbestätigung.
|
||||
Mail::assertSent(WithdrawalRequestReceived::class, fn (WithdrawalRequestReceived $mail) => $mail->hasTo('paula@example.test'));
|
||||
Mail::assertSent(WithdrawalRequestSubmitted::class, fn (WithdrawalRequestSubmitted $mail) => $mail->hasTo('kontakt@pressekonto.de'));
|
||||
});
|
||||
|
||||
test('the order reference is optional', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
|
||||
$this->post('https://pressekonto.test/widerruf', [
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
])->assertSessionHas('withdrawal-status');
|
||||
|
||||
expect(WithdrawalRequest::query()->firstOrFail()->order_reference)->toBeNull();
|
||||
});
|
||||
|
||||
test('withdrawal validation errors land in the withdrawal error bag', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
|
||||
$this->post('https://pressekonto.test/widerruf', [
|
||||
'name' => '',
|
||||
'email' => 'keine-mail',
|
||||
])->assertSessionHasErrorsIn('withdrawal', ['name', 'email']);
|
||||
|
||||
expect(WithdrawalRequest::query()->count())->toBe(0);
|
||||
Mail::assertNothingSent();
|
||||
});
|
||||
|
||||
test('honeypot submissions are silently accepted without persisting or mailing', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
|
||||
$this->post('https://pressekonto.test/widerruf', [
|
||||
'name' => 'Bot',
|
||||
'email' => 'bot@example.test',
|
||||
'website' => 'https://spam.example',
|
||||
])->assertSessionHas('withdrawal-status');
|
||||
|
||||
expect(WithdrawalRequest::query()->count())->toBe(0);
|
||||
Mail::assertNothingSent();
|
||||
});
|
||||
|
||||
test('a withdrawal from a spoke domain goes to that brand address', function () {
|
||||
/** @var TestCase $this */
|
||||
Mail::fake();
|
||||
config()->set('domains.domains.presseecho.brand.contact_email', 'redaktion@presseecho.de');
|
||||
|
||||
$this->post('https://presseecho.test/widerruf', [
|
||||
'name' => 'Paula Presse',
|
||||
'email' => 'paula@example.test',
|
||||
])->assertSessionHas('withdrawal-status');
|
||||
|
||||
Mail::assertSent(WithdrawalRequestSubmitted::class, fn (WithdrawalRequestSubmitted $mail) => $mail->hasTo('redaktion@presseecho.de'));
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue