Changeset View
Changeset View
Standalone View
Standalone View
src/app/Mail/NegativeBalanceReminder.php
- This file was copied from src/app/Mail/NegativeBalance.php.
<?php | <?php | ||||
namespace App\Mail; | namespace App\Mail; | ||||
use App\Jobs\WalletCheck; | |||||
use App\User; | use App\User; | ||||
use App\Utils; | use App\Utils; | ||||
use App\Wallet; | |||||
use Illuminate\Bus\Queueable; | use Illuminate\Bus\Queueable; | ||||
use Illuminate\Mail\Mailable; | use Illuminate\Mail\Mailable; | ||||
use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||
class NegativeBalance extends Mailable | class NegativeBalanceReminder extends Mailable | ||||
{ | { | ||||
use Queueable; | use Queueable; | ||||
use SerializesModels; | use SerializesModels; | ||||
/** @var \App\User A user (account) that is behind with payments */ | /** @var \App\Wallet A wallet with a negative balance */ | ||||
protected $account; | protected $wallet; | ||||
/** @var \App\User A wallet controller to whom the email is being sent */ | |||||
protected $user; | |||||
/** | /** | ||||
* Create a new message instance. | * Create a new message instance. | ||||
* | * | ||||
* @param \App\User $account A user (account) | * @param \App\Wallet $wallet A wallet | ||||
* @param \App\User $user An email recipient | |||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function __construct(User $account) | public function __construct(Wallet $wallet, User $user) | ||||
{ | { | ||||
$this->account = $account; | $this->wallet = $wallet; | ||||
$this->user = $user; | |||||
} | } | ||||
/** | /** | ||||
* Build the message. | * Build the message. | ||||
* | * | ||||
* @return $this | * @return $this | ||||
*/ | */ | ||||
public function build() | public function build() | ||||
{ | { | ||||
$user = $this->account; | $threshold = WalletCheck::threshold($this->wallet, WalletCheck::THRESHOLD_SUSPEND); | ||||
$subject = \trans('mail.negativebalance-subject', ['site' => \config('app.name')]); | $subject = \trans('mail.negativebalancereminder-subject', ['site' => \config('app.name')]); | ||||
$this->view('emails.html.negative_balance') | $this->view('emails.html.negative_balance_reminder') | ||||
->text('emails.plain.negative_balance') | ->text('emails.plain.negative_balance_reminder') | ||||
->subject($subject) | ->subject($subject) | ||||
->with([ | ->with([ | ||||
'site' => \config('app.name'), | 'site' => \config('app.name'), | ||||
'subject' => $subject, | 'subject' => $subject, | ||||
'username' => $user->name(true), | 'username' => $this->user->name(true), | ||||
'supportUrl' => \config('app.support_url'), | 'supportUrl' => \config('app.support_url'), | ||||
'walletUrl' => Utils::serviceUrl('/wallet'), | 'walletUrl' => Utils::serviceUrl('/wallet'), | ||||
'date' => $threshold->toDateString(), | |||||
]); | ]); | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
* Render the mail template with fake data | * Render the mail template with fake data | ||||
* | * | ||||
* @param string $type Output format ('html' or 'text') | * @param string $type Output format ('html' or 'text') | ||||
* | * | ||||
* @return string HTML or Plain Text output | * @return string HTML or Plain Text output | ||||
*/ | */ | ||||
public static function fakeRender(string $type = 'html'): string | public static function fakeRender(string $type = 'html'): string | ||||
{ | { | ||||
$wallet = new Wallet(); | |||||
$user = new User(); | $user = new User(); | ||||
$mail = new self($user); | $mail = new self($wallet, $user); | ||||
return Helper::render($mail, $type); | return Helper::render($mail, $type); | ||||
} | } | ||||
} | } |