An introduction to Laravel Spark for Stripe.
config/spark.php
configuration file.
.env
environment file.
Of course, you should adjust the variable’s values to correspond to your own Stripe account’s credentials. Your Stripe API credentials and public key are available in your Stripe account dashboard:
en
, ensure the ext-intl
PHP extension is installed and configured on your server./spark/webhook
URI. You should enable webhook alerts for the following events:
listen
command. For example, if you are developing locally via the artisan serve
CLI command and serving your site at http://localhost:8000
, you may run the following Stripe CLI command to allow Stripe to communicate with your application:
billables
array of your application’s spark
configuration file. By default, this array contains an entry for the App\Models\User
model. If the billable model is something other than App\Models\User
, you should invoke Cashier’s useCustomerModel
method in the boot
method of your SparkServiceProvider
class in order to inform Cashier of your custom model:
Spark\Billable
trait and that it casts the trial_ends_at
attribute to datetime
. In addition, your billable model’s primary key should be an integer
column named id
:
billables
configuration array is keyed by a “slug” that is a shortened form of the billable model class. This slug can be used when accessing the Spark customer billing portal, such as https://example.com/billing/user
or https://example.com/billing/team
.
App\Providers\SparkServiceProvider
class was created for you. Within this service provider, you will find a callback that is used by Spark to resolve the billable model instance when accessing the Spark billing portal. By default, this callback simply returns the currently authenticated user, which is the desired behavior for most applications using Laravel Spark:
App\Providers\SparkServiceProvider
class was created for you. Within this service provider, you will find the authorization callback definition used to determine if a given user is authorized to view the billing portal for the App\Models\User
billable class. Of course, if your application is not billing users, you should update the billable class and authorization callback logic to fit your application’s needs. By default, Spark will simply verify that the currently authenticated user can only manage its own billing settings:
true
, the currently authenticated user will be authorized to view the billing portal and manage the billing settings for the given $billable
model. If the callback returns false
, the request to access the billing portal will be denied.
You are free to customize the authorize
callback based on your own application’s needs. For example, if your application bills teams instead of individual users, you might update the callback like so:
billables
array of your application’s config/spark.php
configuration file:
The billable configuration within the billables
array contains a plans
array. Within this array you may configure each of the billing plans offered by your application to that particular billable type. The monthly_id
and yearly_id
identifiers should correspond to the price / plan identifiers configured within your Stripe account dashboard:
yearly_id
identifier from your plan configuration. Likewise, if your plan only offers a yearly billing cycle, you may omit the monthly_id
identifier.
In addition, you are free to supply a short description of the plan and a list of features relevant to the plan. This information will be displayed in the Spark billing portal.
If you would like to indicate some features that are not available for a given plan, you may prefix them with --
. These features will be displayed using strikethrough text:
checkoutSessionOptions
method, you can customize the Stripe Checkout experience by providing a closure that receives the billable and chosen plan as its argument.
Typically, you should invoke Spark’s checkoutSessionOptions
method in the boot
method of your SparkServiceProvider
class. The provided closure can return any option accepted by Stripe Checkout:
paymentMethodSessionOptions
method. Typically, you should invoke Spark’s paymentMethodSessionOptions
method in the boot
method of your SparkServiceProvider
class:
/billing
URI. So, if your application is being served on localhost
, you may access your application’s billing portal at http://localhost/billing
.
Of course, you may link to the billing portal from your application’s dashboard however you see fit:
terms_url
configuration value in your application’s config/spark.php
configuration file:
/terms
in the billing portal.
config/spark.php
configuration file:
custom-addresses
option to the feature definition:
paymentNotificationEmails
feature within your application’s config/spark.php
configuration file: