diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index 7a291470e2c6..a84a034ddd78 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -111,7 +111,7 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue ->send( new TemplateEmail( $this->email_entity_builder, - $this->invitation->contact->client + $this->invitation->contact ) ); } catch (\Exception $e) { diff --git a/app/Jobs/Mail/ClientPaymentFailureMailer.php b/app/Jobs/Mail/ClientPaymentFailureMailer.php new file mode 100644 index 000000000000..7db3617995cd --- /dev/null +++ b/app/Jobs/Mail/ClientPaymentFailureMailer.php @@ -0,0 +1,111 @@ +company = $company; + + $this->error = $error; + + $this->client = $client; + + $this->payment_hash = $payment_hash; + + $this->company = $company; + + $this->settings = $client->getMergedSettings(); + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + + /*If we are migrating data we don't want to fire these notification*/ + if ($this->company->is_disabled) { + return true; + } + + //Set DB + MultiDB::setDb($this->company->db); + + //if we need to set an email driver do it now + $this->setMailDriver(); + + $this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); + + $this->invoices->first()->invitations->each(function ($invitation) { + + if ($invitation->contact->send_email && $invitation->contact->email) { + + $mail_obj = (new ClientPaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build(); + $mail_obj->from = [config('mail.from.address'), config('mail.from.name')]; + + //send email + try { + Mail::to($invitation->contact->email) + ->send(new EntityNotificationMailer($mail_obj)); + } catch (\Exception $e) { + + $this->logMailError($e->getMessage(), $this->client); + } + + } + + }); + + + } +} diff --git a/app/Jobs/Payment/EmailPayment.php b/app/Jobs/Payment/EmailPayment.php index 32d9c36395c2..2530636ee993 100644 --- a/app/Jobs/Payment/EmailPayment.php +++ b/app/Jobs/Payment/EmailPayment.php @@ -80,7 +80,7 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue try { $mail = Mail::to($this->contact->email, $this->contact->present()->name()); - $mail->send(new TemplateEmail($email_builder, $this->contact->client)); + $mail->send(new TemplateEmail($email_builder, $this->contact)); } catch (\Exception $e) { nlog("mailing failed with message " . $e->getMessage()); event(new PaymentWasEmailedAndFailed($this->payment, $this->company, Mail::failures(), Ninja::eventVars())); diff --git a/app/Mail/Admin/ClientPaymentFailureObject.php b/app/Mail/Admin/ClientPaymentFailureObject.php new file mode 100644 index 000000000000..0135a2dad1ab --- /dev/null +++ b/app/Mail/Admin/ClientPaymentFailureObject.php @@ -0,0 +1,114 @@ +client = $client; + + $this->error = $error; + + $this->company = $company; + + $this->payment_hash = $payment_hash; + + $this->company = $company; + + } + + public function build() + { + + $this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); + + $mail_obj = new stdClass; + $mail_obj->amount = $this->getAmount(); + $mail_obj->subject = $this->getSubject(); + $mail_obj->data = $this->getData(); + $mail_obj->markdown = 'email.admin.generic'; + $mail_obj->tag = $this->company->company_key; + + return $mail_obj; + } + + private function getAmount() + { + + return array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; + + } + + private function getSubject() + { + + return + ctrans( + 'texts.notification_invoice_payment_failed_subject', + ['invoice' => $this->client->present()->name()] + ); + + } + + private function getData() + { + $signature = $this->client->getSetting('email_signature'); + + $data = [ + 'title' => ctrans( + 'texts.notification_invoice_payment_failed_subject', + [ + 'invoice' => $this->invoices->first()->number + ] + ), + 'greeting' => ctrans('texts.email_salutation', ['name' => $this->client->present()->name]), + 'message' => $this->error, + 'signature' => $signature, + 'logo' => $this->company->present()->logo(), + 'settings' => $this->client->getMergedSettings(), + 'whitelabel' => $this->company->account->isPaid() ? true : false, + 'url' => route('client.login'), + 'button' => ctrans('texts.login'), + 'additional_info' => false + ]; + + return $data; + } + + +} diff --git a/app/Mail/Admin/PaymentFailureObject.php b/app/Mail/Admin/PaymentFailureObject.php index 107437d069ec..3c199f8e491e 100644 --- a/app/Mail/Admin/PaymentFailureObject.php +++ b/app/Mail/Admin/PaymentFailureObject.php @@ -18,7 +18,7 @@ use stdClass; class PaymentFailureObject { - use MakesHash; + use MakesHash; public $client; diff --git a/app/Mail/DownloadInvoices.php b/app/Mail/DownloadInvoices.php index db96f489bd94..8ac8f0db97aa 100644 --- a/app/Mail/DownloadInvoices.php +++ b/app/Mail/DownloadInvoices.php @@ -31,14 +31,14 @@ class DownloadInvoices extends Mailable public function build() { return $this->from(config('mail.from.address'), config('mail.from.name')) - - ->subject(ctrans('texts.download_files')) - ->markdown( - 'email.admin.download_files', - [ - 'url' => $this->file_path, - 'logo' => $this->company->present()->logo, - ] - ); + ->subject(ctrans('texts.download_files')) + ->markdown( + 'email.admin.download_files', + [ + 'url' => $this->file_path, + 'logo' => $this->company->present()->logo, + 'whitelabel' => $this->company->account->isPaid() ? true : false, + ] + ); } } diff --git a/app/Mail/MigrationCompleted.php b/app/Mail/MigrationCompleted.php index 54f158ca9af6..53a5d7f786be 100644 --- a/app/Mail/MigrationCompleted.php +++ b/app/Mail/MigrationCompleted.php @@ -32,7 +32,8 @@ class MigrationCompleted extends Mailable { $data['settings'] = $this->company->settings; $data['company'] = $this->company; - + $data['whitelabel'] = $this->company->account->isPaid() ? true : false; + return $this->from(config('mail.from.address'), config('mail.from.name')) ->view('email.import.completed', $data) ->attach($this->company->invoices->first()->pdf_file_path()); diff --git a/app/Mail/MigrationFailed.php b/app/Mail/MigrationFailed.php index b37e20ce7254..438caf049be4 100644 --- a/app/Mail/MigrationFailed.php +++ b/app/Mail/MigrationFailed.php @@ -32,7 +32,6 @@ class MigrationFailed extends Mailable public function build() { return $this->from(config('mail.from.address'), config('mail.from.name')) - ->view('email.migration.failed'); } } diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 42d9a5273c1b..9b29482186e5 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -25,11 +25,15 @@ class TemplateEmail extends Mailable private $client; - public function __construct($build_email, Client $client) + private $contact; + + public function __construct($build_email, ClientContact $contact) { $this->build_email = $build_email; - $this->client = $client; + $this->contact = $contact; + + $this->client = $contact->client; } /** @@ -64,12 +68,12 @@ class TemplateEmail extends Mailable 'settings' => $settings, ]) ->view($template_name, [ + 'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]), 'body' => $this->build_email->getBody(), 'footer' => $this->build_email->getFooter(), 'view_link' => $this->build_email->getViewLink(), 'view_text' => $this->build_email->getViewText(), 'title' => '', - // 'title' => $this->build_email->getSubject(), 'signature' => $settings->email_signature, 'settings' => $settings, 'company' => $company, diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 116676edd1bd..3f4169ae6dfc 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -17,6 +17,7 @@ use App\Exceptions\PaymentFailed; use App\Factory\PaymentFactory; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Jobs\Mail\AutoBillingFailureMailer; +use App\Jobs\Mail\ClientPaymentFailureMailer; use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\Client; @@ -353,6 +354,13 @@ class BaseDriver extends AbstractPaymentDriver $this->payment_hash ); + ClientPaymentFailureMailer::dispatch( + $gateway->client, + $error, + $gateway->client->company, + $this->payment_hash + ); + SystemLogger::dispatch( $gateway->payment_hash, SystemLog::CATEGORY_GATEWAY_RESPONSE, @@ -364,12 +372,6 @@ class BaseDriver extends AbstractPaymentDriver throw new PaymentFailed($error, $e->getCode()); } - public function tokenBillingFailed($gateway, $e) - { - - - } - /** * Wrapper method for checking if resource is good. * diff --git a/resources/views/email/admin/download_files.blade.php b/resources/views/email/admin/download_files.blade.php index b1c86d2b10b0..d1f58b786d25 100644 --- a/resources/views/email/admin/download_files.blade.php +++ b/resources/views/email/admin/download_files.blade.php @@ -16,10 +16,11 @@ InvoiceNinja (contact@invoiceninja.com) @endslot -@slot('footer') - @component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja']) - For any info, please visit InvoiceNinja. - @endcomponent -@endslot - +@if(!$whitelabel) + @slot('footer') + @component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja']) + For any info, please visit InvoiceNinja. + @endcomponent + @endslot +@endif @endcomponent \ No newline at end of file diff --git a/resources/views/email/admin/generic.blade.php b/resources/views/email/admin/generic.blade.php index 99c527b46dc5..24c56a960aa4 100644 --- a/resources/views/email/admin/generic.blade.php +++ b/resources/views/email/admin/generic.blade.php @@ -1,10 +1,13 @@ @component('email.template.master', ['design' => 'light', 'settings' => $settings]) - @slot('header') @include('email.components.header', ['logo' => $logo]) @endslot + @if($greeting) +

{{ $greeting }}

+ @endif +

{{ $title }}

{{ $message }}

@@ -23,9 +26,11 @@ {{ $signature }} @endslot - @slot('footer') - @component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja']) - For any info, please visit InvoiceNinja. - @endcomponent - @endslot + @if(!$whitelabel) + @slot('footer') + @component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja']) + For any info, please visit InvoiceNinja. + @endcomponent + @endslot + @endif @endcomponent diff --git a/resources/views/email/import/completed.blade.php b/resources/views/email/import/completed.blade.php index 1eb858798fa9..91c63b136012 100644 --- a/resources/views/email/import/completed.blade.php +++ b/resources/views/email/import/completed.blade.php @@ -76,4 +76,12 @@ {{ ctrans('texts.account_login')}}

{{ ctrans('texts.email_signature')}}
{{ ctrans('texts.email_from') }}

-@endcomponent + +@if(!$whitelabel) + @slot('footer') + @component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja']) + For any info, please visit InvoiceNinja. + @endcomponent + @endslot +@endif +@endcomponent \ No newline at end of file