Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/PaymentMandateDisabledEmail.php
<?php | <?php | ||||
namespace App\Jobs; | namespace App\Jobs; | ||||
use App\Mail\PaymentMandateDisabled; | use App\Mail\PaymentMandateDisabled; | ||||
use App\User; | use App\User; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Bus\Queueable; | use Illuminate\Bus\Queueable; | ||||
use Illuminate\Contracts\Queue\ShouldQueue; | use Illuminate\Contracts\Queue\ShouldQueue; | ||||
use Illuminate\Foundation\Bus\Dispatchable; | use Illuminate\Foundation\Bus\Dispatchable; | ||||
use Illuminate\Support\Facades\Mail; | |||||
use Illuminate\Queue\SerializesModels; | use Illuminate\Queue\SerializesModels; | ||||
use Illuminate\Queue\InteractsWithQueue; | use Illuminate\Queue\InteractsWithQueue; | ||||
class PaymentMandateDisabledEmail implements ShouldQueue | class PaymentMandateDisabledEmail implements ShouldQueue | ||||
{ | { | ||||
use Dispatchable; | use Dispatchable; | ||||
use InteractsWithQueue; | use InteractsWithQueue; | ||||
use Queueable; | use Queueable; | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | public function handle() | ||||
return; | return; | ||||
} | } | ||||
$mail = new PaymentMandateDisabled($this->wallet, $this->controller); | $mail = new PaymentMandateDisabled($this->wallet, $this->controller); | ||||
list($to, $cc) = \App\Mail\Helper::userEmails($this->controller); | list($to, $cc) = \App\Mail\Helper::userEmails($this->controller); | ||||
if (!empty($to)) { | if (!empty($to)) { | ||||
try { | $params = [ | ||||
Mail::to($to)->cc($cc)->send($mail); | 'to' => $to, | ||||
'cc' => $cc, | |||||
'add' => " for {$this->wallet->id}", | |||||
]; | |||||
$msg = sprintf( | \App\Mail\Helper::sendMail($mail, $this->controller->tenant_id, $params); | ||||
"[PaymentMandateDisabled] Sent mail for %s (%s)", | |||||
$this->wallet->id, | |||||
empty($cc) ? $to : implode(', ', array_merge([$to], $cc)) | |||||
); | |||||
\Log::info($msg); | |||||
} catch (\Exception $e) { | |||||
$msg = sprintf( | |||||
"[PaymentMandateDisabled] Failed to send mail for wallet %s (%s): %s", | |||||
$this->wallet->id, | |||||
empty($cc) ? $to : implode(', ', array_merge([$to], $cc)), | |||||
$e->getMessage() | |||||
); | |||||
\Log::error($msg); | |||||
throw $e; | |||||
} | |||||
} | } | ||||
/* | /* | ||||
// Send the email to all controllers too | // Send the email to all controllers too | ||||
if ($this->controller->id == $this->wallet->owner->id) { | if ($this->controller->id == $this->wallet->owner->id) { | ||||
$this->wallet->controllers->each(function ($controller) { | $this->wallet->controllers->each(function ($controller) { | ||||
self::dispatch($this->wallet, $controller); | self::dispatch($this->wallet, $controller); | ||||
} | } | ||||
}); | }); | ||||
*/ | */ | ||||
} | } | ||||
} | } |