From b290969ccf973fc1e381f18220ab03d158ebab6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 8 Feb 2024 19:55:33 +0100 Subject: [PATCH] Add Authentication component to BillingPortal --- app/Livewire/BillingPortal/Authentication.php | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 app/Livewire/BillingPortal/Authentication.php diff --git a/app/Livewire/BillingPortal/Authentication.php b/app/Livewire/BillingPortal/Authentication.php new file mode 100644 index 000000000000..fa31d4515b2f --- /dev/null +++ b/app/Livewire/BillingPortal/Authentication.php @@ -0,0 +1,66 @@ + false, + ]; + + public function authenticate() + { + $this->validateOnly('email', ['email' => 'required|bail|email:rfc']); + + $code = rand(100000, 999999); + $hash = sprintf('subscriptions:otp:%s', $code); + + cache()->put($hash, $code, ttl: 120); + + $cc = new ClientContact(); + $cc->email = $this->email; + + $nmo = new NinjaMailerObject(); + $nmo->mailable = new OtpCode($this->subscription->company, $this->contact, $code); + $nmo->company = $this->subscription->company; + $nmo->settings = $this->subscription->company->settings; + $nmo->to_user = $cc; + + NinjaMailerJob::dispatch($nmo); + + $this->state['code'] = true; + } + + public function mount() + { + if (auth()->guard('contact')->check()) { + $this->dispatch('purchase.next'); + } + } + + public function render() + { + return view('billing-portal.v3.authentication'); + } +}