diff --git a/src/app/Jobs/WalletCheck.php b/src/app/Jobs/WalletCheck.php --- a/src/app/Jobs/WalletCheck.php +++ b/src/app/Jobs/WalletCheck.php @@ -20,13 +20,9 @@ public const THRESHOLD_DEGRADE = 'degrade'; public const THRESHOLD_DEGRADE_REMINDER = 'degrade-reminder'; - public const THRESHOLD_BEFORE_DEGRADE = 'before_degrade'; - public const THRESHOLD_DELETE = 'delete'; - public const THRESHOLD_BEFORE_DELETE = 'before_delete'; - public const THRESHOLD_SUSPEND = 'suspend'; - public const THRESHOLD_BEFORE_SUSPEND = 'before_suspend'; + public const THRESHOLD_BEFORE_DEGRADE = 'before-degrade'; public const THRESHOLD_REMINDER = 'reminder'; - public const THRESHOLD_BEFORE_REMINDER = 'before_reminder'; + public const THRESHOLD_BEFORE_REMINDER = 'before-reminder'; public const THRESHOLD_INITIAL = 'initial'; /** @var int The number of seconds to wait before retrying the job. */ @@ -66,26 +62,7 @@ } $now = Carbon::now(); -/* - // Steps for old "first suspend then delete" approach - $steps = [ - // Send the initial reminder - self::THRESHOLD_INITIAL => 'initialReminder', - // Try to top-up the wallet before the second reminder - self::THRESHOLD_BEFORE_REMINDER => 'topUpWallet', - // Send the second reminder - self::THRESHOLD_REMINDER => 'secondReminder', - // Try to top-up the wallet before suspending the account - self::THRESHOLD_BEFORE_SUSPEND => 'topUpWallet', - // Suspend the account - self::THRESHOLD_SUSPEND => 'suspendAccount', - // Warn about the upcomming account deletion - self::THRESHOLD_BEFORE_DELETE => 'warnBeforeDelete', - // Delete the account - self::THRESHOLD_DELETE => 'deleteAccount', - ]; -*/ - // Steps for "demote instead of suspend+delete" approach + $steps = [ // Send the initial reminder self::THRESHOLD_INITIAL => 'initialReminderForDegrade', @@ -115,23 +92,6 @@ } /** - * Send the initial reminder (for the suspend+delete process) - */ - protected function initialReminder() - { - if ($this->wallet->getSetting('balance_warning_initial')) { - return; - } - - // TODO: Should we check if the account is already suspended? - - $this->sendMail(\App\Mail\NegativeBalance::class, false); - - $now = \Carbon\Carbon::now()->toDateTimeString(); - $this->wallet->setSetting('balance_warning_initial', $now); - } - - /** * Send the initial reminder (for the process of degrading a account) */ protected function initialReminderForDegrade() @@ -144,27 +104,12 @@ return; } - $this->sendMail(\App\Mail\NegativeBalance::class, false); - - $now = \Carbon\Carbon::now()->toDateTimeString(); - $this->wallet->setSetting('balance_warning_initial', $now); - } - - /** - * Send the second reminder (for the suspend+delete process) - */ - protected function secondReminder() - { - if ($this->wallet->getSetting('balance_warning_reminder')) { - return; + if (!$this->wallet->owner->isSuspended()) { + $this->sendMail(\App\Mail\NegativeBalance::class, false); } - // TODO: Should we check if the account is already suspended? - - $this->sendMail(\App\Mail\NegativeBalanceReminder::class, false); - $now = \Carbon\Carbon::now()->toDateTimeString(); - $this->wallet->setSetting('balance_warning_reminder', $now); + $this->wallet->setSetting('balance_warning_initial', $now); } /** @@ -180,53 +125,40 @@ return; } - $this->sendMail(\App\Mail\NegativeBalanceReminderDegrade::class, true); + if (!$this->wallet->owner->isSuspended()) { + $this->sendMail(\App\Mail\NegativeBalanceReminderDegrade::class, true); + } $now = \Carbon\Carbon::now()->toDateTimeString(); $this->wallet->setSetting('balance_warning_reminder', $now); } /** - * Suspend the account (and send the warning) + * Degrade the account */ - protected function suspendAccount() + protected function degradeAccount() { - if ($this->wallet->getSetting('balance_warning_suspended')) { - return; - } - - // Sanity check, already deleted - if (!$this->wallet->owner) { + // The account may be already deleted, or degraded + if (!$this->wallet->owner || $this->wallet->owner->isDegraded()) { return; } - // Suspend the account - $this->wallet->owner->suspendAccount(); - - $this->sendMail(\App\Mail\NegativeBalanceSuspended::class, true); + $email = $this->wallet->owner->email; - $now = \Carbon\Carbon::now()->toDateTimeString(); - $this->wallet->setSetting('balance_warning_suspended', $now); - } + // The dirty work will be done by UserObserver + $this->wallet->owner->degrade(); - /** - * Send the last warning before delete - */ - protected function warnBeforeDelete() - { - if ($this->wallet->getSetting('balance_warning_before_delete')) { - return; - } + \Log::info( + sprintf( + "[WalletCheck] Account degraded %s (%s)", + $this->wallet->id, + $email + ) + ); - // Sanity check, already deleted - if (!$this->wallet->owner) { - return; + if (!$this->wallet->owner->isSuspended()) { + $this->sendMail(\App\Mail\NegativeBalanceDegraded::class, true); } - - $this->sendMail(\App\Mail\NegativeBalanceBeforeDelete::class, true); - - $now = \Carbon\Carbon::now()->toDateTimeString(); - $this->wallet->setSetting('balance_warning_before_delete', $now); } /** @@ -239,6 +171,10 @@ return; } + if ($this->wallet->owner->isSuspended()) { + return; + } + $now = \Carbon\Carbon::now(); $last = $this->wallet->getSetting('degraded_last_reminder'); @@ -250,63 +186,13 @@ return; } - $this->sendMail(\App\Mail\DegradedAccountReminder::class, true); + $this->sendMail(\App\Mail\DegradedAccountReminder::class, false); } $this->wallet->setSetting('degraded_last_reminder', $now->toDateTimeString()); } /** - * Degrade the account - */ - protected function degradeAccount() - { - // The account may be already deleted, or degraded - if (!$this->wallet->owner || $this->wallet->owner->isDegraded()) { - return; - } - - $email = $this->wallet->owner->email; - - // The dirty work will be done by UserObserver - $this->wallet->owner->degrade(); - - \Log::info( - sprintf( - "[WalletCheck] Account degraded %s (%s)", - $this->wallet->id, - $email - ) - ); - - $this->sendMail(\App\Mail\NegativeBalanceDegraded::class, true); - } - - /** - * Delete the account - */ - protected function deleteAccount() - { - // TODO: This will not work when we actually allow multiple-wallets per account - // but in this case we anyway have to change the whole thing - // and calculate summarized balance from all wallets. - // The dirty work will be done by UserObserver - if ($this->wallet->owner) { - $email = $this->wallet->owner->email; - - $this->wallet->owner->delete(); - - \Log::info( - sprintf( - "[WalletCheck] Account deleted %s (%s)", - $this->wallet->id, - $email - ) - ); - } - } - - /** * Send the email * * @param string $class Mailable class name @@ -364,16 +250,6 @@ self::THRESHOLD_BEFORE_REMINDER => 7 - 1, // Second notification self::THRESHOLD_REMINDER => 7, - - // A day before account suspension - self::THRESHOLD_BEFORE_SUSPEND => 14 + 7 - 1, - // Account suspension - self::THRESHOLD_SUSPEND => 14 + 7, - // Warning about the upcomming account deletion - self::THRESHOLD_BEFORE_DELETE => 21 + 14 + 7 - 3, - // Acount deletion - self::THRESHOLD_DELETE => 21 + 14 + 7, - // Last chance to top-up the wallet self::THRESHOLD_BEFORE_DEGRADE => 13, // Account degradation diff --git a/src/app/Mail/NegativeBalanceBeforeDelete.php b/src/app/Mail/NegativeBalanceBeforeDelete.php deleted file mode 100644 --- a/src/app/Mail/NegativeBalanceBeforeDelete.php +++ /dev/null @@ -1,84 +0,0 @@ -wallet = $wallet; - $this->user = $user; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - $threshold = WalletCheck::threshold($this->wallet, WalletCheck::THRESHOLD_DELETE); - $appName = Tenant::getConfig($this->user->tenant_id, 'app.name'); - $supportUrl = Tenant::getConfig($this->user->tenant_id, 'app.support_url'); - - $subject = \trans('mail.negativebalancebeforedelete-subject', ['site' => $appName]); - - $this->view('emails.html.negative_balance_before_delete') - ->text('emails.plain.negative_balance_before_delete') - ->subject($subject) - ->with([ - 'site' => $appName, - 'subject' => $subject, - 'username' => $this->user->name(true), - 'supportUrl' => Utils::serviceUrl($supportUrl, $this->user->tenant_id), - 'walletUrl' => Utils::serviceUrl('/wallet', $this->user->tenant_id), - 'date' => $threshold->toDateString(), - ]); - - return $this; - } - - /** - * Render the mail template with fake data - * - * @param string $type Output format ('html' or 'text') - * - * @return string HTML or Plain Text output - */ - public static function fakeRender(string $type = 'html'): string - { - $wallet = new Wallet(); - $user = new User(); - - $mail = new self($wallet, $user); - - return Helper::render($mail, $type); - } -} diff --git a/src/app/Mail/NegativeBalanceReminder.php b/src/app/Mail/NegativeBalanceReminder.php deleted file mode 100644 --- a/src/app/Mail/NegativeBalanceReminder.php +++ /dev/null @@ -1,84 +0,0 @@ -wallet = $wallet; - $this->user = $user; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - $threshold = WalletCheck::threshold($this->wallet, WalletCheck::THRESHOLD_SUSPEND); - $appName = Tenant::getConfig($this->user->tenant_id, 'app.name'); - $supportUrl = Tenant::getConfig($this->user->tenant_id, 'app.support_url'); - - $subject = \trans('mail.negativebalancereminder-subject', ['site' => $appName]); - - $this->view('emails.html.negative_balance_reminder') - ->text('emails.plain.negative_balance_reminder') - ->subject($subject) - ->with([ - 'site' => $appName, - 'subject' => $subject, - 'username' => $this->user->name(true), - 'supportUrl' => Utils::serviceUrl($supportUrl, $this->user->tenant_id), - 'walletUrl' => Utils::serviceUrl('/wallet', $this->user->tenant_id), - 'date' => $threshold->toDateString(), - ]); - - return $this; - } - - /** - * Render the mail template with fake data - * - * @param string $type Output format ('html' or 'text') - * - * @return string HTML or Plain Text output - */ - public static function fakeRender(string $type = 'html'): string - { - $wallet = new Wallet(); - $user = new User(); - - $mail = new self($wallet, $user); - - return Helper::render($mail, $type); - } -} diff --git a/src/app/Mail/NegativeBalanceSuspended.php b/src/app/Mail/NegativeBalanceSuspended.php deleted file mode 100644 --- a/src/app/Mail/NegativeBalanceSuspended.php +++ /dev/null @@ -1,84 +0,0 @@ -wallet = $wallet; - $this->user = $user; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - $threshold = WalletCheck::threshold($this->wallet, WalletCheck::THRESHOLD_DELETE); - $appName = Tenant::getConfig($this->user->tenant_id, 'app.name'); - $supportUrl = Tenant::getConfig($this->user->tenant_id, 'app.support_url'); - - $subject = \trans('mail.negativebalancesuspended-subject', ['site' => $appName]); - - $this->view('emails.html.negative_balance_suspended') - ->text('emails.plain.negative_balance_suspended') - ->subject($subject) - ->with([ - 'site' => $appName, - 'subject' => $subject, - 'username' => $this->user->name(true), - 'supportUrl' => Utils::serviceUrl($supportUrl, $this->user->tenant_id), - 'walletUrl' => Utils::serviceUrl('/wallet', $this->user->tenant_id), - 'date' => $threshold->toDateString(), - ]); - - return $this; - } - - /** - * Render the mail template with fake data - * - * @param string $type Output format ('html' or 'text') - * - * @return string HTML or Plain Text output - */ - public static function fakeRender(string $type = 'html'): string - { - $wallet = new Wallet(); - $user = new User(); - - $mail = new self($wallet, $user); - - return Helper::render($mail, $type); - } -} diff --git a/src/app/Mail/SuspendedDebtor.php b/src/app/Mail/SuspendedDebtor.php deleted file mode 100644 --- a/src/app/Mail/SuspendedDebtor.php +++ /dev/null @@ -1,86 +0,0 @@ -account = $account; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - $appName = Tenant::getConfig($this->account->tenant_id, 'app.name'); - $supportUrl = Tenant::getConfig($this->account->tenant_id, 'app.support_url'); - $cancelUrl = Tenant::getConfig($this->account->tenant_id, 'app.kb.account_delete'); - - $subject = \trans('mail.suspendeddebtor-subject', ['site' => $appName]); - - $moreInfoHtml = null; - $moreInfoText = null; - if ($moreInfoUrl = Tenant::getConfig($this->account->tenant_id, 'app.kb.account_suspended')) { - $moreInfoHtml = \trans('mail.more-info-html', ['href' => $moreInfoUrl]); - $moreInfoText = \trans('mail.more-info-text', ['href' => $moreInfoUrl]); - } - - $this->view('emails.html.suspended_debtor') - ->text('emails.plain.suspended_debtor') - ->subject($subject) - ->with([ - 'site' => $appName, - 'subject' => $subject, - 'username' => $this->account->name(true), - 'cancelUrl' => $cancelUrl, - 'supportUrl' => Utils::serviceUrl($supportUrl, $this->account->tenant_id), - 'walletUrl' => Utils::serviceUrl('/wallet', $this->account->tenant_id), - 'moreInfoHtml' => $moreInfoHtml, - 'moreInfoText' => $moreInfoText, - 'days' => 14 // TODO: Configurable - ]); - - return $this; - } - - /** - * Render the mail template with fake data - * - * @param string $type Output format ('html' or 'text') - * - * @return string HTML or Plain Text output - */ - public static function fakeRender(string $type = 'html'): string - { - $user = new User(); - - $mail = new self($user); - - return Helper::render($mail, $type); - } -} diff --git a/src/resources/lang/en/mail.php b/src/resources/lang/en/mail.php --- a/src/resources/lang/en/mail.php +++ b/src/resources/lang/en/mail.php @@ -36,8 +36,6 @@ 'negativebalancereminder-body' => "It has probably skipped your attention that you are behind on paying for your :site account. " . "Consider setting up an automatic payment to avoid messages like this in the future.", 'negativebalancereminder-body-ext' => "Settle up to keep your account running:", - 'negativebalancereminder-body-warning' => "Please, be aware that your account will be suspended " - . "if your account balance is not settled by :date.", 'negativebalancereminderdegrade-body-warning' => "Please, be aware that your account will be degraded " . "if your account balance is not settled by :date.", @@ -47,18 +45,6 @@ . "Consider setting up an automatic payment to avoid messages like this in the future.", 'negativebalancedegraded-body-ext' => "Settle up now to undegrade your account:", - 'negativebalancesuspended-subject' => ":site Account Suspended", - 'negativebalancesuspended-body' => "Your :site account has been suspended for having a negative balance for too long. " - . "Consider setting up an automatic payment to avoid messages like this in the future.", - 'negativebalancesuspended-body-ext' => "Settle up now to unsuspend your account:", - 'negativebalancesuspended-body-warning' => "Please, be aware that your account and all its data will be deleted " - . "if your account balance is not settled by :date.", - - 'negativebalancebeforedelete-subject' => ":site Final Warning", - 'negativebalancebeforedelete-body' => "This is a final reminder to settle your :site account balance. " - . "Your account and all its data will be deleted if your account balance is not settled by :date.", - 'negativebalancebeforedelete-body-ext' => "Settle up now to keep your account:", - 'passwordreset-subject' => ":site Password Reset", 'passwordreset-body1' => "Someone recently asked to change your :site password.", 'passwordreset-body2' => "If this was you, use this verification code to complete the process:", @@ -101,13 +87,6 @@ 'signupinvitation-body1' => "You have been invited to join :site. Click the link below to sign up.", 'signupinvitation-body2' => "", - 'suspendeddebtor-subject' => ":site Account Suspended", - 'suspendeddebtor-body' => "You have been behind on paying for your :site account " - . "for over :days days. Your account has been suspended.", - 'suspendeddebtor-middle' => "Settle up now to reactivate your account.", - 'suspendeddebtor-cancel' => "Don't want to be our customer anymore? " - . "Here is how you can cancel your account:", - 'trialend-subject' => ":site: Your trial phase has ended", 'trialend-intro' => "We hope you enjoyed the 30 days of free :site trial." . " Your subscriptions become active after the first month of use and the fee is due after another month.", diff --git a/src/resources/lang/fr/mail.php b/src/resources/lang/fr/mail.php --- a/src/resources/lang/fr/mail.php +++ b/src/resources/lang/fr/mail.php @@ -36,20 +36,6 @@ 'negativebalancereminder-body' => "Vous n'avez peut-être pas rendu compte que vous êtes en retard avec votre paiement pour :site compte." . " Veillez à mettre en place un auto-paiement pour éviter de tel avertissement comme celui-ci dans le future.", 'negativebalancereminder-body-ext' => "Régler votre compte pour le maintenir en fontion:", - 'negativebalancereminder-body-warning' => "Soyez conscient que votre compte sera suspendu si le" - . " solde de votre compte n'est réglé avant le :date.", - - 'negativebalancesuspended-subject' => ":site Compte Suspendu", - 'negativebalancesuspended-body' => "Votre :site compte a été suspendu à la suite d'un solde négatif pendant trop longtemps." - . " Veillez nvisager de mettre en place un auto-paiement pour éviter de tel avertissement comme celui-ci dans le future.", - 'negativebalancesuspended-body-ext' => "Régler votre compte pour le maintenir en fontion:", - 'negativebalancesuspended-body-warning' => "Veuillez vous assurer que votre compte et toutes ses données seront supprimés" - . " si le solde de votre compte n'est pas réglé avant le :date.", - - 'negativebalancebeforedelete-subject' => ":site Dernier Avertissement", - 'negativebalancebeforedelete-body' => "Ceci-ci est le dernier rappel pour régler votre :site solde de compte." - . " votre compte et toutes ses données seront supprimés si le solde de votre compte nest pas régler avant le :date.", - 'negativebalancebeforedelete-body-ext' => "Régler votre compte immédiatement:", 'negativebalancereminderdegrade-body-warning' => "Veuillez noter que votre compte sera dégradé" . " si le solde de votre compte n'est pas réglé avant le :date.", @@ -98,11 +84,4 @@ 'signupinvitation-body1' => "Vous êtes invité à joindre :site. Cliquez sur le lien ci-dessous pour vous inscrire.", 'signupinvitation-body2' => "", - 'suspendeddebtor-subject' => ":site Compte Suspendu", - 'suspendeddebtor-body' => "Vous êtes en retard avec le paiement de votre :site compte" - . " pour plus de :days jours. Votre compte est suspendu.", - 'suspendeddebtor-middle' => "Réglez immédiatement pour réactiver votre compte.", - 'suspendeddebtor-cancel' => "Vous ne souhaitez plus être notre client?" - . " Voici la démarche à suivre pour annuler votre compte:", - ]; diff --git a/src/resources/views/emails/html/negative_balance_before_delete.blade.php b/src/resources/views/emails/html/negative_balance_before_delete.blade.php deleted file mode 100644 --- a/src/resources/views/emails/html/negative_balance_before_delete.blade.php +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - -

