From 4163c28e3786d8c3fb401ba33293b242b9de5669 Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Mon, 22 Mar 2021 15:41:47 +0100 Subject: [PATCH] - Get plan from cache in StripeService.php --- app/Services/StripeService.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Services/StripeService.php b/app/Services/StripeService.php index 6277e1ec..89161c54 100644 --- a/app/Services/StripeService.php +++ b/app/Services/StripeService.php @@ -5,6 +5,7 @@ namespace App\Services; use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\Str; use Laravel\Cashier\Exceptions\IncompletePayment; use Laravel\Cashier\Exceptions\PaymentActionRequired; @@ -241,10 +242,20 @@ class StripeService */ public function getPlan($id) { - $plan = $this->stripe->plans()->find($id); - $product = $this->stripe->products()->find($plan['product']); + if (Cache::has("plan-$id")) { + return Cache::get("plan-$id"); + } - return compact('plan', 'product'); + return Cache::rememberForever("plan-$id", function () use ($id) { + + $plan = $this->stripe->plans()->find($id); + $product = $this->stripe->products()->find($plan['product']); + + return [ + 'plan' => $plan, + 'product' => $product, + ]; + }); } /**