feat(addons): finalize event addon catalog and ai styling upgrade flow
This commit is contained in:
@@ -27,21 +27,22 @@ class PackageController extends Controller
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$type = $request->query('type', 'endcustomer');
|
||||
$provider = strtolower((string) config('checkout.default_provider', CheckoutSession::PROVIDER_PAYPAL));
|
||||
$packages = Package::where('type', $type)
|
||||
->orderBy('price')
|
||||
->get();
|
||||
|
||||
$packages->each(function ($package) {
|
||||
$packages->each(function ($package) use ($provider) {
|
||||
if (is_string($package->features)) {
|
||||
$decoded = json_decode($package->features, true);
|
||||
$package->features = is_array($decoded) ? $decoded : [];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_array($package->features)) {
|
||||
} elseif (! is_array($package->features)) {
|
||||
$package->features = [];
|
||||
}
|
||||
|
||||
$package->setAttribute('checkout_provider', $provider);
|
||||
$package->setAttribute('can_checkout', $this->canCheckoutPackage($package, $provider));
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
@@ -365,4 +366,17 @@ class PackageController extends Controller
|
||||
'cancel_url' => $cancelUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
private function canCheckoutPackage(Package $package, string $provider): bool
|
||||
{
|
||||
if ((float) $package->price <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($provider === CheckoutSession::PROVIDER_LEMONSQUEEZY) {
|
||||
return filled($package->lemonsqueezy_variant_id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user