akyroslabs/laravel-polar
Composer 安装命令:
composer require akyroslabs/laravel-polar
包简介
Polar.sh integration for Laravel — subscriptions, checkout, customer portal, webhooks, plan limits, usage billing, and benefits. Polar as Merchant of Record.
README 文档
README
Caution
This package is deprecated and unmaintained.
Polar's API has moved on (checkout body shape, webhook secret format,
signature verification semantics) and keeping this package in step
would be a permanent moving-target chase. Use
danestves/laravel-polar
instead — it ships against the current Polar API, is built on the
official polar-sh/sdk,
and has a healthy upstream maintenance cadence.
Quick migration map (≈30 min for a typical app)
| This package | danestves/laravel-polar |
|---|---|
use AkyrosLabs\Polar\Billable; |
use Danestves\LaravelPolar\Billable; |
$user->checkout($productId) |
$user->checkout([$productId]) (array) |
->metadata([...]) / ->successUrl(...) |
->withMetadata([...]) / ->withSuccessUrl(...) |
Event: AkyrosLabs\Polar\Events\OrderCreated with $event->data array |
Danestves\LaravelPolar\Events\OrderCreated with $event->billable, $event->order, $event->payload |
POLAR_API_KEY, POLAR_SANDBOX=true|false |
POLAR_ACCESS_TOKEN, POLAR_SERVER=sandbox|production, POLAR_ORGANIZATION_ID |
polar_orders.polar_customer_id column |
renames to customer_id |
Webhook URL /polar/webhook |
unchanged (/polar/webhook) |
The webhook controller + event names are deliberately close enough
that most listeners just need an import swap and a small refactor of
how they read order metadata (the new event ships the full SDK
payload as $event->payload; round-trip via
json_decode(json_encode($event->payload), true) if you need the
flat array shape this package used to provide).
The repository will be archived shortly. Issues and PRs will not be reviewed.
Polar.sh integration for Laravel — subscriptions, checkout, customer portal, webhooks, plan limits, usage billing, benefits, and more. Polar as Merchant of Record.
No tax headaches. No invoice logic. Polar handles it all.
Installation
composer require akyroslabs/laravel-polar
Publish config and migrations:
php artisan vendor:publish --tag=polar-config php artisan vendor:publish --tag=polar-migrations php artisan migrate
Configuration
Add to your .env:
POLAR_API_KEY=polar_key_... POLAR_WEBHOOK_SECRET=whsec_... POLAR_SANDBOX=false POLAR_BILLABLE_MODEL=App\Models\Tenant
Configure plans in config/polar.php:
'plans' => [ 'free' => [ 'product_id' => null, 'limits' => ['servers' => 2, 'users' => 1], 'features' => ['basic_monitoring'], ], 'starter' => [ 'product_id' => 'polar-product-id', 'limits' => ['servers' => 10, 'users' => 3], 'features' => ['*'], ], 'pro' => [ 'product_id' => 'polar-product-id', 'limits' => ['servers' => 50, 'users' => 10], 'features' => ['*'], ], ],
Setup
Add the Billable trait to your model:
use AkyrosLabs\Polar\Billable; class Tenant extends Model { use Billable; }
Register the webhook URL in your Polar dashboard:
https://your-app.com/polar/webhook
Checkout
// Redirect to Polar checkout return $tenant->checkout('price_id') ->successUrl('/dashboard?upgraded=1') ->redirect(); // Subscribe to a plan return $tenant->subscribe('price_id') ->successUrl('/dashboard') ->redirect(); // One-time charge return $tenant->charge(4999, 'product_id') ->redirect(); // Just get the URL $url = $tenant->checkout('price_id')->url();
Subscription Management
// Check status $tenant->subscribed(); // Has active subscription? $tenant->subscribed('default', $productId); // On specific product? $tenant->onTrial(); // In trial? $tenant->onGracePeriod(); // Canceled but still active? // Get subscription $sub = $tenant->subscription(); $sub->active(); // Active? $sub->canceled(); // Canceled? $sub->valid(); // Active, trial, or grace period? $sub->ended(); // Fully ended? $sub->pastDue(); // Payment past due? // Actions $sub->swap('new_price_id'); // Change plan $sub->cancel(); // Cancel at period end $sub->resume(); // Resume during grace period
Customer Portal
return redirect($tenant->customerPortalUrl()); // Or shorthand return $tenant->redirectToCustomerPortal();
Plan Limits & Features
$tenant->planName(); // "pro" $tenant->planLimit('servers'); // 50 $tenant->planLimit('users'); // 10 $tenant->hasFeature('attack_mode'); // true $tenant->onFreePlan(); // false $tenant->exceedsLimit('servers', 48); // false $tenant->exceedsLimit('servers', 50); // true $tenant->planLimits(); // ['servers' => 50, 'users' => 10] $tenant->planFeatures(); // ['*']
Usage-Based Billing
// Track single event $tenant->ingestUsageEvent('api_call', ['endpoint' => '/servers']); // Batch events $tenant->ingestUsageEvents([ ['name' => 'api_call', 'metadata' => ['endpoint' => '/alerts']], ['name' => 'api_call', 'metadata' => ['endpoint' => '/servers']], ]); // Get meters $tenant->listCustomerMeters();
Benefits
$tenant->listBenefits(); $tenant->getBenefit('benefit_id'); $tenant->listBenefitGrants('benefit_id');
Orders
$tenant->orders; // All orders $tenant->hasPurchasedProduct('product_id'); // Check purchase
Webhooks
The package automatically processes these Polar events:
| Event | Action |
|---|---|
subscription.created |
Creates subscription + customer record |
subscription.updated |
Syncs status, product, period end |
subscription.active |
Sets status to active |
subscription.canceled |
Sets status to canceled |
subscription.revoked |
Sets status to revoked |
order.created |
Creates order record |
order.updated |
Syncs order data |
customer.created/updated/deleted |
Syncs customer records |
checkout.created/updated |
Fires events |
benefit_grant.created/updated/revoked |
Fires events |
Custom Event Listeners
use AkyrosLabs\Polar\Events\SubscriptionCreated; class HandleNewSubscription { public function handle(SubscriptionCreated $event): void { $tenant = $event->billable; // Send welcome email, provision resources, etc. } }
17 events available: WebhookReceived, WebhookHandled, SubscriptionCreated, SubscriptionUpdated, SubscriptionActive, SubscriptionCanceled, SubscriptionRevoked, OrderCreated, OrderUpdated, CustomerCreated, CustomerUpdated, CustomerDeleted, CheckoutCreated, CheckoutUpdated, BenefitGrantCreated, BenefitGrantUpdated, BenefitGrantRevoked
Middleware
// In bootstrap/app.php — auto-registered as 'subscribed' Route::middleware('subscribed')->group(function () { // Requires any active subscription }); Route::middleware('subscribed:pro')->group(function () { // Requires specific plan });
Blade Directives
@subscribed <p>You have an active subscription.</p> @endsubscribed @onPlan('pro') <p>Pro features here.</p> @endonPlan @onTrial <p>Your trial ends soon.</p> @endonTrial @feature('attack_mode') <button>Activate Attack Mode</button> @endfeature
Artisan Commands
# Sync all subscriptions with Polar php artisan polar:sync # List all products php artisan polar:products
Facade
use AkyrosLabs\Polar\Facades\Polar; $products = Polar::listProducts(); $subscription = Polar::getSubscription($id); $session = Polar::createCustomerSession($customerId);
Database Tables
| Table | Purpose |
|---|---|
polar_customers |
Billable ↔ Polar customer mapping, generic trial |
polar_subscriptions |
Active subscriptions with status, product, period |
polar_orders |
Orders with amounts, tax, refund tracking |
All tables use polymorphic billable relationships — works with any model.
Sandbox Mode
Set POLAR_SANDBOX=true to use sandbox-api.polar.sh for testing.
Requirements
- PHP 8.2+
- Laravel 11 or 12
License
MIT License
Built by Akyros Labs LLC — hello@akyroslabs.com
akyroslabs/laravel-polar 适用场景与选型建议
akyroslabs/laravel-polar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「saas」 「billing」 「subscriptions」 「polar」 「merchant-of-record」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 akyroslabs/laravel-polar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 akyroslabs/laravel-polar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 akyroslabs/laravel-polar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Cashier provides an expressive, fluent interface to Braintree's subscription billing services.
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
Metamel Addresses is a polymorphic Laravel package, for address book management. You can add addresses to any eloquent model with ease.
Asaas.com PHP API v3 Wrapper
Adaptaçao Asaas.com PHP API Wrapper para PHP 5.6
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 46
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-04