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-15 19:33:07 +01:00
|
|
|
use App\Livewire\BillingPortal\Payments\Methods;
|
2024-02-08 19:55:35 +01:00
|
|
|
use App\Models\Subscription;
|
|
|
|
use Livewire\Attributes\Computed;
|
|
|
|
use Livewire\Attributes\On;
|
|
|
|
use Livewire\Component;
|
2024-02-14 18:29:48 +01:00
|
|
|
use Illuminate\Support\Str;
|
2024-02-08 19:55:35 +01:00
|
|
|
|
|
|
|
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-15 19:33:07 +01:00
|
|
|
Methods::class,
|
2024-02-22 14:07:15 +01:00
|
|
|
RFF::class,
|
2024-02-19 18:16:44 +01:00
|
|
|
Submit::class,
|
2024-02-08 19:55:35 +01:00
|
|
|
];
|
|
|
|
|
2024-02-14 18:29:48 +01:00
|
|
|
public string $id;
|
|
|
|
|
2024-02-17 01:15:55 +01:00
|
|
|
/** $context = [
|
|
|
|
* 'hash' => string,
|
|
|
|
* 'quantity' => int,
|
|
|
|
* 'request_data' => [
|
|
|
|
* 'q' => string,
|
|
|
|
* ],
|
|
|
|
* 'campaign => ?string,
|
|
|
|
* 'bundle' => $bundle,
|
|
|
|
* 'contact' => [
|
|
|
|
* 'first_name' => ?string,
|
|
|
|
* 'last_name' => ?string,
|
|
|
|
* 'phone' => ?string,
|
|
|
|
* 'custom_value1' => ?string,
|
|
|
|
* 'custom_value2' => ?string,
|
|
|
|
* 'custom_value3' => ?string,
|
|
|
|
* 'custom_value4' => ?string,
|
|
|
|
* 'email' => ?string,
|
|
|
|
* 'email_verified_at' => ?int,
|
|
|
|
* 'confirmation_code' => ?string,
|
|
|
|
* 'is_primary' => bool,
|
|
|
|
* 'confirmed' => bool,
|
|
|
|
* 'last_login' => ?datetime,
|
|
|
|
* 'failed_logins' => ?int,
|
|
|
|
* 'accepted_terms_version' => ?string,
|
|
|
|
* 'avatar' => ?string,
|
|
|
|
* 'avatar_type' => ?string,
|
|
|
|
* 'avatar_size' => ?string,
|
|
|
|
* 'is_locked' => bool,
|
|
|
|
* 'send_email' => bool,
|
|
|
|
* 'contact_key' => string,
|
|
|
|
* 'created_at' => int,
|
|
|
|
* 'updated_at' => int,
|
|
|
|
* 'deleted_at' => int,
|
|
|
|
* 'hashed_id' => string,
|
|
|
|
* ],
|
|
|
|
* 'client_id' => string,
|
|
|
|
* 'quantity' => int,
|
|
|
|
* 'products' => [
|
|
|
|
* [
|
|
|
|
* 'product_key' => string,
|
|
|
|
* 'quantity' => int,
|
|
|
|
* 'total_raw' => float,
|
|
|
|
* 'total' => string,
|
|
|
|
* ],
|
|
|
|
* ]
|
|
|
|
* ];
|
|
|
|
*
|
|
|
|
* $bundle =[
|
|
|
|
* 'optional_one_time_products' => array,
|
|
|
|
* 'one_time_products' => array,
|
|
|
|
* 'optional_recurring_products' => array,
|
|
|
|
* 'recurring_products' => [
|
|
|
|
* 'hashed_id' => [
|
|
|
|
* 'product' => [
|
|
|
|
* 'id' => int,
|
|
|
|
* 'company_id' => int,
|
|
|
|
* 'user_id' => int,
|
|
|
|
* 'assigned_user_id' => ?int,
|
|
|
|
* 'project_id' => ?int,
|
|
|
|
* 'vendor_id' => ?int,
|
|
|
|
* 'custom_value1' => ?string,
|
|
|
|
* 'custom_value2' => ?string,
|
|
|
|
* 'custom_value3' => ?string,
|
|
|
|
* 'custom_value4' => ?string,
|
|
|
|
* 'product_key' => ?string,
|
|
|
|
* 'notes' => ?string,
|
|
|
|
* 'cost' => float,
|
|
|
|
* 'price' => float,
|
|
|
|
* 'quantity' => float,
|
|
|
|
* 'tax_name1' => ?string,
|
|
|
|
* 'tax_rate1' => float,
|
|
|
|
* 'tax_name2' => ?string,
|
|
|
|
* 'tax_rate2' => float,
|
|
|
|
* 'tax_name3' => ?string,
|
|
|
|
* 'tax_rate3' => float,
|
|
|
|
* 'deleted_at' => ?int,
|
|
|
|
* 'created_at' => ?int,
|
|
|
|
* 'updated_at' => ?int,
|
|
|
|
* 'is_deleted' => bool,
|
|
|
|
* 'in_stock_quantity' => ?int,
|
|
|
|
* 'stock_notification' => bool,
|
|
|
|
* 'stock_notification_threshold' => ?int,
|
|
|
|
* 'max_quantity' => ?int,
|
|
|
|
* 'product_image' => ?string,
|
|
|
|
* 'tax_id' => ?int,
|
|
|
|
* 'hashed_id' => ?string,
|
|
|
|
* ],
|
|
|
|
* ],
|
|
|
|
* ],
|
|
|
|
* ] $bundle
|
|
|
|
*/
|
2024-02-08 19:55:35 +01:00
|
|
|
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
|
|
|
{
|
2024-02-16 17:42:26 +01:00
|
|
|
$clone = $this->context;
|
|
|
|
|
2024-02-14 18:29:48 +01:00
|
|
|
data_set($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);
|
|
|
|
|
2024-02-16 17:42:26 +01:00
|
|
|
if ($clone !== $this->context) {
|
|
|
|
$this->id = Str::uuid();
|
|
|
|
}
|
2024-02-14 18:29:48 +01:00
|
|
|
|
2024-02-12 18:55:03 +01:00
|
|
|
return $this;
|
2024-02-08 19:55:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[On('purchase.next')]
|
|
|
|
public function handleNext(): void
|
|
|
|
{
|
2024-02-22 04:00:39 +01:00
|
|
|
|
2024-02-08 19:55:35 +01:00
|
|
|
if ($this->step < count($this->steps) - 1) {
|
|
|
|
$this->step++;
|
|
|
|
}
|
2024-02-14 18:29:48 +01:00
|
|
|
|
|
|
|
$this->id = Str::uuid();
|
2024-02-08 19:55:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[On('purchase.forward')]
|
|
|
|
public function handleForward(string $component): void
|
|
|
|
{
|
|
|
|
$this->step = array_search($component, $this->steps);
|
2024-02-14 18:29:48 +01:00
|
|
|
|
|
|
|
$this->id = Str::uuid();
|
2024-02-08 19:55:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[Computed()]
|
|
|
|
public function component(): string
|
|
|
|
{
|
|
|
|
return $this->steps[$this->step];
|
|
|
|
}
|
|
|
|
|
2024-02-16 17:42:26 +01:00
|
|
|
#[Computed()]
|
|
|
|
public function componentUniqueId(): string
|
|
|
|
{
|
|
|
|
return "purchase-{$this->id}";
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Computed()]
|
|
|
|
public function summaryUniqueId(): string
|
|
|
|
{
|
|
|
|
return "summary-{$this->id}";
|
|
|
|
}
|
|
|
|
|
2024-02-08 19:55:35 +01:00
|
|
|
public function mount()
|
|
|
|
{
|
2024-02-14 18:29:48 +01:00
|
|
|
$this->id = Str::uuid();
|
|
|
|
|
2024-02-08 19:55:35 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|