Subscriptions v2

This commit is contained in:
David Bomba 2022-12-09 19:39:27 +11:00
parent 1ca6810132
commit 68688e5b98
4 changed files with 65 additions and 19 deletions

View File

@ -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.
*

View File

@ -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')];

View File

@ -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;

View File

@ -254,6 +254,7 @@
<span class="absolute top-0 bottom-0 right-0 px-4 py-3">
</div>
@enderror
</div>
</form>
@endif
@ -261,7 +262,7 @@
@if($email && !$errors->has('email'))
<div class="py-6 px-6 w-80 border mx-auto text-center my-6">
<form wire:submit.prevent="handleLogin" class="" x-data="otpForm()">
<p class="mb-4">Enter the code we emailed</p>
<p class="mb-4">{{ ctrans('texts.otp_code_message')}}</p>
<div class="flex justify-between">
<template x-for="(input, index) in length" :key="index">
<input
@ -275,10 +276,13 @@
/>
</template>
</div>
<button x-on:click="buttonDisabled = true" x-bind:disabled="buttonDisabled" class="btn-primary mx-auto block bg-gray-500 w-full p-2 mt-2 text-white">
{{ ctrans('texts.verify') }}
</button>
</form>
@error("login")
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
<span class="block sm:inline">{{ $message }} </span>
<span class="absolute top-0 bottom-0 right-0 px-4 py-3">
</div>
@enderror
</div>
@endif
</div>
@ -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();
},
};
}