amounts = $this->plans() ->mapWithKeys(fn (array $plan): array => [ $plan['key'] => self::formatMajorUnits(Organization::planAmount($plan['key'])), ]) ->all(); } /** * The price of each configured plan, keyed by plan, in major units so that * it can be edited and shown as an administrator typed it. * * @var array */ public array $amounts = []; /** * Get every configured plan, including any that cannot be sold yet, so a * price can be set before the Stripe price is in place. * * @return Collection */ #[Computed] public function plans(): Collection { $configured = config('plans.plans'); $available = Organization::availablePlans(); if (! is_array($configured)) { return collect(); } return collect($configured)->map(function ($plan, string $key) use ($available): array { $plan = is_array($plan) ? $plan : []; return [ 'key' => $key, 'name' => is_string($plan['name'] ?? null) ? $plan['name'] : $key, 'interval' => is_string($plan['interval'] ?? null) ? $plan['interval'] : 'month', 'purchasable' => array_key_exists($key, $available), ]; }); } public function saveAmounts(): void { Gate::authorize('accessAdmin'); $validated = $this->validate([ 'amounts' => ['required', 'array'], 'amounts.*' => ['required', 'numeric', 'min:0', 'decimal:0,2'], ]); foreach ($validated['amounts'] as $key => $amount) { Setting::put(Setting::planAmountKey($key), (string) Setting::toMinorUnits((string) $amount)); } unset($this->plans); Flux::toast(variant: 'success', text: __('Plan pricing updated.')); } /** * Render a stored amount, in minor units, as the major units an * administrator edits it in. */ protected static function formatMajorUnits(int $amount): string { return intdiv($amount, 100).'.'.str_pad((string) ($amount % 100), 2, '0', STR_PAD_LEFT); } }; ?>
{{ __('Plan pricing') }} {{ __('Set the price shown for each plan on the pricing page and at signup.') }}
@if ($this->plans->isEmpty()) {{ __('No plans are configured.') }} @else
@foreach ($this->plans as $plan) {{ $plan['name'] }} {{ __('Billed every :interval.', ['interval' => $plan['interval']]) }} @unless ($plan['purchasable']) {{ __('This plan is not on sale yet, because it has no Stripe price configured.') }} @endunless @endforeach
{{ __('Save') }}
@endif