json([ 'data' => $credits->summary($request->user()), ]); } public function storeRewardedAdSession( RewardedAdSessionRequest $request, GenerationCreditService $credits, ): JsonResponse { try { $session = $credits->createRewardedAdSession( $request->user(), $request->validated('platform'), ); } catch (RewardedAdUnavailable $exception) { return response()->json([ 'message' => $exception->getMessage(), ], 422); } catch (MissingRewardedAdUnit $exception) { return response()->json([ 'message' => $exception->getMessage(), ], 503); } return response()->json([ 'data' => $this->rewardedAdSessionPayload($session), ], $session->wasRecentlyCreated ? 201 : 200); } /** * @return array{id: string, adUnitId: ?string, customData: string, userId: string, expiresAt: string} */ private function rewardedAdSessionPayload(RewardedAdSession $session): array { return [ 'id' => $session->id, 'adUnitId' => $session->ad_unit_id, 'customData' => $session->custom_data, 'userId' => $session->user_id, 'expiresAt' => $session->expires_at->toIso8601String(), ]; } }