An introduction to Laravel Spark for Paddle.
config/spark.php
configuration file.
.env
environment file.
Of course, you should adjust the variable’s values to correspond to your own Paddle account’s credentials. In addition, you should set the PADDLE_SANDBOX
variable to true
if you are using Paddle’s sandbox environment. Your Paddle API credentials and webhook secret are available in your Paddle account dashboard via the “Developer Tools” section’s “Authentication” and “Notifications”:
en
, ensure the ext-intl
PHP extension is installed and configured on your server./paddle/webhook
URI. You should enable webhook alerts for the following events:
billables
array of your application’s spark
configuration file. By default, this array contains an entry for the App\Models\User
model.
Before continuing, you should ensure that the model class that corresponds to your billable model is using the Spark\Billable
trait. 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:
name
and email
attributes as the name and email address associated with the Paddle customer record it creates for the model. If you would like to specify another attribute that should be used instead, you may define a paddleName
and paddleEmail
method on your billable model:
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 plan identifiers associated with the subscription plan within your Paddle 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:
/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.