Admin-Zahlungsmodul: Zahlungs-Übersicht + Tarif-Verwaltung mit Stripe-Sync
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
8f3261d0b4
commit
bda755fcf8
9 changed files with 1109 additions and 23 deletions
121
app/Services/Billing/StripePlanSyncService.php
Normal file
121
app/Services/Billing/StripePlanSyncService.php
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Billing;
|
||||
|
||||
use App\Models\Plan;
|
||||
use Laravel\Cashier\Cashier;
|
||||
use Stripe\StripeClient;
|
||||
|
||||
/**
|
||||
* Spiegelt Tarif-Änderungen aus der Admin-Verwaltung sofort nach Stripe.
|
||||
*
|
||||
* Stripe-Preise sind unveränderlich: Eine Preisänderung legt deshalb einen
|
||||
* neuen Price an (netto, `tax_behavior: exclusive` wie beim Sync-Command),
|
||||
* deaktiviert den alten für neue Buchungen und schreibt die neue ID in
|
||||
* `plans` zurück. Bestandsabos behalten bewusst ihren bisherigen Preis —
|
||||
* Stripe rechnet laufende Subscriptions auf dem alten Price-Objekt weiter.
|
||||
*/
|
||||
class StripePlanSyncService
|
||||
{
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return (bool) config('cashier.secret');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gleicht einen lokal gespeicherten Tarif mit Stripe ab. `$changes`
|
||||
* sind die tatsächlich geänderten Attribute (`Model::getChanges()`),
|
||||
* damit nur die nötigen Stripe-Aufrufe passieren.
|
||||
*
|
||||
* @param array<string, mixed> $changes
|
||||
*/
|
||||
public function syncAfterUpdate(Plan $plan, array $changes): void
|
||||
{
|
||||
if (! $this->isConfigured()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stripe = Cashier::stripe();
|
||||
|
||||
if (! $plan->stripe_product_id) {
|
||||
$this->createProductWithPrices($stripe, $plan);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (array_key_exists('name', $changes)) {
|
||||
$stripe->products->update($plan->stripe_product_id, ['name' => $plan->name]);
|
||||
}
|
||||
|
||||
if (array_key_exists('monthly_price_cents', $changes)) {
|
||||
$plan->forceFill([
|
||||
'stripe_price_id_monthly' => $this->rotatePrice(
|
||||
$stripe,
|
||||
$plan,
|
||||
$plan->stripe_price_id_monthly,
|
||||
$plan->monthly_price_cents,
|
||||
'month',
|
||||
),
|
||||
])->save();
|
||||
}
|
||||
|
||||
if (array_key_exists('yearly_price_cents', $changes)) {
|
||||
$plan->forceFill([
|
||||
'stripe_price_id_yearly' => $this->rotatePrice(
|
||||
$stripe,
|
||||
$plan,
|
||||
$plan->stripe_price_id_yearly,
|
||||
$plan->yearly_price_cents,
|
||||
'year',
|
||||
),
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstanlage für Tarife ohne Stripe-Verknüpfung — gleiche Struktur wie
|
||||
* `billing:sync-stripe-plans`, nur direkt aus der Admin-Oberfläche.
|
||||
*/
|
||||
private function createProductWithPrices(StripeClient $stripe, Plan $plan): void
|
||||
{
|
||||
$product = $stripe->products->create([
|
||||
'name' => $plan->name,
|
||||
'metadata' => ['plan_slug' => $plan->slug],
|
||||
]);
|
||||
|
||||
$plan->forceFill([
|
||||
'stripe_product_id' => $product->id,
|
||||
'stripe_price_id_monthly' => $this->createPrice($stripe, $product->id, $plan, $plan->monthly_price_cents, 'month'),
|
||||
'stripe_price_id_yearly' => $this->createPrice($stripe, $product->id, $plan, $plan->yearly_price_cents, 'year'),
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Neuen Preis anlegen und den bisherigen (falls vorhanden) für neue
|
||||
* Buchungen deaktivieren. Gibt die neue Price-ID zurück.
|
||||
*/
|
||||
private function rotatePrice(StripeClient $stripe, Plan $plan, ?string $oldPriceId, int $unitAmount, string $interval): string
|
||||
{
|
||||
$newPriceId = $this->createPrice($stripe, (string) $plan->stripe_product_id, $plan, $unitAmount, $interval);
|
||||
|
||||
if ($oldPriceId) {
|
||||
$stripe->prices->update($oldPriceId, ['active' => false]);
|
||||
}
|
||||
|
||||
return $newPriceId;
|
||||
}
|
||||
|
||||
private function createPrice(StripeClient $stripe, string $productId, Plan $plan, int $unitAmount, string $interval): string
|
||||
{
|
||||
$price = $stripe->prices->create([
|
||||
'product' => $productId,
|
||||
'currency' => strtolower($plan->currency),
|
||||
'unit_amount' => $unitAmount,
|
||||
'tax_behavior' => 'exclusive',
|
||||
'recurring' => ['interval' => $interval],
|
||||
'metadata' => ['plan_slug' => $plan->slug],
|
||||
]);
|
||||
|
||||
return $price->id;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,34 @@
|
|||
|
||||
---
|
||||
|
||||
## 2026-06-12 · Admin-Zahlungsmodul (P8-Rest) · Zahlungen + Tarif-Verwaltung ✅
|
||||
|
||||
- **Was**: Den Phase-8-Platzhalter `/admin/payments` durch das echte
|
||||
Zahlungsmodul ersetzt: KPI-Reihe (aktive Abos, MRR netto, Umsatz
|
||||
30 Tage brutto, offene Einzel-PMs), Tabellen für Stripe-Abos (mit
|
||||
Tarif-Auflösung über die Price-IDs), Einmalkäufe (Typ/Status/PM-Link)
|
||||
und den lokalen Rechnungsausgang (STR-/MAN-Badge), User-Suche über
|
||||
alle drei Bereiche. Neu: `/admin/payments/plans` — Tarif-Verwaltung
|
||||
mit Edit-Modal (Name, Netto-Preise, PM-Kontingent, Tageslimit,
|
||||
aktiv/inaktiv, Sortierung) und **Sofort-Sync nach Stripe** über den
|
||||
neuen `StripePlanSyncService`: Preisänderung legt ein neues
|
||||
Price-Objekt an und deaktiviert das alte (Stripe-Preise sind
|
||||
unveränderlich), Namensänderung aktualisiert das Produkt, unverknüpfte
|
||||
Tarife werden komplett angelegt. Bestandsabos behalten ihren Preis
|
||||
(Hinweis in UI und Speichermeldung). Buchungs-Seite zieht die Preise
|
||||
ohnehin live aus `plans` → Änderungen wirken sofort überall.
|
||||
Sidebar: eigener Eintrag „Tarife & Pakete" unter Billing.
|
||||
- **Dateien**: `resources/views/livewire/admin/payments/index.blade.php`
|
||||
(Neufassung), `resources/views/livewire/admin/payments/plans.blade.php`
|
||||
(neu), `app/Services/Billing/StripePlanSyncService.php` (neu),
|
||||
`routes/admin.php`, Sidebar.
|
||||
- **Build/Test**: Suite 532 passed / 4 skipped, Pint clean; 13 neue Tests
|
||||
(`AdminPlansPageTest`, `AdminPaymentsPageTest`), Stripe im Test gemockt.
|
||||
- **Offene Fragen**: Refund-Workflow aus dem Admin (vorerst über das
|
||||
Stripe-Dashboard); Einzel-PM-Preis bleibt Config/ENV-basiert.
|
||||
- **Nächster Schritt**: User-Panel-Restarbeiten (Kevin sammelt Liste),
|
||||
Login/Registrierungs-Flow durchtesten, 9G Tageslimit.
|
||||
|
||||
## 2026-06-12 · Phase 9F · Tarif-Seite + Checkout-UI ✅
|
||||
|
||||
- **Was**: „Buchungen & Add-ons" vom Credit-Konzept-Mock auf echte Daten
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ Rechnungsadresse bestimmt:
|
|||
|---|---|---|
|
||||
| `billing:generate-manual-invoices` | MAN-Fälligkeitslauf (Abschnitt 3) | täglich 04:30 |
|
||||
| `billing:sync-stripe-plans` | Tarife + Einzel-PM als Netto-Produkte/Preise nach Stripe synchronisieren (idempotent; `--dry-run`) | manuell |
|
||||
| — Admin-UI: `/admin/payments/plans` | Tarif-Pflege (Preise, Kontingent, Tageslimit, aktiv/inaktiv) mit Sofort-Sync nach Stripe (`StripePlanSyncService`): Preisänderung legt ein neues Price-Objekt an und deaktiviert das alte; Bestandsabos behalten ihren Preis | — |
|
||||
| `legacy:grandfather-subscriptions` | Aktive Legacy-Abos aus dem Archiv migrieren | manuell (Migrations-Runbook) |
|
||||
| `press-releases:reset-monthly-quota` | Monatlicher Reset des Plan-Kontingent-Zählers (`press_release_quota_used_this_month`) | monatlich, 1. um 00:05 |
|
||||
|
||||
|
|
@ -184,6 +185,12 @@ CLI ausgegebene `whsec_…` temporär als `STRIPE_WEBHOOK_SECRET` in die `.env`.
|
|||
1. **Phase 9F erledigt** (12.06.2026): Die Buchungs-Seite zeigt das echte
|
||||
Tarif-Raster (Monat/Jahr-Toggle), den Einzel-PM-Block, Bestandstarife
|
||||
und „Abo verwalten" (Stripe Billing Portal, `me.checkout.billing-portal`).
|
||||
1b. **Admin-Zahlungsmodul erledigt** (12.06.2026): `/admin/payments` zeigt
|
||||
KPIs (aktive Abos, MRR netto, Umsatz 30 Tage, offene Einzel-PMs) plus
|
||||
Abo-, Einmalkauf- und Rechnungstabellen (STR/MAN) mit User-Suche;
|
||||
`/admin/payments/plans` pflegt die Tarife mit Sofort-Sync nach Stripe
|
||||
(Abschnitt 5). Refund-Workflow direkt aus dem Admin bleibt offen
|
||||
(vorerst über das Stripe-Dashboard).
|
||||
2. **Stripe Tax**: im Dashboard aktiviert (12.06.2026, Produkt-Steuercode
|
||||
„SaaS – business use", Steuer nicht im Preis enthalten — passt zu den
|
||||
Netto-Preisen). Vor Relaunch im **Live-Mode** wiederholen; dort auch
|
||||
|
|
|
|||
|
|
@ -144,9 +144,13 @@
|
|||
{{ __('Legacy Rechnungen') }}
|
||||
</flux:navlist.item>
|
||||
<flux:navlist.item icon="credit-card" :href="route('admin.payments.index')"
|
||||
:current="request()->routeIs('admin.payments.*')" wire:navigate>
|
||||
:current="request()->routeIs('admin.payments.index')" wire:navigate>
|
||||
{{ __('Zahlungen') }}
|
||||
</flux:navlist.item>
|
||||
<flux:navlist.item icon="rectangle-stack" :href="route('admin.payments.plans')"
|
||||
:current="request()->routeIs('admin.payments.plans')" wire:navigate>
|
||||
{{ __('Tarife & Pakete') }}
|
||||
</flux:navlist.item>
|
||||
<flux:navlist.item icon="ticket" :href="route('admin.coupons.index')"
|
||||
:current="request()->routeIs('admin.coupons.*')" wire:navigate>
|
||||
{{ __('Gutscheine') }}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,102 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\InvoiceStatus;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Plan;
|
||||
use App\Models\SinglePurchase;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Laravel\Cashier\Subscription;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Volt\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
new #[Layout('components.layouts.app'), Title('Zahlungen')] class extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public string $search = '';
|
||||
|
||||
public function updatedSearch(): void
|
||||
{
|
||||
$this->resetPage('subscriptionsPage');
|
||||
$this->resetPage('purchasesPage');
|
||||
$this->resetPage('invoicesPage');
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [];
|
||||
$plans = Plan::query()->get();
|
||||
|
||||
/** @var array<string, array{plan: Plan, interval: string}> $plansByPriceId */
|
||||
$plansByPriceId = [];
|
||||
|
||||
foreach ($plans as $plan) {
|
||||
if ($plan->stripe_price_id_monthly) {
|
||||
$plansByPriceId[$plan->stripe_price_id_monthly] = ['plan' => $plan, 'interval' => __('monatlich')];
|
||||
}
|
||||
if ($plan->stripe_price_id_yearly) {
|
||||
$plansByPriceId[$plan->stripe_price_id_yearly] = ['plan' => $plan, 'interval' => __('jährlich')];
|
||||
}
|
||||
}
|
||||
|
||||
$activeSubscriptions = Subscription::query()->active()->get();
|
||||
|
||||
$monthlyRecurringCents = $activeSubscriptions->sum(function (Subscription $subscription) use ($plansByPriceId): int {
|
||||
$entry = $plansByPriceId[$subscription->stripe_price] ?? null;
|
||||
|
||||
if (! $entry) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $entry['interval'] === __('jährlich')
|
||||
? (int) round($entry['plan']->yearly_price_cents / 12)
|
||||
: $entry['plan']->monthly_price_cents;
|
||||
});
|
||||
|
||||
return [
|
||||
'plansByPriceId' => $plansByPriceId,
|
||||
'stats' => [
|
||||
'active_subscriptions' => $activeSubscriptions->count(),
|
||||
'mrr_cents' => $monthlyRecurringCents,
|
||||
'revenue_30d_cents' => (int) Invoice::query()
|
||||
->where('status', InvoiceStatus::Paid->value)
|
||||
->where('paid_at', '>=', now()->subDays(30))
|
||||
->sum('total_cents'),
|
||||
'open_purchases' => SinglePurchase::query()->grantingSubmission()->count(),
|
||||
],
|
||||
'subscriptions' => $this->searchByUser(Subscription::query()->with('owner'))
|
||||
->latest('created_at')
|
||||
->paginate(25, pageName: 'subscriptionsPage'),
|
||||
'purchases' => $this->searchByUser(SinglePurchase::query()->with(['user', 'pressRelease']))
|
||||
->latest('created_at')
|
||||
->paginate(25, pageName: 'purchasesPage'),
|
||||
'invoices' => $this->searchByUser(Invoice::query()->with('user'))
|
||||
->latest('invoice_date')
|
||||
->latest('id')
|
||||
->paginate(25, pageName: 'invoicesPage'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wendet die User-Suche (Name oder E-Mail) auf eine der drei
|
||||
* Zahlungs-Tabellen an. Abos hängen über `owner` am User, Käufe und
|
||||
* Rechnungen über `user`.
|
||||
*/
|
||||
private function searchByUser(Builder $query): Builder
|
||||
{
|
||||
if (! filled($this->search)) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
$search = trim($this->search);
|
||||
$relation = $query->getModel() instanceof Subscription ? 'owner' : 'user';
|
||||
|
||||
return $query->whereHas($relation, function (Builder $query) use ($search): void {
|
||||
$query
|
||||
->where('name', 'like', '%'.$search.'%')
|
||||
->orWhere('email', 'like', '%'.$search.'%');
|
||||
});
|
||||
}
|
||||
}; ?>
|
||||
|
||||
|
|
@ -19,40 +107,280 @@ new #[Layout('components.layouts.app'), Title('Zahlungen')] class extends Compon
|
|||
<div class="flex items-center gap-3 mb-3 flex-wrap">
|
||||
<span class="badge hub dot">{{ __('Admin Backend') }}</span>
|
||||
<span class="eyebrow muted">{{ __('Administration · Finanzen') }}</span>
|
||||
<span class="badge warn">{{ __('In Vorbereitung') }}</span>
|
||||
</div>
|
||||
<h1 class="text-[30px] font-bold tracking-[-0.6px] leading-[1.15] m-0 text-[color:var(--color-ink)]">
|
||||
{{ __('Zahlungen') }}
|
||||
</h1>
|
||||
<p class="text-[13px] leading-[1.55] mt-2 m-0 max-w-[720px] text-[color:var(--color-ink-2)]">
|
||||
{{ __('Zahlungsabwicklung läuft in Phase 8 ausschließlich über Stripe – alte Zahlungsarten (Rechnung, PayPal, SPK Berlin, Cortal Consors, Bar/Post) entfallen komplett.') }}
|
||||
{{ __('Stripe-Abos, Einmalkäufe und der lokale Rechnungsausgang (STR-/MAN-Kreis) auf einen Blick. Stripe bleibt Zahlungs- und Belegquelle — diese Übersicht spiegelt die per Webhook synchronisierten Daten.') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<flux:button size="sm" variant="filled" icon="archive-box" :href="route('admin.invoices.index')" wire:navigate>
|
||||
{{ __('Legacy-Rechnungen') }}
|
||||
</flux:button>
|
||||
<flux:button size="sm" variant="primary" icon="rectangle-stack" :href="route('admin.payments.plans')" wire:navigate>
|
||||
{{ __('Tarife & Pakete') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{{-- ============== KPI-Reihe ============== --}}
|
||||
<section class="grid grid-cols-2 gap-4 lg:grid-cols-4">
|
||||
<x-portal.stat-card variant="primary" :label="__('Aktive Abos')" :value="number_format($stats['active_subscriptions'], 0, ',', '.')">
|
||||
<x-slot:meta>{{ __('Stripe-Subscriptions') }}</x-slot:meta>
|
||||
</x-portal.stat-card>
|
||||
<x-portal.stat-card variant="ok" :label="__('MRR (netto)')" :value="number_format($stats['mrr_cents'] / 100, 2, ',', '.').' €'">
|
||||
<x-slot:meta>{{ __('monatlich wiederkehrend') }}</x-slot:meta>
|
||||
</x-portal.stat-card>
|
||||
<x-portal.stat-card variant="ok" :label="__('Umsatz 30 Tage')" :value="number_format($stats['revenue_30d_cents'] / 100, 2, ',', '.').' €'">
|
||||
<x-slot:meta>{{ __('bezahlte Rechnungen, brutto') }}</x-slot:meta>
|
||||
</x-portal.stat-card>
|
||||
<x-portal.stat-card variant="muted" :label="__('Offene Einzel-PMs')" :value="number_format($stats['open_purchases'], 0, ',', '.')">
|
||||
<x-slot:meta>{{ __('bezahlt, noch nicht eingelöst') }}</x-slot:meta>
|
||||
</x-portal.stat-card>
|
||||
</section>
|
||||
|
||||
{{-- ============== SUCHE ============== --}}
|
||||
<article class="panel">
|
||||
<div class="panel-head">
|
||||
<span class="section-eyebrow">{{ __('Geplant für P8') }}</span>
|
||||
<span class="section-eyebrow">{{ __('Suche') }}</span>
|
||||
</div>
|
||||
<div class="p-5 space-y-4">
|
||||
<ul class="space-y-3 text-[12.5px] text-[color:var(--color-ink-2)] list-none m-0">
|
||||
<li class="flex gap-2">
|
||||
<flux:icon.check-circle class="size-[16px] shrink-0 mt-0.5 text-[color:var(--color-ok)]" />
|
||||
<span>{{ __('Live-Anzeige aller Stripe-Zahlungen mit Filtern nach Status, Methode und Zeitraum.') }}</span>
|
||||
</li>
|
||||
<li class="flex gap-2">
|
||||
<flux:icon.check-circle class="size-[16px] shrink-0 mt-0.5 text-[color:var(--color-ok)]" />
|
||||
<span>{{ __('Detail-Ansicht mit Stripe-Transaktions-ID, Webhook-Trail und zugeordneter Rechnung.') }}</span>
|
||||
</li>
|
||||
<li class="flex gap-2">
|
||||
<flux:icon.check-circle class="size-[16px] shrink-0 mt-0.5 text-[color:var(--color-ok)]" />
|
||||
<span>{{ __('Refund-Workflow direkt aus dem Admin (sofern Stripe-Berechtigung gegeben).') }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="p-5">
|
||||
<flux:input
|
||||
wire:model.live.debounce.300ms="search"
|
||||
placeholder="{{ __('Nach User-Name oder E-Mail suchen — filtert Abos, Käufe und Rechnungen...') }}"
|
||||
icon="magnifying-glass"
|
||||
class="max-w-xl"
|
||||
/>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<p class="pt-4 border-t border-[color:var(--color-bg-rule)] text-[12px] text-[color:var(--color-ink-3)] m-0">
|
||||
{{ __('Datenmodell (user_payments, user_payment_options) ist bereits angelegt; die Anbindung folgt mit Stripe-Webhooks.') }}
|
||||
</p>
|
||||
{{-- ============== ABOS ============== --}}
|
||||
<article class="panel overflow-hidden">
|
||||
<div class="panel-head">
|
||||
<span class="section-eyebrow">{{ __('Abos') }}</span>
|
||||
<span class="text-[11.5px] text-[color:var(--color-ink-3)]">
|
||||
{{ __(':count Einträge', ['count' => number_format($subscriptions->total(), 0, ',', '.')]) }}
|
||||
</span>
|
||||
</div>
|
||||
<flux:table>
|
||||
<flux:table.columns>
|
||||
<flux:table.column>{{ __('User') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Tarif') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Seit') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Endet') }}</flux:table.column>
|
||||
</flux:table.columns>
|
||||
|
||||
@forelse ($subscriptions as $subscription)
|
||||
<flux:table.row wire:key="admin-subscription-{{ $subscription->id }}">
|
||||
<flux:table.cell>
|
||||
@if ($subscription->owner)
|
||||
<div class="space-y-0.5">
|
||||
<flux:button size="xs" variant="filled" :href="route('admin.users.show', $subscription->owner)" wire:navigate>
|
||||
{{ $subscription->owner->name }}
|
||||
</flux:button>
|
||||
<div class="text-[11px] text-[color:var(--color-ink-3)]">{{ $subscription->owner->email }}</div>
|
||||
</div>
|
||||
@else
|
||||
<span class="text-[12px] text-[color:var(--color-ink-3)]">–</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@php($planEntry = $plansByPriceId[$subscription->stripe_price] ?? null)
|
||||
@if ($planEntry)
|
||||
<div class="space-y-0.5">
|
||||
<div class="text-[13px] font-semibold text-[color:var(--color-ink)]">{{ $planEntry['plan']->name }}</div>
|
||||
<div class="text-[11px] text-[color:var(--color-ink-3)]">{{ $planEntry['interval'] }}</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="text-[11px] text-[color:var(--color-ink-3)] font-mono">{{ $subscription->stripe_price ?? '–' }}</div>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if (in_array($subscription->stripe_status, ['active', 'trialing'], true))
|
||||
<span class="badge ok dot">{{ $subscription->stripe_status === 'trialing' ? __('Testphase') : __('Aktiv') }}</span>
|
||||
@elseif (in_array($subscription->stripe_status, ['past_due', 'unpaid', 'incomplete'], true))
|
||||
<span class="badge warn dot">{{ $subscription->stripe_status }}</span>
|
||||
@else
|
||||
<span class="badge">{{ $subscription->stripe_status }}</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[12px] text-[color:var(--color-ink-2)]">{{ $subscription->created_at?->format('d.m.Y') ?? '–' }}</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[12px] text-[color:var(--color-ink-2)]">{{ $subscription->ends_at?->format('d.m.Y') ?? '–' }}</span>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@empty
|
||||
<flux:table.row>
|
||||
<flux:table.cell colspan="5">
|
||||
<div class="px-4 py-8 text-center text-[13px] text-[color:var(--color-ink-3)]">
|
||||
{{ __('Noch keine Stripe-Abos vorhanden.') }}
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@endforelse
|
||||
</flux:table>
|
||||
<div class="border-t border-[color:var(--color-bg-rule)] p-4">
|
||||
{{ $subscriptions->links('components.portal.pagination') }}
|
||||
</div>
|
||||
</article>
|
||||
|
||||
{{-- ============== EINMALKÄUFE ============== --}}
|
||||
<article class="panel overflow-hidden">
|
||||
<div class="panel-head">
|
||||
<span class="section-eyebrow">{{ __('Einmalkäufe') }}</span>
|
||||
<span class="text-[11.5px] text-[color:var(--color-ink-3)]">
|
||||
{{ __(':count Einträge', ['count' => number_format($purchases->total(), 0, ',', '.')]) }}
|
||||
</span>
|
||||
</div>
|
||||
<flux:table>
|
||||
<flux:table.columns>
|
||||
<flux:table.column>{{ __('User') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Typ') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Betrag (netto)') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Bezahlt am') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Eingelöst für') }}</flux:table.column>
|
||||
</flux:table.columns>
|
||||
|
||||
@forelse ($purchases as $purchase)
|
||||
<flux:table.row wire:key="admin-purchase-{{ $purchase->id }}">
|
||||
<flux:table.cell>
|
||||
@if ($purchase->user)
|
||||
<div class="space-y-0.5">
|
||||
<flux:button size="xs" variant="filled" :href="route('admin.users.show', $purchase->user)" wire:navigate>
|
||||
{{ $purchase->user->name }}
|
||||
</flux:button>
|
||||
<div class="text-[11px] text-[color:var(--color-ink-3)]">{{ $purchase->user->email }}</div>
|
||||
</div>
|
||||
@else
|
||||
<span class="text-[12px] text-[color:var(--color-ink-3)]">–</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[12.5px] text-[color:var(--color-ink-2)]">{{ $purchase->type->label() }}</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[13px] font-semibold text-[color:var(--color-ink)] tabular-nums">{{ number_format($purchase->price_cents / 100, 2, ',', '.') }} €</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if ($purchase->status === \App\Enums\SinglePurchaseStatus::Paid)
|
||||
<span class="badge ok dot">{{ $purchase->status->label() }}</span>
|
||||
@elseif ($purchase->status === \App\Enums\SinglePurchaseStatus::Consumed)
|
||||
<span class="badge hub dot">{{ $purchase->status->label() }}</span>
|
||||
@elseif ($purchase->status === \App\Enums\SinglePurchaseStatus::Pending)
|
||||
<span class="badge warn dot">{{ $purchase->status->label() }}</span>
|
||||
@else
|
||||
<span class="badge">{{ $purchase->status->label() }}</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[12px] text-[color:var(--color-ink-2)]">{{ $purchase->paid_at?->format('d.m.Y H:i') ?? '–' }}</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if ($purchase->pressRelease)
|
||||
<flux:button size="xs" variant="filled" :href="route('admin.press-releases.show', $purchase->pressRelease->id)" wire:navigate>
|
||||
{{ \Illuminate\Support\Str::limit($purchase->pressRelease->title, 40) }}
|
||||
</flux:button>
|
||||
@else
|
||||
<span class="text-[12px] text-[color:var(--color-ink-3)]">–</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@empty
|
||||
<flux:table.row>
|
||||
<flux:table.cell colspan="6">
|
||||
<div class="px-4 py-8 text-center text-[13px] text-[color:var(--color-ink-3)]">
|
||||
{{ __('Noch keine Einmalkäufe vorhanden.') }}
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@endforelse
|
||||
</flux:table>
|
||||
<div class="border-t border-[color:var(--color-bg-rule)] p-4">
|
||||
{{ $purchases->links('components.portal.pagination') }}
|
||||
</div>
|
||||
</article>
|
||||
|
||||
{{-- ============== RECHNUNGEN (STR/MAN) ============== --}}
|
||||
<article class="panel overflow-hidden">
|
||||
<div class="panel-head">
|
||||
<span class="section-eyebrow">{{ __('Rechnungsausgang (STR/MAN)') }}</span>
|
||||
<span class="text-[11.5px] text-[color:var(--color-ink-3)]">
|
||||
{{ __(':count Einträge', ['count' => number_format($invoices->total(), 0, ',', '.')]) }}
|
||||
</span>
|
||||
</div>
|
||||
<flux:table>
|
||||
<flux:table.columns>
|
||||
<flux:table.column>{{ __('Nummer') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Kreis') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('User') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Betrag (brutto)') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Rechnungsdatum') }}</flux:table.column>
|
||||
</flux:table.columns>
|
||||
|
||||
@forelse ($invoices as $invoice)
|
||||
<flux:table.row wire:key="admin-invoice-{{ $invoice->id }}">
|
||||
<flux:table.cell>
|
||||
<span class="text-[13px] font-semibold text-[color:var(--color-ink)] font-mono">{{ $invoice->number }}</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if ($invoice->stripe_invoice_id)
|
||||
<span class="badge hub">{{ __('Stripe (STR)') }}</span>
|
||||
@else
|
||||
<span class="badge">{{ __('Manuell (MAN)') }}</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if ($invoice->user)
|
||||
<div class="space-y-0.5">
|
||||
<flux:button size="xs" variant="filled" :href="route('admin.users.show', $invoice->user)" wire:navigate>
|
||||
{{ $invoice->user->name }}
|
||||
</flux:button>
|
||||
<div class="text-[11px] text-[color:var(--color-ink-3)]">{{ $invoice->user->email }}</div>
|
||||
</div>
|
||||
@else
|
||||
<span class="text-[12px] text-[color:var(--color-ink-3)]">–</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[13px] font-semibold text-[color:var(--color-ink)] tabular-nums">{{ number_format($invoice->total_cents / 100, 2, ',', '.') }} €</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if ($invoice->status === \App\Enums\InvoiceStatus::Paid)
|
||||
<span class="badge ok dot">{{ $invoice->status->label() }}</span>
|
||||
@elseif ($invoice->status === \App\Enums\InvoiceStatus::Open)
|
||||
<span class="badge warn dot">{{ $invoice->status->label() }}</span>
|
||||
@else
|
||||
<span class="badge">{{ $invoice->status->label() }}</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<div class="space-y-0.5">
|
||||
<div class="text-[12px] text-[color:var(--color-ink-2)]">{{ $invoice->invoice_date?->format('d.m.Y') ?? '–' }}</div>
|
||||
@if ($invoice->paid_at)
|
||||
<div class="text-[11px] text-[color:var(--color-ink-3)]">{{ __('bezahlt: :date', ['date' => $invoice->paid_at->format('d.m.Y')]) }}</div>
|
||||
@endif
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@empty
|
||||
<flux:table.row>
|
||||
<flux:table.cell colspan="6">
|
||||
<div class="px-4 py-8 text-center text-[13px] text-[color:var(--color-ink-3)]">
|
||||
{{ __('Noch keine Rechnungen im neuen Rechnungsausgang.') }}
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@endforelse
|
||||
</flux:table>
|
||||
<div class="border-t border-[color:var(--color-bg-rule)] p-4">
|
||||
{{ $invoices->links('components.portal.pagination') }}
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
|
|
|
|||
288
resources/views/livewire/admin/payments/plans.blade.php
Normal file
288
resources/views/livewire/admin/payments/plans.blade.php
Normal file
|
|
@ -0,0 +1,288 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Services\Billing\StripePlanSyncService;
|
||||
use Flux\Flux;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new #[Layout('components.layouts.app'), Title('Tarife & Pakete')] class extends Component
|
||||
{
|
||||
public ?int $editingPlanId = null;
|
||||
|
||||
public string $name = '';
|
||||
|
||||
public string $monthlyPrice = '';
|
||||
|
||||
public string $yearlyPrice = '';
|
||||
|
||||
public string $quota = '';
|
||||
|
||||
public string $dailyLimit = '';
|
||||
|
||||
public bool $isActive = true;
|
||||
|
||||
public string $sortOrder = '0';
|
||||
|
||||
public ?string $savedMessage = null;
|
||||
|
||||
public function edit(int $planId): void
|
||||
{
|
||||
$plan = Plan::query()->findOrFail($planId);
|
||||
|
||||
$this->editingPlanId = $plan->id;
|
||||
$this->name = $plan->name;
|
||||
$this->monthlyPrice = number_format($plan->monthly_price_cents / 100, 2, ',', '');
|
||||
$this->yearlyPrice = number_format($plan->yearly_price_cents / 100, 2, ',', '');
|
||||
$this->quota = (string) $plan->press_release_quota;
|
||||
$this->dailyLimit = $plan->daily_limit === null ? '' : (string) $plan->daily_limit;
|
||||
$this->isActive = $plan->is_active;
|
||||
$this->sortOrder = (string) $plan->sort_order;
|
||||
$this->resetValidation();
|
||||
|
||||
Flux::modal('plan-edit')->show();
|
||||
}
|
||||
|
||||
public function save(StripePlanSyncService $stripeSync): void
|
||||
{
|
||||
// Deutsche Dezimal-Eingaben (49,00) für die numeric-Regel normalisieren.
|
||||
$this->monthlyPrice = str_replace(',', '.', trim($this->monthlyPrice));
|
||||
$this->yearlyPrice = str_replace(',', '.', trim($this->yearlyPrice));
|
||||
|
||||
$validated = $this->validate(
|
||||
[
|
||||
'name' => ['required', 'string', 'max:120'],
|
||||
'monthlyPrice' => ['required', 'numeric', 'min:0'],
|
||||
'yearlyPrice' => ['required', 'numeric', 'min:0'],
|
||||
'quota' => ['required', 'integer', 'min:0'],
|
||||
'dailyLimit' => ['nullable', 'integer', 'min:1'],
|
||||
'sortOrder' => ['required', 'integer', 'min:0'],
|
||||
],
|
||||
attributes: [
|
||||
'name' => __('Name'),
|
||||
'monthlyPrice' => __('Monatspreis'),
|
||||
'yearlyPrice' => __('Jahrespreis'),
|
||||
'quota' => __('PM-Kontingent'),
|
||||
'dailyLimit' => __('Tageslimit'),
|
||||
'sortOrder' => __('Sortierung'),
|
||||
],
|
||||
);
|
||||
|
||||
$plan = Plan::query()->findOrFail($this->editingPlanId);
|
||||
|
||||
$plan->fill([
|
||||
'name' => trim($validated['name']),
|
||||
'monthly_price_cents' => $this->toCents($validated['monthlyPrice']),
|
||||
'yearly_price_cents' => $this->toCents($validated['yearlyPrice']),
|
||||
'press_release_quota' => (int) $validated['quota'],
|
||||
'daily_limit' => $validated['dailyLimit'] === null || $validated['dailyLimit'] === '' ? null : (int) $validated['dailyLimit'],
|
||||
'is_active' => $this->isActive,
|
||||
'sort_order' => (int) $validated['sortOrder'],
|
||||
]);
|
||||
|
||||
$priceChanged = $plan->isDirty(['monthly_price_cents', 'yearly_price_cents']);
|
||||
|
||||
$plan->save();
|
||||
$stripeSync->syncAfterUpdate($plan, $plan->getChanges());
|
||||
|
||||
$this->savedMessage = $priceChanged
|
||||
? __('Tarif „:name" gespeichert. Der neue Preis gilt sofort für neue Buchungen — Bestandsabos behalten ihren bisherigen Preis.', ['name' => $plan->name])
|
||||
: __('Tarif „:name" gespeichert.', ['name' => $plan->name]);
|
||||
|
||||
Flux::modal('plan-edit')->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wandelt eine Preiseingabe (deutsches oder englisches Dezimalformat)
|
||||
* verlustfrei in Cent um.
|
||||
*/
|
||||
private function toCents(string $price): int
|
||||
{
|
||||
return (int) round(((float) str_replace(',', '.', $price)) * 100);
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'plans' => Plan::query()->orderBy('sort_order')->orderBy('id')->get(),
|
||||
'singlePmPriceCents' => (int) config('billing.single_pm_price_cents'),
|
||||
'singlePmPriceId' => config('billing.single_pm_stripe_price_id'),
|
||||
];
|
||||
}
|
||||
}; ?>
|
||||
|
||||
<div class="space-y-8">
|
||||
{{-- ============== PAGE HEADER ============== --}}
|
||||
<header class="grid items-end gap-8" style="grid-template-columns:1fr auto;">
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center gap-3 mb-3 flex-wrap">
|
||||
<span class="badge hub dot">{{ __('Admin Backend') }}</span>
|
||||
<span class="eyebrow muted">{{ __('Administration · Finanzen') }}</span>
|
||||
</div>
|
||||
<h1 class="text-[30px] font-bold tracking-[-0.6px] leading-[1.15] m-0 text-[color:var(--color-ink)]">
|
||||
{{ __('Tarife & Pakete') }}
|
||||
</h1>
|
||||
<p class="text-[13px] leading-[1.55] mt-2 m-0 max-w-[720px] text-[color:var(--color-ink-2)]">
|
||||
{{ __('Preise, Kontingente und Limits der Tarife pflegen. Änderungen erscheinen sofort auf der Buchungs-Seite und werden direkt nach Stripe synchronisiert.') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<flux:button size="sm" variant="filled" icon="credit-card" :href="route('admin.payments.index')" wire:navigate>
|
||||
{{ __('Zahlungen') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@if ($savedMessage)
|
||||
<div class="px-4 py-3 rounded-[5px] border text-[12.5px] flex items-start gap-3
|
||||
bg-[color:var(--color-ok-soft)] border-[color:var(--color-ok)]/30 text-[color:var(--color-ink-2)]">
|
||||
<flux:icon.check-circle class="size-[16px] flex-shrink-0 mt-0.5 text-[color:var(--color-ok)]" />
|
||||
<div class="flex-1">{{ $savedMessage }}</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{{-- ============== HINWEIS STRIPE-PREISLOGIK ============== --}}
|
||||
<div class="px-4 py-3 rounded-[5px] border text-[12.5px] flex items-start gap-3
|
||||
bg-[color:var(--color-hub-soft)] border-[color:var(--color-hub-soft-2)] text-[color:var(--color-ink-2)]">
|
||||
<flux:icon.information-circle class="size-[16px] flex-shrink-0 mt-0.5 text-[color:var(--color-hub)]" />
|
||||
<div class="flex-1">
|
||||
{{ __('Stripe-Preise sind unveränderlich: Eine Preisänderung legt automatisch ein neues Preis-Objekt in Stripe an und deaktiviert das alte für neue Buchungen. Laufende Abos behalten ihren bisherigen Preis. Alle Preise sind Netto-Preise — die Umsatzsteuer ergänzt Stripe Tax im Checkout.') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{-- ============== TARIF-TABELLE ============== --}}
|
||||
<article class="panel overflow-hidden">
|
||||
<div class="panel-head">
|
||||
<span class="section-eyebrow">{{ __('Tarife') }}</span>
|
||||
<span class="text-[11.5px] text-[color:var(--color-ink-3)]">
|
||||
{{ __(':count Tarife', ['count' => $plans->count()]) }}
|
||||
</span>
|
||||
</div>
|
||||
<flux:table>
|
||||
<flux:table.columns>
|
||||
<flux:table.column>{{ __('Tarif') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Monatlich (netto)') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Jährlich (netto)') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('PM-Kontingent') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Tageslimit') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Stripe') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Status') }}</flux:table.column>
|
||||
<flux:table.column></flux:table.column>
|
||||
</flux:table.columns>
|
||||
|
||||
@forelse ($plans as $plan)
|
||||
<flux:table.row wire:key="admin-plan-{{ $plan->id }}">
|
||||
<flux:table.cell>
|
||||
<div class="space-y-0.5">
|
||||
<div class="text-[13px] font-semibold text-[color:var(--color-ink)]">{{ $plan->name }}</div>
|
||||
<div class="text-[11px] text-[color:var(--color-ink-3)] font-mono">{{ $plan->slug }}</div>
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[13px] font-semibold text-[color:var(--color-ink)] tabular-nums">{{ number_format($plan->monthly_price_cents / 100, 2, ',', '.') }} €</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[13px] font-semibold text-[color:var(--color-ink)] tabular-nums">{{ number_format($plan->yearly_price_cents / 100, 2, ',', '.') }} €</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[12.5px] text-[color:var(--color-ink-2)]">{{ __(':count PM / Monat', ['count' => $plan->press_release_quota]) }}</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<span class="text-[12.5px] text-[color:var(--color-ink-2)]">{{ $plan->daily_limit ? __('max. :count / Tag', ['count' => $plan->daily_limit]) : __('ohne') }}</span>
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if ($plan->stripe_product_id && $plan->stripe_price_id_monthly && $plan->stripe_price_id_yearly)
|
||||
<span class="badge ok dot">{{ __('verknüpft') }}</span>
|
||||
@else
|
||||
<span class="badge warn dot">{{ __('nicht synchronisiert') }}</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
@if ($plan->is_active)
|
||||
<span class="badge ok">{{ __('Aktiv') }}</span>
|
||||
@else
|
||||
<span class="badge">{{ __('Inaktiv') }}</span>
|
||||
@endif
|
||||
</flux:table.cell>
|
||||
<flux:table.cell>
|
||||
<flux:button size="sm" variant="filled" icon="pencil-square" wire:click="edit({{ $plan->id }})">
|
||||
{{ __('Bearbeiten') }}
|
||||
</flux:button>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@empty
|
||||
<flux:table.row>
|
||||
<flux:table.cell colspan="8">
|
||||
<div class="px-4 py-10 text-center text-[13px] text-[color:var(--color-ink-3)]">
|
||||
{{ __('Noch keine Tarife angelegt. Der Tarif-Katalog wird über den Seeder bzw. die Migrationen befüllt.') }}
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
@endforelse
|
||||
</flux:table>
|
||||
</article>
|
||||
|
||||
{{-- ============== EINZEL-PM (KONFIGURATION) ============== --}}
|
||||
<article class="panel">
|
||||
<div class="panel-head">
|
||||
<span class="section-eyebrow">{{ __('Einzel-Pressemitteilung') }}</span>
|
||||
</div>
|
||||
<div class="p-5 flex items-start gap-3">
|
||||
<flux:icon.megaphone class="size-[16px] shrink-0 mt-0.5 text-[color:var(--color-hub)]" />
|
||||
<div class="text-[12.5px] text-[color:var(--color-ink-2)] space-y-1">
|
||||
<p class="m-0">
|
||||
{{ __('Preis: :price € netto pro Veröffentlichung.', ['price' => number_format($singlePmPriceCents / 100, 2, ',', '.')]) }}
|
||||
@if ($singlePmPriceId)
|
||||
<span class="badge ok ml-2">{{ __('Stripe verknüpft') }}</span>
|
||||
@else
|
||||
<span class="badge warn ml-2">{{ __('STRIPE_PRICE_SINGLE_PM fehlt') }}</span>
|
||||
@endif
|
||||
</p>
|
||||
<p class="m-0 text-[12px] text-[color:var(--color-ink-3)]">
|
||||
{{ __('Der Einzel-PM-Preis wird in config/billing.php bzw. über die ENV-Variable STRIPE_PRICE_SINGLE_PM gepflegt (ein fester Preis, kein Tarif). Eine Änderung erfordert „billing:sync-stripe-plans" mit geleerter ENV-Variable.') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
{{-- ============== EDIT-MODAL ============== --}}
|
||||
<flux:modal name="plan-edit" class="max-w-xl">
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('Tarif bearbeiten') }}</flux:heading>
|
||||
<flux:text class="mt-1">
|
||||
{{ __('Preisänderungen erzeugen ein neues Stripe-Preis-Objekt und gelten nur für neue Buchungen.') }}
|
||||
</flux:text>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<flux:input wire:model="name" :label="__('Name')" />
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-2">
|
||||
<flux:input wire:model="monthlyPrice" :label="__('Monatspreis (netto, €)')" inputmode="decimal" />
|
||||
<flux:input wire:model="yearlyPrice" :label="__('Jahrespreis (netto, €)')" inputmode="decimal"
|
||||
:description="__('Konzept: 10 Monatsbeiträge („2 Monate gratis").')" />
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-3">
|
||||
<flux:input wire:model="quota" type="number" min="0" :label="__('PM-Kontingent / Monat')" />
|
||||
<flux:input wire:model="dailyLimit" type="number" min="1" :label="__('Tageslimit')"
|
||||
:placeholder="__('ohne')" />
|
||||
<flux:input wire:model="sortOrder" type="number" min="0" :label="__('Sortierung')" />
|
||||
</div>
|
||||
|
||||
<flux:switch wire:model="isActive" :label="__('Tarif aktiv (buchbar und auf der Tarif-Seite sichtbar)')" />
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end gap-2">
|
||||
<flux:modal.close>
|
||||
<flux:button variant="filled">{{ __('Abbrechen') }}</flux:button>
|
||||
</flux:modal.close>
|
||||
<flux:button variant="primary" wire:click="save">
|
||||
{{ __('Speichern & mit Stripe abgleichen') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
</flux:modal>
|
||||
</div>
|
||||
|
|
@ -64,6 +64,7 @@ Route::middleware(['auth', 'verified', EnsureUserIsAdmin::class, LogSlowAdminReq
|
|||
Volt::route('admin/invoices', 'admin.invoices.index')->name('admin.invoices.index');
|
||||
Route::get('admin/legacy-invoices/{legacyInvoice}/pdf', LegacyInvoicePdfController::class)->name('admin.legacy-invoices.pdf');
|
||||
Volt::route('admin/payments', 'admin.payments.index')->name('admin.payments.index');
|
||||
Volt::route('admin/payments/plans', 'admin.payments.plans')->name('admin.payments.plans');
|
||||
Volt::route('admin/coupons', 'admin.coupons.index')->name('admin.coupons.index');
|
||||
Volt::route('admin/newsletter-sync', 'admin.newsletter.sync')->name('admin.newsletter.sync');
|
||||
|
||||
|
|
|
|||
150
tests/Feature/Billing/AdminPaymentsPageTest.php
Normal file
150
tests/Feature/Billing/AdminPaymentsPageTest.php
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\InvoiceStatus;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Plan;
|
||||
use App\Models\SinglePurchase;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Livewire\Volt\Volt as LivewireVolt;
|
||||
use Tests\TestCase;
|
||||
|
||||
beforeEach(function (): void {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
});
|
||||
|
||||
function paymentsPageAdmin(): User
|
||||
{
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
test('the payments page shows subscriptions with plan name and mrr', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['name' => 'Abo Kunde']);
|
||||
$plan = Plan::factory()->create([
|
||||
'name' => 'Business',
|
||||
'monthly_price_cents' => 4900,
|
||||
'stripe_price_id_monthly' => 'price_test_m_biz',
|
||||
]);
|
||||
subscribeUserToPlan($customer, $plan);
|
||||
|
||||
$this->actingAs(paymentsPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.index')
|
||||
->assertSee('Aktive Abos')
|
||||
->assertSee('MRR (netto)')
|
||||
->assertSee('49,00 €')
|
||||
->assertSee('Abo Kunde')
|
||||
->assertSee('Business')
|
||||
->assertSee('monatlich');
|
||||
});
|
||||
|
||||
test('a yearly subscription contributes one twelfth to the mrr', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create();
|
||||
$plan = Plan::factory()->create([
|
||||
'monthly_price_cents' => 4900,
|
||||
'yearly_price_cents' => 49000,
|
||||
'stripe_price_id_monthly' => 'price_test_m_y',
|
||||
'stripe_price_id_yearly' => 'price_test_y_y',
|
||||
]);
|
||||
subscribeUserToPlan($customer, $plan, 'yearly');
|
||||
|
||||
$this->actingAs(paymentsPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.index')
|
||||
->assertSee('40,83 €')
|
||||
->assertSee('jährlich');
|
||||
});
|
||||
|
||||
test('single purchases appear with type and status', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['name' => 'Einzel Käufer']);
|
||||
SinglePurchase::factory()->paid()->create(['user_id' => $customer->id]);
|
||||
|
||||
$this->actingAs(paymentsPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.index')
|
||||
->assertSee('Einzel Käufer')
|
||||
->assertSee('Einzel-Pressemitteilung')
|
||||
->assertSee('Bezahlt')
|
||||
->assertSee('19,00 €');
|
||||
});
|
||||
|
||||
test('local invoices appear with number and circle badge', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create();
|
||||
Invoice::factory()->create([
|
||||
'user_id' => $customer->id,
|
||||
'number' => 'STR-2026-000042',
|
||||
'status' => InvoiceStatus::Paid->value,
|
||||
'paid_at' => now(),
|
||||
'stripe_invoice_id' => 'in_test_123',
|
||||
]);
|
||||
Invoice::factory()->create([
|
||||
'user_id' => $customer->id,
|
||||
'number' => 'MAN-2026-000007',
|
||||
'status' => InvoiceStatus::Open->value,
|
||||
'stripe_invoice_id' => null,
|
||||
]);
|
||||
|
||||
$this->actingAs(paymentsPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.index')
|
||||
->assertSee('STR-2026-000042')
|
||||
->assertSee('Stripe (STR)')
|
||||
->assertSee('MAN-2026-000007')
|
||||
->assertSee('Manuell (MAN)');
|
||||
});
|
||||
|
||||
test('paid invoices of the last 30 days are summed as revenue', function () {
|
||||
/** @var TestCase $this */
|
||||
Invoice::factory()->create([
|
||||
'status' => InvoiceStatus::Paid->value,
|
||||
'paid_at' => now()->subDays(5),
|
||||
'total_cents' => 11900,
|
||||
]);
|
||||
// Außerhalb des 30-Tage-Fensters: erscheint in der Tabelle,
|
||||
// zählt aber nicht in die Umsatz-KPI (sonst stünde dort 1.118,00 €).
|
||||
Invoice::factory()->create([
|
||||
'status' => InvoiceStatus::Paid->value,
|
||||
'paid_at' => now()->subDays(60),
|
||||
'total_cents' => 99900,
|
||||
]);
|
||||
|
||||
$this->actingAs(paymentsPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.index')
|
||||
->assertSee('Umsatz 30 Tage')
|
||||
->assertSee('119,00 €')
|
||||
->assertDontSee('1.118,00 €');
|
||||
});
|
||||
|
||||
test('the search filters all panels by user name or email', function () {
|
||||
/** @var TestCase $this */
|
||||
$match = User::factory()->create(['name' => 'Maria Treffer']);
|
||||
$other = User::factory()->create(['name' => 'Olaf Anders']);
|
||||
SinglePurchase::factory()->paid()->create(['user_id' => $match->id]);
|
||||
SinglePurchase::factory()->paid()->create(['user_id' => $other->id]);
|
||||
|
||||
$this->actingAs(paymentsPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.index')
|
||||
->set('search', 'Maria')
|
||||
->assertSee('Maria Treffer')
|
||||
->assertDontSee('Olaf Anders');
|
||||
});
|
||||
|
||||
test('the payments page is not accessible for customers', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
|
||||
$this->actingAs($customer)
|
||||
->get(route('admin.payments.index'))
|
||||
->assertForbidden();
|
||||
});
|
||||
159
tests/Feature/Billing/AdminPlansPageTest.php
Normal file
159
tests/Feature/Billing/AdminPlansPageTest.php
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Services\Billing\StripePlanSyncService;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Livewire\Volt\Volt as LivewireVolt;
|
||||
use Tests\TestCase;
|
||||
|
||||
beforeEach(function (): void {
|
||||
/** @var TestCase $this */
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
});
|
||||
|
||||
function plansPageAdmin(): User
|
||||
{
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
$admin->assignRole('admin');
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
test('the plans page lists active and inactive plans with prices', function () {
|
||||
/** @var TestCase $this */
|
||||
Plan::factory()->create([
|
||||
'name' => 'Business',
|
||||
'monthly_price_cents' => 4900,
|
||||
'yearly_price_cents' => 49000,
|
||||
'press_release_quota' => 10,
|
||||
'daily_limit' => 2,
|
||||
'stripe_product_id' => 'prod_test',
|
||||
'stripe_price_id_monthly' => 'price_test_m',
|
||||
'stripe_price_id_yearly' => 'price_test_y',
|
||||
]);
|
||||
Plan::factory()->inactive()->create(['name' => 'Altpaket']);
|
||||
|
||||
$this->actingAs(plansPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.plans')
|
||||
->assertSee('Tarife & Pakete')
|
||||
->assertSee('Business')
|
||||
->assertSee('49,00 €')
|
||||
->assertSee('490,00 €')
|
||||
->assertSee('10 PM / Monat')
|
||||
->assertSee('max. 2 / Tag')
|
||||
->assertSee('verknüpft')
|
||||
->assertSee('Altpaket')
|
||||
->assertSee('Inaktiv');
|
||||
});
|
||||
|
||||
test('a plan without stripe ids is marked as unsynced', function () {
|
||||
/** @var TestCase $this */
|
||||
Plan::factory()->create(['name' => 'Neu', 'stripe_product_id' => null]);
|
||||
|
||||
$this->actingAs(plansPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.plans')
|
||||
->assertSee('nicht synchronisiert');
|
||||
});
|
||||
|
||||
test('saving a plan updates the local record and triggers the stripe sync', function () {
|
||||
/** @var TestCase $this */
|
||||
$plan = Plan::factory()->create([
|
||||
'name' => 'Business',
|
||||
'monthly_price_cents' => 4900,
|
||||
'yearly_price_cents' => 49000,
|
||||
'press_release_quota' => 10,
|
||||
'daily_limit' => null,
|
||||
]);
|
||||
|
||||
$this->mock(StripePlanSyncService::class, function ($mock) use ($plan) {
|
||||
$mock->shouldReceive('syncAfterUpdate')
|
||||
->once()
|
||||
->withArgs(function (Plan $synced, array $changes) use ($plan): bool {
|
||||
return $synced->is($plan)
|
||||
&& array_key_exists('monthly_price_cents', $changes)
|
||||
&& array_key_exists('name', $changes);
|
||||
});
|
||||
});
|
||||
|
||||
$this->actingAs(plansPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.plans')
|
||||
->call('edit', $plan->id)
|
||||
->set('name', 'Business Plus')
|
||||
->set('monthlyPrice', '59,00')
|
||||
->set('yearlyPrice', '590')
|
||||
->set('quota', '15')
|
||||
->set('dailyLimit', '3')
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Bestandsabos behalten ihren bisherigen Preis');
|
||||
|
||||
$plan->refresh();
|
||||
|
||||
expect($plan->name)->toBe('Business Plus')
|
||||
->and($plan->monthly_price_cents)->toBe(5900)
|
||||
->and($plan->yearly_price_cents)->toBe(59000)
|
||||
->and($plan->press_release_quota)->toBe(15)
|
||||
->and($plan->daily_limit)->toBe(3);
|
||||
});
|
||||
|
||||
test('saving without a price change shows the plain success message', function () {
|
||||
/** @var TestCase $this */
|
||||
$plan = Plan::factory()->create([
|
||||
'name' => 'Starter',
|
||||
'monthly_price_cents' => 2900,
|
||||
'yearly_price_cents' => 29000,
|
||||
'daily_limit' => 1,
|
||||
]);
|
||||
|
||||
$this->mock(StripePlanSyncService::class, function ($mock) {
|
||||
$mock->shouldReceive('syncAfterUpdate')->once();
|
||||
});
|
||||
|
||||
$this->actingAs(plansPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.plans')
|
||||
->call('edit', $plan->id)
|
||||
->set('quota', '5')
|
||||
->set('dailyLimit', '')
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertSee('Tarif „Starter" gespeichert.')
|
||||
->assertDontSee('Bestandsabos behalten');
|
||||
|
||||
$plan->refresh();
|
||||
|
||||
expect($plan->press_release_quota)->toBe(5)
|
||||
->and($plan->daily_limit)->toBeNull();
|
||||
});
|
||||
|
||||
test('invalid prices are rejected with validation errors', function () {
|
||||
/** @var TestCase $this */
|
||||
$plan = Plan::factory()->create();
|
||||
|
||||
$this->mock(StripePlanSyncService::class, function ($mock) {
|
||||
$mock->shouldNotReceive('syncAfterUpdate');
|
||||
});
|
||||
|
||||
$this->actingAs(plansPageAdmin());
|
||||
|
||||
LivewireVolt::test('admin.payments.plans')
|
||||
->call('edit', $plan->id)
|
||||
->set('monthlyPrice', '-5')
|
||||
->set('quota', 'abc')
|
||||
->call('save')
|
||||
->assertHasErrors(['monthlyPrice', 'quota']);
|
||||
});
|
||||
|
||||
test('the plans page is not accessible for customers', function () {
|
||||
/** @var TestCase $this */
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
|
||||
$this->actingAs($customer)
|
||||
->get(route('admin.payments.plans'))
|
||||
->assertForbidden();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue