From 546619a4987cdd6872123d08c0fe19f9f2898a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 13:24:58 +0100 Subject: [PATCH 01/10] Wrap quantity if per_seat_enabled --- .../billing-portal-purchase.blade.php | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index 5b2420d63997..e548b1a2c65c 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -20,25 +20,27 @@ @endif -
- {{ ctrans('texts.qty') }} - - - -
+ @if($billing_subscription->per_seat_enabled) +
+ {{ ctrans('texts.qty') }} + + + +
+ @endif @if(auth('contact')->user()) From 8839bfabd3abc3cbd6fdb42c5a31cf80b8025d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 13:32:29 +0100 Subject: [PATCH 02/10] Hide quantity if max_seats_limit = 1 --- app/Http/Livewire/BillingPortalPurchase.php | 3 +-- .../components/livewire/billing-portal-purchase.blade.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index b3a5148c7fc4..9e198d4aaa0f 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -309,8 +309,7 @@ class BillingPortalPurchase extends Component return $this->quantity; } - // TODO: Dave review. - if ($this->quantity >= $this->billing_subscription->max_seats_limit) { + if ($this->quantity >= $this->billing_subscription->max_seats_limit && $option == 'increment') { return $this->quantity; } diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index e548b1a2c65c..9719bcc3376c 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -20,7 +20,7 @@ @endif - @if($billing_subscription->per_seat_enabled) + @if($billing_subscription->per_seat_enabled && $billing_subscription->max_seats_limit > 1)
{{ ctrans('texts.qty') }}
From b2c7226057f97e6c84b1609be509d9b93d5188d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 13:37:26 +0100 Subject: [PATCH 04/10] Hide coupon if trial is enabled --- .../components/livewire/billing-portal-purchase.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index c5f92ba13cd6..2d53fb497d67 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -139,7 +139,7 @@ @endif - @if(!empty($billing_subscription->promo_code)) + @if(!empty($billing_subscription->promo_code) && !$billing_subscription->trial_enabled)
From edbcb0690ebb193db891cad014df8a557cce4fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 13:38:01 +0100 Subject: [PATCH 05/10] Remove /unit from product quantity --- .../components/livewire/billing-portal-purchase.blade.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index 2d53fb497d67..8679a7ed844f 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -14,10 +14,6 @@

{{ App\Utils\Number::formatMoney($billing_subscription->product->price, $billing_subscription->company) }}

