@extends('layouts.app') @section('title', __('Affiliate Account')) @php /* * Use the currency selected in Payment Settings for all * affiliate earnings. */ $displayCurrency = currency_code( $displayCurrency ?? $currency ?? default_currency() ); $affiliateEnabled = (bool) ( $affiliateEnabled ?? false ); $applicationStatus = strtolower( trim( (string) ( $applicationStatus ?? $user->affiliate_application_status ?? '' ) ) ); $stats = is_array($stats ?? null) ? $stats : []; $statCards = [ [ 'key' => 'links', 'label' => __('Links'), 'icon' => 'fa-link', 'color' => 'primary', 'decimals' => 0, 'suffix' => '', ], [ 'key' => 'clicks', 'label' => __('Clicks'), 'icon' => 'fa-mouse-pointer', 'color' => 'info', 'decimals' => 0, 'suffix' => '', ], [ 'key' => 'unique_visitors', 'label' => __('Visitors'), 'icon' => 'fa-users', 'color' => 'success', 'decimals' => 0, 'suffix' => '', ], [ 'key' => 'conversions', 'label' => __('Conversions'), 'icon' => 'fa-shopping-cart', 'color' => 'warning', 'decimals' => 0, 'suffix' => '', ], [ 'key' => 'conversion_rate', 'label' => __('Conversion Rate'), 'icon' => 'fa-percentage', 'color' => 'danger', 'decimals' => 2, 'suffix' => '%', ], ]; $isAffiliate = (bool) ( $user->is_affiliate ?? false ); $exportRouteExists = \Illuminate\Support\Facades\Route::has( 'account.affiliate.export' ); $joinRouteExists = \Illuminate\Support\Facades\Route::has( 'account.affiliate.join' ); $redirectRouteExists = \Illuminate\Support\Facades\Route::has( 'affiliate.redirect' ); @endphp @section('content')
{{-- Page Header --}}

{{ __('Affiliate Account') }}

{{ __( 'Promote eligible products and earn commission from confirmed sales.' ) }}

@if($isAffiliate && $exportRouteExists) {{ __('Export Earnings') }} @endif
{{-- Session Messages --}} @if(session('success')) @endif @if(session('error')) @endif @if(! $affiliateEnabled)
{{ __( 'The affiliate programme is currently disabled.' ) }}
@elseif(! $isAffiliate) @if($applicationStatus === 'pending')
{{ __( 'Your affiliate application is awaiting administrator review.' ) }}
@else @if( $applicationStatus === 'rejected' && filled($user->affiliate_rejection_reason) )
{{ __('Previous application feedback:') }}
{{ $user->affiliate_rejection_reason }}
@endif

{{ __('Become an Affiliate') }}

{{ __( 'Create referral links, share products, and earn commission when referred customers complete payment.' ) }}

@if($joinRouteExists)
@csrf
@error('accept_terms')
{{ $message }}
@enderror
@else
{{ __( 'Affiliate applications are temporarily unavailable.' ) }}
@endif
@endif @else {{-- Statistics --}}
@foreach($statCards as $stat) @php $statValue = max( 0, (float) data_get( $stats, $stat['key'], 0 ) ); @endphp
{{ $stat['label'] }}

{{ number_format( $statValue, $stat['decimals'] ) }}{{ $stat['suffix'] }}

@endforeach
{{-- Referral Links --}}
{{ __('My Referral Links') }}
{{ number_format($links->total()) }}
@if($links->isNotEmpty())
@foreach($links as $link) @php $productTitle = trim( (string) ( $link->product ?->details ?->first() ?->title ?? __( 'Product #:id', [ 'id' => $link ->product_id, ] ) ) ); $sellerName = trim( (string) ( $link->seller ?->username ?? __('N/A') ) ); $referralUrl = null; if ($redirectRouteExists) { try { $referralUrl = route( 'affiliate.redirect', $link ); } catch (\Throwable) { $referralUrl = null; } } @endphp @endforeach
{{ __('Product') }} {{ __('Seller') }} {{ __('Clicks') }} {{ __('Referral URL') }}
{{ $productTitle }}
{{ $sellerName }} {{ number_format( max( 0, (int) ( $link ->clicks_count ?? 0 ) ) ) }} @if(filled($referralUrl)) @else {{ __('Unavailable') }} @endif
@else
{{ __( 'No referral links yet. Browse eligible products to generate one.' ) }}
@endif
@if($links->hasPages()) @endif
{{-- Earnings --}}
{{ __('Earnings') }}
{{ number_format($earnings->total()) }}
@if($earnings->isNotEmpty())
@foreach($earnings as $earning) @php $earningStatus = strtolower( trim( (string) ( $earning->status ?? 'pending' ) ) ); [ $earningBadge, $earningIcon, $earningLabel, ] = match ($earningStatus) { 'approved', 'earned', 'paid', 'completed' => [ 'bg-success', 'fa-check-circle', \Illuminate\Support\Str::headline( $earningStatus ), ], 'pending', 'processing' => [ 'bg-warning text-dark', 'fa-clock', \Illuminate\Support\Str::headline( $earningStatus ), ], 'reversed', 'cancelled', 'canceled', 'rejected' => [ 'bg-danger', 'fa-undo', \Illuminate\Support\Str::headline( $earningStatus ), ], default => [ 'bg-secondary', 'fa-question-circle', filled($earningStatus) ? \Illuminate\Support\Str::headline( $earningStatus ) : __('Unknown'), ], }; $earningAmount = max( 0, (float) ( $earning ->earned_amount ?? 0 ) ); $commissionRate = max( 0, (float) ( $earning ->commission_rate ?? 0 ) ); $earningDate = null; if ( filled( $earning->created_at ) ) { try { $earningDate = \Illuminate\Support\Carbon::parse( $earning ->created_at ); } catch (\Throwable) { $earningDate = null; } } $earningProductTitle = trim( (string) ( $earning->product ?->details ?->first() ?->title ?? __( 'Product #:id', [ 'id' => $earning ->product_id, ] ) ) ); $earningOrderNumber = $earning->order ?->order_number ?? $earning->order_id ?? __('N/A'); @endphp @endforeach
{{ __('Order') }} {{ __('Product') }} {{ __('Status') }} {{ __('Rate') }} {{ __('Amount') }} {{ __('Date') }}
#{{ $earningOrderNumber }}
{{ $earningProductTitle }}
{{ $earningLabel }} {{ number_format( $commissionRate, 2 ) }}% {{ money( $earningAmount, $displayCurrency ) }} @if($earningDate) {{ $earningDate->format( 'M d, Y' ) }}
{{ $earningDate ->diffForHumans() }}
@else {{ __('N/A') }} @endif
@else
{{ __('No affiliate earnings yet.') }}
@endif
@if($earnings->hasPages()) @endif
@endif
@endsection @once @push('styles') @endpush @endonce @once @push('scripts') @endpush @endonce