定制 lacodix/laravel-plans 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lacodix/laravel-plans

Composer 安装命令:

composer require lacodix/laravel-plans

包简介

A Laravel package to manage plans, features and subscriptions and track billing in your Laravel SAAS.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Documentation

You can find the entire documentation for this package on our documentation site. Including several usecases with detailed explanation.

What it does

  • Manage all Plans and Addons of your SaaS where users can subscribe to.
  • Subscribe to one or more plans with different billing intervals.
  • Manage optional features, if you need it. You can also stick with plans and just check for a subscribed plan.
  • Offer countable and uncountable features. Use uncountable features to just enable/disable a functionality. Use countable features, for things like tokens, credits, and others. Attach different values of the feature to different plans, including "unlimited". Auto reset the values after given intervals.
  • Consume Features as long as some amount is available. Split up usage on different plans, depending on the order of the plans.
  • Translate your plans and features. Identify both by slug in your app, but offer it to your users localized, powered by spatie/laravel-translatable
  • Order your plans, features (for visualisation to your users) and subscriptions (to keep control over usage order)
  • Allow meta data in plans and subscriptions. The usage of meta data is up to you. In some usecase we take meta data to save currency or additional price information. This information can be used by a subsequent billing system.

What it doesn't

  • Billing. We don't create invoices or keep track on bills. Use the invoice service of your choice, doesn't matter which. Stripe, PayPal, your own software and any other. You just get events from this package, when subscriptions are created or renewed, and this can be used to trigger invoices. You are also free to wait for payment before you create the subscription or the other way round.
  • Pricing. Yes there is a price column in the plan model, that can be used for visualisation. You also can use meta data for additional price information like we do it in some examples. But you don't need to use it. You can keep your prices in your billing system or save it separate from the plans. But indeed, if you use the price-column you can also get calculated prices for partial subscription intervals.

Installation

composer require lacodix/laravel-plans

Quickstart

To get familiar with all settings and possibilities, please see the more detailed examples. This is only a very quick overview how the package can work.

Subscribers

Add our HasSubscription Trait to any model.

use Lacodix\LaravelPlans\Models\Traits\HasSubscriptions;

class User extends Authenticatable {
    use HasSubscriptions;
    
    ...
}

Plans and Features

Create a Plan with Features (the latter is optional, if you don't need feature functionality).

use Lacodix\LaravelPlans\Enums\Interval;
use Lacodix\LaravelPlans\Models\Feature;
use Lacodix\LaravelPlans\Models\Plan;

$myPlan = Plan::create([
    'slug' => 'my-plan',
    'name' => 'My Plan', // can also be locale-array - see Feature below
    'price' => 50.0,
    'active' => true,
    'billing_interval' => Interval::MONTH,
    'billing_period' => 1,
    'meta' => [
        'price_per_token' => 0.05,
    ],
]);

$myFeature = Feature::create([
    'slug' => 'tokens',
    'name' => [
        'de' => 'Zusätzliche Tokens',
        'en' => 'Additional Tokens',
    ],
]);

$myPlan->features()->attach($myFeature, [
    'value' => 1000,
    'resettable_period' => 1,
    'resettable_interval' => Interval::MONTH,
]);

Subscribe and renew

// Subscribe to multiple plans
$user->subscribe($myPlan1, 'main');
$user->subscribe($myPlan2, 'addon');

// Change Subscription
$user->subscribe($myPlan3, 'main'); // will replace myPlan1 subscription

// Renew
$user->subscriptions()->first()->renew();

// Cancel
$user->subscriptions()->first()->cancel();

Testing

composer test

Contributing

Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.

composer rector:test
composer csfixer:test
composer phpstan:test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

This package is inspired by Laravel Subscriptions created by Laravel Cameroon and was initially started as a fork of it. After several decisions to go different ways for subscription calculation, it was rewritten from scratch, but still contains several simple methods and other code parts of the original. So if this package doesn't fit your needs, try a look into Laravel Cameroons subscription package.

License

The MIT License (MIT). Please see License File for more information.

lacodix/laravel-plans 适用场景与选型建议

lacodix/laravel-plans 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 986 次下载、GitHub Stars 达 5, 最近一次更新时间为 2024 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「subscription」 「features」 「laravel」 「saas」 「plan」 「bill」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 lacodix/laravel-plans 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lacodix/laravel-plans 我们能提供哪些服务?
定制开发 / 二次开发

基于 lacodix/laravel-plans 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 986
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-03