- - @if($billing_subscription->per_seat_enabled) - /unit - @endif
@if($billing_subscription->per_seat_enabled && $billing_subscription->max_seats_limit > 1) From 6e714747bd21cefcd2bf0d183daa7a05bf39f54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 13:53:34 +0100 Subject: [PATCH 06/10] Update price per quantity --- app/Http/Livewire/BillingPortalPurchase.php | 19 ++++++++++++++++--- .../views/billing-portal/purchase.blade.php | 2 +- .../billing-portal-purchase.blade.php | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index 144f721e313a..aa98fdc17da6 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -138,6 +138,13 @@ class BillingPortalPurchase extends Component */ public $request_data; + /** + * Price of product. + * + * @var string + */ + public $price; + /** * Handle user authentication * @@ -313,9 +320,15 @@ class BillingPortalPurchase extends Component return $this->quantity; } - return $option == 'increment' - ? $this->quantity++ - : $this->quantity--; + if ($option == 'increment') { + $this->quantity++; + return $this->price = (int) $this->price + $this->billing_subscription->product->price; + } + + $this->quantity--; + $this->price = (int) $this->price - $this->billing_subscription->product->price; + + return 0; } public function render() diff --git a/resources/views/billing-portal/purchase.blade.php b/resources/views/billing-portal/purchase.blade.php index 34ea32ccf0e8..b264ac635810 100644 --- a/resources/views/billing-portal/purchase.blade.php +++ b/resources/views/billing-portal/purchase.blade.php @@ -2,7 +2,7 @@ @section('meta_title', $billing_subscription->product->product_key) @section('body') - @livewire('billing-portal-purchase', ['billing_subscription' => $billing_subscription, 'contact' => auth('contact')->user(), 'hash' => $hash, 'request_data' => $request_data]) + @livewire('billing-portal-purchase', ['billing_subscription' => $billing_subscription, 'contact' => auth('contact')->user(), 'hash' => $hash, 'request_data' => $request_data, 'price' => $billing_subscription->product->price]) @stop @push('footer') diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index 8679a7ed844f..d5eb2719ca3e 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -13,7 +13,7 @@ {{ ctrans('texts.price') }}:
-

{{ App\Utils\Number::formatMoney($billing_subscription->product->price, $billing_subscription->company) }}

+

{{ App\Utils\Number::formatMoney($price, $billing_subscription->company) }}

@if($billing_subscription->per_seat_enabled && $billing_subscription->max_seats_limit > 1) From d5ad6088f6e25eb7dd3eeb2b65b9bcbb50788254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 13:56:26 +0100 Subject: [PATCH 07/10] Create data mapper for cached data / billing context --- .../Billing/BillingContextMapper.php | 47 +++++++++++++++++++ app/Http/Livewire/BillingPortalPurchase.php | 3 +- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 app/DataMapper/Billing/BillingContextMapper.php diff --git a/app/DataMapper/Billing/BillingContextMapper.php b/app/DataMapper/Billing/BillingContextMapper.php new file mode 100644 index 000000000000..3d878f38841e --- /dev/null +++ b/app/DataMapper/Billing/BillingContextMapper.php @@ -0,0 +1,47 @@ + 'integer', + 'email' => 'string', + 'client_id' => 'integer', + 'invoice_id' => 'integer', + ]; +} diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index aa98fdc17da6..950065bd8551 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -284,8 +284,7 @@ class BillingPortalPurchase extends Component 'billing_subscription_id' => $this->billing_subscription->id, 'email' => $this->email ?? $this->contact->email, 'client_id' => $this->contact->client->id, - 'invoice_id' => $this->invoice->id, - 'subscription_id' => $this->billing_subscription->id], + 'invoice_id' => $this->invoice->id], now()->addMinutes(60) ); From e04ed7c2bf95865ca7d774fdd642175a8e851d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 14:01:36 +0100 Subject: [PATCH 08/10] Show per year per month as recurring_invoice frequency is defined using RecurringInvoice method helper --- .../components/livewire/billing-portal-purchase.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index d5eb2719ca3e..9d82874eb76c 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -14,8 +14,13 @@

{{ App\Utils\Number::formatMoney($price, $billing_subscription->company) }}

+ + @if($billing_subscription->is_recurring) + / {{ \App\Models\RecurringInvoice::frequencyForKey($billing_subscription->frequency_id) }} + @endif
+ @if($billing_subscription->per_seat_enabled && $billing_subscription->max_seats_limit > 1)
{{ ctrans('texts.qty') }} From 535d9ae471855d105711231decdbd66d2ba71478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 14:03:32 +0100 Subject: [PATCH 09/10] Update data passed to startTrial --- app/Http/Livewire/BillingPortalPurchase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index 950065bd8551..0ad02c1683b0 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -300,6 +300,8 @@ class BillingPortalPurchase extends Component { return $this->billing_subscription->service()->startTrial([ 'email' => $this->email ?? $this->contact->email, + 'quantity' => $this->quantity, + 'contact_id' => $this->contact->id, ]); } From e78fb7e891c3adbe5518bbe912376bece750caab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 22 Mar 2021 14:09:29 +0100 Subject: [PATCH 10/10] Update quering the language/locale using Cache instead of DB --- .../BillingSubscriptionPurchaseController.php | 5 ++++- app/Http/Livewire/BillingPortalPurchase.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php b/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php index 0ba39d8d7f91..b6a545e96b53 100644 --- a/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php +++ b/app/Http/Controllers/ClientPortal/BillingSubscriptionPurchaseController.php @@ -16,6 +16,7 @@ use App\Http\Controllers\Controller; use App\Models\BillingSubscription; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; @@ -41,7 +42,9 @@ class BillingSubscriptionPurchaseController extends Controller */ private function setLocale(string $locale): void { - $record = DB::table('languages')->where('locale', $locale)->first(); + $record = Cache::get('languages')->filter(function ($item) use ($locale) { + return $item->locale == $locale; + })->first(); if ($record) { App::setLocale($record->locale); diff --git a/app/Http/Livewire/BillingPortalPurchase.php b/app/Http/Livewire/BillingPortalPurchase.php index 0ad02c1683b0..e8ae73290987 100644 --- a/app/Http/Livewire/BillingPortalPurchase.php +++ b/app/Http/Livewire/BillingPortalPurchase.php @@ -17,6 +17,7 @@ use App\Models\ClientContact; use App\Models\Invoice; use App\Repositories\ClientContactRepository; use App\Repositories\ClientRepository; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; @@ -199,7 +200,11 @@ class BillingPortalPurchase extends Component ]; if (array_key_exists('locale', $this->request_data)) { - $record = DB::table('languages')->where('locale', $this->request_data['locale'])->first(); + $request = $this->request_data; + + $record = Cache::get('languages')->filter(function ($item) use ($request) { + return $item->locale == $request['locale']; + })->first(); if ($record) { $data['settings']['language_id'] = (string)$record->id; @@ -323,11 +328,11 @@ class BillingPortalPurchase extends Component if ($option == 'increment') { $this->quantity++; - return $this->price = (int) $this->price + $this->billing_subscription->product->price; + return $this->price = (int)$this->price + $this->billing_subscription->product->price; } $this->quantity--; - $this->price = (int) $this->price - $this->billing_subscription->product->price; + $this->price = (int)$this->price - $this->billing_subscription->product->price; return 0; }