Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/PaymentMandateDisabledEmail.php
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | class PaymentMandateDisabledEmail implements ShouldQueue | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
if (empty($this->controller)) { | if (empty($this->controller)) { | ||||
$this->controller = $this->wallet->owner; | $this->controller = $this->wallet->owner; | ||||
} | } | ||||
$ext_email = $this->controller->getSetting('external_email'); | if (empty($this->controller)) { | ||||
$cc = []; | return; | ||||
if ($ext_email && $ext_email != $this->controller->email) { | |||||
$cc[] = $ext_email; | |||||
} | } | ||||
$mail = new PaymentMandateDisabled($this->wallet, $this->controller); | $mail = new PaymentMandateDisabled($this->wallet, $this->controller); | ||||
Mail::to($this->controller->email)->cc($cc)->send($mail); | list($to, $cc) = \App\Mail\Helper::userEmails($this->controller); | ||||
if (!empty($to)) { | |||||
try { | |||||
Mail::to($to)->cc($cc)->send($mail); | |||||
$msg = sprintf( | |||||
"[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); | ||||
} | } | ||||
}); | }); | ||||
*/ | */ | ||||
} | } | ||||
} | } |