CluPilotCloud/app/Livewire/ConfirmBookStorage.php

63 lines
2.3 KiB
PHP

<?php
namespace App\Livewire;
use App\Livewire\Concerns\ResolvesCustomer;
use App\Services\Billing\AddonCatalogue;
use App\Services\Billing\CustomDomainAccess;
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
{
use ResolvesCustomer;
public int $packs = 1;
public int $packGb = 0;
public function mount(int $packs = 1): void
{
$catalogue = app(AddonCatalogue::class);
// Der eigene Vertrag, aufgelöst wie in jedem anderen Bestätigungs-Modal
// (siehe ConfirmCancelAddon, ConfirmRevokeSeat) — nicht aus dem Markup
// übernommen, denn ein Modal ist ohne die Middleware der Seite
// erreichbar. Dieselbe Auflösung, die Billing::purchase() nachher
// tatsächlich bucht (CustomDomainAccess::contractOf()): sonst könnte
// der Dialog eine Zahl versprechen, die die Aktion nicht einhält.
$subscription = app(CustomDomainAccess::class)->contractOf($this->customer());
// Geklemmt an der tatsächlich noch buchbaren Menge, nicht an der
// absoluten Grenze: ein Vertrag, der schon einen Block hält, darf im
// Dialog nicht mehr versprechen, als purchase() nachher wirklich in
// den Warenkorb legt.
$max = $catalogue->bookableQuantity($subscription, AddonCatalogue::STORAGE);
$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');
}
}