payment_hash = $payment_hash; $this->client = $client; $this->error = $error; $this->company = $company; } /** * Execute the job. * * @return void */ public function handle() { //Set DB MultiDB::setDb($this->company->db); App::setLocale($this->client->locale()); $settings = $this->client->getMergedSettings(); $amount = 0; $invoice = false; if($this->payment_hash){ $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); } //iterate through company_users $this->company->company_users->each(function ($company_user) use($amount, $settings, $invoice){ $methods = $this->findUserEntityNotificationType($invoice ?: $this->client, $company_user, ['payment_failure_user', 'payment_failure_all', 'payment_failure', 'all_notifications']); //if mail is a method type -fire mail!! if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); $mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $amount, $this->payment_hash))->build(); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer($mail_obj); $nmo->company = $this->company; $nmo->to_user = $company_user->user; $nmo->settings = $settings; NinjaMailerJob::dispatch($nmo); } }); //add client payment failures here. // if($contact = $this->client->primary_contact()->first()) { $mail_obj = (new ClientPaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build(); $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer($mail_obj); $nmo->company = $this->company; $nmo->to_user = $contact; $nmo->settings = $settings; NinjaMailerJob::dispatch($nmo); } } }