select-provider.blade.php
SelectProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="flex flex-col items-start w-full"> | |
Need to get your payment provider details... | |
</div> | |
<div class="flex flex-col md:flex-row w-full"> | |
<div class="flex flex-col items-start w-full md:w-1/2 pr-4"> | |
<div class="flex w-full my-2"> | |
<label for="stripe_public_key" class="flex w-full">stripe public key</label> | |
<input type="text" wire:change="updateStripeDetails('stripePublicKey', $event.target.value)" id="stripe_public_key" class="flex w-full border-b" /> | |
</div> | |
<div class="flex w-full mb-2"> | |
<label for="stripe_private_key" class="flex w-full">stripe secret key</label> | |
<input type="text" wire:change="updateStripeDetails('stripePrivateKey', $event.target.value)" id="stripe_private_key" class="flex w-full border-b" /> | |
</div> | |
{!! $hasStripeDetails ? '<div class="flex w-full text-red mb-2">we already have these</div>' : '' !!} | |
@if ($hasEnoughStripeDetails) | |
@startphpx('Gitstore\Components\Atoms\Button', [ | |
'type' => 'primary', | |
'className' => 'ml-0', | |
'wire:loading.class' => 'gone', | |
'wire:click' => "\$emit('select-provider:selected', 'stripe')", | |
'wire:key' => 'enabled-use-stripe-button', | |
]) | |
@usephpx('Gitstore\Components\Icons\Forward') | |
<span class="ml-2">Use Stripe</span> | |
@endphpx | |
@startphpx('Gitstore\Components\Atoms\Button', [ | |
'type' => 'disabled', | |
'className' => 'ml-0 gone', | |
'wire:loading.class.remove' => 'gone', | |
'wire:key' => 'disabled-use-stripe-button', | |
]) | |
@usephpx('Gitstore\Components\Icons\Forward') | |
<span class="ml-2">Use Stripe</span> | |
@endphpx | |
@endif | |
</div> | |
<div class="flex flex-col w-full md:w-1/2"> | |
<div class="flex w-full my-2"> | |
<label for="paypal_email" class="flex w-full">paypal email</label> | |
<input type="text" wire:change="updatePaypalDetails('paypalEmail', $event.target.value)" id="paypal_email" class="flex w-full border-b" /> | |
</div> | |
{!! $hasPaypalDetails ? '<div class="flex w-full text-red mb-2">we already have this</div>' : '' !!} | |
@if ($hasEnoughPaypalDetails) | |
@startphpx('Gitstore\Components\Atoms\Button', [ | |
'type' => 'primary', | |
'className' => 'ml-0', | |
'wire:loading.class' => 'gone', | |
'wire:click' => "\$emit('select-provider:selected', 'paypal')", | |
'wire:key' => 'enabled-use-paypal-button', | |
]) | |
@usephpx('Gitstore\Components\Icons\Forward') | |
<span class="ml-2">Use PayPal</span> | |
@endphpx | |
@startphpx('Gitstore\Components\Atoms\Button', [ | |
'type' => 'disabled', | |
'className' => 'ml-0 gone', | |
'wire:loading.class.remove' => 'gone', | |
'wire:key' => 'disabled-use-paypal-button', | |
]) | |
@usephpx('Gitstore\Components\Icons\Forward') | |
<span class="ml-2">Use PayPal</span> | |
@endphpx | |
@endif | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Livewire; | |
use Livewire\Component; | |
class SelectProvider extends Component | |
{ | |
const hasSeenComponentSessionKey = 'livewire:has-seen-providers'; | |
public $continueText = null; | |
protected $stripePublicKey = null; | |
protected $stripePrivateKey = null; | |
public $hasStripeDetails = false; | |
public $hasEnoughStripeDetails = false; | |
public $hasChangedStripeDetails = false; | |
protected $paypalEmail = null; | |
public $hasPaypalDetails = false; | |
public $hasEnoughPaypalDetails = false; | |
public $hasChangedPaypalDetails = false; | |
public function mount($continueText = "Continue") | |
{ | |
$this->continueText = $continueText; | |
$this->stripePublicKey = auth()->user()->stripe_public_key; | |
$this->stripePrivateKey = auth()->user()->stripe_private_key; | |
if ($this->stripePublicKey && $this->stripePrivateKey) { | |
$this->hasStripeDetails = true; | |
} | |
$this->paypalEmail = auth()->user()->paypal_email; | |
if ($this->paypalEmail) { | |
$this->hasPaypalDetails = true; | |
} | |
$this->checkProviderDetails(); | |
session()->put(static::hasSeenComponentSessionKey, (bool) true); | |
} | |
public function updateStripeDetails($field = null, $value = null) | |
{ | |
$this->hasChangedStripeDetails = true; | |
$this->updateProviderDetails($field, $value); | |
} | |
public function updatePaypalDetails($field = null, $value = null) | |
{ | |
$this->hasChangedStripeDetails = true; | |
$this->updateProviderDetails($field, $value); | |
} | |
public function updateProviderDetails($field = null, $value = null) | |
{ | |
$this->$field = $value; | |
$this->checkProviderDetails(); | |
} | |
public function checkProviderDetails() | |
{ | |
$user = auth()->user(); | |
if ($this->stripePublicKey && $this->stripePrivateKey) { | |
if (!$this->hasEnoughStripeDetails) { | |
if ($this->hasChangedStripeDetails) { | |
$user->stripe_public_key = $this->stripePublicKey; | |
$user->stripe_private_key - $this->stripePrivateKey; | |
$user->save(); | |
} | |
$this->hasEnoughStripeDetails = true; | |
} | |
} else { | |
if ($this->hasEnoughStripeDetails) { | |
$this->hasEnoughStripeDetails = false; | |
} | |
} | |
if ($this->paypalEmail) { | |
if (!$this->hasEnoughPaypalDetails) { | |
if ($this->hasChangedPaypalDetails) { | |
$user->paypal_email = $this->paypalEmail; | |
$user->save(); | |
} | |
$this->hasEnoughPaypalDetails = true; | |
} | |
} else { | |
if ($this->hasEnoughPaypalDetails) { | |
$this->hasEnoughPaypalDetails = false; | |
} | |
} | |
} | |
public function render() | |
{ | |
return view('livewire.select-provider'); | |
} | |
} |