{{ __('mail.header', ['name' => $username]) }}

- -

{{ __('mail.negativebalancebeforedelete-body', ['site' => $site, 'date' => $date]) }}

-

{{ __('mail.negativebalancebeforedelete-body-ext', ['site' => $site]) }}

-

{{ $walletUrl }}

- -@if ($supportUrl) -

{{ __('mail.support', ['site' => $site]) }}

-

{{ $supportUrl }}

-@endif - -

{{ __('mail.footer1') }}

-

{{ __('mail.footer2', ['site' => $site]) }}

- - diff --git a/src/resources/views/emails/html/negative_balance_reminder.blade.php b/src/resources/views/emails/html/negative_balance_reminder.blade.php deleted file mode 100644 --- a/src/resources/views/emails/html/negative_balance_reminder.blade.php +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - -

{{ __('mail.header', ['name' => $username]) }}

- -

{{ __('mail.negativebalancereminder-body', ['site' => $site]) }}

-

{{ __('mail.negativebalancereminder-body-ext', ['site' => $site]) }}

-

{{ $walletUrl }}

-

{{ __('mail.negativebalancereminder-body-warning', ['site' => $site, 'date' => $date]) }}

- -@if ($supportUrl) -

{{ __('mail.support', ['site' => $site]) }}

-

