Creating Private/Free Plans in Laravel Spark

Creating Private/Free Plans in Laravel Spark

Laravel/Spark is an amazing SaaS framework built on top of the equally elegant Laravel framework. With it, you get some pretty solid out-of-the-box functionality for creating SaaS applications, such as recurring billing, team/user subscriptions, etc. This serves to free up your time to focus on creating the business logic for your SaaS application itself. Brilliant stuff! One thing that it doesn't easily do, however, is allow you to create a "private" (possibly "free" plan) for use by your own organization, your beta customers, etc. This article will show you how to achieve that result with as little mucking about as possible.

Step 1:  Setting up the plan in Spark

Create your free/private plan in the booted() method of your app/Providers/SparkProvider.php file. Here is an example:


        Spark::TeamPlan('My Private Plan', 'my-private-plan-slug')
            ->price(0.00)
            ->archived()
            ->yearly()
            ->maxTeams(5)
            ->maxTeamMembers(250)
            ->features([
                'Feature 1',
                'Feature 2',
                'Feature 3',
            ]);

The key items here are a zero price (could be non-zero, if you'd like), and the archived() method which will hide the plan from new users so they don't choose it.

Step 2:  Setting up the plan in Stripe

Now that you've set up your private/free plan in Spark, it is time to head over to your Stripe.com account (or Braintree, I suppose, if you are using that payment processor). Go to the Stripe dashboard and choose the Subscription option, and then Plans. Add your new private/free plan there as well, paying careful attention to make sure you provide the same details as you configured in your Spark plan (pricing, name, slug, etc). Make sure that the plan ID in Stripe is the same as your slug in Spark (in the case of the example above, it would be my-private-plan-slug).

Step 3: Manually adding a customer in stripe

Now that you've set up your private/free plan in Spark AND Stripe, you will also need to stay at Stripe.com and set up your organization, your partner organization, or whoever you want to use this plan as a "customer". Normally, this is handled by Spark, but we're circumventing that process and doing it ourselves. It is quite simple, and only required that you add an email address and an optional description for the customer. Once you save it, you will see that Stripe has assigned a customer ID for the account. Copy this value to your clipboard as you will need it in Step 4 below!

Step 4: Add the plan to the new customer in Stripe

Now that you've set up your customer in Stripe, view that customer, and choose the option to add a subscription plan to the account. Of course, you'll want to choose the private/free plan you set up in Step 2 above!

Step 5: Manually add the subscription in your app's database

Fire up your favorite database client and make the following column value changes to the teams and team_subscriptions tables for the rows associated with the existing team to which you wish to assign the plan:

team_subscriptions.name = 'default'
​​​​​​team_subscriptions.stripe_id = <Paste from your clipboard!>
team_subscriptions.stripe_plan = 'my-private-plan-slug'
team_subscriptions.quantity= 1
team_subscriptions.trial_ends_at = NULL
team_subscriptions.ends_at = NULL

teams.stripe_id = <Paste from your clipboard!>
teams.current_billing_plan = 'my-private-plan-slug'

That's it! Moving forward, you need only repeat steps 3 and 4 above for future teams that you wish to use your private/free plan!

Hope this little tutorial has been helpful!