Merge pull request #5305 from turbo124/v5-develop

Payment mailer fixes
This commit is contained in:
David Bomba 2021-04-01 08:29:12 +11:00 committed by GitHub
commit 9bf9bc35ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 54 additions and 17 deletions

View File

@ -75,6 +75,10 @@ class SendRemindersCron extends Command
} }
private function webHookExpiredQuotes()
{
}
private function executeWebhooks() private function executeWebhooks()
{ {

View File

@ -51,7 +51,7 @@ class InvoiceItem
public $custom_value4 = ''; public $custom_value4 = '';
public $type_id = '1'; //1 = product, 2 = service, 3 unpaid gateway fee, 4 paid gateway fee, 5 late fee, 6 promo code public $type_id = '1'; //1 = product, 2 = service, 3 unpaid gateway fee, 4 paid gateway fee, 5 late fee, 6 expense
public static $casts = [ public static $casts = [
'type_id' => 'string', 'type_id' => 'string',

View File

@ -77,8 +77,13 @@ class EmailPayment implements ShouldQueue
$email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build(); $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build();
$invitation = null;
if($this->payment->invoices()->exists())
$invitation = $this->payment->invoices()->first()->invitations()->first();
$nmo = new NinjaMailerObject; $nmo = new NinjaMailerObject;
$nmo->mailable = new TemplateEmail($email_builder, $this->contact); $nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation);
$nmo->to_user = $this->contact; $nmo->to_user = $this->contact;
$nmo->settings = $this->settings; $nmo->settings = $this->settings;
$nmo->company = $this->company; $nmo->company = $this->company;

View File

@ -59,7 +59,7 @@ class PaymentNotification implements ShouldQueue
foreach ($payment->company->company_users as $company_user) { foreach ($payment->company->company_users as $company_user) {
$user = $company_user->user; $user = $company_user->user;
$methods = $this->findUserEntityNotificationType($payment, $company_user, ['payment_success_all', 'all_notifications']); $methods = $this->findUserEntityNotificationType($payment, $company_user, ['payment_success', 'payment_success_all', 'all_notifications']);
if (($key = array_search('mail', $methods)) !== false) { if (($key = array_search('mail', $methods)) !== false) {
unset($methods[$key]); unset($methods[$key]);

View File

@ -12,6 +12,7 @@
namespace App\Mail\Admin; namespace App\Mail\Admin;
use App\Models\Invoice; use App\Models\Invoice;
use App\Utils\HtmlEngine;
use App\Utils\Number; use App\Utils\Number;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use stdClass; use stdClass;
@ -84,6 +85,8 @@ class AutoBillingFailureObject
private function getData() private function getData()
{ {
$signature = $this->client->getSetting('email_signature'); $signature = $this->client->getSetting('email_signature');
$html_variables = (new HtmlEngine($this->invoices->first()->invitations->first()))->makeValues();
$signature = str_replace(array_keys($html_variables), array_values($html_variables), $signature);
$data = [ $data = [
'title' => ctrans( 'title' => ctrans(

View File

@ -12,6 +12,7 @@
namespace App\Mail\Admin; namespace App\Mail\Admin;
use App\Models\Invoice; use App\Models\Invoice;
use App\Utils\HtmlEngine;
use App\Utils\Number; use App\Utils\Number;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use stdClass; use stdClass;
@ -88,6 +89,8 @@ class ClientPaymentFailureObject
private function getData() private function getData()
{ {
$signature = $this->client->getSetting('email_signature'); $signature = $this->client->getSetting('email_signature');
$html_variables = (new HtmlEngine($this->invoices->first()->invitations->first()))->makeValues();
$signature = str_replace(array_keys($html_variables), array_values($html_variables), $signature);
$data = [ $data = [
'title' => ctrans( 'title' => ctrans(

View File

@ -11,6 +11,7 @@
namespace App\Mail\Admin; namespace App\Mail\Admin;
use App\Utils\HtmlEngine;
use App\Utils\Number; use App\Utils\Number;
use stdClass; use stdClass;
@ -121,6 +122,10 @@ class EntityFailedSendObject
private function getData() private function getData()
{ {
$settings = $this->entity->client->getMergedSettings(); $settings = $this->entity->client->getMergedSettings();
$signature = $settings->email_signature;
$html_variables = (new HtmlEngine($this->invitation)->makeValues();
$signature = str_replace(array_keys($html_variables), array_values($html_variables), $signature);
return [ return [
'title' => $this->getSubject(), 'title' => $this->getSubject(),
@ -136,7 +141,7 @@ class EntityFailedSendObject
), ),
'url' => $this->invitation->getAdminLink(), 'url' => $this->invitation->getAdminLink(),
'button' => ctrans("texts.view_{$this->entity_type}"), 'button' => ctrans("texts.view_{$this->entity_type}"),
'signature' => $settings->email_signature, 'signature' => $signature,
'logo' => $this->company->present()->logo(), 'logo' => $this->company->present()->logo(),
'settings' => $settings, 'settings' => $settings,
'whitelabel' => $this->company->account->isPaid() ? true : false, 'whitelabel' => $this->company->account->isPaid() ? true : false,

View File

@ -11,6 +11,7 @@
namespace App\Mail\Admin; namespace App\Mail\Admin;
use App\Mail\Engine\PaymentEmailEngine;
use App\Utils\Number; use App\Utils\Number;
use stdClass; use stdClass;
@ -62,6 +63,8 @@ class EntityPaidObject
{ {
$settings = $this->payment->client->getMergedSettings(); $settings = $this->payment->client->getMergedSettings();
$signature = $this->generateSignature($settings);
$amount = Number::formatMoney($this->payment->amount, $this->payment->client); $amount = Number::formatMoney($this->payment->amount, $this->payment->client);
$invoice_texts = ctrans('texts.invoice_number_short'); $invoice_texts = ctrans('texts.invoice_number_short');
@ -85,7 +88,6 @@ class EntityPaidObject
] ]
), ),
'url' => config('ninja.app_url'), 'url' => config('ninja.app_url'),
// 'url' => config('ninja.app_url') . '/payments/' . $this->payment->hashed_id, //because we have no deep linking we cannot use this
'button' => ctrans('texts.view_payment'), 'button' => ctrans('texts.view_payment'),
'signature' => $settings->email_signature, 'signature' => $settings->email_signature,
'logo' => $this->company->present()->logo(), 'logo' => $this->company->present()->logo(),
@ -95,4 +97,13 @@ class EntityPaidObject
return $data; return $data;
} }
private function generateSignature($settings)
{
$html_variables = (new PaymentEmailEngine($this->payment, $this->payment->client->primary_contact()->first()))->makeValues();
$signature = str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature);
return $signature;
}
} }

View File

@ -69,6 +69,7 @@ class BaseEmailEngine implements EngineInterface
{ {
if (! empty($this->variables)) { if (! empty($this->variables)) {
$body = str_replace(array_keys($this->variables), array_values($this->variables), $body); $body = str_replace(array_keys($this->variables), array_values($this->variables), $body);
$body = str_replace(array_keys($this->variables), array_values($this->variables), $body);
} }
$this->body = $body; $this->body = $body;

View File

@ -76,7 +76,7 @@ class PaymentEmailEngine extends BaseEmailEngine
} }
private function makePaymentVariables() public function makePaymentVariables()
{ {
$data = []; $data = [];
@ -132,9 +132,9 @@ class PaymentEmailEngine extends BaseEmailEngine
$data['$client_balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')]; $data['$client_balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
$data['$paid_to_date'] = ['value' => Number::formatMoney($this->client->paid_to_date, $this->client), 'label' => ctrans('texts.paid_to_date')]; $data['$paid_to_date'] = ['value' => Number::formatMoney($this->client->paid_to_date, $this->client), 'label' => ctrans('texts.paid_to_date')];
$data['$contact.full_name'] = ['value' => $this->contact->present()->name(), 'label' => ctrans('texts.name')]; $data['$contact.full_name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : '', 'label' => ctrans('texts.name')];
$data['$contact.email'] = ['value' => $this->contact->email, 'label' => ctrans('texts.email')]; $data['$contact.email'] = ['value' => isset($this->contact) ? $this->contact->email : '', 'label' => ctrans('texts.email')];
$data['$contact.phone'] = ['value' => $this->contact->phone, 'label' => ctrans('texts.phone')]; $data['$contact.phone'] = ['value' => isset($this->contact) ? $this->contact->phone: '', 'label' => ctrans('texts.phone')];
$data['$contact.name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')]; $data['$contact.name'] = ['value' => isset($this->contact) ? $this->contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')];
$data['$contact.first_name'] = ['value' => isset($this->contact) ? $this->contact->first_name : '', 'label' => ctrans('texts.first_name')]; $data['$contact.first_name'] = ['value' => isset($this->contact) ? $this->contact->first_name : '', 'label' => ctrans('texts.first_name')];

View File

@ -53,9 +53,14 @@ class TemplateEmail extends Mailable
$company = $this->client->company; $company = $this->client->company;
$html_variables = (new HtmlEngine($this->invitation))->makeValues(); if($this->invitation)
{
$html_variables = (new HtmlEngine($this->invitation))->makeValues();
$signature = str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature);
}
else
$signature = $settings->email_signature;
//str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature)
$this->from(config('mail.from.address'), $this->company->present()->name()); $this->from(config('mail.from.address'), $this->company->present()->name());
if (strlen($settings->bcc_email) > 1) if (strlen($settings->bcc_email) > 1)
@ -75,7 +80,7 @@ class TemplateEmail extends Mailable
'view_link' => $this->build_email->getViewLink(), 'view_link' => $this->build_email->getViewLink(),
'view_text' => $this->build_email->getViewText(), 'view_text' => $this->build_email->getViewText(),
'title' => '', 'title' => '',
'signature' => str_replace(array_keys($html_variables), array_values($html_variables), $settings->email_signature), 'signature' => $signature,
'settings' => $settings, 'settings' => $settings,
'company' => $company, 'company' => $company,
'whitelabel' => $this->client->user->account->isPaid() ? true : false, 'whitelabel' => $this->client->user->account->isPaid() ? true : false,

View File

@ -29,7 +29,7 @@ class Subscription extends BaseModel
'promo_discount', 'promo_discount',
'is_amount_discount', 'is_amount_discount',
'allow_cancellation', 'allow_cancellation',
'per_set_enabled', 'per_seat_enabled',
'min_seats_limit', 'min_seats_limit',
'max_seats_limit', 'max_seats_limit',
'trial_enabled', 'trial_enabled',

View File

@ -44,6 +44,7 @@ class SubscriptionTransformer extends EntityTransformer
'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id), 'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id),
'company_id' => $this->encodePrimaryKey($subscription->company_id), 'company_id' => $this->encodePrimaryKey($subscription->company_id),
'price' => (float) $subscription->price, 'price' => (float) $subscription->price,
'promo_price' => (float) $subscription->promo_price,
'frequency_id' => (string)$subscription->frequency_id, 'frequency_id' => (string)$subscription->frequency_id,
'auto_bill' => (string)$subscription->auto_bill, 'auto_bill' => (string)$subscription->auto_bill,
'promo_code' => (string)$subscription->promo_code, 'promo_code' => (string)$subscription->promo_code,

View File

@ -38,8 +38,6 @@ trait UserNotifies
array_push($notifiable_methods, 'mail'); array_push($notifiable_methods, 'mail');
} }
nlog($notifiable_methods);
// if(count(array_intersect($required_permissions, $notifications->slack)) >=1) // if(count(array_intersect($required_permissions, $notifications->slack)) >=1)
// array_push($notifiable_methods, 'slack'); // array_push($notifiable_methods, 'slack');
@ -63,10 +61,11 @@ nlog($notifiable_methods);
array_push($required_permissions, 'all_user_notifications'); array_push($required_permissions, 'all_user_notifications');
} }
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) { if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect(['all_user_notifications'], $notifications->email)) >= 1 || count(array_intersect(['all_notifications'],$notifications->email)) >= 1) {
array_push($notifiable_methods, 'mail'); array_push($notifiable_methods, 'mail');
} }
return $notifiable_methods; return $notifiable_methods;
} }