Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tonning committed Mar 28, 2023
1 parent 8de1f63 commit 0706d09
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -3,6 +3,7 @@
namespace Astrogoat\Courses\Http\Livewire\RegistrationServices\StripeCheckout\Courses;

use Astrogoat\Courses\Models\Course;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Laravel\Cashier\Cashier;
Expand Down Expand Up @@ -39,14 +40,18 @@ public function updating($property, $value)
);
}

public function getProducts()
public function getProducts(): Collection
{
$prices = Cache::remember('stripe-prices', now()->addMinutes(5), fn () => Cashier::stripe()->prices->all()->data);
$products = Cache::remember('stripe-products', now()->addMinutes(5), fn () => Cashier::stripe()->products->all()->data);

return collect($prices)->mapWithKeys(function (Price $price) use ($products) {
$product = collect($products)->where('id', $price->product)->sole();

if (! $product) {
return [];
}

return [$price->id => $product->name . ' - $' . ($price->unit_amount / 100)];
});
}
Expand Down

0 comments on commit 0706d09

Please sign in to comment.