CluPilotCloud/app/Livewire/ConfirmBookStorage.php

50 lines
1.5 KiB
PHP

<?php
namespace App\Livewire;
use App\Services\Billing\AddonCatalogue;
use LivewireUI\Modal\ModalComponent;
/**
* Confirmation before several storage packs go into the cart at once (R23).
*
* The offer comes from a card that has just told the customer their downgrade is
* blocked, and it answers with a recurring charge — three packs is thirty euros
* a month, every month, until they cancel them. That is not something a stray
* click on a card about SAVING money should do, and the dialog that says so is
* drawn by this product rather than by the browser.
*
* No mutation here. Billing::bookStoragePacks() keeps the work and the customer
* resolution it already had; this only says yes, with the number it was opened
* for.
*/
class ConfirmBookStorage extends ModalComponent
{
public int $packs = 1;
public int $packGb = 0;
public function mount(int $packs = 1): void
{
$catalogue = app(AddonCatalogue::class);
$max = $catalogue->maxQuantity(AddonCatalogue::STORAGE) ?? 50;
// Geklemmt wie bisher, nur an der kaufmännischen Grenze statt an einer
// erfundenen: ein Modal wird mit Argumenten aus der Seite geöffnet, und
// eine Seite ist Markup.
$this->packs = max(1, min($max, $packs));
$this->packGb = $catalogue->packGb();
}
public function proceed(): void
{
$this->dispatch('storage-packs-confirmed', packs: $this->packs);
$this->closeModal();
}
public function render()
{
return view('livewire.confirm-book-storage');
}
}