diff --git a/.gitignore b/.gitignore
index 3048ba1..836ac0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,4 @@ Icon?
ehthumbs.db
Thumbs.db
*.mo
+*.phpunit.result.cache
diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results
new file mode 100644
index 0000000..fcf3c4f
--- /dev/null
+++ b/.phpunit.cache/test-results
@@ -0,0 +1 @@
+{"version":1,"defects":{"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCreateAFeature":8,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCalculateResetTime":8,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\PlanTest::testItCanCreateAPlanAndAttachFeatures":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanGetAllIntervalsWithTranslations":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#0":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#1":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#2":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#3":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#4":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#5":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#6":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#7":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#8":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#9":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#10":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#11":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriodWithEmptyStart":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItThrowExceptionOnInvalidInterval":8,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanValidateIntervalUnit":8},"times":{"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCreateAFeature":0.027,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCalculateResetTime":0.008,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\PlanTest::testItCanCreateAPlanAndAttachFeatures":0.013,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanGetAllIntervalsWithTranslations":0.007,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#0":0.007,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#1":0.007,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#2":0.007,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#3":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#4":0.011,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#5":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#6":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#7":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#8":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#9":0.007,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#10":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#11":0.009,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriodWithEmptyStart":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItThrowExceptionOnInvalidInterval":0.008,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanValidateIntervalUnit":0.006}}
\ No newline at end of file
diff --git a/.phpunit.result.cache b/.phpunit.result.cache
new file mode 100644
index 0000000..e9facca
--- /dev/null
+++ b/.phpunit.result.cache
@@ -0,0 +1 @@
+{"version":1,"defects":{"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCreateAFeature":4,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCalculateResetTime":4,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\PlanTest::testItCanCreateAPlanAndAttachFeatures":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanGetAllIntervalsWithTranslations":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #0":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #1":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #2":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #3":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #4":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #5":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #6":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #7":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #8":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #9":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #10":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #11":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriodWithEmptyStart":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItThrowExceptionOnInvalidInterval":4,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanValidateIntervalUnit":4},"times":{"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCreateAFeature":0.047,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\FeatureTest::testItCanCalculateResetTime":0.013,"Laravel\\PricingPlans\\Tests\\Integration\\Models\\PlanTest::testItCanCreateAPlanAndAttachFeatures":0.022,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanGetAllIntervalsWithTranslations":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #0":0.017,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #1":0.019,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #2":0.016,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #3":0.017,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #4":0.017,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #5":0.018,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #6":0.016,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #7":0.017,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #8":0.022,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #9":0.017,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #10":0.017,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod with data set #11":0.016,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriodWithEmptyStart":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItThrowExceptionOnInvalidInterval":0.008,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanValidateIntervalUnit":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#0":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#1":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#2":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#3":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#4":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#5":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#6":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#7":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#8":0.006,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#9":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#10":0.005,"Laravel\\PricingPlans\\Tests\\Unit\\PeriodTest::testItCanCalculateAPeriod#11":0.005}}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6936570..35a5d1d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,98 +27,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Nothing
+## [0.3.4] - 2020-08-25
-## [0.3.3] - 2018-08-09
-
-### Fixed
-- Fixed #10: Missing `plan_id` when create new subscription. Thank @Georde ([7af238e](https://github.com/oanhnn/laravel-pricing-plans/commit/7af238ebc0368e2170643385ece0e1aa9903bcb4))
-
-
-
-## [0.3.2] - 2018-08-07
-
-### Fixed
-- Fixed #3 : Incorrect `belongTo` parameters in `BelongsToPlanModel` Trait. ([32ee324](https://github.com/oanhnn/laravel-pricing-plans/commit/32ee3243907feffbe80f3ae0a2f226ce3ca1f5df))
-- Fixed #8 : Missing `findByCode` method. ([32ee324](https://github.com/oanhnn/laravel-pricing-plans/commit/32ee3243907feffbe80f3ae0a2f226ce3ca1f5df))
-- Fixed: `SubscriptionAbility::consumed()` method return incorrect value. ([32ee324](https://github.com/oanhnn/laravel-pricing-plans/commit/32ee3243907feffbe80f3ae0a2f226ce3ca1f5df))
-
-
-
-## [0.3.1] - 2018-07-20
-
-### Fixed
-- Fixed: `Subscribable` trait with `Subscriber` interface. ([304f7b6](https://github.com/oanhnn/laravel-pricing-plans/tree/304f7b60db149b52e76f847a7913349f113bb602))
-- Fixed: TravisCI send coverage. ([b329094](https://github.com/oanhnn/laravel-pricing-plans/commit/b32909481d2116fc51793567f78acaec20cf9f98))
-
-
-
-## [0.3.0] - 2018-05-27
-
-### Added
-- Add local scope `code` for `Plan` and `Feature` model
-
-### Fixed
-- Fixed: Missing `value` and `node` attributes of `$plan->features->pivot`
-
-
-
-## [0.2.3] - 2018-03-27
-
-### Fixed
-- Fixed: incorrect relationship in Feature and Plan models. ([51ff5f3](https://github.com/oanhnn/laravel-pricing-plans/commit/51ff5f3644a318b999cc47491baa5d7c9d36d7ad))
- Thank @cimon77
+## [0.4.0] - 2021-01-19
+### Support for Laravel 7 and Symphony 5
+- Added support for laravel 7.* and Symphony 5
+## [0.5.0] - 2021-01-19
+### Support for Laravel 8
+- Added support for laravel 8.*
+## [0.5.1] - 2021-05-11
+### Support for PHP 8
+- Added support for php 8.*
-## [0.2.2] - 2018-03-27
+## [0.5.2] - 2023-02-15
+### Support for PHP 8.1 and Laravel 9.*
+- Added support for php 8.1 and Laravel 9
-### Changed
-- Update TravisCI, remove allow failure on Laravel 5.6.* ([d7f934f](https://github.com/oanhnn/laravel-pricing-plans/commit/d7f934f49637460d9978fac1d803b6fae095e6d4))
-
-### Fixed
-- Fixed: Incorrect relationship in Feature model. ([7b26b76](https://github.com/oanhnn/laravel-pricing-plans/commit/7b26b7619a34af2e9a81921d50e343f552f081c4))
- Thank @cimon77
+## [0.6.1] - 2024-02-16
+### Support for PHP 8.2 and Laravel 10.*
+- Added support for php 8.2 and Laravel 10
+## [0.6.3] - 2023-02-15
+### Fixed date casting issues for laravel 10
+- Fixed date casting issues for laravel 10
-## [0.2.1] - 2018-02-26
-### Added
-- Add link to origin repository in README ([afe05ce](https://github.com/oanhnn/laravel-pricing-plans/commit/afe05cee6fd1c0b1e9f5fbfe672f48dd2cbb4967))
-
-### Changed
-- Changed CHANGELOG format ([afe05ce](https://github.com/oanhnn/laravel-pricing-plans/commit/afe05cee6fd1c0b1e9f5fbfe672f48dd2cbb4967))
-- Update LICENSE ([afe05ce](https://github.com/oanhnn/laravel-pricing-plans/commit/afe05cee6fd1c0b1e9f5fbfe672f48dd2cbb4967))
-
-### Fixed
-- Fixed: TravisCI build ([358dcee](https://github.com/oanhnn/laravel-pricing-plans/commit/358dcee6afbc99b75da967fcd25f4656d3dfa16b))
-
-
-
-## [0.2.0] - 2018-02-22
-### Added
-- Laravel 5.6 Compatibility ([e754ae0](https://github.com/oanhnn/laravel-pricing-plans/commit/e754ae01a6c086d1c5b75074b1376a057d616b35))
-- Added matrix test with TravisCI ([e754ae0](https://github.com/oanhnn/laravel-pricing-plans/commit/e754ae01a6c086d1c5b75074b1376a057d616b35))
-
-### Changed
-- Added `code` column to `plans` and `features` tables ([dce3518](https://github.com/oanhnn/laravel-pricing-plans/commit/dce351893d386d8cd8207608c8f92820767c8ac8))
-
-
-
-## 0.1.0 - 2018-01-09
-### Added
-- Initial repository and package
-- Added migration file
-- Added config file
-- Added some tests
-
-
-
-[Unreleased]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.3.3...develop
-[0.3.3]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.3.2...v0.3.3
-[0.3.2]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.3.1...v0.3.2
-[0.3.1]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.3.0...v0.3.1
-[0.3.0]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.2.3...v0.3.0
-[0.2.3]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.2.2...v0.2.3
-[0.2.2]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.2.1...v0.2.2
-[0.2.1]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.2.0...v0.2.1
-[0.2.0]: https://github.com/oanhnn/laravel-pricing-plans/compare/v0.1.0...v0.2.0
diff --git a/README.md b/README.md
index fd627bf..cc2681e 100644
--- a/README.md
+++ b/README.md
@@ -2,66 +2,23 @@
[![Build Status](https://travis-ci.org/oanhnn/laravel-pricing-plans.svg?branch=master)](https://travis-ci.org/oanhnn/laravel-pricing-plans)
[![Coverage Status](https://coveralls.io/repos/github/oanhnn/laravel-pricing-plans/badge.svg?branch=master)](https://coveralls.io/github/oanhnn/laravel-pricing-plans?branch=master)
-[![Latest Version](https://img.shields.io/github/release/oanhnn/laravel-pricing-plans.svg?style=flat-square)](https://github.com/oanhnn/laravel-pricing-plans/releases)
+[![Latest Version](https://img.shields.io/github/v/release/andychukse/laravel-pricing-plans)](https://github.com/andychukse/laravel-pricing-plans/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
-Easy provide pricing plans for Your Laravel 5.4+ Application.
+Easy provide pricing plans for Your Laravel 7|8|9|10 Application. Update of oanhnn/laravel-pricing-plans
-
-
-- [Main features](#main-features)
-- [TODO](#todo)
-- [Requirements](#requirements)
-- [Installation](#installation)
- - [Composer](#composer)
- - [Service Provider](#service-provider)
- - [Config file and Migrations](#config-file-and-migrations)
- - [Contract and Traits](#contract-and-traits)
-- [Config File](#config-file)
-- [Models](#models)
- - [Feature model](#feature-model)
- - [Plan model](#plan-model)
- - [PlanFeature model](#planfeature-model)
- - [PlanSubscription model](#plansubscription-model)
- - [PlanSubscriptionUsage model](#plansubscriptionusage-model)
-- [Events](#events)
- - [SubscriptionRenewed event](#subscriptionrenewed-event)
- - [SubscriptionCanceled event](#subscriptioncanceled-event)
- - [SubscriptionPlanChanged event](#subscriptionplanchanged-event)
-- [Usage](#usage)
- - [Create features and plan](#create-features-and-plan)
- - [Creating subscriptions](#creating-subscriptions)
- - [Subscription Ability](#subscription-ability)
- - [Record Feature Usage](#record-feature-usage)
- - [Reduce Feature Usage](#reduce-feature-usage)
- - [Clear The Subscription Usage Data](#clear-the-subscription-usage-data)
- - [Check Subscription Status](#check-subscription-status)
- - [Renew a Subscription](#renew-a-subscription)
- - [Cancel a Subscription](#cancel-a-subscription)
- - [Scopes](#scopes)
-- [Changelog](#changelog)
-- [Testing](#testing)
-- [Contributing](#contributing)
-- [Security](#security)
-- [Credits](#credits)
-- [License](#license)
-
-
## Main features
-Easy provide pricing plans for Your Laravel 5.4+ Application.
-
-## TODO
+Easy provide pricing plans for Your Laravel 7+ Application.
+For Laravel 7.0+ use v0.4, for Laravel 8.0|9.0+ use v0.5, for Laravel 10.0+ use v0.6
+for Laravel 11.0+ use v0.7
-- [ ] Caching some select query
-- [ ] Add unit test scripts
-- [ ] Make better documents
## Requirements
-* php >=7.0
-* Laravel 5.4+
+* php >=7.3 || ^8.0+
+* Laravel 7.0+ || 8.0+ || 9.0+ || 10.0+ || 11.0+
## Installation
@@ -70,384 +27,25 @@ Easy provide pricing plans for Your Laravel 5.4+ Application.
Begin by pulling in the package through Composer.
```bash
-$ composer require oanhnn/laravel-pricing-plans
-```
-
-### Service Provider
-
-Next, if using Laravel 5.5+, you done. If using Laravel 5.4, you must include the service provider within your `config/app.php` file.
-
-```php
-// config/app.php
-
- 'providers' => [
- // Other service providers...
-
- Laravel\PricingPlans\PricingPlansServiceProvider::class,
- ],
-```
-
-### Config file and Migrations
-
-Publish package config file and migrations with the command:
-
-```bash
-$ php artisan vendor:publish --provider="Laravel\PricingPlans\PricingPlansServiceProvider"
-```
-
-Then run migrations:
-
-```bash
-$ php artisan migrate
-```
-
-### Contract and Traits
-
-Add `Laravel\PricingPlans\Contacts\Subscriber` contract and `Laravel\PricingPlans\Models\Concerns\Subscribable` trait
-to your subscriber model (Eg. `User`).
-
-See the following example:
-
-```php
- 'Upload images',
- 'code' => 'upload-images',
- 'description' => null,
- 'interval_unit' => 'day',
- 'interval_count' => 1,
- 'sort_order' => 1,
-]);
-
-$feature2 = Feature::create([
- 'name' => 'upload video',
- 'code' => 'upload-video',
- 'description' => null,
- 'interval_unit' => 'day',
- 'interval_count' => 1,
- 'sort_order' => 2,
-]);
-
-$plan = Plan::create([
- 'name' => 'Pro',
- 'code' => 'pro',
- 'description' => 'Pro plan',
- 'price' => 9.99,
- 'interval_unit' => 'month',
- 'interval_count' => 1,
- 'trial_period_days' => 5,
- 'sort_order' => 1,
-]);
-
-$plan->features()->attach([
- $feature1->id => ['value' => 5, 'note' => 'Can upload maximum 5 images daily'],
- $feature2->id => ['value' => 1, 'note' => 'Can upload maximum 1 video daily'],
-]);
-```
-
-### Creating subscriptions
-
-You can subscribe a user to a plan by using the `newSubscription()` function available in the `Subscribable` trait.
-First, retrieve an instance of your subscriber model, which typically will be your user model and an instance of the plan
-your user is subscribing to. Once you have retrieved the model instance, you may use the `newSubscription` method
-to create the model's subscription.
-
-```php
-firstOrFail();
-
-$user->newSubscription('main', $plan)->create();
-```
-
-The first argument passed to `newSubscription` method should be the name of the subscription. If your application offer
-a single subscription, you might call this `main` or `primary`. The second argument is the plan instance your user is subscribing to.
-
-
-
-
-
-### Subscription Ability
-
-There's multiple ways to determine the usage and ability of a particular feature in the user subscription, the most common one is `canUse`:
-
-The `canUse` method returns `true` or `false` depending on multiple factors:
-
-- Feature _is enabled_.
-- Feature value isn't `0`.
-- Or feature has remaining uses available.
-
-```php
-$user->subscription('main')->ability()->canUse(Feature::FEATURE_UPLOAD_IMAGES);
-```
-
-Other methods are:
-
-- `enabled`: returns `true` when the value of the feature is a _positive word_ listed in the config file.
-- `consumed`: returns how many times the user has used a particular feature.
-- `remainings`: returns available uses for a particular feature.
-- `value`: returns the feature value.
-
-> All methods share the same signature: e.g.
->`$user->subscription('main')->ability()->consumed(Feature::FEATURE_UPLOAD_IMAGES);`.
-
-
-### Record Feature Usage
-
-In order to efectively use the ability methods you will need to keep track of every usage of each feature
-(or at least those that require it). You may use the `record` method available through the user `subscriptionUsage()`
-method:
-
-```php
-$user->subscriptionUsage('main')->record(Feature::FEATURE_UPLOAD_IMAGES);
-```
-
-The `record` method accept 3 parameters: the first one is the feature's code, the second one is the quantity of
-uses to add (default is `1`), and the third one indicates if the addition should be incremental (default behavior),
-when disabled the usage will be override by the quantity provided. E.g.:
-
-```php
-// Increment by 2
-$user->subscriptionUsage('main')->record(Feature::FEATURE_UPLOAD_IMAGES, 2);
-
-// Override with 9
-$user->subscriptionUsage('main')->record(Feature::FEATURE_UPLOAD_IMAGES, 9, false);
-```
-
-### Reduce Feature Usage
-
-Reducing the feature usage is _almost_ the same as incrementing it. Here we only _substract_ a given quantity (default is `1`)
-to the actual usage:
-
-```php
-$user->subscriptionUsage('main')->reduce(Feature::FEATURE_UPLOAD_IMAGES, 2);
-```
-
-### Clear The Subscription Usage Data
-
-```php
-$user->subscriptionUsage('main')->clear();
-```
-
-### Check Subscription Status
-
-For a subscription to be considered active _one of the following must be `true`_:
-
-- Subscription has an active trial.
-- Subscription `ends_at` is in the future.
-
-```php
-$user->subscribed('main');
-$user->subscribed('main', $planId); // Check if user is using a particular plan
-```
-
-Alternatively you can use the following methods available in the subscription model:
-
-```php
-$user->subscription('main')->isActive();
-$user->subscription('main')->isCanceled();
-$user->subscription('main')->isCanceledImmediately();
-$user->subscription('main')->isEnded();
-$user->subscription('main')->onTrial();
-```
-
-> Canceled subscriptions with an active trial or `ends_at` in the future are considered active.
-
-### Renew a Subscription
-
-To renew a subscription you may use the `renew` method available in the subscription model.
-This will set a new `ends_at` date based on the selected plan and _will clear the usage data_ of the subscription.
-
-```php
-$user->subscription('main')->renew();
-```
-
-_Canceled subscriptions with an ended period can't be renewed._
-
-### Cancel a Subscription
-
-To cancel a subscription, simply use the `cancel` method on the user's subscription:
-
-```php
-$user->subscription('main')->cancel();
-```
-
-By default the subscription will remain active until the end of the period, you may pass `true` to end the subscription _immediately_:
-
-```php
-$user->subscription('main')->cancel(true);
-```
-
-### Scopes
-
-#### Subscription Model
-```php
-get();
-
-// Get subscription by subscriber:
-$subscription = PlanSubscription::bySubscriber($user)->first();
-
-// Get subscriptions with trial ending in 3 days:
-$subscriptions = PlanSubscription::findEndingTrial(3)->get();
-
-// Get subscriptions with ended trial:
-$subscriptions = PlanSubscription::findEndedTrial()->get();
-
-// Get subscriptions with period ending in 3 days:
-$subscriptions = PlanSubscription::findEndingPeriod(3)->get();
-
-// Get subscriptions with ended period:
-$subscriptions = PlanSubscription::findEndedPeriod()->get();
-```
-
-## Changelog
-
-See all change logs in [CHANGELOG](CHANGELOG.md)
## Testing
```bash
-$ git clone git@github.com/oanhnn/laravel-pricing-plans.git /path
+$ git clone git@github.com/andychukse/laravel-pricing-plans.git /path
$ cd /path
$ composer install
$ composer phpunit
```
-## Contributing
-
-Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
-
-## Security
-
-If you discover any security related issues, please email to [Oanh Nguyen](mailto:oanhnn.bk@gmail.com) instead of
-using the issue tracker.
## Credits
-I forked and recreated this project from [gerardojbaez/laraplans](https://github.com/gerardojbaez/laraplans) project in mid-2017.
-Thank [Gerardo Baez](https://github.com/gerardojbaez)
+I forked and updated this project to support laravel 8/9/10/11 from [oanhnn/laravel-pricing-plans](https://github.com/oanhnn/laravel-pricing-plans) project.
-- [Oanh Nguyen](https://github.com/oanhnn)
-- [Gerardo Baez](https://github.com/gerardojbaez)
-- [All Contributors](../../contributors)
## License
This project is released under the MIT License.
-Copyright © 2017-2018 [Oanh Nguyen](https://oanhnn.github.io/).
diff --git a/composer.json b/composer.json
index 5a7feeb..b732855 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
- "name": "oanhnn/laravel-pricing-plans",
+ "name": "andychukse/laravel-pricing-plans",
"type": "library",
- "description": "A package provide pricing plans for Laravel.",
+ "description": "A package provide pricing plans for Laravel. Forked from oanhnn/laravel-pricing-plans",
"keywords": [
"plans",
"laravel",
@@ -9,10 +9,10 @@
"pricing"
],
"license": "MIT",
- "homepage": "https://github.com/oanhnn/laravel-pricing-plans",
+ "homepage": "https://github.com/andychukse/laravel-pricing-plans",
"support": {
- "issues": "https://github.com/oanhnn/laravel-pricing-plans/issues",
- "source": "https://github.com/oanhnn/laravel-pricing-plans"
+ "issues": "https://github.com/andychukse/laravel-pricing-plans/issues",
+ "source": "https://github.com/andychukse/laravel-pricing-plans"
},
"authors": [
{
@@ -26,23 +26,24 @@
}
},
"require": {
- "php": ">=7.0",
- "illuminate/database": "~5.4",
- "illuminate/support": "~5.4",
- "nesbot/carbon": "~1.21"
+ "php": "^7.3 || ^8.0",
+ "illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0",
+ "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0",
+ "nesbot/carbon": "^2.72.1"
},
"require-dev": {
- "fzaninotto/faker": "^1.4",
- "mockery/mockery": "^0.9",
- "orchestra/database": "^3.4",
- "orchestra/testbench": "^3.4",
- "phpunit/phpunit": "~6.1|~7.0",
- "squizlabs/php_codesniffer": "^3.0"
+ "fakerphp/faker": "^1.23",
+ "mockery/mockery": "^1.6.7",
+ "andychukse/database": "7.0.x-dev",
+ "orchestra/testbench": "^9.0",
+ "phpunit/phpunit": "^11.0",
+ "squizlabs/php_codesniffer": "3.*",
+ "laravie/query-filter": "dev-master"
},
"scripts": {
- "phpunit": "php vendor/phpunit/phpunit/phpunit --coverage-html build/coverage",
- "phpcs": "php vendor/squizlabs/php_codesniffer/bin/phpcs",
- "phpcbf": "php vendor/squizlabs/php_codesniffer/bin/phpcbf"
+ "phpunit": "php ./vendor/bin/phpunit --coverage-html build/coverage",
+ "phpcs": "php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
+ "phpcbf": "php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
},
"config": {
"preferred-install": "dist",
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 307be0b..f0000ea 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,36 +1,34 @@
-
-
-
-
-
-
-
-
-
- tests
-
-
-
-
-
-
- vendor
-
-
- src
-
-
+
+
+
+
+
+
+
+ tests
+
+
+
+
diff --git a/phpunit.xml.dist.bak b/phpunit.xml.dist.bak
new file mode 100644
index 0000000..b267575
--- /dev/null
+++ b/phpunit.xml.dist.bak
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+ tests
+
+
+
+
+
+
+ vendor
+
+
+ src
+
+
+
diff --git a/resources/migrations/2018_01_01_000000_create_plans_tables.php b/resources/migrations/2018_01_01_000000_create_plans_tables.php
old mode 100644
new mode 100755
diff --git a/src/Models/Concerns/Subscribable.php b/src/Models/Concerns/Subscribable.php
index e3c5d3b..d119475 100644
--- a/src/Models/Concerns/Subscribable.php
+++ b/src/Models/Concerns/Subscribable.php
@@ -63,7 +63,7 @@ public function subscribed(string $subscription, string $planCode = null): bool
}
if (is_null($planCode) || $planCode == $planSubscription->plan->code) {
- return $subscription->isActive();
+ return $planSubscription->isActive();
}
return false;
diff --git a/src/Models/Feature.php b/src/Models/Feature.php
index 9049b9e..8690ac8 100644
--- a/src/Models/Feature.php
+++ b/src/Models/Feature.php
@@ -41,15 +41,16 @@ class Feature extends Model
];
/**
- * The attributes that should be mutated to dates.
+ * The attributes that should be mutated to dates
*
* @var array
*/
- protected $dates = [
- 'created_at',
- 'updated_at',
+ protected $casts = [
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
];
+
/**
* Plan constructor.
*
diff --git a/src/Models/Plan.php b/src/Models/Plan.php
index 33c42ae..1831fa8 100644
--- a/src/Models/Plan.php
+++ b/src/Models/Plan.php
@@ -44,15 +44,16 @@ class Plan extends Model
];
/**
- * The attributes that should be mutated to dates.
+ * The attributes that should be mutated to dates
*
* @var array
*/
- protected $dates = [
- 'created_at',
- 'updated_at',
+ protected $casts = [
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
];
+
/**
* Boot function for using with User Events.
*
diff --git a/src/Models/PlanFeature.php b/src/Models/PlanFeature.php
index e5b6652..88a7bd5 100644
--- a/src/Models/PlanFeature.php
+++ b/src/Models/PlanFeature.php
@@ -4,6 +4,7 @@
use Illuminate\Database\Eloquent\Relations\Pivot;
use Laravel\PricingPlans\Models\Concerns\BelongsToPlanModel;
+use Illuminate\Support\Facades\Config;
/**
* Class PlanFeature
@@ -31,15 +32,16 @@ class PlanFeature extends Pivot
];
/**
- * The attributes that should be mutated to dates.
+ * The attributes that should be mutated to dates
*
* @var array
*/
- protected $dates = [
- 'created_at',
- 'updated_at',
+ protected $casts = [
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
];
+
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
diff --git a/src/Models/PlanSubscription.php b/src/Models/PlanSubscription.php
index 3a31a69..319949a 100644
--- a/src/Models/PlanSubscription.php
+++ b/src/Models/PlanSubscription.php
@@ -10,6 +10,8 @@
use Illuminate\Support\Facades\Event;
use InvalidArgumentException;
use Laravel\PricingPlans\Events\SubscriptionRenewed;
+use Laravel\PricingPlans\Events\SubscriptionCanceled;
+use Laravel\PricingPlans\Events\SubscriptionPlanChanged;
use Laravel\PricingPlans\Period;
use Laravel\PricingPlans\SubscriptionAbility;
use Laravel\PricingPlans\SubscriptionUsageManager;
@@ -59,17 +61,17 @@ class PlanSubscription extends Model
];
/**
- * The attributes that should be mutated to dates.
+ * The attributes that should be mutated to dates
*
* @var array
*/
- protected $dates = [
- 'created_at',
- 'updated_at',
- 'starts_at',
- 'ends_at',
- 'canceled_at',
- 'trial_ends_at',
+ protected $casts = [
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
+ 'starts_at' => 'datetime',
+ 'ends_at' => 'datetime',
+ 'canceled_at' => 'datetime',
+ 'trial_ends_at' => 'datetime',
];
/**
diff --git a/src/Models/PlanSubscriptionUsage.php b/src/Models/PlanSubscriptionUsage.php
index 9687e3e..de384a3 100644
--- a/src/Models/PlanSubscriptionUsage.php
+++ b/src/Models/PlanSubscriptionUsage.php
@@ -31,14 +31,14 @@ class PlanSubscriptionUsage extends Model
];
/**
- * The attributes that should be mutated to dates.
+ * The attributes that should be mutated to dates
*
* @var array
*/
- protected $dates = [
- 'created_at',
- 'updated_at',
- 'valid_until',
+ protected $casts = [
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
+ 'valid_until' => 'datetime',
];
/**
diff --git a/src/Period.php b/src/Period.php
index 2fcb6ba..87ea1c3 100644
--- a/src/Period.php
+++ b/src/Period.php
@@ -161,7 +161,7 @@ public static function getAllIntervals()
$intervals = [];
foreach (array_keys(self::$intervalMapping) as $interval) {
- $intervals[$interval] = Lang::trans('plans::messages.' . $interval);
+ $intervals[$interval] = Lang::get('plans::messages.' . $interval);
}
return $intervals;
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 4086c10..c105146 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -17,7 +17,7 @@ class TestCase extends Testbench
*
* @throws \Exception
*/
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
@@ -25,10 +25,11 @@ public function setUp()
$this->loadLaravelMigrations('testbench');
// Run package migrations
- $this->loadMigrationsFrom([
- '--database' => 'testbench',
- '--realpath' => realpath(__DIR__ . '/../resources/migrations'),
- ]);
+ // $this->loadMigrationsFrom([
+ // '--database' => 'testbench',
+ // '--realpath' => realpath(__DIR__ . '/../resources/migrations'),
+ // ]);
+ $this->loadMigrationsFrom(realpath(__DIR__ . '/../resources/migrations'));
}
/**
diff --git a/tests/Unit/PeriodTest.php b/tests/Unit/PeriodTest.php
index 5f4faac..7c0c3f2 100644
--- a/tests/Unit/PeriodTest.php
+++ b/tests/Unit/PeriodTest.php
@@ -49,7 +49,7 @@ public function testItCanCalculateAPeriod($unit, $count, $start, $expectedStartA
/**
* @return array
*/
- public function periodDataProvider()
+ public static function periodDataProvider()
{
$st1 = new DateTime('2018-01-04 10:00:09');
$st2 = new DateTime('2018-01-04 10:10:09');