2024-02-08 19:55:35 +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;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
2024-02-12 18:55:03 +01:00
|
|
|
use App\Livewire\BillingPortal\Cart\Cart;
|
2024-02-08 19:55:35 +01:00
|
|
|
use App\Models\Subscription;
|
|
|
|
use Livewire\Attributes\Computed;
|
|
|
|
use Livewire\Attributes\On;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Purchase extends Component
|
|
|
|
{
|
|
|
|
public Subscription $subscription;
|
|
|
|
|
|
|
|
public string $db;
|
|
|
|
|
2024-02-09 17:53:38 +01:00
|
|
|
public array $request_data;
|
|
|
|
|
2024-02-12 18:55:03 +01:00
|
|
|
public string $hash;
|
|
|
|
|
2024-02-09 17:53:38 +01:00
|
|
|
public ?string $campaign;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
2024-02-08 19:55:35 +01:00
|
|
|
public int $step = 0;
|
|
|
|
|
|
|
|
public array $steps = [
|
|
|
|
Setup::class,
|
2024-02-12 18:55:03 +01:00
|
|
|
Cart::class,
|
2024-02-08 19:55:35 +01:00
|
|
|
Authentication::class,
|
2024-02-13 18:57:13 +01:00
|
|
|
RFF::class,
|
2024-02-08 19:55:35 +01:00
|
|
|
Example::class,
|
|
|
|
];
|
|
|
|
|
|
|
|
public array $context = [];
|
|
|
|
|
|
|
|
#[On('purchase.context')]
|
2024-02-12 18:55:03 +01:00
|
|
|
public function handleContext(string $property, $value): self
|
2024-02-08 19:55:35 +01:00
|
|
|
{
|
|
|
|
$this->context[$property] = $value;
|
2024-02-12 18:55:03 +01:00
|
|
|
|
|
|
|
// The following may not be needed, as we can pass arround $context.
|
|
|
|
// cache()->set($this->hash, $this->context);
|
|
|
|
|
|
|
|
return $this;
|
2024-02-08 19:55:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[On('purchase.next')]
|
|
|
|
public function handleNext(): void
|
|
|
|
{
|
|
|
|
if ($this->step < count($this->steps) - 1) {
|
|
|
|
$this->step++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[On('purchase.forward')]
|
|
|
|
public function handleForward(string $component): void
|
|
|
|
{
|
|
|
|
$this->step = array_search($component, $this->steps);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Computed()]
|
|
|
|
public function component(): string
|
|
|
|
{
|
|
|
|
return $this->steps[$this->step];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
MultiDB::setDb($this->db);
|
|
|
|
|
2024-02-12 18:55:03 +01:00
|
|
|
$this
|
|
|
|
->handleContext('hash', $this->hash)
|
|
|
|
->handleContext('quantity', 1)
|
|
|
|
->handleContext('request_data', $this->request_data)
|
|
|
|
->handleContext('campaign', $this->campaign);
|
2024-02-08 19:55:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('billing-portal.v3.purchase');
|
|
|
|
}
|
|
|
|
}
|