From f3f91f75b827c9bd6c0fc9ba878cccf88bcdee37 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 17 Feb 2024 11:15:55 +1100 Subject: [PATCH] Updates for logic --- .../BillingPortal/Payments/Methods.php | 14 +-- app/Livewire/BillingPortal/Purchase.php | 91 +++++++++++++++++++ app/Livewire/BillingPortal/Summary.php | 3 +- .../Subscription/SubscriptionCalculator.php | 4 +- 4 files changed, 101 insertions(+), 11 deletions(-) diff --git a/app/Livewire/BillingPortal/Payments/Methods.php b/app/Livewire/BillingPortal/Payments/Methods.php index d7b75781dfd9..e5e969a9c5ef 100644 --- a/app/Livewire/BillingPortal/Payments/Methods.php +++ b/app/Livewire/BillingPortal/Payments/Methods.php @@ -37,8 +37,10 @@ class Methods extends Component public function handleSelect(string $company_gateway_id, string $gateway_type_id) { - - $this->dispatch('purchase.context', property: 'client_id', value: auth()->guard('contact')->user()->client->hashed_id); + /** @var \App\Models\ClientContact $contact */ + $contact = auth()->guard('contact')->user(); + + $this->dispatch('purchase.context', property: 'client_id', value: $contact->client->hashed_id); nlog($this->context); @@ -50,12 +52,10 @@ class Methods extends Component ->adjustInventory() ->save(); - - - Cache::put($this->hash, [ + Cache::put($this->context['hash'], [ 'subscription_id' => $this->subscription->hashed_id, - 'email' => auth()->guard('contact')->user()->email, - 'client_id' => auth()->guard('contact')->user()->client->hashed_id, + 'email' => $contact->email, + 'client_id' => $contact->client->hashed_id, 'invoice_id' => $invoice->hashed_id, 'context' => 'purchase', 'campaign' => $this->context['campaign'], diff --git a/app/Livewire/BillingPortal/Purchase.php b/app/Livewire/BillingPortal/Purchase.php index 96762313a13a..7f6e1a1ab4ce 100644 --- a/app/Livewire/BillingPortal/Purchase.php +++ b/app/Livewire/BillingPortal/Purchase.php @@ -47,6 +47,97 @@ class Purchase extends Component public string $id; + /** $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 + */ public array $context = []; #[On('purchase.context')] diff --git a/app/Livewire/BillingPortal/Summary.php b/app/Livewire/BillingPortal/Summary.php index cfe9cb590b13..fdd0076c4036 100644 --- a/app/Livewire/BillingPortal/Summary.php +++ b/app/Livewire/BillingPortal/Summary.php @@ -133,7 +133,8 @@ class Summary extends Component if (isset($this->context['bundle']) === false) { return []; } - + $products = []; + foreach ($this->context['bundle']['recurring_products'] as $key => $item) { $products[] = [ 'product_key' => $item['product']['product_key'], diff --git a/app/Services/Subscription/SubscriptionCalculator.php b/app/Services/Subscription/SubscriptionCalculator.php index b7b7e37eec53..be968dba1452 100644 --- a/app/Services/Subscription/SubscriptionCalculator.php +++ b/app/Services/Subscription/SubscriptionCalculator.php @@ -35,7 +35,6 @@ class SubscriptionCalculator { $invoice_repo = new InvoiceRepository(); - $subscription_repo = new SubscriptionRepository(); $invoice = InvoiceFactory::create($this->subscription->company_id, $this->subscription->user_id); $invoice->subscription_id = $this->subscription->id; @@ -55,8 +54,7 @@ class SubscriptionCalculator /** * Build Line Items - * - * @param array $context + * @param array $context * @return array */ private function buildItems(array $context): array