To handle a free plan in Laravel Spark, you can indeed define a free plan in Stripe. This is a common approach and it allows you to manage all your plans, including free ones, within the same billing system. Here’s how you can set it up:
-
Define the Free Plan in Stripe:
- Go to your Stripe Dashboard.
- Navigate to the "Products" section and create a new product.
- Under this product, create a new pricing plan with a price of $0.00.
-
Add the Free Plan to Your Laravel Spark Configuration:
- Open your
spark.phpconfiguration file. - Add the free plan to the
plansarray.
- Open your
Here’s an example of how you can define the free plan in your spark.php configuration file:
'subscriptions' => [
'plans' => [
[
'name' => 'Free Plan',
'short_description' => 'This is a free plan.',
'monthly_id' => 'free-plan-id', // The ID from Stripe
'yearly_id' => null, // Set to null if you don't have a yearly option
'features' => [
'Feature 1',
'Feature 2',
],
],
// Other plans...
],
],
-
Handle Downgrades in Your Application:
- When a user wants to downgrade to the free plan, you can update their subscription to the free plan using Spark’s subscription management methods.
Here’s an example of how you can handle the downgrade in your controller:
public function downgradeToFreePlan(Request $request)
{
$user = $request->user();
// Assuming 'free-plan-id' is the ID of your free plan in Stripe
$user->subscription('default')->swap('free-plan-id');
return redirect()->route('home')->with('status', 'You have been downgraded to the free plan.');
}
By following these steps, you can effectively manage a free plan within Laravel Spark and allow users to downgrade from a paid plan to a free plan seamlessly.