- Get plan from cache in StripeService.php

This commit is contained in:
Peter Papp
2021-03-22 15:41:47 +01:00
parent 80f27d7448
commit 4163c28e37
+14 -3
View File
@@ -5,6 +5,7 @@ namespace App\Services;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Laravel\Cashier\Exceptions\IncompletePayment; use Laravel\Cashier\Exceptions\IncompletePayment;
use Laravel\Cashier\Exceptions\PaymentActionRequired; use Laravel\Cashier\Exceptions\PaymentActionRequired;
@@ -241,10 +242,20 @@ class StripeService
*/ */
public function getPlan($id) public function getPlan($id)
{ {
$plan = $this->stripe->plans()->find($id); if (Cache::has("plan-$id")) {
$product = $this->stripe->products()->find($plan['product']); 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,
];
});
} }
/** /**