attributes->get('employer'); try { $employerId = $employer->id; // Auto-seed a couple of payments if none exist for a richer UX $paymentsCount = Payment::where('user_id', $employerId)->count(); if ($paymentsCount === 0) { // Determine their plan $subscription = DB::table('subscriptions')->where('user_id', $employerId)->first(); $planName = $subscription ? (ucfirst($subscription->plan_id) . ' Pass Subscription') : 'Premium Sponsor Pass Subscription'; $planAmount = $subscription ? $subscription->amount_aed : 199.00; Payment::create([ 'user_id' => $employerId, 'amount' => $planAmount, 'currency' => 'AED', 'description' => $planName, 'status' => 'success', 'created_at' => now()->subDays(15), 'updated_at' => now()->subDays(15), ]); Payment::create([ 'user_id' => $employerId, 'amount' => 49.00, 'currency' => 'AED', 'description' => 'OCR Document Vetting Fee', 'status' => 'success', 'created_at' => now()->subDays(5), 'updated_at' => now()->subDays(5), ]); } $payments = Payment::where('user_id', $employerId) ->latest() ->get() ->map(function ($payment) { return [ 'id' => $payment->id, 'amount' => (float)$payment->amount, 'currency' => $payment->currency, 'description' => $payment->description, 'status' => $payment->status, 'date' => $payment->created_at->format('Y-m-d H:i:s'), 'formatted_date' => $payment->created_at->format('M d, Y'), ]; }); return response()->json([ 'success' => true, 'data' => [ 'payments' => $payments ] ], 200); } catch (\Exception $e) { logger()->error('Mobile API Employer Get Payments Failure: ' . $e->getMessage()); return response()->json([ 'success' => false, 'message' => 'An error occurred while fetching the payment history.', 'error' => app()->environment('local') ? $e->getMessage() : 'Internal Server Error' ], 500); } } }