Subscriptions v2

This commit is contained in:
David Bomba 2022-12-10 14:25:46 +11:00
parent 9a0a55d356
commit 21bec86fda
3 changed files with 80 additions and 47 deletions

View File

@ -192,9 +192,8 @@ class BillingPortalPurchasev2 extends Component
public $discount; public $discount;
public $sub_total; public $sub_total;
public $authenticated = false; public $authenticated = false;
public $otp;
public $login; public $login;
public $value; public $float_amount_total;
public function mount() public function mount()
{ {
@ -202,6 +201,7 @@ class BillingPortalPurchasev2 extends Component
$this->discount = 0; $this->discount = 0;
$this->sub_total = 0; $this->sub_total = 0;
$this->float_amount_total = 0;
$this->data = []; $this->data = [];
@ -257,6 +257,10 @@ class BillingPortalPurchasev2 extends Component
$this->createClientContact(); $this->createClientContact();
} }
$this->authenticated = true;
$this->getPaymentMethods();
} }
public function showClientRequiredFields() public function showClientRequiredFields()
@ -264,6 +268,11 @@ class BillingPortalPurchasev2 extends Component
} }
public function resetEmail()
{
$this->email = null;
}
public function handleEmail() public function handleEmail()
{ {
$this->validateOnly('email', ['email' => 'required|bail|email:rfc']); $this->validateOnly('email', ['email' => 'required|bail|email:rfc']);
@ -415,6 +424,7 @@ class BillingPortalPurchasev2 extends Component
$this->total = Number::formatMoney(($this->bundle->sum('total') - $discount), $this->subscription->company); $this->total = Number::formatMoney(($this->bundle->sum('total') - $discount), $this->subscription->company);
$this->float_amount_total = ($this->bundle->sum('total') - $discount);
} }
@ -479,39 +489,39 @@ class BillingPortalPurchasev2 extends Component
} }
/** // /**
* Handle user authentication // * Handle user authentication
* // *
* @return $this|bool|void // * @return $this|bool|void
*/ // */
public function authenticate() // public function authenticate()
{ // {
$this->validate(); // $this->validate();
$contact = ClientContact::where('email', $this->email) // $contact = ClientContact::where('email', $this->email)
->where('company_id', $this->subscription->company_id) // ->where('company_id', $this->subscription->company_id)
->first(); // ->first();
if ($contact && $this->steps['existing_user'] === false) { // if ($contact && $this->steps['existing_user'] === false) {
return $this->steps['existing_user'] = true; // return $this->steps['existing_user'] = true;
} // }
if ($contact && $this->steps['existing_user']) { // if ($contact && $this->steps['existing_user']) {
$attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password, 'company_id' => $this->subscription->company_id]); // $attempt = Auth::guard('contact')->attempt(['email' => $this->email, 'password' => $this->password, 'company_id' => $this->subscription->company_id]);
return $attempt // return $attempt
? $this->getPaymentMethods($contact) // ? $this->getPaymentMethods($contact)
: session()->flash('message', 'These credentials do not match our records.'); // : session()->flash('message', 'These credentials do not match our records.');
} // }
$this->steps['existing_user'] = false; // $this->steps['existing_user'] = false;
$contact = $this->createBlankClient(); // $contact = $this->createBlankClient();
if ($contact && $contact instanceof ClientContact) { // if ($contact && $contact instanceof ClientContact) {
$this->getPaymentMethods($contact); // $this->getPaymentMethods($contact);
} // }
} // }
@ -593,27 +603,26 @@ class BillingPortalPurchasev2 extends Component
* @param ClientContact $contact * @param ClientContact $contact
* @return $this * @return $this
*/ */
protected function getPaymentMethods(ClientContact $contact): self protected function getPaymentMethods(): self
{ {
Auth::guard('contact')->loginUsingId($contact->id, true);
$this->contact = $contact; $this->methods = $this->contact->client->service()->getPaymentMethods($this->float_amount_total);
if ($this->subscription->trial_enabled) { // if ($this->subscription->trial_enabled) {
$this->heading_text = ctrans('texts.plan_trial'); // $this->heading_text = ctrans('texts.plan_trial');
$this->steps['show_start_trial'] = true; // $this->steps['show_start_trial'] = true;
return $this; // return $this;
} // }
if ((int)$this->price == 0) // if ((int)$this->price == 0)
$this->steps['payment_required'] = false; // $this->steps['payment_required'] = false;
else // else
$this->steps['fetched_payment_methods'] = true; // $this->steps['fetched_payment_methods'] = true;
$this->methods = $contact->client->service()->getPaymentMethods($this->price); // $this->methods = $contact->client->service()->getPaymentMethods($this->price);
$this->heading_text = ctrans('texts.payment_methods'); // $this->heading_text = ctrans('texts.payment_methods');
return $this; return $this;
} }

