diff --git a/extensions/Others/CreditsPlus/CreditsPlus.php b/extensions/Others/CreditsPlus/CreditsPlus.php
index e2bb10c88..8c92812db 100644
--- a/extensions/Others/CreditsPlus/CreditsPlus.php
+++ b/extensions/Others/CreditsPlus/CreditsPlus.php
@@ -13,6 +13,9 @@
namespace Paymenter\Extensions\Others\CreditsPlus;
use App\Classes\Extension\Extension;
+use Illuminate\Support\Facades\View;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Storage;
class CreditsPlus extends Extension
{
@@ -28,7 +31,7 @@ class CreditsPlus extends Extension
public function getVersion(): string
{
- return '2.0.0';
+ return '2.1.0';
}
public function getAuthor(): string
@@ -52,50 +55,79 @@ class CreditsPlus extends Extension
private function registerCreditsNavigation(): void
{
try {
- if (function_exists('app') && app()->bound('view')) {
- // Register the view namespace for custom components
- app('view')->addNamespace('creditsplus', __DIR__ . '/resources/views');
-
- app('view')->composer('components.navigation.index', function ($view) {
- try {
- if (!function_exists('auth') || !auth()->check() || !auth()->user()) {
- return;
- }
-
- $user = auth()->user();
- $creditsDisplay = $this->calculateUserCreditsDisplay($user);
- $creditsUrl = function_exists('route') ? route('account.credits') : '/account/credits';
-
- $customPath = __DIR__ . '/resources/views/components/navigation/index.blade.php';
- if (file_exists($customPath)) {
- $view->setPath($customPath);
- }
-
- $view->with([
- 'userCreditsDisplay' => $creditsDisplay,
- 'creditsUrl' => $creditsUrl,
- ]);
- } catch (\Exception $e) {
+ // Register the view namespace
+ View::addNamespace('creditsplus', __DIR__ . '/resources/views');
+
+ // Store reference to this instance for use in closure
+ $extension = $this;
+ $extensionPath = __DIR__;
+
+ // Use view composer to add credits data to navigation
+ View::composer('components.navigation.index', function ($view) use ($extension, $extensionPath) {
+ try {
+ if (!Auth::check()) {
+ return;
}
- });
- }
+
+ // Only show credits if the feature is enabled
+ if (!config('settings.credits_enabled', false)) {
+ return;
+ }
+
+ $user = Auth::user();
+ $creditsDisplay = $extension->calculateUserCreditsDisplay($user);
+
+ // Determine logo path using storage_url helper if available
+ $logoHtml = '';
+ if (config('settings.logo')) {
+ $logoUrl = function_exists('storage_url')
+ ? storage_url(config('settings.logo'))
+ : Storage::url(config('settings.logo'));
+ $logoHtml = '';
+ }
+
+ // Inject credits data, logo HTML, and credits URL into the view
+ $creditsUrlPath = '#';
+ try {
+ if (function_exists('route')) {
+ $creditsUrlPath = route('account.credits');
+ }
+ } catch (\Exception $e) {
+ $creditsUrlPath = '/account/credits';
+ }
+
+ $view->with([
+ 'userCreditsDisplay' => $creditsDisplay,
+ 'creditsLogoHtml' => $logoHtml,
+ 'creditsUrl' => $creditsUrlPath,
+ ]);
+
+ // Replace the view path with our custom navigation
+ $customPath = $extensionPath . '/resources/views/components/navigation/index.blade.php';
+ if (file_exists($customPath)) {
+ $view->setPath($customPath);
+ }
+ } catch (\Exception $e) {
+ // Silently fail
+ }
+ });
} catch (\Exception $e) {
+ // Silently fail
}
}
- private function calculateUserCreditsDisplay($user): string
+ public function calculateUserCreditsDisplay($user): string
{
try {
+ // Check if the credits relationship exists
+ if (!method_exists($user, 'credits')) {
+ return $this->getDefaultCurrencyDisplay();
+ }
+
$credits = $user->credits()->with('currency')->get();
if ($credits->isEmpty()) {
- $currencyCode = session('currency', config('settings.default_currency', 'USD'));
- $currency = \App\Models\Currency::where('code', $currencyCode)->first();
- if ($currency) {
- return $currency->prefix . '0.00' . $currency->suffix;
- } else {
- return '0.00 ' . $currencyCode;
- }
+ return $this->getDefaultCurrencyDisplay();
}
$creditsByCurrency = $credits->groupBy('currency_code');
@@ -111,33 +143,42 @@ class CreditsPlus extends Extension
if ($maxAmount === null || $totalAmount > $maxAmount) {
$maxAmount = $totalAmount;
$maxCurrencyCode = $currencyCode;
- $maxCurrency = $userCredits->first()->currency;
+ $maxCurrency = $userCredits->first()->currency ?? null;
}
}
if ($maxAmount === null) {
- $currencyCode = session('currency', config('settings.default_currency', 'USD'));
- $currency = \App\Models\Currency::where('code', $currencyCode)->first();
- if ($currency) {
- return $currency->prefix . '0.00' . $currency->suffix;
- } else {
- return '0.00 ' . $currencyCode;
- }
+ return $this->getDefaultCurrencyDisplay();
}
- if ($maxCurrency) {
+ if ($maxCurrency && isset($maxCurrency->prefix) && isset($maxCurrency->suffix)) {
return $maxCurrency->prefix . number_format($maxAmount, 2) . $maxCurrency->suffix;
} else {
- return number_format($maxAmount, 2) . ' ' . $maxCurrencyCode;
+ return number_format($maxAmount, 2) . ' ' . ($maxCurrencyCode ?? '');
}
} catch (\Exception $e) {
+ return $this->getDefaultCurrencyDisplay();
+ }
+ }
+
+ /**
+ * Get default currency display (0.00 with currency symbol)
+ */
+ private function getDefaultCurrencyDisplay(): string
+ {
+ try {
$currencyCode = session('currency', config('settings.default_currency', 'USD'));
- $currency = class_exists('\App\Models\Currency') ? \App\Models\Currency::where('code', $currencyCode)->first() : null;
- if ($currency) {
- return $currency->prefix . '0.00' . $currency->suffix;
- } else {
- return '0.00 ' . $currencyCode;
+
+ if (class_exists('\App\Models\Currency')) {
+ $currency = \App\Models\Currency::where('code', $currencyCode)->first();
+ if ($currency && isset($currency->prefix) && isset($currency->suffix)) {
+ return $currency->prefix . '0.00' . $currency->suffix;
+ }
}
+
+ return '0.00 ' . $currencyCode;
+ } catch (\Exception $e) {
+ return '0.00 USD';
}
}
}
diff --git a/extensions/Others/CreditsPlus/resources/views/components/navigation/index.blade.php b/extensions/Others/CreditsPlus/resources/views/components/navigation/index.blade.php
index ba4aff93b..2a3157817 100644
--- a/extensions/Others/CreditsPlus/resources/views/components/navigation/index.blade.php
+++ b/extensions/Others/CreditsPlus/resources/views/components/navigation/index.blade.php
@@ -43,9 +43,7 @@ Unauthorized copying, modification, or distribution is prohibited.