mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +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)
|
||||
{
|
||||
if (str_starts_with($method, 'can')) {
|
||||
if (str_starts_with($method, 'can') || str_starts_with($method, 'get')) {
|
||||
return resolve(RestrictionsManager::class)
|
||||
->driver()
|
||||
->$method($this, ...$parameters);
|
||||
|
||||
@@ -69,6 +69,7 @@ class UserResource extends JsonResource
|
||||
'canCreateFolder' => $this->canCreateFolder(),
|
||||
'canCreateTeamFolder' => $this->canCreateTeamFolder(),
|
||||
'canInviteTeamMembers' => $this->canInviteTeamMembers(),
|
||||
'reason' => $this->getRestrictionReason(),
|
||||
],
|
||||
$this->mergeWhen($isFixedSubscription, fn () => [
|
||||
'limitations' => $this->limitations->summary(),
|
||||
|
||||
@@ -47,4 +47,9 @@ class DefaultRestrictionsEngine implements RestrictionsEngine
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRestrictionReason(User $user): string|null
|
||||
{
|
||||
// TODO: Implement getRestrictionReason() method.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,4 +43,9 @@ class FixedBillingRestrictionsEngine implements RestrictionsEngine
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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 canVisitShared(User $user): bool;
|
||||
|
||||
public function getRestrictionReason(User $user): string|null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user