2024-02-15 19:33:34 +01:00
|
|
|
<?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 Livewire\Component;
|
2024-02-17 00:09:59 +01:00
|
|
|
use App\Models\Subscription;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
2024-02-15 19:33:34 +01:00
|
|
|
|
|
|
|
class Methods extends Component
|
|
|
|
{
|
|
|
|
public Subscription $subscription;
|
|
|
|
|
|
|
|
public array $context;
|
|
|
|
|
|
|
|
public array $methods;
|
|
|
|
|
|
|
|
public function mount(): void
|
|
|
|
{
|
|
|
|
$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)
|
|
|
|
{
|
2024-02-17 01:15:55 +01:00
|
|
|
/** @var \App\Models\ClientContact $contact */
|
|
|
|
$contact = auth()->guard('contact')->user();
|
2024-02-19 18:16:37 +01:00
|
|
|
|
2024-02-17 01:15:55 +01:00
|
|
|
$this->dispatch('purchase.context', property: 'client_id', value: $contact->client->hashed_id);
|
2024-02-19 18:16:37 +01:00
|
|
|
|
2024-02-19 17:52:07 +01:00
|
|
|
$this->context['client_id'] = $contact->client->hashed_id;
|
|
|
|
|
2024-02-17 00:09:59 +01:00
|
|
|
$invoice = $this->subscription
|
2024-02-19 18:16:37 +01:00
|
|
|
->calc()
|
|
|
|
->buildPurchaseInvoice($this->context)
|
|
|
|
->service()
|
2024-02-20 06:05:00 +01:00
|
|
|
->markSent()
|
2024-02-19 18:16:37 +01:00
|
|
|
->fillDefaults()
|
|
|
|
->adjustInventory()
|
|
|
|
->save();
|
|
|
|
|
2024-02-17 01:15:55 +01:00
|
|
|
Cache::put($this->context['hash'], [
|
2024-02-17 00:09:59 +01:00
|
|
|
'subscription_id' => $this->subscription->hashed_id,
|
2024-02-17 01:15:55 +01:00
|
|
|
'email' => $contact->email,
|
|
|
|
'client_id' => $contact->client->hashed_id,
|
2024-02-17 00:09:59 +01:00
|
|
|
'invoice_id' => $invoice->hashed_id,
|
|
|
|
'context' => 'purchase',
|
|
|
|
'campaign' => $this->context['campaign'],
|
|
|
|
'bundle' => $this->context['bundle'],
|
|
|
|
], now()->addMinutes(60));
|
|
|
|
|
2024-02-19 18:16:37 +01:00
|
|
|
$payable_amount = $invoice->partial > 0
|
|
|
|
? \App\Utils\Number::formatValue($invoice->partial, $invoice->client->currency())
|
|
|
|
: \App\Utils\Number::formatValue($invoice->balance, $invoice->client->currency());
|
|
|
|
|
|
|
|
$this->dispatch('purchase.context', property: 'form.company_gateway_id', value: $company_gateway_id);
|
|
|
|
$this->dispatch('purchase.context', property: 'form.payment_method_id', value: $gateway_type_id);
|
|
|
|
$this->dispatch('purchase.context', property: 'form.invoice_hashed_id', value: $invoice->hashed_id);
|
|
|
|
$this->dispatch('purchase.context', property: 'form.payable_amount', value: $payable_amount);
|
2024-02-17 00:09:59 +01:00
|
|
|
|
2024-02-19 18:16:37 +01:00
|
|
|
$this->dispatch('purchase.next');
|
2024-02-15 19:33:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('billing-portal.v3.payments.methods');
|
|
|
|
}
|
|
|
|
}
|