This package integrates Freemius subscription management with Laravel, inspired by Laravel Cashier. It allows you to manage subscriptions, plans, and payments using Freemius, along with providing easy-to-use methods for interacting with the Freemius API.
- Subscribe users to Freemius plans
- Retrieve user subscription details from Freemius
- Swap plans, update payment methods, and cancel subscriptions
- Download invoices directly
- Webhook support for real-time subscription events
Add your Freemius credentials to your .env
file:
FREEMIUS_API_TOKEN=1a5dd
FREEMIUS_PRODUCT_SECRET_KEY=sk_
FREEMIUS_PRODUCT_ID=12345
FREEMIUS_STORE_ID=1234
To make sure we can actually create checkouts for our customers, we'll need to configure a model to be our "billable" model. This is typical the User
model of your app. To do this, import and use the Billable
trait on your model:
use Freemius\Laravel\Billable;
class User extends Authenticatable
{
use Billable;
}
Incoming webhooks should not be affected by CSRF protection. To prevent this, add your webhook path to the except list of your App\Http\Middleware\VerifyCsrfToken
middleware:
protected $except = [
'freemius/*',
];
Or if you're using Laravel v11 and up, you should exclude freemius/* in your application's bootstrap/app.php
file:
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'freemius/*',
]);
})
http://127.0.0.1:8000/freemius/webhook
$user = $request->user();
$checkout = $user->checkout($planId)
->withEmail('john@example.com')
->withTitle('my saas product')
->showReviews(true)
->showRefundBadge(true)
->withCancelUrl('https://site.com/checkout/')
->withCancelIcon('https://example.com/logo.png');
return $checkout->redirect();
if ($user->subscribed()) {
// User has an active subscription
}
if ($user->subscription()->valid()) {
// Subscription is valid
}
use Freemius\Laravel\Freemius;
$url = Freemius::downloadInvoice($paymentId);
$subscription = $request->user()->subscription();
$subscription->cancelUrl = 'https://site.com/checkout/';
$subscription->cancelIcon = 'https://example.com/logo.png';
$url = $subscription->swap($planId);
return redirect()->away($url);
$subscription = $request->user()->subscription();
$url = $subscription->updatePaymentMethodUrl();
return redirect()->away($url);
$subscription = $request->user()->subscription();
if (! $subscription) {
return response()->json(['error' => 'No active subscription found.'], 404);
}
// Cancel subscription
$subscription->cancel($subscription->subscription_id);
We welcome contributions! Steps to contribute:
-
Fork the repository and clone to your local machine
-
Create a feature branch for your changes
-
Implement your changes or add new features
-
Test thoroughly
-
Submit a pull request with a detailed description
-
This package is still in development. Some features may be incomplete.
-
Contributions, bug reports, and feature requests are highly appreciated.