• Added the two‑step Widerruf flow with an auth‑only CTA on the Widerrufsbelehrung page and a dedicated confirmation

screen where users pick an eligible end‑customer purchase and confirm. Eligibility is enforced server‑side
  (endcustomer_event, within 14 days, no event package created after purchase), refund is issued via Paddle, the
  purchase is marked refunded, the tenant package is deactivated, and a new confirmation email is sent using resources/
  views/emails/partials/layout.blade.php.

  Details

  - New controller + form request for the confirm flow: app/Http/Controllers/WithdrawalController.php, app/Http/
    Requests/Marketing/WithdrawalConfirmRequest.php
  - New confirmation page + CTA: resources/js/pages/marketing/WithdrawalConfirm.tsx, resources/js/pages/legal/Show.tsx
  - Routes + locale rewrites: routes/web.php, resources/js/lib/localizedPath.ts
  - New email notification + template: app/Notifications/Customer/WithdrawalConfirmed.php, resources/views/emails/
    withdrawal-confirmation.blade.php
  - Translations added for marketing UI + backend flash + email copy: public/lang/de/marketing.json, public/lang/en/
    marketing.json, resources/lang/de/marketing.php, resources/lang/en/marketing.php, resources/lang/de/emails.php,
    resources/lang/en/emails.php
  - Tests: tests/Feature/Marketing/WithdrawalConfirmationTest.php
This commit is contained in:
Codex Agent
2025-12-24 11:54:15 +01:00
parent f6e7c72d14
commit 42b4b647d7
15 changed files with 808 additions and 1 deletions

View File

@@ -0,0 +1,134 @@
<?php
namespace Tests\Feature\Marketing;
use App\Models\Event;
use App\Models\EventPackage;
use App\Models\Package;
use App\Models\PackagePurchase;
use App\Models\Tenant;
use App\Models\TenantPackage;
use App\Models\User;
use App\Notifications\Customer\WithdrawalConfirmed;
use App\Services\Paddle\PaddleTransactionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
class WithdrawalConfirmationTest extends TestCase
{
use RefreshDatabase;
public function test_withdrawal_page_lists_eligible_purchases(): void
{
$user = User::factory()->create();
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
$user->forceFill(['tenant_id' => $tenant->id])->save();
$package = Package::factory()->create(['type' => 'endcustomer']);
$purchase = PackagePurchase::factory()->create([
'tenant_id' => $tenant->id,
'package_id' => $package->id,
'provider' => 'paddle',
'provider_id' => 'txn_123',
'refunded' => false,
'type' => 'endcustomer_event',
'purchased_at' => now()->subDays(2),
]);
$response = $this->actingAs($user)->get('/de/widerruf');
$response->assertOk();
$response->assertInertia(fn (Assert $page) => $page
->component('marketing/WithdrawalConfirm')
->where('windowDays', 14)
->has('eligiblePurchases', 1)
->where('eligiblePurchases.0.id', $purchase->id)
);
}
public function test_withdrawal_confirmation_refunds_and_sends_email(): void
{
Notification::fake();
$user = User::factory()->create();
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
$user->forceFill(['tenant_id' => $tenant->id])->save();
$package = Package::factory()->create(['type' => 'endcustomer']);
$purchase = PackagePurchase::factory()->create([
'tenant_id' => $tenant->id,
'package_id' => $package->id,
'provider' => 'paddle',
'provider_id' => 'txn_456',
'refunded' => false,
'type' => 'endcustomer_event',
'purchased_at' => now()->subDays(5),
]);
$tenantPackage = TenantPackage::factory()->create([
'tenant_id' => $tenant->id,
'package_id' => $package->id,
'active' => true,
]);
$this->mock(PaddleTransactionService::class, function ($mock) {
$mock->shouldReceive('refund')
->once()
->andReturn([]);
});
$response = $this->actingAs($user)->post('/de/widerruf', [
'purchase_id' => $purchase->id,
]);
$response->assertSessionHas('success');
$this->assertTrue($purchase->fresh()->refunded);
$this->assertFalse($tenantPackage->fresh()->active);
Notification::assertSentOnDemand(
WithdrawalConfirmed::class,
function (WithdrawalConfirmed $notification, array $channels) {
return in_array('mail', $channels, true);
}
);
}
public function test_withdrawal_rejected_when_event_exists(): void
{
$user = User::factory()->create();
$tenant = Tenant::factory()->create(['user_id' => $user->id]);
$user->forceFill(['tenant_id' => $tenant->id])->save();
$package = Package::factory()->create(['type' => 'endcustomer']);
$purchase = PackagePurchase::factory()->create([
'tenant_id' => $tenant->id,
'package_id' => $package->id,
'provider' => 'paddle',
'provider_id' => 'txn_789',
'refunded' => false,
'type' => 'endcustomer_event',
'purchased_at' => now()->subDays(3),
]);
$event = Event::factory()->create(['tenant_id' => $tenant->id]);
EventPackage::create([
'event_id' => $event->id,
'package_id' => $package->id,
'purchased_price' => $package->price,
'purchased_at' => now(),
]);
$this->mock(PaddleTransactionService::class, function ($mock) {
$mock->shouldReceive('refund')->never();
});
$response = $this->actingAs($user)->post('/de/widerruf', [
'purchase_id' => $purchase->id,
]);
$response->assertSessionHas('error');
$this->assertFalse($purchase->fresh()->refunded);
}
}