netcore/module-subscription

该包最新版本(v1.0.6)没有提供许可证信息。

v1.0.6 2018-04-07 20:42 UTC

This package is not auto-updated.

Last update: 2024-09-23 07:33:02 UTC


README

此模块允许您管理订阅计划,并让用户可以订阅计划。

预安装

仅当您使用完全自定义的支付方式时才使用此模块。如果您使用Laravel Cashier,将提供支持!

此包是Netcore CMS生态系统的一部分,仅在以下包安装的项目中功能正常

  1. https://github.com/netcore/netcore
  2. https://github.com/netcore/module-admin
  3. https://github.com/netcore/module-translate

安装

  • 使用composer安装此包
composer require netcore/module-subscription
  • 发布配置/迁移
php artisan module:publish-config Subscription
php artisan module:publish-migration Subscription
php artisan migrate
  • config/netcore/module-subscription.php文件中配置计划和计费周期。

  • 将配置种子到数据库

php artisan module:seed Subscription
  • Modules\Subscription\Traits\Subscribable特性添加到您的User模型中

使用方法

  • 以价格规范订阅计划
$plan      = Modules\Subscription\Models\Plan::where('key', 'premium')->first();
$planPrice = $plan->prices()->inPeriod('monthly')->first();
$user      = App\User::first();
$user->subscribe($planPrice, true);
/*
 The boolean stands for whether the user has already paid for the subscription or not.
 If a boolean is not provided, it'll be automatically set to false.
*/
  • 获取用户计划
$plan = $user->plan;
  • 获取用户订阅
$subscription   = $user->subscription;
$expirationDate = $subscription->expires_at;
$userHasPaid    = $subscription->is_paid;
  • 取消订阅
$user->cancelSubscription();
  • 续订订阅
$user->renewSubscription(true);
// The boolean stands for whether the user has already paid for the subscription or not