rememberForever('plans', fn () => $this->stripe->getPlans()); return response(new PlanCollection($plans), 200); } /** * Get plan record */ public function show(string $id): Response { // Store or Get plan to cache $plan = cache() ->rememberForever("plan-$id", fn () => $this->stripe->getPlan($id)); return response(new PlanResource($plan), 200); } /** * Create new plan * TODO: store request */ public function store(Request $request): Response | PlanResource { if (is_demo()) { $plan = cache() ->rememberForever('plan-starter-pack', fn () => $this->stripe->getPlan('starter-pack')); return new PlanResource($plan); } $plan = new PlanResource( $this->stripe->createPlan($request) ); // Clear cached plans cache_forget_many(['plans', 'pricing']); return response($plan, 201); } /** * Update plan attribute */ public function update(Request $request, string $id): Response { // Abort in demo mode abort_if(is_demo(), 204, 'Done.'); // Update plan $this->stripe->updatePlan($request, $id); // Clear cached plans cache_forget_many(['plans', 'pricing', "plan-$id"]); return response('Saved!', 201); } /** * Delete plan */ public function delete($id): Response { // Abort in demo mode abort_if(is_demo(), 204, 'Done.'); // Delete plan $this->stripe->deletePlan($id); // Clear cached plans cache_forget_many(['plans', 'pricing']); return response('Done!', 204); } }