juzaweb/subscription

订阅支付支持

安装量: 71,756

依赖者: 1

建议者: 0

安全: 0

星标: 3

关注者: 1

分支: 0

开放问题: 0

类型:juzaweb-plugin

1.0.9 2024-04-18 10:46 UTC

This package is auto-updated.

Last update: 2024-08-29 03:48:15 UTC


README

功能

  • 计划管理
  • Paypal 订阅
  • 个人资料页面中的支付历史
  • 个人资料页面中的升级
  • 订阅管理
  • 按计划禁用广告(使用广告管理插件)
  • Stripe 支付
  • 限制查看帖子功能

使用

注册模块

要使用此插件,在钩子操作中,您可以使用订阅功能注册模块:在示例插件中,我们使用 membership

  • 注册菜单父级
$this->hookAction->addAdminMenu(
    'subscription',
    'subscription',
    [
        'label' => trans('Subscription'),
    ]
);
  • 将模块注册到菜单父级 subscription
$this->subscription->registerModule(
    'membership',
    [
        'label' => trans('Membership'),
        'menu' => [
            'label' => trans('Subscription'),
            'parent' => 'subscription',
        ]
    ]
);

注册模块所有选项

$this->subscription->registerModule(
    'membership',
    [
        'label' => trans('Membership'),
        'menu' => [
            'label' => trans('Membership'),
            'parent' => 'subscription',
        ],
        'allow_plans' => true,
        'allow_payment_methods' => true,
        'allow_user_subscriptions' => true,
        'allow_payment_histories' => true,
        'allow_setting_page' => true,
    ]
);

注册功能

use Juzaweb\Subscription\Contrasts\Subscription;

app()->make(Subscription::class)->registerPlanFeature(
    'view_ads',
    [
        'label' => __('No Ads on website'),
        'module' => 'membership',
    ]
);
  • 处理功能
# Action Class
public function handle(): void
{
    if (plugin_enabled('juzaweb/ads-manager')) {
        $this->addFilter('jwad.can_show_ads', [$this, 'filterCanShowAds']);
    }
}

/**
 * A function that filters whether ads can be shown based on user subscription plan.
 *
 * @param mixed $canShowAds The current value indicating if ads can be shown.
 * @return bool
 */
public function filterCanShowAds($canShowAds): bool
{
    $user = request()?->user();

    if (!$user) {
        return $canShowAds;
    }

    $plan = subscripted_plan($user, 'membership');

    if (!$plan) {
        return $canShowAds;
    }

    $planFeature = $plan->features()
        ->where(['feature_key' => 'view_ads'])
        ->first();

    if (!$planFeature || $planFeature->value != 1) {
        return $canShowAds;
    }

    return false;
}