Skip to content

Commit

Permalink
Fix bug #3 and #8
Browse files Browse the repository at this point in the history
  • Loading branch information
oanhnn committed Aug 7, 2018
1 parent 1a0411a commit 32ee324
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/Models/Concerns/BelongsToPlanModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function plan()
{
return $this->belongsTo(
Config::get('plans.models.Plan'),
Config::get('plans.tables.plans'),
'plan_id',
'id'
);
Expand Down
1 change: 0 additions & 1 deletion src/Models/PlanFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function feature()
{
return $this->belongsTo(
Config::get('plans.models.Feature'),
Config::get('plans.tables.features'),
'feature_id',
'id'
);
Expand Down
3 changes: 2 additions & 1 deletion src/Models/PlanSubscriptionUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class PlanSubscriptionUsage extends Model
*/
protected $fillable = [
'valid_until',
'used'
'used',
'feature_code',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/SubscriptionAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function consumed(string $featureCode): int
{
/** @var \Laravel\PricingPlans\Models\PlanSubscriptionUsage $usage */
foreach ($this->subscription->usage as $usage) {
if ($usage->feature_code === $featureCode && $usage->isExpired()) {
if ($usage->feature_code === $featureCode && !$usage->isExpired()) {
return (int) $usage->used;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SubscriptionUsageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(PlanSubscription $subscription)
public function record(string $featureCode, $uses = 1, $incremental = true)
{
/** @var \Laravel\PricingPlans\Models\Feature $feature */
$feature = Feature::findByCode($featureCode);
$feature = Feature::code($featureCode)->first();

$usage = $this->subscription->usage()->firstOrNew([
'feature_code' => $feature->code,
Expand Down

0 comments on commit 32ee324

Please sign in to comment.