1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 14:42:42 +01:00
invoiceninja/app/Livewire/BillingPortal/Payments/Methods.php
2024-02-19 17:52:07 +01:00

82 lines
2.2 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Livewire\BillingPortal\Payments;
use App\Livewire\BillingPortal\Authentication;
use Livewire\Component;
use App\Models\Subscription;
use Illuminate\Support\Facades\Cache;
class Methods extends Component
{
public Subscription $subscription;
public array $context;
public array $methods;
public function mount(): void
{
if (auth()->guard('contact')->guest()) {
$this->dispatch('purchase.forward', component: Authentication::class);
return;
}
$total = collect($this->context['products'])->sum('total_raw');
$methods = auth()->guard('contact')->user()->client->service()->getPaymentMethods(
$total,
);
$this->methods = $methods;
}
public function handleSelect(string $company_gateway_id, string $gateway_type_id)
{
/** @var \App\Models\ClientContact $contact */
$contact = auth()->guard('contact')->user();
$this->dispatch('purchase.context', property: 'client_id', value: $contact->client->hashed_id);
$this->context['client_id'] = $contact->client->hashed_id;
nlog($this->context);
$invoice = $this->subscription
->calc()
->buildPurchaseInvoice($this->context)
->service()
->fillDefaults()
->adjustInventory()
->save();
Cache::put($this->context['hash'], [
'subscription_id' => $this->subscription->hashed_id,
'email' => $contact->email,
'client_id' => $contact->client->hashed_id,
'invoice_id' => $invoice->hashed_id,
'context' => 'purchase',
'campaign' => $this->context['campaign'],
'bundle' => $this->context['bundle'],
], now()->addMinutes(60));
}
public function render()
{
return view('billing-portal.v3.payments.methods');
}
}