{{ $supportUrl }}

-@endif - -

{{ __('mail.footer1') }}

-

{{ __('mail.footer2', ['site' => $site]) }}

- - diff --git a/src/resources/views/emails/html/negative_balance_suspended.blade.php b/src/resources/views/emails/html/negative_balance_suspended.blade.php deleted file mode 100644 --- a/src/resources/views/emails/html/negative_balance_suspended.blade.php +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - -

{{ __('mail.header', ['name' => $username]) }}

- -

{{ __('mail.negativebalancesuspended-body', ['site' => $site]) }}

-

{{ __('mail.negativebalancesuspended-body-ext', ['site' => $site]) }}

-

{{ $walletUrl }}

-

{{ __('mail.negativebalancesuspended-body-warning', ['site' => $site, 'date' => $date]) }}

- -@if ($supportUrl) -

{{ __('mail.support', ['site' => $site]) }}

-

{{ $supportUrl }}

-@endif - -

{{ __('mail.footer1') }}

-

{{ __('mail.footer2', ['site' => $site]) }}

- - diff --git a/src/resources/views/emails/html/suspended_debtor.blade.php b/src/resources/views/emails/html/suspended_debtor.blade.php deleted file mode 100644 --- a/src/resources/views/emails/html/suspended_debtor.blade.php +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - -

