diff --git a/app/Http/Controllers/ClientPortal/SubscriptionPlanSwitchController.php b/app/Http/Controllers/ClientPortal/SubscriptionPlanSwitchController.php index 9dfd6da20912..9f5a4275a9d1 100644 --- a/app/Http/Controllers/ClientPortal/SubscriptionPlanSwitchController.php +++ b/app/Http/Controllers/ClientPortal/SubscriptionPlanSwitchController.php @@ -24,14 +24,14 @@ class SubscriptionPlanSwitchController extends Controller * * @param ShowPlanSwitchRequest $request * @param Subscription $subscription - * @param string $target_subscription + * @param string $target * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function index(ShowPlanSwitchRequest $request, Subscription $subscription, Subscription $target_subscription) + public function index(ShowPlanSwitchRequest $request, Subscription $subscription, Subscription $target) { return render('subscriptions.switch', [ 'subscription' => $subscription, - 'target_subscription' => $target_subscription, + 'target' => $target, ]); } } diff --git a/app/Http/Livewire/RecurringInvoiceCancellation.php b/app/Http/Livewire/RecurringInvoiceCancellation.php new file mode 100644 index 000000000000..4e03e3b09745 --- /dev/null +++ b/app/Http/Livewire/RecurringInvoiceCancellation.php @@ -0,0 +1,38 @@ +invoice->subscription) { + return $this->invoice->subscription->service()->handleCancellation(); + } + + return redirect()->route('client.recurring_invoices.request_cancellation', ['recurring_invoice' => $this->invoice->hashed_id]); + } + + public function render() + { + return render('components.livewire.recurring-invoice-cancellation'); + } +} diff --git a/app/Http/Livewire/SubscriptionPlanSwitch.php b/app/Http/Livewire/SubscriptionPlanSwitch.php index 8b26fd4ab851..a6afc69c445c 100644 --- a/app/Http/Livewire/SubscriptionPlanSwitch.php +++ b/app/Http/Livewire/SubscriptionPlanSwitch.php @@ -12,30 +12,90 @@ namespace App\Http\Livewire; +use App\Models\ClientContact; +use App\Models\Subscription; +use Illuminate\Support\Str; use Livewire\Component; class SubscriptionPlanSwitch extends Component { + /** + * @var Subscription + */ public $subscription; - public $target_subscription; + /** + * @var Subscription + */ + public $target; + /** + * @var ClientContact + */ public $contact; + /** + * @var array + */ public $methods = []; + /** + * @var string + */ public $total; + /** + * @var array + */ + public $state = [ + 'payment_initialised' => false, + 'show_loading_bar' => false, + 'invoice' => null, + 'company_gateway_id' => null, + 'payment_method_id' => null, + ]; + + /** + * @var mixed|string + */ + public $hash; + public function mount() { + $this->total = $this->subscription->service()->getPriceBetweenSubscriptions($this->subscription, $this->target); + $this->methods = $this->contact->client->service()->getPaymentMethods(100); - $this->total = 1; + $this->hash = Str::uuid()->toString(); } - public function handleBeforePaymentEvents() + public function handleBeforePaymentEvents(): void { - // .. + $this->state['show_loading_bar'] = true; + + $this->state['invoice'] = $this->subscription->service()->createChangePlanInvoice([ + 'subscription' => $this->subscription, + 'target' => $this->target, + ]); + + $this->state['payment_initialised'] = true; + + $this->emit('beforePaymentEventsCompleted'); + } + + /** + * Middle method between selecting payment method & + * submitting the from to the backend. + * + * @param $company_gateway_id + * @param $gateway_type_id + */ + public function handleMethodSelectingEvent($company_gateway_id, $gateway_type_id) + { + $this->state['company_gateway_id'] = $company_gateway_id; + $this->state['payment_method_id'] = $gateway_type_id; + + $this->handleBeforePaymentEvents(); } public function render() diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 6e4ce1ed96dc..ec0867065619 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -184,7 +184,7 @@ class SubscriptionService public function createChangePlanInvoice($data) { - + return Invoice::where('status_id', Invoice::STATUS_SENT)->first(); } public function createInvoice($data): ?\App\Models\Invoice @@ -275,9 +275,9 @@ class SubscriptionService } /** - * Get the single charge products for the + * Get the single charge products for the * subscription - * + * * @return ?Product Collection */ public function products() @@ -286,9 +286,9 @@ class SubscriptionService } /** - * Get the recurring products for the + * Get the recurring products for the * subscription - * + * * @return ?Product Collection */ public function recurring_products() @@ -317,6 +317,21 @@ class SubscriptionService public function handleCancellation() { + dd('Cancelling using SubscriptionService'); + // .. } + + /** + * Get pro rata calculation between subscriptions. + * + * @param Subscription $current + * @param Subscription $target + */ + public function getPriceBetweenSubscriptions(Subscription $current, Subscription $target): int + { + // Calculate the pro rata. Return negative value if credits needed. + + return 1; + } } 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 cf8828355734..f40e4ce8bf7c 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 @@ -41,7 +41,7 @@ @foreach($subscription->service()->recurring_products() as $product)
-
{{ $product->product_key }}
+
{{ $product->notes }}
{{ \App\Utils\Number::formatMoney($product->price, $subscription->company) }} @@ -136,9 +136,6 @@ @elseif($steps['show_start_trial'])
@csrf -

Some text about the trial goes here. Details about the days, etc.

- - diff --git a/resources/views/portal/ninja2020/components/livewire/recurring-invoice-cancellation.blade.php b/resources/views/portal/ninja2020/components/livewire/recurring-invoice-cancellation.blade.php new file mode 100644 index 000000000000..f133a0a8ec6f --- /dev/null +++ b/resources/views/portal/ninja2020/components/livewire/recurring-invoice-cancellation.blade.php @@ -0,0 +1,3 @@ + diff --git a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php index 1f4daa421508..ff43981e9128 100644 --- a/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/subscription-plan-switch.blade.php @@ -7,24 +7,58 @@
-

- {{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($total, $subscription->company) }} - {{-- {{ \App\Utils\Number::formatMoney($subscription->price, $subscription->company) }}--}} -

+ Select a payment method: + {{--

--}} + {{-- {{ ctrans('texts.total') }}: {{ \App\Utils\Number::formatMoney($total, $subscription->company) }}--}} + {{-- {{ \App\Utils\Number::formatMoney($subscription->price, $subscription->company) }}--}} + {{--

--}}
- + @if($state['invoice']) + + @csrf + + @if($state['invoice'] instanceof \App\Models\Invoice) + + + + @endif + + + + + + @endif + +
- Select a payment method:
- @foreach($this->methods as $method) - - @endforeach + + @if(!$state['payment_initialised']) + @foreach($this->methods as $method) + + @endforeach + @endif + + @if($state['show_loading_bar']) +
+ + + + +
+ @endif
diff --git a/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php b/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php index df1b98e6fd20..c75064b298f9 100644 --- a/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php +++ b/resources/views/portal/ninja2020/recurring_invoices/includes/modals/cancellation.blade.php @@ -1,4 +1,5 @@ -