Changeset View
Changeset View
Standalone View
Standalone View
src/app/Jobs/PaymentEmail.php
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | class PaymentEmail implements ShouldQueue | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$wallet = $this->payment->wallet; | $wallet = $this->payment->wallet; | ||||
if (empty($this->controller)) { | if (empty($this->controller)) { | ||||
$this->controller = $wallet->owner; | $this->controller = $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; | |||||
} | } | ||||
if ($this->payment->status == PaymentProvider::STATUS_PAID) { | if ($this->payment->status == PaymentProvider::STATUS_PAID) { | ||||
$mail = new \App\Mail\PaymentSuccess($this->payment, $this->controller); | $mail = new \App\Mail\PaymentSuccess($this->payment, $this->controller); | ||||
$label = "Success"; | |||||
} elseif ( | } elseif ( | ||||
$this->payment->status == PaymentProvider::STATUS_EXPIRED | $this->payment->status == PaymentProvider::STATUS_EXPIRED | ||||
|| $this->payment->status == PaymentProvider::STATUS_FAILED | || $this->payment->status == PaymentProvider::STATUS_FAILED | ||||
) { | ) { | ||||
$mail = new \App\Mail\PaymentFailure($this->payment, $this->controller); | $mail = new \App\Mail\PaymentFailure($this->payment, $this->controller); | ||||
$label = "Failure"; | |||||
} else { | } else { | ||||
return; | return; | ||||
} | } | ||||
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( | |||||
"[Payment] %s mail sent for %s (%s)", | |||||
$label, | |||||
$wallet->id, | |||||
empty($cc) ? $to : implode(', ', array_merge([$to], $cc)) | |||||
); | |||||
\Log::info($msg); | |||||
} catch (\Exception $e) { | |||||
$msg = sprintf( | |||||
"[Payment] Failed to send mail for wallet %s (%s): %s", | |||||
$wallet->id, | |||||
empty($cc) ? $to : implode(', ', array_merge([$to], $cc)), | |||||
$e->getMessage() | |||||
); | |||||
\Log::error($msg); | |||||
throw $e; | |||||
} | |||||
} | |||||
/* | /* | ||||
// Send the email to all wallet controllers too | // Send the email to all wallet controllers too | ||||
if ($wallet->owner->id == $this->controller->id) { | if ($wallet->owner->id == $this->controller->id) { | ||||
$this->wallet->controllers->each(function ($controller) { | $this->wallet->controllers->each(function ($controller) { | ||||
self::dispatch($this->payment, $controller); | self::dispatch($this->payment, $controller); | ||||
} | } | ||||
}); | }); | ||||
*/ | */ | ||||
} | } | ||||
} | } |