Stripe and Billing setup for Laravel Spark

Scott Anderson
May 31 · 3 min read
Image for post
Image for post

Laravel Spark comes with a Stripe integration for processing subscription payments via Credit Card.
This is a quick guide for configuring Stripe and Spark to work together.
The official documentation is here https://spark.laravel.com/docs/10.0/billing

1. Create a Stripe account

Go to https://stripe.com and register an account

2. Get your test API keys

In your Stripe Dashboard you should see a link that says ‘Get your test API keys’.

If not, use the ‘Developer’ menu item on the left side, then select ‘API keys’.

This may show your live keys by default. If so, then toggle the Test / Live data view using the switch in the top right corner.

Image for post
Image for post

Copy your test API keys somewhere safe, to be added to your Spark configuration.

3. Add your API keys to your .env file

Edit your .env file and set the following config values using the keys you saved in the previous step:

STRIPE_KEY=
STRIPE_SECRET=

4. Set up Stripe webhooks

In your Stripe Dashboard, click on Developer->Webhooks in the left side menu.

Click ‘Add Endpoint’

Enter your ‘Endpoint URL’ as your site’s domain plus /webhook/stripe
E.g. https://your-domain.com/webhook/stripe

Under ‘Events to send’ add the following 6 events, one at a time:

  • customer.subscription.updated
  • customer.subscription.deleted
  • customer.updated
  • customer.deleted
  • invoice.payment_action_required
  • invoice.payment_succeeded
Image for post
Image for post

5. Configure Plans/Products in Stripe

We need to configure a Product in Stripe for each available subscription plan you intend to offer in your Spark application.

In your Stripe Dashboard click on ‘Products’ on the left side menu.

Click ‘Add Product’.

Add your product name and price details.

Note: You don’t need to add a Free Trial as this functionality is already built into Spark.

Click on ‘Save Product’, or ‘Save and add more’, if you are configuring multiple plans.

After saving, you’ll see a summary of the Product.

Click on the Copy to Clipboard button next to the ‘API ID’ field. You’ll need to copy the API ID for each Product you create.

Image for post
Image for post

6. Add your Product API ID(s) to your SparkServiceProvider.php

Edit app/Providers/SparkServiceProvider.php and within the booted() function, edit or add Stripe Plans to match each of the Products you added within Stripe.

The 2nd argument in the Stripe::Plan() function should be the API ID(s) you copied from each Product in the previous step.

E.g.

Spark::plan(‘Pro’, ‘price_HNQvdu4lQHTBVX’)
->price(99)
->features([
‘All the best features.’
]);

Also, make sure the price matches the price for the product set in Stripe.

Bingo! You’re done.

By default, Spark configures a free trial period of 10 days, which doesn’t require a credit card.

You can modify or remove this by changing the following line in SparkServiceProvider.php

Spark::noCardUpFront()->trialDays(10);

For more details on setting up Team Billing and for checking a user’s subscription status within the application, see the Spark documentation https://spark.laravel.com/docs/10.0/billing

More Spark tutorials

Configuring email verification in Laravel Spark

Setting up Laravel Spark for local development

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store