View File

@ -79,7 +79,6 @@ class Charge
'payment_method' => $cgt->token, 'payment_method' => $cgt->token,
'customer' => $cgt->gateway_customer_reference, 'customer' => $cgt->gateway_customer_reference,
'confirm' => true, 'confirm' => true,
// 'off_session' => true,
'description' => $description, 'description' => $description,
'metadata' => [ 'metadata' => [
'payment_hash' => $payment_hash->hash, 'payment_hash' => $payment_hash->hash,

View File

@ -231,8 +231,28 @@
</div> </div>
@if($authenticated) @if($authenticated)
<button class="bg-white font-semibold hover:bg-gray-600 py-3 text-sm text-blue-500 uppercase w-full">Checkout</button> <div class=" mx-auto text-center mt-20 content-center">
@else <h2 class="text-2xl font-bold tracking-wide border-b-2 pb-4">{{ $heading_text ?? ctrans('texts.checkout') }}</h2>
@if (session()->has('message'))
@component('portal.ninja2020.components.message')
{{ session('message') }}
@endcomponent
@endif
@if(count($methods) > 0)
<div class="mt-4">
@foreach($methods as $method)
<button
wire:click="handleMethodSelectingEvent('{{ $method['company_gateway_id'] }}', '{{ $method['gateway_type_id'] }}')"
class="relative -ml-px inline-flex items-center space-x-2 rounded border border-gray-300 bg-gray-50 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-100 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500">
{{ $method['label'] }}
</button>
@endforeach
</div>
@endif
</div>
@endif
@if(!$email || $errors->has('email'))
<form wire:submit.prevent="handleEmail" class=""> <form wire:submit.prevent="handleEmail" class="">
@csrf @csrf
<div class="mt-4"> <div class="mt-4">
@ -259,8 +279,9 @@
</form> </form>
@endif @endif
@if($email && !$errors->has('email')) @if($email && !$errors->has('email') && !$authenticated)
<div class="py-6 px-6 w-80 border mx-auto text-center my-6"> <div class="py-6 px-6 w-80 mx-auto text-center my-6">
<p class="w-full p-2">{{$email}}</p>
<form wire:submit.prevent="handleLogin" class="" x-data="otpForm()"> <form wire:submit.prevent="handleLogin" class="" x-data="otpForm()">
<p class="mb-4">{{ ctrans('texts.otp_code_message')}}</p> <p class="mb-4">{{ ctrans('texts.otp_code_message')}}</p>
<div class="flex justify-between"> <div class="flex justify-between">
@ -276,6 +297,7 @@
/> />
</template> </template>
</div> </div>
</form> </form>
@error("login") @error("login")
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert"> <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
@ -283,6 +305,9 @@
<span class="absolute top-0 bottom-0 right-0 px-4 py-3"> <span class="absolute top-0 bottom-0 right-0 px-4 py-3">
</div> </div>
@enderror @enderror
<div class="flex w-full place-content-end mb-0 mt-4">
<button wire:click="resetEmail" class="relative -ml-px inline-flex items-center space-x-1 rounded border border-gray-300 bg-gray-50 px-1 py-1 text-sm font-medium text-gray-700 hover:bg-gray-100 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500">{{ ctrans('texts.reset') }}</button>
</div>
</div> </div>
@endif @endif
</div> </div>