Files
timebank-cc-public/app/Mail/ReversalIssued.php
T

76 lines
2.7 KiB
PHP

<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class ReversalIssued extends Mailable implements ShouldQueue
{
use Queueable;
use SerializesModels;
protected $profile;
protected $bank;
protected $amount;
protected $originalTransactionId;
protected $description;
protected $buttonUrl;
public $locale;
public function __construct($profile, $bank, int $amount, int $originalTransactionId, string $description)
{
$this->profile = $profile;
$this->bank = $bank;
$this->amount = $amount;
$this->originalTransactionId = $originalTransactionId;
$this->description = $description;
$this->locale = $profile->lang_preference ?? config('app.fallback_locale');
if (empty($this->locale)) {
$this->locale = config('app.fallback_locale');
}
$profileClass = get_class($profile);
$transactionsPath = LaravelLocalization::getURLFromRouteNameTranslated($this->locale, 'routes.transactions');
$transactionsUrl = url($transactionsPath);
if ($profileClass === 'App\\Models\\User') {
$this->buttonUrl = LaravelLocalization::localizeURL(
route('user.direct-login', ['userId' => $profile->id, 'intended' => $transactionsUrl, 'name' => $profile->name]),
$this->locale
);
} elseif ($profileClass === 'App\\Models\\Organization') {
$this->buttonUrl = LaravelLocalization::localizeURL(
route('organization.direct-login', ['organizationId' => $profile->id, 'intended' => $transactionsUrl]),
$this->locale
);
} else {
$this->buttonUrl = LaravelLocalization::localizeURL(route('login'), $this->locale);
}
}
public function build()
{
app()->setLocale($this->locale);
$subject = trans('messages.reversal_issued_subject', [], $this->locale);
return $this
->from(timebank_config('mail.support.email'), timebank_config('mail.support.name'))
->subject($subject)
->view('emails.reversal-issued.reversal-issued')
->with([
'profile' => $this->profile,
'bank' => $this->bank,
'amountFormatted' => tbFormat($this->amount),
'originalTransactionId' => $this->originalTransactionId,
'description' => $this->description,
'buttonUrl' => $this->buttonUrl,
]);
}
}