{{ __('mail.header', ['name' => $username]) }}

- -

{{ __('mail.suspendeddebtor-body', ['site' => $site, 'days' => $days]) }} {!! $moreInfoHtml !!}

-

{{ __('mail.suspendeddebtor-middle') }}

-

{{ $walletUrl }}

- -@if ($supportUrl) -

{{ __('mail.support', ['site' => $site]) }}

-

{{ $supportUrl }}

-@endif -@if ($cancelUrl) -

{{ __('mail.suspendeddebtor-cancel') }}

-

{{ $cancelUrl }}

-@endif - -

{{ __('mail.footer1') }}

-

{{ __('mail.footer2', ['site' => $site]) }}

- - diff --git a/src/resources/views/emails/plain/negative_balance_before_delete.blade.php b/src/resources/views/emails/plain/negative_balance_before_delete.blade.php deleted file mode 100644 --- a/src/resources/views/emails/plain/negative_balance_before_delete.blade.php +++ /dev/null @@ -1,17 +0,0 @@ -{!! __('mail.header', ['name' => $username]) !!} - -{!! __('mail.negativebalancebeforedelete-body', ['site' => $site, 'date' => $date]) !!} - -{!! __('mail.negativebalancebeforedelete-body-ext', ['site' => $site]) !!} - -{!! $walletUrl !!} - -@if ($supportUrl) -{!! __('mail.support', ['site' => $site]) !!} - -{!! $supportUrl !!} -@endif - --- -{!! __('mail.footer1') !!} -{!! __('mail.footer2', ['site' => $site]) !!} diff --git a/src/resources/views/emails/plain/negative_balance_reminder.blade.php b/src/resources/views/emails/plain/negative_balance_reminder.blade.php deleted file mode 100644 --- a/src/resources/views/emails/plain/negative_balance_reminder.blade.php +++ /dev/null @@ -1,19 +0,0 @@ -{!! __('mail.header', ['name' => $username]) !!} - -{!! __('mail.negativebalancereminder-body', ['site' => $site]) !!} - -{!! __('mail.negativebalancereminder-body-ext', ['site' => $site]) !!} - -{!! $walletUrl !!} - -{!! __('mail.negativebalancereminder-body-warning', ['site' => $site, 'date' => $date]) !!} - -@if ($supportUrl) -{!! __('mail.support', ['site' => $site]) !!} - -{!! $supportUrl !!} -@endif - --- -{!! __('mail.footer1') !!} -{!! __('mail.footer2', ['site' => $site]) !!} diff --git a/src/resources/views/emails/plain/negative_balance_suspended.blade.php b/src/resources/views/emails/plain/negative_balance_suspended.blade.php deleted file mode 100644 --- a/src/resources/views/emails/plain/negative_balance_suspended.blade.php +++ /dev/null @@ -1,19 +0,0 @@ -{!! __('mail.header', ['name' => $username]) !!} - -{!! __('mail.negativebalancesuspended-body', ['site' => $site]) !!} - -{!! __('mail.negativebalancesuspended-body-ext', ['site' => $site]) !!} - -{!! $walletUrl !!} - -{!! __('mail.negativebalancesuspended-body-warning', ['site' => $site, 'date' => $date]) !!} - -@if ($supportUrl) -{!! __('mail.support', ['site' => $site]) !!} - -{!! $supportUrl !!} -@endif - --- -{!! __('mail.footer1') !!} -{!! __('mail.footer2', ['site' => $site]) !!} diff --git a/src/resources/views/emails/plain/suspended_debtor.blade.php b/src/resources/views/emails/plain/suspended_debtor.blade.php deleted file mode 100644 --- a/src/resources/views/emails/plain/suspended_debtor.blade.php +++ /dev/null @@ -1,23 +0,0 @@ -{!! __('mail.header', ['name' => $username]) !!} - -{!! __('mail.suspendeddebtor-body', ['site' => $site, 'days' => $days]) !!} {!! $moreInfoText !!} - -{!! __('mail.suspendeddebtor-middle') !!} - -{!! $walletUrl !!} - -@if ($supportUrl) -{!! __('mail.support', ['site' => $site]) !!} - -{!! $supportUrl !!} -@endif -@if ($cancelUrl) - -{!! __('mail.suspendeddebtor-cancel') !!} - -{!! $cancelUrl !!} -@endif - --- -{!! __('mail.footer1') !!} -{!! __('mail.footer2', ['site' => $site]) !!} diff --git a/src/tests/Feature/Jobs/WalletCheckTest.php b/src/tests/Feature/Jobs/WalletCheckTest.php --- a/src/tests/Feature/Jobs/WalletCheckTest.php +++ b/src/tests/Feature/Jobs/WalletCheckTest.php @@ -97,6 +97,16 @@ $today_regexp = '/' . Carbon::now()->toDateString() . ' [0-9]{2}:[0-9]{2}:[0-9]{2}/'; $this->assertMatchesRegularExpression($today_regexp, $wallet->getSetting('balance_negative_since')); $this->assertMatchesRegularExpression($today_regexp, $wallet->getSetting('balance_warning_initial')); + + // Test suspended user - no mail sent + Mail::fake(); + $wallet->owner->suspend(); + $wallet->setSetting('balance_warning_initial', null); + + $job = new WalletCheck($wallet); + $job->handle(); + + Mail::assertNothingSent(); } /** @@ -121,7 +131,6 @@ // TODO: Test that it actually executed the topUpWallet() $this->assertSame(WalletCheck::THRESHOLD_BEFORE_REMINDER, $res); - $this->assertFalse($user->fresh()->isSuspended()); } /** @@ -154,143 +163,17 @@ $job->handle(); Mail::assertNothingSent(); - } - - /** - * Test job handle, top-up wallet before account suspending - * - * @depends testHandleReminder - */ -/* - public function testHandleBeforeSuspended(): void - { - Mail::fake(); - - $user = $this->prepareTestUser($wallet); - $now = Carbon::now(); - - // Balance turned negative 7+14-1 days ago - $days = 7 + 14 - 1; - $wallet->setSetting('balance_negative_since', $now->subDays($days)->toDateTimeString()); - - $job = new WalletCheck($wallet); - $res = $job->handle(); - - Mail::assertNothingSent(); - - // TODO: Test that it actually executed the topUpWallet() - $this->assertSame(WalletCheck::THRESHOLD_BEFORE_SUSPEND, $res); - $this->assertFalse($user->fresh()->isSuspended()); - } -*/ - /** - * Test job handle, account suspending - * - * @depends testHandleBeforeSuspended - */ -/* - public function testHandleSuspended(): void - { - Mail::fake(); - - $user = $this->prepareTestUser($wallet); - $now = Carbon::now(); - - // Balance turned negative 7+14+1 days ago, expect mail sent - $days = 7 + 14 + 1; - $wallet->setSetting('balance_negative_since', $now->subDays($days)->toDateTimeString()); - - $job = new WalletCheck($wallet); - $job->handle(); - - // Assert the mail was sent to the user's email, but not to his external email - Mail::assertSent(\App\Mail\NegativeBalanceSuspended::class, 1); - Mail::assertSent(\App\Mail\NegativeBalanceSuspended::class, function ($mail) use ($user) { - return $mail->hasTo($user->email) && $mail->hasCc('external@test.com'); - }); - - // Check that it has been suspended - $this->assertTrue($user->fresh()->isSuspended()); - - // TODO: Test that group account members/domain are also being suspended - - // Run the job again to make sure the notification is not sent again - Mail::fake(); - $job = new WalletCheck($wallet); - $job->handle(); - - Mail::assertNothingSent(); - } -*/ - /** - * Test job handle, final warning before delete - * - * @depends testHandleSuspended - */ -/* - public function testHandleBeforeDelete(): void - { - Mail::fake(); - - $user = $this->prepareTestUser($wallet); - $now = Carbon::now(); - - // Balance turned negative 7+14+21-3+1 days ago, expect mail sent - $days = 7 + 14 + 21 - 3 + 1; - $wallet->setSetting('balance_negative_since', $now->subDays($days)->toDateTimeString()); - - $job = new WalletCheck($wallet); - $job->handle(); - // Assert the mail was sent to the user's email, and his external email - Mail::assertSent(\App\Mail\NegativeBalanceBeforeDelete::class, 1); - Mail::assertSent(\App\Mail\NegativeBalanceBeforeDelete::class, function ($mail) use ($user) { - return $mail->hasTo($user->email) && $mail->hasCc('external@test.com'); - }); - - // Check that it has not been deleted yet - $this->assertFalse($user->fresh()->isDeleted()); - - // Run the job again to make sure the notification is not sent again + // Test suspended user - no mail sent Mail::fake(); - $job = new WalletCheck($wallet); - $job->handle(); - - Mail::assertNothingSent(); - } -*/ - /** - * Test job handle, account delete - * - * @depends testHandleBeforeDelete - */ -/* - public function testHandleDelete(): void - { - Mail::fake(); - - $user = $this->prepareTestUser($wallet); - $now = Carbon::now(); - - $this->assertFalse($user->isDeleted()); - $this->assertCount(7, $user->entitlements()->get()); - - // Balance turned negative 7+14+21+1 days ago, expect mail sent - $days = 7 + 14 + 21 + 1; - $wallet->setSetting('balance_negative_since', $now->subDays($days)->toDateTimeString()); + $wallet->owner->suspend(); + $wallet->setSetting('balance_warning_reminder', null); $job = new WalletCheck($wallet); $job->handle(); Mail::assertNothingSent(); - - // Check that it has not been deleted - $this->assertTrue($user->fresh()->trashed()); - $this->assertCount(0, $user->entitlements()->get()); - - // TODO: Test it deletes all members of the group account } -*/ /** * Test job handle, account degrade @@ -321,6 +204,16 @@ // Check that it has been degraded $this->assertTrue($user->fresh()->isDegraded()); + + // Test suspended user - no mail sent + Mail::fake(); + $wallet->owner->suspend(); + $wallet->owner->undegrade(); + + $job = new WalletCheck($wallet); + $job->handle(); + + Mail::assertNothingSent(); } /** @@ -372,12 +265,23 @@ // Assert the mail was sent to the user's email, and his external email Mail::assertSent(\App\Mail\DegradedAccountReminder::class, 1); Mail::assertSent(\App\Mail\DegradedAccountReminder::class, function ($mail) use ($user) { - return $mail->hasTo($user->email) && $mail->hasCc('external@test.com'); + return $mail->hasTo($user->email) && !$mail->hasCc('external@test.com'); }); $_last = $wallet->fresh()->getSetting('degraded_last_reminder'); $this->assertSame(Carbon::now()->toDateTimeString(), $_last); $this->assertSame(WalletCheck::THRESHOLD_DEGRADE_REMINDER, $res); + + // Test suspended user - no mail sent + Mail::fake(); + $wallet->owner->suspend(); + $wallet->owner->undegrade(); + $wallet->setSetting('degraded_last_reminder', null); + + $job = new WalletCheck($wallet); + $job->handle(); + + Mail::assertNothingSent(); } /** diff --git a/src/tests/Unit/Mail/NegativeBalanceBeforeDeleteTest.php b/src/tests/Unit/Mail/NegativeBalanceBeforeDeleteTest.php deleted file mode 100644 --- a/src/tests/Unit/Mail/NegativeBalanceBeforeDeleteTest.php +++ /dev/null @@ -1,122 +0,0 @@ -getTestUser('ned@kolab.org'); - $wallet = $user->wallets->first(); - $wallet->balance = -100; - $wallet->save(); - - $threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DELETE); - - \config([ - 'app.support_url' => 'https://kolab.org/support', - ]); - - $mail = $this->renderMail(new NegativeBalanceBeforeDelete($wallet, $user)); - - $html = $mail['html']; - $plain = $mail['plain']; - - $walletUrl = \App\Utils::serviceUrl('/wallet'); - $walletLink = sprintf('%s', $walletUrl, $walletUrl); - $supportUrl = \config('app.support_url'); - $supportLink = sprintf('%s', $supportUrl, $supportUrl); - $appName = $user->tenant->title; - - $this->assertSame("$appName Final Warning", $mail['subject']); - - $this->assertStringStartsWith('', $html); - $this->assertTrue(strpos($html, $user->name(true)) > 0); - $this->assertTrue(strpos($html, $walletLink) > 0); - $this->assertTrue(strpos($html, $supportLink) > 0); - $this->assertTrue(strpos($html, "This is a final reminder to settle your $appName") > 0); - $this->assertTrue(strpos($html, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($html, "$appName Support") > 0); - $this->assertTrue(strpos($html, "$appName Team") > 0); - - $this->assertStringStartsWith('Dear ' . $user->name(true), $plain); - $this->assertTrue(strpos($plain, $walletUrl) > 0); - $this->assertTrue(strpos($plain, $supportUrl) > 0); - $this->assertTrue(strpos($plain, "This is a final reminder to settle your $appName") > 0); - $this->assertTrue(strpos($plain, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($plain, "$appName Support") > 0); - $this->assertTrue(strpos($plain, "$appName Team") > 0); - - // Test with user that is not the same tenant as in .env - $user = $this->getTestUser('user@sample-tenant.dev-local'); - $tenant = $user->tenant; - $wallet = $user->wallets->first(); - $wallet->balance = -100; - $wallet->save(); - - $threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DELETE); - - $tenant->setSettings([ - 'app.support_url' => 'https://test.org/support', - 'app.public_url' => 'https://test.org', - ]); - - $mail = $this->renderMail(new NegativeBalanceBeforeDelete($wallet, $user)); - - $html = $mail['html']; - $plain = $mail['plain']; - - $walletUrl = 'https://test.org/wallet'; - $walletLink = sprintf('%s', $walletUrl, $walletUrl); - $supportUrl = 'https://test.org/support'; - $supportLink = sprintf('%s', $supportUrl, $supportUrl); - - $this->assertSame("{$tenant->title} Final Warning", $mail['subject']); - - $this->assertStringStartsWith('', $html); - $this->assertTrue(strpos($html, $user->name(true)) > 0); - $this->assertTrue(strpos($html, $walletLink) > 0); - $this->assertTrue(strpos($html, $supportLink) > 0); - $this->assertTrue(strpos($html, "This is a final reminder to settle your {$tenant->title}") > 0); - $this->assertTrue(strpos($html, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($html, "{$tenant->title} Support") > 0); - $this->assertTrue(strpos($html, "{$tenant->title} Team") > 0); - - $this->assertStringStartsWith('Dear ' . $user->name(true), $plain); - $this->assertTrue(strpos($plain, $walletUrl) > 0); - $this->assertTrue(strpos($plain, $supportUrl) > 0); - $this->assertTrue(strpos($plain, "This is a final reminder to settle your {$tenant->title}") > 0); - $this->assertTrue(strpos($plain, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($plain, "{$tenant->title} Support") > 0); - $this->assertTrue(strpos($plain, "{$tenant->title} Team") > 0); - } -} diff --git a/src/tests/Unit/Mail/NegativeBalanceReminderTest.php b/src/tests/Unit/Mail/NegativeBalanceReminderTest.php deleted file mode 100644 --- a/src/tests/Unit/Mail/NegativeBalanceReminderTest.php +++ /dev/null @@ -1,59 +0,0 @@ -getTestUser('ned@kolab.org'); - $wallet = $user->wallets->first(); - $wallet->balance = -100; - $wallet->save(); - - $threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_SUSPEND); - - \config([ - 'app.support_url' => 'https://kolab.org/support', - ]); - - $mail = $this->renderMail(new NegativeBalanceReminder($wallet, $user)); - - $html = $mail['html']; - $plain = $mail['plain']; - - $walletUrl = \App\Utils::serviceUrl('/wallet'); - $walletLink = sprintf('%s', $walletUrl, $walletUrl); - $supportUrl = \config('app.support_url'); - $supportLink = sprintf('%s', $supportUrl, $supportUrl); - $appName = $user->tenant->title; - - $this->assertSame("$appName Payment Reminder", $mail['subject']); - - $this->assertStringStartsWith('', $html); - $this->assertTrue(strpos($html, $user->name(true)) > 0); - $this->assertTrue(strpos($html, $walletLink) > 0); - $this->assertTrue(strpos($html, $supportLink) > 0); - $this->assertTrue(strpos($html, "you are behind on paying for your $appName account") > 0); - $this->assertTrue(strpos($html, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($html, "$appName Support") > 0); - $this->assertTrue(strpos($html, "$appName Team") > 0); - - $this->assertStringStartsWith('Dear ' . $user->name(true), $plain); - $this->assertTrue(strpos($plain, $walletUrl) > 0); - $this->assertTrue(strpos($plain, $supportUrl) > 0); - $this->assertTrue(strpos($plain, "you are behind on paying for your $appName account") > 0); - $this->assertTrue(strpos($plain, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($plain, "$appName Support") > 0); - $this->assertTrue(strpos($plain, "$appName Team") > 0); - } -} diff --git a/src/tests/Unit/Mail/NegativeBalanceSuspendedTest.php b/src/tests/Unit/Mail/NegativeBalanceSuspendedTest.php deleted file mode 100644 --- a/src/tests/Unit/Mail/NegativeBalanceSuspendedTest.php +++ /dev/null @@ -1,59 +0,0 @@ -getTestUser('ned@kolab.org'); - $wallet = $user->wallets->first(); - $wallet->balance = -100; - $wallet->save(); - - $threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DELETE); - - \config([ - 'app.support_url' => 'https://kolab.org/support', - ]); - - $mail = $this->renderMail(new NegativeBalanceSuspended($wallet, $user)); - - $html = $mail['html']; - $plain = $mail['plain']; - - $walletUrl = \App\Utils::serviceUrl('/wallet'); - $walletLink = sprintf('%s', $walletUrl, $walletUrl); - $supportUrl = \config('app.support_url'); - $supportLink = sprintf('%s', $supportUrl, $supportUrl); - $appName = $user->tenant->title; - - $this->assertSame("$appName Account Suspended", $mail['subject']); - - $this->assertStringStartsWith('', $html); - $this->assertTrue(strpos($html, $user->name(true)) > 0); - $this->assertTrue(strpos($html, $walletLink) > 0); - $this->assertTrue(strpos($html, $supportLink) > 0); - $this->assertTrue(strpos($html, "Your $appName account has been suspended") > 0); - $this->assertTrue(strpos($html, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($html, "$appName Support") > 0); - $this->assertTrue(strpos($html, "$appName Team") > 0); - - $this->assertStringStartsWith('Dear ' . $user->name(true), $plain); - $this->assertTrue(strpos($plain, $walletUrl) > 0); - $this->assertTrue(strpos($plain, $supportUrl) > 0); - $this->assertTrue(strpos($plain, "Your $appName account has been suspended") > 0); - $this->assertTrue(strpos($plain, $threshold->toDateString()) > 0); - $this->assertTrue(strpos($plain, "$appName Support") > 0); - $this->assertTrue(strpos($plain, "$appName Team") > 0); - } -} diff --git a/src/tests/Unit/Mail/SuspendedDebtorTest.php b/src/tests/Unit/Mail/SuspendedDebtorTest.php deleted file mode 100644 --- a/src/tests/Unit/Mail/SuspendedDebtorTest.php +++ /dev/null @@ -1,62 +0,0 @@ - 'https://kolab.org/support', - 'app.kb.account_suspended' => 'https://kb.kolab.org/account-suspended', - 'app.kb.account_delete' => 'https://kb.kolab.org/account-delete', - ]); - - $mail = $this->renderMail(new SuspendedDebtor($user)); - - $html = $mail['html']; - $plain = $mail['plain']; - - $walletUrl = \App\Utils::serviceUrl('/wallet'); - $walletLink = sprintf('%s', $walletUrl, $walletUrl); - $supportUrl = \config('app.support_url'); - $supportLink = sprintf('%s', $supportUrl, $supportUrl); - $deleteUrl = \config('app.kb.account_delete'); - $deleteLink = sprintf('%s', $deleteUrl, $deleteUrl); - $moreUrl = \config('app.kb.account_suspended'); - $moreLink = sprintf('here', $moreUrl); - $appName = \config('app.name'); - - $this->assertSame("$appName Account Suspended", $mail['subject']); - - $this->assertStringStartsWith('', $html); - $this->assertTrue(strpos($html, $user->name(true)) > 0); - $this->assertTrue(strpos($html, $walletLink) > 0); - $this->assertTrue(strpos($html, $supportLink) > 0); - $this->assertTrue(strpos($html, $deleteLink) > 0); - $this->assertTrue(strpos($html, "You have been behind on paying for your $appName account") > 0); - $this->assertTrue(strpos($html, "over 14 days") > 0); - $this->assertTrue(strpos($html, "See $moreLink for more information") > 0); - $this->assertTrue(strpos($html, "$appName Support") > 0); - $this->assertTrue(strpos($html, "$appName Team") > 0); - - $this->assertStringStartsWith('Dear ' . $user->name(true), $plain); - $this->assertTrue(strpos($plain, $walletUrl) > 0); - $this->assertTrue(strpos($plain, $supportUrl) > 0); - $this->assertTrue(strpos($plain, $deleteUrl) > 0); - $this->assertTrue(strpos($plain, "You have been behind on paying for your $appName account") > 0); - $this->assertTrue(strpos($plain, "over 14 days") > 0); - $this->assertTrue(strpos($plain, "See $moreUrl for more information") > 0); - $this->assertTrue(strpos($plain, "$appName Support") > 0); - $this->assertTrue(strpos($plain, "$appName Team") > 0); - } -}