Skip to content

Commit

Permalink
📝 Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
juzaweb committed Apr 29, 2024
1 parent a485b3a commit 2abd961
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 18 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/schedule-test.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Run phpunit test suite

on: [push, pull_request]
on:
push:
pull_request:
schedule:
- cron: '0 * * * *'

jobs:
phpunit-test-suite:
Expand Down
78 changes: 73 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
# Subscription paymemt for Juzaweb CMS

## Features
- [x] Plan management
- [x] Paypal subscription
- [x] Payment history in profile page
- [x] Upgrade in profile page
- [x] Subscription management
- [x] Disabled ADs by plan (using Ads Manager plugin)
- [ ] Stripe payment
- [ ] Limit view posts feature

## Using

### Register module
To use this plugin, in Hook Action, you register the module using the subscription feature:
In demo plugin, we use `membership`

- Register menu Parent
```php
Expand All @@ -18,9 +30,9 @@ $this->hookAction->addAdminMenu(
- Register module to menu parent `subscription`
```php
$this->subscription->registerModule(
'module_key',
'membership',
[
'label' => trans('Subscription'),
'label' => trans('Membership'),
'menu' => [
'label' => trans('Subscription'),
'parent' => 'subscription',
Expand All @@ -33,11 +45,11 @@ $this->subscription->registerModule(

```php
$this->subscription->registerModule(
'module_key',
'membership',
[
'label' => trans('Subscription'),
'label' => trans('Membership'),
'menu' => [
'label' => trans('Subscription'),
'label' => trans('Membership'),
'parent' => 'subscription',
],
'allow_plans' => true,
Expand All @@ -47,4 +59,60 @@ $this->subscription->registerModule(
'allow_setting_page' => true,
]
);
```

### Register Features

```php
use Juzaweb\Subscription\Contrasts\Subscription;

app()->make(Subscription::class)->registerPlanFeature(
'view_ads',
[
'label' => __('No Ads on website'),
'module' => 'membership',
]
);
```

- Handle feature
```php
# 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;
}
```

0 comments on commit 2abd961

Please sign in to comment.