chore: code refactor via rector
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Livewire\Dashboard;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use App\Models\ActivationKey;
|
||||
use App\Models\Plan;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Log;
|
||||
|
||||
class Pricing extends Component
|
||||
{
|
||||
@@ -34,8 +36,8 @@ class Pricing extends Component
|
||||
'activation_key.max' => 'The activation key must not exceed 30 characters.',
|
||||
]);
|
||||
|
||||
$trimmedKey = trim($this->activation_key);
|
||||
$activation = ActivationKey::where('activation_key', $trimmedKey)
|
||||
$trimmedKey = trim((string) $this->activation_key);
|
||||
$activation = ActivationKey::query()->where('activation_key', $trimmedKey)
|
||||
->where('is_activated', false)
|
||||
->first();
|
||||
|
||||
@@ -43,7 +45,7 @@ class Pricing extends Component
|
||||
if ($activation->price_id !== null) {
|
||||
$result = $this->addSubscription($activation->price_id);
|
||||
}
|
||||
if ($result === true) {
|
||||
if ($result) {
|
||||
$activation->is_activated = true;
|
||||
$activation->user_id = auth()->id();
|
||||
$activation->save();
|
||||
@@ -61,7 +63,7 @@ class Pricing extends Component
|
||||
private function addSubscription($price_id): bool
|
||||
{
|
||||
try {
|
||||
$plan = Plan::where('pricing_id', $price_id)->firstOrFail();
|
||||
$plan = Plan::query()->where('pricing_id', $price_id)->firstOrFail();
|
||||
$user = auth()->user();
|
||||
$user->createOrGetStripeCustomer();
|
||||
$user->updateStripeCustomer([
|
||||
@@ -76,11 +78,7 @@ class Pricing extends Component
|
||||
$balance = $user->balance();
|
||||
$user->newSubscription('default', $plan->pricing_id)->create();
|
||||
|
||||
if ($plan->monthly_billing == 1) {
|
||||
$ends_at = now()->addMonth();
|
||||
} else {
|
||||
$ends_at = now()->addYear();
|
||||
}
|
||||
$ends_at = $plan->monthly_billing == 1 ? now()->addMonth() : now()->addYear();
|
||||
$user->subscription('default')->cancelAt($ends_at);
|
||||
|
||||
return true;
|
||||
@@ -91,7 +89,7 @@ class Pricing extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
public function render(): Factory|View
|
||||
{
|
||||
return view('livewire.dashboard.pricing');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user