false, 'show_loading_bar' => false, 'invoice' => null, 'company_gateway_id' => null, 'payment_method_id' => null, ]; /** * @var mixed|string */ public $hash; public $company; public function mount() { MultiDB::setDb($this->company->db); $this->total = $this->amount; $this->methods = $this->contact->client->service()->getPaymentMethods($this->amount); $this->hash = Str::uuid()->toString(); } public function handleBeforePaymentEvents(): void { $this->state['show_loading_bar'] = true; $payment_required = $this->target->service()->changePlanPaymentCheck([ 'recurring_invoice' => $this->recurring_invoice, 'subscription' => $this->subscription, 'target' => $this->target, 'hash' => $this->hash, ]); if ($payment_required) { $this->state['invoice'] = $this->target->service()->createChangePlanInvoice([ 'recurring_invoice' => $this->recurring_invoice, 'subscription' => $this->subscription, 'target' => $this->target, 'hash' => $this->hash, ]); Cache::put( $this->hash, [ 'subscription_id' => $this->target->hashed_id, 'target_id' => $this->target->hashed_id, 'recurring_invoice' => $this->recurring_invoice->hashed_id, 'client_id' => $this->recurring_invoice->client->hashed_id, 'invoice_id' => $this->state['invoice']->hashed_id, 'context' => 'change_plan', now()->addMinutes(60), ] ); $this->state['payment_initialised'] = true; } else { $this->handlePaymentNotRequired(); } $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 handlePaymentNotRequired() { $this->hide_button = true; $response = $this->target->service()->createChangePlanCreditV2([ 'recurring_invoice' => $this->recurring_invoice, 'subscription' => $this->subscription, 'target' => $this->target, 'hash' => $this->hash, ]); $this->hide_button = true; $this->dispatchBrowserEvent('redirectRoute', ['route' => $response]); // return redirect($response); } public function render() { return render('components.livewire.subscription-plan-switch'); } }