Stripe and Billing setup for Laravel Spark

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

2. 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.

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

3. Add your API keys to your .env file

STRIPE_KEY=
STRIPE_SECRET=

4. Set up Stripe webhooks

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

5. Configure Plans/Products in Stripe

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.

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

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

CTO @technocrat_au. Web developing for over 17 years using PHP, Drupal, Laravel, React, VueJS, .NET, AWS… Author of https://buff.ly/2yZYw3Z