Skip to main content

Billing and Payments

FilamentFlow comes with subscription payment processing using Stripe for both single and multi-tenant applications. You can easily add subscriptions to your application by configuring the config/filament-flow.php file, but you don't need to if you plan to sync with stripe automatically using the flow:sync-with-stripe command.

Enabling Stripe Payments

Ensure that your Stripe API keys are set in your .env file (see the Laravel Cashier documentation):

.env
STRIPE_KEY=your-stripe-key
STRIPE_SECRET=your-stripe-secret
STRIPE_WEBHOOK_SECRET=your-stripe-webhook-secret

Automatically Syncing Stripe Plans and Products

FilamentFlow provides one-click/command syncing with your existing Stripe products and plans. Just run flow:sync-with-stripe to sync your products and plans with Stripe.

Automatic Stripe Syncing

If you're running the sync-with-stripe comand, you can ignore the stripe_details array in the config/filament-flow.php file.

Manually Syncing Stripe Plans and Products

You may also create products and plans in Stripe by updating the stripe_details key in the config/filament-flow.php file. The key is an array of arrays for products and plans.

Just run flow:setup-stripe to create the products and plans in Stripe.

Requiring Subscriptions to Access Your Application

Sometimes you want may want to prevent users from accessing your application without a subscription, or you may want to allow access to certain parts of your application without a subscription. FilamentFlow makes this easy to configure using the billing.allowed_routes array in the config/filament-flow.php file.

Allowing Access to Certain Routes Without a Subscription

These routes may be either the route name or the class name of the route. For example, the Filament\Pages\Dashboard\Dashboard route can be added to the billing.allowed_routes array to allow access to the dashboard without a subscription.

config/filament-flow.php
'billing' => [
... // other keys
'allowed_routes' => [
\App\Filament\App\Pages\UserBilling::class,
\Filament\Pages\Dashboard::class, // could also be 'filament.app.pages.dashboard'
\Filament\Pages\Auth\EditProfile::class,
],
],

Required Configuration for Stripe Subscriptions

If using Stripe subscriptions, ensure that your config/cashier.php contains something similar to the following configuration, as Stripe requires a default subscription ID:

config/cashier.php
'plans' => [
'default' => [
'price_id' => env('CASHIER_STRIPE_SUBSCRIPTION_DEFAULT_PRICE_ID', 'monthly-starter'),
'quantity' => 1, // Optional
'allow_promotion_codes' => true, // Optional
'collect_tax_ids' => true, // Optional
'metered_price' => false, // Optional
],
],

If you use the php artisan flow:configure command, it will automatically set the CASHIER_STRIPE_SUBSCRIPTION_DEFAULT_PRICE_ID in your .env file if you have subscriptions available in Stripe during the setup process.

To enable payments, you need to set the enabled key to true in the billing array in the config/filament-flow.php file.

You can also set the require_subscription key to true if you want to require a subscription to access your application, and the allowed_routes key to an array of routes that are allowed to be accessed without a subscription.

By default, the home route and the Filament\Pages\Dashboard\Dashboard route are allowed without a subscription.

Stripe Options

config/filament-flow.php
  /**
* The model to use for billing. Adjust this if you are using a different model.
* It affects AppServiceProvider.php
*/
'billable_model' => env( 'BILLABLE_MODEL', \App\Models\User::class ),

/**
* If you're using Stripe subscriptions, you can configure the details here, then
* run php artisan flow:setup-stripe.
*/
'stripe_details' => [

/**
* See https://docs.stripe.com/api/products/object for more information on the fields
* The 'id' field should match the 'product' field in the 'plans' array below.
*/
'products' => [
[
'id' => 'monthly',
'name' => 'Monthly'
],
// Add more products here
],

/**
* See https://docs.stripe.com/api/plans/object for more information on the fields
* The 'product' field should match the 'id' of a product in the 'products' array above.
*/
'plans' => [
[
'id' => 'monthly-starter',
'amount' => 3499, // Amount in cents
'billing_scheme' => 'per_unit',
'currency' => 'usd',
'interval' => 'month', // Options are day, week, month, year
'interval_count' => 1,
'usage_type' => 'licensed',
'product' => 'monthly'
],
// Add more plans here that match the id of a product above
],
],

Configuration

config/filament-flow.php
'billing' => [
'enabled' => env( 'BILLING_ENABLED', true ),

'require_subscription' => env( 'REQUIRE_SUBSCRIPTION', false ),

'allowed_routes' => [
\App\Filament\App\Pages\UserBilling::class,
\Filament\Pages\Dashboard::class, // could also be 'filament.app.pages.dashboard'
\Filament\Pages\Auth\EditProfile::class,
],
],