Skip to content

Commit

Permalink
Merge pull request #13 from maartenpaauw/feature/metered-price
Browse files Browse the repository at this point in the history
Add support for metered price
  • Loading branch information
maartenpaauw committed Apr 29, 2024
2 parents 86b9864 + 219657b commit 8756ee0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public function collectTaxIds(): bool
{
return $this->repository->get("cashier.plans.$this->type.collect_tax_ids", false);
}

public function isMeteredPrice(): bool
{
return $this->repository->get("cashier.plans.$this->type.metered_price", false);
}
}
6 changes: 5 additions & 1 deletion src/Stripe/RedirectIfUserNotSubscribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public function handle(Request $request, Closure $next, string $plan = 'default'
}

return $tenant
->newSubscription($plan->type(), $plan->priceId())
->newSubscription($plan->type(), $plan->isMeteredPrice() ? [] : $plan->priceId())
->when(
$plan->isMeteredPrice(),
static fn (SubscriptionBuilder $subscription): SubscriptionBuilder => $subscription->meteredPrice($plan->priceId()),
)
->when(
$plan->trialDays() !== false,
static fn (SubscriptionBuilder $subscription): SubscriptionBuilder => $subscription->trialDays($plan->trialDays()),
Expand Down
5 changes: 5 additions & 0 deletions tests/PlanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'trial_days' => 14,
'allow_promotion_codes' => true,
'collect_tax_ids' => true,
'metered_price' => true,
],
'basic' => [
'price_id' => 'price_ruVAAh5dwyhwbtWIVQn0lUvc',
Expand All @@ -34,6 +35,8 @@
->allowPromotionCodes()
->toBeTrue()
->collectTaxIds()
->toBeTrue()
->isMeteredPrice()
->toBeTrue();
});

Expand All @@ -48,6 +51,8 @@
->allowPromotionCodes()
->toBeFalse()
->collectTaxIds()
->toBeFalse()
->isMeteredPrice()
->toBeFalse();
});

Expand Down

0 comments on commit 8756ee0

Please sign in to comment.