CluPilotCloud/app/Livewire/ConfirmWithdraw.php

53 lines
2.0 KiB
PHP

<?php
namespace App\Livewire;
use App\Livewire\Concerns\ResolvesCustomer;
use App\Services\Billing\CustomDomainAccess;
use App\Services\Billing\WithdrawalRight;
use LivewireUI\Modal\ModalComponent;
/**
* Confirmation before a consumer withdraws from their contract (R23).
*
* The heaviest button in the portal: it ends the cloud the same afternoon, takes
* the address down and sends the money back, and none of that can be undone by
* clicking again. So it is confirmed in a dialog this product draws rather than
* one the browser does.
*
* The figures are read again here, not handed in from the page. A modal is
* opened with arguments from markup, and markup is not evidence — a dialog that
* says "37,00 € kommen zurück" has to have worked that out from the contract it
* is about, or it is a promise nobody made.
*
* No mutation here. Settings::withdraw() keeps the work and its own server-side
* refusal; the confirm button only says yes.
*/
class ConfirmWithdraw extends ModalComponent
{
use ResolvesCustomer;
public function proceed(): void
{
$this->dispatch('withdrawal-confirmed');
$this->closeModal();
}
public function render()
{
$contract = app(CustomDomainAccess::class)->contractOf($this->customer());
$right = WithdrawalRight::for($contract);
return view('livewire.confirm-withdraw', [
'right' => $right,
// What they would owe for the days the cloud has already run, and
// therefore what does NOT come back. Zero where the express request
// to start at once was never given — then the whole amount returns,
// and the dialog says so.
'owedNetCents' => $contract === null ? 0 : WithdrawalRight::owedNetCents($contract),
'deliveredDays' => $contract === null ? 0 : WithdrawalRight::deliveredDays($contract),
'termDays' => $contract === null ? 0 : WithdrawalRight::termDays($contract),
]);
}
}