diff --git a/src/app/Console/Development/TemplateRender.php b/src/app/Console/Development/TemplateRender.php --- a/src/app/Console/Development/TemplateRender.php +++ b/src/app/Console/Development/TemplateRender.php @@ -11,7 +11,7 @@ * * @var string */ - protected $signature = 'template:render {template} {--html} {--pdf}'; + protected $signature = 'template:render {template} {--html} {--text} {--pdf}'; /** * The console command description. @@ -52,6 +52,8 @@ $mode = 'html'; if (!empty($this->option('pdf'))) { $mode = 'pdf'; + } elseif (!empty($this->option('text'))) { + $mode = 'text'; } echo $class::fakeRender($mode); diff --git a/src/app/Documents/Receipt.php b/src/app/Documents/Receipt.php --- a/src/app/Documents/Receipt.php +++ b/src/app/Documents/Receipt.php @@ -42,6 +42,8 @@ /** * Render the mail template with fake data * + * @param string $type Output format ('html' or 'pdf') + * * @return string HTML or PDF output */ public static function fakeRender(string $type = 'html'): string @@ -56,6 +58,8 @@ if ($type == 'pdf') { return $receipt->pdfOutput(); + } elseif ($type !== 'html') { + throw new \Exception("Unsupported output format"); } return $receipt->htmlOutput(); diff --git a/src/app/Mail/Helper.php b/src/app/Mail/Helper.php new file mode 100644 --- /dev/null +++ b/src/app/Mail/Helper.php @@ -0,0 +1,33 @@ +build(); // @phpstan-ignore-line + + $mailer = \Illuminate\Container\Container::getInstance()->make('mailer'); + + return $mailer->render(['text' => $mail->textView], $mail->buildViewData()); + } elseif ($type != 'html') { + throw new \Exception("Unsupported output format"); + } + + // HTML output + return $mail->build()->render(); // @phpstan-ignore-line + } +} diff --git a/src/app/Mail/NegativeBalance.php b/src/app/Mail/NegativeBalance.php --- a/src/app/Mail/NegativeBalance.php +++ b/src/app/Mail/NegativeBalance.php @@ -40,7 +40,8 @@ $subject = \trans('mail.negativebalance-subject', ['site' => \config('app.name')]); - $this->view('emails.negative_balance') + $this->view('emails.html.negative_balance') + ->text('emails.plain.negative_balance') ->subject($subject) ->with([ 'site' => \config('app.name'), @@ -56,14 +57,16 @@ /** * Render the mail template with fake data * - * @return string HTML output + * @param string $type Output format ('html' or 'text') + * + * @return string HTML or Plain Text output */ - public static function fakeRender(): string + public static function fakeRender(string $type = 'html'): string { $user = new User(); $mail = new self($user); - return $mail->build()->render(); + return Helper::render($mail, $type); } } diff --git a/src/app/Mail/PasswordReset.php b/src/app/Mail/PasswordReset.php --- a/src/app/Mail/PasswordReset.php +++ b/src/app/Mail/PasswordReset.php @@ -42,7 +42,8 @@ sprintf('/login/reset/%s-%s', $this->code->short_code, $this->code->code) ); - $this->view('emails.password_reset') + $this->view('emails.html.password_reset') + ->text('emails.plain.password_reset') ->subject(__('mail.passwordreset-subject', ['site' => \config('app.name')])) ->with([ 'site' => \config('app.name'), @@ -58,9 +59,11 @@ /** * Render the mail template with fake data * - * @return string HTML output + * @param string $type Output format ('html' or 'text') + * + * @return string HTML or Plain Text output */ - public static function fakeRender(): string + public static function fakeRender(string $type = 'html'): string { $code = new VerificationCode([ 'code' => Str::random(VerificationCode::CODE_LENGTH), @@ -73,6 +76,6 @@ $mail = new self($code); - return $mail->build()->render(); + return Helper::render($mail, $type); } } diff --git a/src/app/Mail/PaymentFailure.php b/src/app/Mail/PaymentFailure.php --- a/src/app/Mail/PaymentFailure.php +++ b/src/app/Mail/PaymentFailure.php @@ -46,7 +46,8 @@ $subject = \trans('mail.paymentfailure-subject', ['site' => \config('app.name')]); - $this->view('emails.payment_failure') + $this->view('emails.html.payment_failure') + ->text('emails.plain.payment_failure') ->subject($subject) ->with([ 'site' => \config('app.name'), @@ -62,21 +63,19 @@ /** * Render the mail template with fake data * - * @return string HTML output + * @param string $type Output format ('html' or 'text') + * + * @return string HTML or Plain Text output */ - public static function fakeRender(): string + public static function fakeRender(string $type = 'mail'): string { $payment = new Payment(); $user = new User([ 'email' => 'test@' . \config('app.domain'), ]); - if (!\config('app.support_url')) { - \config(['app.support_url' => 'https://not-configured-support.url']); - } - $mail = new self($payment, $user); - return $mail->build()->render(); + return Helper::render($mail, $type); } } diff --git a/src/app/Mail/PaymentMandateDisabled.php b/src/app/Mail/PaymentMandateDisabled.php --- a/src/app/Mail/PaymentMandateDisabled.php +++ b/src/app/Mail/PaymentMandateDisabled.php @@ -46,7 +46,8 @@ $subject = \trans('mail.paymentmandatedisabled-subject', ['site' => \config('app.name')]); - $this->view('emails.payment_mandate_disabled') + $this->view('emails.html.payment_mandate_disabled') + ->text('emails.plain.payment_mandate_disabled') ->subject($subject) ->with([ 'site' => \config('app.name'), @@ -62,21 +63,19 @@ /** * Render the mail template with fake data * - * @return string HTML output + * @param string $type Output format ('html' or 'text') + * + * @return string HTML or Plain Text output */ - public static function fakeRender(): string + public static function fakeRender(string $type = 'html'): string { $wallet = new Wallet(); $user = new User([ 'email' => 'test@' . \config('app.domain'), ]); - if (!\config('app.support_url')) { - \config(['app.support_url' => 'https://not-configured-support.url']); - } - $mail = new self($wallet, $user); - return $mail->build()->render(); + return Helper::render($mail, $type); } } diff --git a/src/app/Mail/PaymentSuccess.php b/src/app/Mail/PaymentSuccess.php --- a/src/app/Mail/PaymentSuccess.php +++ b/src/app/Mail/PaymentSuccess.php @@ -46,7 +46,8 @@ $subject = \trans('mail.paymentsuccess-subject', ['site' => \config('app.name')]); - $this->view('emails.payment_success') + $this->view('emails.html.payment_success') + ->text('emails.plain.payment_success') ->subject($subject) ->with([ 'site' => \config('app.name'), @@ -62,21 +63,19 @@ /** * Render the mail template with fake data * - * @return string HTML output + * @param string $type Output format ('html' or 'text') + * + * @return string HTML or Plain Text output */ - public static function fakeRender(): string + public static function fakeRender(string $type = 'html'): string { $payment = new Payment(); $user = new User([ 'email' => 'test@' . \config('app.domain'), ]); - if (!\config('app.support_url')) { - \config(['app.support_url' => 'https://not-configured-support.url']); - } - $mail = new self($payment, $user); - return $mail->build()->render(); + return Helper::render($mail, $type); } } diff --git a/src/app/Mail/SignupVerification.php b/src/app/Mail/SignupVerification.php --- a/src/app/Mail/SignupVerification.php +++ b/src/app/Mail/SignupVerification.php @@ -47,14 +47,15 @@ } $username = trim($username); - $this->view('emails.signup_code') + $this->view('emails.html.signup_code') + ->text('emails.plain.signup_code') ->subject(__('mail.signupcode-subject', ['site' => \config('app.name')])) ->with([ 'site' => \config('app.name'), 'username' => $username ?: 'User', 'code' => $this->code->code, 'short_code' => $this->code->short_code, - 'link' => sprintf('%s', $href, $href), + 'href' => $href, ]); return $this; @@ -63,9 +64,11 @@ /** * Render the mail template with fake data * - * @return string HTML output + * @param string $type Output format ('html' or 'text') + * + * @return string HTML or Plain Text output */ - public static function fakeRender(): string + public static function fakeRender(string $type = 'html'): string { $code = new SignupCode([ 'code' => Str::random(SignupCode::CODE_LENGTH), @@ -77,9 +80,8 @@ ], ]); - $mail = new self($code); - return $mail->build()->render(); + return Helper::render($mail, $type); } } diff --git a/src/app/Mail/SuspendedDebtor.php b/src/app/Mail/SuspendedDebtor.php --- a/src/app/Mail/SuspendedDebtor.php +++ b/src/app/Mail/SuspendedDebtor.php @@ -40,12 +40,15 @@ $subject = \trans('mail.suspendeddebtor-subject', ['site' => \config('app.name')]); - $moreInfo = null; + $moreInfoHtml = null; + $moreInfoText = null; if ($moreInfoUrl = \config('app.kb.account_suspended')) { - $moreInfo = \trans('mail.more-info-html', ['href' => $moreInfoUrl]); + $moreInfoHtml = \trans('mail.more-info-html', ['href' => $moreInfoUrl]); + $moreInfoText = \trans('mail.more-info-text', ['href' => $moreInfoUrl]); } - $this->view('emails.suspended_debtor') + $this->view('emails.html.suspended_debtor') + ->text('emails.plain.suspended_debtor') ->subject($subject) ->with([ 'site' => \config('app.name'), @@ -54,7 +57,8 @@ 'cancelUrl' => \config('app.kb.account_delete'), 'supportUrl' => \config('app.support_url'), 'walletUrl' => Utils::serviceUrl('/wallet'), - 'moreInfo' => $moreInfo, + 'moreInfoHtml' => $moreInfoHtml, + 'moreInfoText' => $moreInfoText, 'days' => 14 // TODO: Configurable ]); @@ -64,26 +68,16 @@ /** * Render the mail template with fake data * - * @return string HTML output + * @param string $type Output format ('html' or 'text') + * + * @return string HTML or Plain Text output */ - public static function fakeRender(): string + public static function fakeRender(string $type = 'html'): string { $user = new User(); - if (!\config('app.support_url')) { - \config(['app.support_url' => 'https://not-configured-support.url']); - } - - if (!\config('app.kb.account_delete')) { - \config(['app.kb.account_delete' => 'https://not-configured-kb.url']); - } - - if (!\config('app.kb.account_suspended')) { - \config(['app.kb.account_suspended' => 'https://not-configured-kb.url']); - } - $mail = new self($user); - return $mail->build()->render(); + return Helper::render($mail, $type); } } diff --git a/src/composer.json b/src/composer.json --- a/src/composer.json +++ b/src/composer.json @@ -22,7 +22,7 @@ "iatstuti/laravel-nullable-fields": "*", "kolab/net_ldap3": "dev-master", "laravel/framework": "6.*", - "laravel/tinker": "^1.0", + "laravel/tinker": "^2.4", "mollie/laravel-mollie": "^2.9", "morrislaptop/laravel-queue-clear": "^1.2", "silviolleite/laravelpwa": "^1.0", @@ -39,10 +39,11 @@ "beyondcode/laravel-er-diagram-generator": "^1.3", "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", + "kirschbaum-development/mail-intercept": "^0.2.4", "laravel/dusk": "~5.11.0", "mockery/mockery": "^1.0", "nunomaduro/larastan": "^0.5", - "phpstan/phpstan": "^0.12", + "phpstan/phpstan": "0.12.25", "phpunit/phpunit": "^8" }, "config": { 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 @@ -14,11 +14,12 @@ 'footer' => "Best regards,\nYour :site Team", 'more-info-html' => "See here for more information.", + 'more-info-text' => "See :href for more information.", 'negativebalance-subject' => ":site Payment Reminder", 'negativebalance-body' => "It has probably skipped your attention that you are behind on paying for your :site account. " - . "Consider setting up auto-payment to avoid messages like this in the future.\n\n" - . "Settle up to keep your account running.", + . "Consider setting up auto-payment to avoid messages like this in the future.", + 'negativebalance-body-extd' => "Settle up to keep your account running.", 'passwordreset-subject' => ":site Password Reset", 'passwordreset-body' => "Someone recently asked to change your :site password.\n" @@ -29,16 +30,16 @@ 'paymentmandatedisabled-subject' => ":site Auto-payment Problem", 'paymentmandatedisabled-body' => "Your :site account balance is negative " . "and the configured amount for automatically topping up the balance does not cover " - . "the costs of subscriptions consumed.\n\n" - . "Charging you multiple times for the same amount in short succession " + . "the costs of subscriptions consumed.", + 'paymentmandatedisabled-body-ext' => "Charging you multiple times for the same amount in short succession " . "could lead to issues with the payment provider. " . "In order to not cause any problems, we suspended auto-payment for your account. " . "To resolve this issue, login to your account settings and adjust your auto-payment amount.", 'paymentfailure-subject' => ":site Payment Failed", 'paymentfailure-body' => "Something went wrong with auto-payment for your :site account.\n" - . "We tried to charge you via your preferred payment method, but the charge did not go through.\n\n" - . "In order to not cause any further issues, we suspended auto-payment for your account. " + . "We tried to charge you via your preferred payment method, but the charge did not go through.", + 'paymentfailure-body-ext' => "In order to not cause any further issues, we suspended auto-payment for your account. " . "To resolve this issue, login to your account settings at", 'paymentfailure-body-rest' => "There you can pay manually for your account and " . "change your auto-payment settings.", @@ -47,8 +48,8 @@ 'paymentsuccess-body' => "The auto-payment for your :site account went through without issues. " . "You can check your new account balance and more details here:", - 'support' => "Special circumstances? Something wrong with a charge?\n" - . " :site Support is here to help:", + 'support' => "Special circumstances? Something is wrong with a charge?\n" + . ":site Support is here to help.", 'signupcode-subject' => ":site Registration", 'signupcode-body' => "This is your verification code for the :site registration process: :code.\n" diff --git a/src/resources/views/documents/receipt.blade.php b/src/resources/views/documents/receipt.blade.php --- a/src/resources/views/documents/receipt.blade.php +++ b/src/resources/views/documents/receipt.blade.php @@ -3,7 +3,7 @@
diff --git a/src/resources/views/emails/negative_balance.blade.php b/src/resources/views/emails/html/negative_balance.blade.php rename from src/resources/views/emails/negative_balance.blade.php rename to src/resources/views/emails/html/negative_balance.blade.php --- a/src/resources/views/emails/negative_balance.blade.php +++ b/src/resources/views/emails/html/negative_balance.blade.php @@ -7,6 +7,7 @@{{ __('mail.header', ['name' => $username]) }}
{{ __('mail.negativebalance-body', ['site' => $site]) }}
+{{ __('mail.negativebalance-body-ext', ['site' => $site]) }}
@if ($supportUrl) @@ -14,6 +15,6 @@ @endif -{{ __('mail.footer', ['site' => $site, 'appurl' => config('app.url')]) }}
+{{ __('mail.footer', ['site' => $site]) }}