attributes->get('employer'); try { $employerId = $employer->id; $page = (int)$request->input('page', 1); $perPage = (int)$request->input('per_page', 15); $query = DB::table('subscriptions') ->where('user_id', $employerId) ->orderBy('created_at', 'desc'); $total = $query->count(); $offset = ($page - 1) * $perPage; $payments = $query->skip($offset)->take($perPage)->get() ->map(function ($sub) { $planLabel = ucfirst($sub->plan_id) . ' Sponsor Pass'; $startsAt = $sub->starts_at ?? $sub->created_at; return [ 'id' => $sub->id, 'amount' => (float)$sub->amount_aed, 'currency' => 'AED', 'description' => $planLabel, 'status' => $sub->status === 'active' ? 'success' : $sub->status, 'date' => date('Y-m-d H:i:s', strtotime($startsAt)), 'formatted_date' => date('M d, Y', strtotime($startsAt)), ]; }); return response()->json([ 'success' => true, 'data' => [ 'payments' => $payments, 'pagination' => [ 'total' => $total, 'per_page' => $perPage, 'current_page' => $page, 'last_page' => max(1, (int)ceil($total / $perPage)), ] ] ], 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); } } }