diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index 4f0569f2fcf7..35933f13d043 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -31,6 +31,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; +use Illuminate\Validation\Rule; use Livewire\Component; class BillingPortalPurchasev2 extends Component @@ -222,10 +223,30 @@ class BillingPortalPurchasev2 extends Component } - - public function handleLogin($log) + public function loginValidation() { - nlog($log); + $this->resetErrorBag('login'); + $this->resetValidation('login'); + } + + public function handleLogin() + { + + $code = Cache::get("subscriptions:otp:{$this->email}"); + + $this->validateOnly('login', ['login' => ['required',Rule::in([$code])]], ['login' => ctrans('texts.invalid_code')]); + + $contact = ClientContact::where('email', $this->email)->first(); + + if($contact){ + Auth::guard('contact')->loginUsingId($contact->id, true); + $this->contact = $contact; + } + else { + + } + + } public function handleEmail() @@ -234,9 +255,9 @@ class BillingPortalPurchasev2 extends Component $rand = rand(100000,999999); - $email_hash = "{$this->email}:" . $rand; + $email_hash = "subscriptions:otp:{$this->email}"; - Cache::put($email_hash, 120); + Cache::put($email_hash, $rand, 120); } @@ -368,18 +389,36 @@ class BillingPortalPurchasev2 extends Component return $this; } - public function updatedData() + private function createClientContact() { - } + $company = $this->subscription->company; + $user = $this->subscription->user; + $user->setCompany($company); - public function updating($prop) - { + $client_repo = new ClientRepository(new ClientContactRepository()); + $data = [ + 'name' => '', + 'contacts' => [ + ['email' => $this->email], + ], + 'client_hash' => Str::random(40), + 'settings' => ClientSettings::defaults(), + ]; - } + $client = $client_repo->save($data, ClientFactory::create($company->id, $user->id)); + + $this->contact = $client->fresh()->contacts()->first(); + Auth::guard('contact')->loginUsingId($this->contact->id, true); + + } + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public function updated($propertyName) { + if(in_array($propertyName, ['login','email'])) + return; $this->buildBundle(); @@ -440,6 +479,9 @@ class BillingPortalPurchasev2 extends Component } } + + + /** * Create a blank client. Used for new customers purchasing. * diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index a2a98275804e..f1958ef62195 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -285,6 +285,9 @@ class HtmlEngine $data['$amount_raw'] = ['value' => $this->entity->amount, 'label' => ctrans('texts.amount')]; } + // $data['$amount_in_words'] = ['value' => (new \NumberFormatter($this->client->locale(), \NumberFormatter::SPELLOUT))->format($this->entity->amount), 'label' => '']; + // $data['$balance_in_words'] = ['value' => (new \NumberFormatter($this->client->locale(), \NumberFormatter::SPELLOUT))->format($this->entity->balance), 'label' => '']; + // $data['$balance_due'] = $data['$balance_due']; $data['$outstanding'] = &$data['$balance_due']; $data['$partial_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')]; diff --git a/lang/en/texts.php b/lang/en/texts.php index f210375b12ef..090ba0f2dde9 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -4895,6 +4895,7 @@ $LANG = array( 'delete_bank_account' => 'Delete Bank Account', 'archive_transaction' => 'Archive Transaction', 'delete_transaction' => 'Delete Transaction', + 'otp_code_message' => 'Enter the code emailed.' ); return $LANG; diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php index 67c5e676d34c..c8e5dd7e2d5e 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php @@ -254,6 +254,7 @@ @enderror + @endif @@ -261,7 +262,7 @@ @if($email && !$errors->has('email'))
-

Enter the code we emailed

+

{{ ctrans('texts.otp_code_message')}}

-
+ @error("login") + + @enderror
@endif @@ -290,7 +294,6 @@ return { length: 6, login: "", - buttonDisabled: true, handleInput(e) { const input = e.target; @@ -306,10 +309,6 @@ if(this.login.length == 6){ this.$wire.handleLogin(this.login); - this.buttonDisabled = false; - } - else{ - this.buttonDisabled = true; } }, @@ -328,6 +327,7 @@ handleBackspace(e) { const previous = parseInt(e, 10) - 1; this.$refs[previous] && this.$refs[previous].focus(); + this.$wire.loginValidation(); }, }; }