2024-06-27 02:29:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Livewire\Flow2;
|
|
|
|
|
2024-07-05 07:13:38 +02:00
|
|
|
use App\Utils\Traits\WithSecureContext;
|
2024-06-27 02:29:36 +02:00
|
|
|
use Livewire\Component;
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
|
|
|
|
class PaymentMethod extends Component
|
|
|
|
{
|
2024-07-05 07:13:38 +02:00
|
|
|
use WithSecureContext;
|
2024-06-27 02:29:36 +02:00
|
|
|
|
2024-07-05 07:13:38 +02:00
|
|
|
public $invoice;
|
2024-06-27 02:29:36 +02:00
|
|
|
|
|
|
|
public $variables;
|
|
|
|
|
2024-07-02 00:20:10 +02:00
|
|
|
public $methods = [];
|
|
|
|
|
2024-07-02 07:06:45 +02:00
|
|
|
public $isLoading = true;
|
2024-07-02 00:20:10 +02:00
|
|
|
|
2024-07-02 09:09:46 +02:00
|
|
|
public $amount = 0;
|
|
|
|
|
2024-07-09 04:02:54 +02:00
|
|
|
public function placeholder()
|
2024-07-02 07:06:45 +02:00
|
|
|
{
|
|
|
|
return <<<'HTML'
|
|
|
|
<div class="flex items-center justify-center min-h-screen">
|
|
|
|
<svg class="animate-spin h-10 w-10 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
|
|
|
|
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
|
|
|
|
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
2024-07-05 07:13:38 +02:00
|
|
|
</svg>
|
2024-07-02 07:06:45 +02:00
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
}
|
2024-07-02 00:20:10 +02:00
|
|
|
|
2024-07-09 04:02:54 +02:00
|
|
|
public function handleSelect(string $company_gateway_id, string $gateway_type_id, string $amount)
|
2024-06-27 02:29:36 +02:00
|
|
|
{
|
2024-07-09 04:02:54 +02:00
|
|
|
$this->isLoading = true;
|
|
|
|
|
|
|
|
$this->dispatch(
|
|
|
|
event: 'payment-method-selected',
|
|
|
|
company_gateway_id: $company_gateway_id,
|
|
|
|
gateway_type_id: $gateway_type_id,
|
|
|
|
amount: $amount,
|
|
|
|
);
|
|
|
|
}
|
2024-07-02 07:06:45 +02:00
|
|
|
|
2024-07-09 04:02:54 +02:00
|
|
|
public function mount()
|
|
|
|
{
|
2024-07-05 07:13:38 +02:00
|
|
|
$this->variables = $this->getContext()['variables'];
|
|
|
|
$this->amount = array_sum(array_column($this->getContext()['payable_invoices'], 'amount'));
|
2024-07-02 10:32:14 +02:00
|
|
|
|
2024-07-05 07:13:38 +02:00
|
|
|
MultiDB::setDb($this->getContext()['db']);
|
2024-07-02 00:20:10 +02:00
|
|
|
|
2024-07-05 07:13:38 +02:00
|
|
|
$this->methods = $this->getContext()['invitation']->contact->client->service()->getPaymentMethods($this->amount);
|
2024-07-02 00:20:10 +02:00
|
|
|
|
2024-07-09 04:02:54 +02:00
|
|
|
if (count($this->methods) == 1) {
|
2024-07-02 09:09:46 +02:00
|
|
|
$this->dispatch('singlePaymentMethodFound', company_gateway_id: $this->methods[0]['company_gateway_id'], gateway_type_id: $this->methods[0]['gateway_type_id'], amount: $this->amount);
|
2024-07-09 04:02:54 +02:00
|
|
|
} else {
|
2024-07-02 07:06:45 +02:00
|
|
|
$this->isLoading = false;
|
|
|
|
$this->dispatch('loadingCompleted');
|
|
|
|
}
|
2024-07-02 06:54:50 +02:00
|
|
|
}
|
2024-07-02 00:20:10 +02:00
|
|
|
|
2024-07-05 07:13:38 +02:00
|
|
|
public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
|
|
{
|
|
|
|
return render('flow2.payment-method', ['methods' => $this->methods]);
|
2024-06-27 02:29:36 +02:00
|
|
|
}
|
|
|
|
}
|