mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-29 03:10:51 +00:00
MeteredBillingRestrictionsEngine update with the new rule for dunning
This commit is contained in:
@@ -196,7 +196,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
|
|
||||||
public function __call($method, $parameters)
|
public function __call($method, $parameters)
|
||||||
{
|
{
|
||||||
if (str_starts_with($method, 'can')) {
|
if (str_starts_with($method, 'can') || str_starts_with($method, 'get')) {
|
||||||
return resolve(RestrictionsManager::class)
|
return resolve(RestrictionsManager::class)
|
||||||
->driver()
|
->driver()
|
||||||
->$method($this, ...$parameters);
|
->$method($this, ...$parameters);
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class UserResource extends JsonResource
|
|||||||
'canCreateFolder' => $this->canCreateFolder(),
|
'canCreateFolder' => $this->canCreateFolder(),
|
||||||
'canCreateTeamFolder' => $this->canCreateTeamFolder(),
|
'canCreateTeamFolder' => $this->canCreateTeamFolder(),
|
||||||
'canInviteTeamMembers' => $this->canInviteTeamMembers(),
|
'canInviteTeamMembers' => $this->canInviteTeamMembers(),
|
||||||
|
'reason' => $this->getRestrictionReason(),
|
||||||
],
|
],
|
||||||
$this->mergeWhen($isFixedSubscription, fn () => [
|
$this->mergeWhen($isFixedSubscription, fn () => [
|
||||||
'limitations' => $this->limitations->summary(),
|
'limitations' => $this->limitations->summary(),
|
||||||
|
|||||||
@@ -47,4 +47,9 @@ class DefaultRestrictionsEngine implements RestrictionsEngine
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRestrictionReason(User $user): string|null
|
||||||
|
{
|
||||||
|
// TODO: Implement getRestrictionReason() method.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,9 @@ class FixedBillingRestrictionsEngine implements RestrictionsEngine
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRestrictionReason(User $user): string|null
|
||||||
|
{
|
||||||
|
// TODO: Implement getRestrictionReason() method.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,22 @@ class MeteredBillingRestrictionsEngine implements RestrictionsEngine
|
|||||||
return $this->checkFailedPayments($user);
|
return $this->checkFailedPayments($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRestrictionReason(User $user): string|null
|
||||||
|
{
|
||||||
|
if ($this->getDunningSequenceCount($user) === 3) {
|
||||||
|
return match ($user->dunning->type) {
|
||||||
|
'limit_usage_in_new_accounts' => 'Please make your first payment.',
|
||||||
|
'usage_bigger_than_balance' => 'Please increase your account balance.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->checkFailedPayments($user)) {
|
||||||
|
return 'Please update your credit card.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private function getDunningSequenceCount(User $user): int
|
private function getDunningSequenceCount(User $user): int
|
||||||
{
|
{
|
||||||
return cache()->remember("dunning-count.$user->id", 3600, fn () => $user?->dunning->sequence ?? 0);
|
return cache()->remember("dunning-count.$user->id", 3600, fn () => $user?->dunning->sequence ?? 0);
|
||||||
|
|||||||
@@ -16,4 +16,6 @@ interface RestrictionsEngine
|
|||||||
public function canInviteTeamMembers(User $user, array $newInvites = []): bool;
|
public function canInviteTeamMembers(User $user, array $newInvites = []): bool;
|
||||||
|
|
||||||
public function canVisitShared(User $user): bool;
|
public function canVisitShared(User $user): bool;
|
||||||
|
|
||||||
|
public function getRestrictionReason(User $user): string|null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user