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/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..5734e23634c6 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() @@ -319,4 +319,17 @@ class 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/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 @@