diff --git a/app/Filters/ClientFilters.php b/app/Filters/ClientFilters.php index ffc3e4fd7717..f1b9f1303d80 100644 --- a/app/Filters/ClientFilters.php +++ b/app/Filters/ClientFilters.php @@ -41,7 +41,7 @@ class ClientFilters extends QueryFilters */ public function balance(string $balance = ''): Builder { - if (strlen($balance) == 0) { + if (strlen($balance) == 0 || count(explode(":", $balance)) < 2) { return $this->builder; } diff --git a/app/Http/Controllers/MailgunWebhookController.php b/app/Http/Controllers/MailgunWebhookController.php index 0585ebc02d97..88985e136158 100644 --- a/app/Http/Controllers/MailgunWebhookController.php +++ b/app/Http/Controllers/MailgunWebhookController.php @@ -35,7 +35,7 @@ class MailgunWebhookController extends BaseController } if(\hash_equals(\hash_hmac('sha256', $input['signature']['timestamp'] . $input['signature']['token'], config('services.mailgun.webhook_signing_key')), $input['signature']['signature'])) { - ProcessMailgunWebhook::dispatch($request->all())->delay(10); + ProcessMailgunWebhook::dispatch($request->all())->delay(rand(2,10)); } return response()->json(['message' => 'Success.'], 200); diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 0326f34effbe..1124fec9c812 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -297,12 +297,13 @@ class NinjaMailerJob implements ShouldQueue $t->replace(Ninja::transformTranslations($this->nmo->settings)); /** Force free/trials onto specific mail driver */ - // if(Ninja::isHosted() && !$this->company->account->isPaid()) - // { - // $this->mailer = 'mailgun'; - // $this->setHostedMailgunMailer(); - // return $this; - // } + + if($this->mailer == 'default' && $this->company->account->isNewHostedAccount()) { + $this->mailer = 'mailgun'; + $this->setHostedMailgunMailer(); + return $this; + } + if (Ninja::isHosted() && $this->company->account->isPaid() && $this->nmo->settings->email_sending_method == 'default') { //check if outlook. @@ -391,7 +392,7 @@ class NinjaMailerJob implements ShouldQueue $smtp_username = $company->smtp_username ?? ''; $smtp_password = $company->smtp_password ?? ''; $smtp_encryption = $company->smtp_encryption ?? 'tls'; - $smtp_local_domain = strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null; + $smtp_local_domain = strlen($company->smtp_local_domain ?? '') > 2 ? $company->smtp_local_domain : null; $smtp_verify_peer = $company->smtp_verify_peer ?? true; if(strlen($smtp_host) <= 1 || diff --git a/app/Jobs/Mailgun/ProcessMailgunWebhook.php b/app/Jobs/Mailgun/ProcessMailgunWebhook.php index 73d32f39e9f7..69be326cd288 100644 --- a/app/Jobs/Mailgun/ProcessMailgunWebhook.php +++ b/app/Jobs/Mailgun/ProcessMailgunWebhook.php @@ -181,7 +181,7 @@ class ProcessMailgunWebhook implements ShouldQueue $sl = $this->getSystemLog($this->request['MessageID']); /** Prevents Gmail tracking from firing inappropriately */ - if($this->request['signature']['timestamp'] < $sl->log['signature']['timestamp'] + 3) { + if(!$sl || $this->request['signature']['timestamp'] < $sl->log['signature']['timestamp'] + 3) { return; } diff --git a/app/Models/Account.php b/app/Models/Account.php index 9ce846a367de..001b05100dcc 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -364,16 +364,19 @@ class Account extends BaseModel return $this->isProClient() && $this->isPaid(); } + public function isNewHostedAccount() + { + return Ninja::isHosted() && Carbon::createFromTimestamp($this->created_at)->diffInWeeks() <= 2; + } + public function isTrial(): bool { if (!Ninja::isNinja()) { return false; } - //@27-01-2024 - updates for logic around trials return !$this->plan_paid && $this->trial_started && Carbon::parse($this->trial_started)->addDays(14)->gte(now()->subHours(12)); - // $plan_details = $this->getPlanDetails(); - // return $plan_details && $plan_details['trial']; + } public function startTrial($plan): void diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 04492da8fa77..77edc44542eb 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -526,11 +526,11 @@ class Email implements ShouldQueue { /** Force free/trials onto specific mail driver */ - // if(Ninja::isHosted() && !$this->company->account->isPaid()) { - // $this->mailer = 'mailgun'; - // $this->setHostedMailgunMailer(); - // return $this; - // } + if($this->mailer == 'default' && $this->company->account->isNewHostedAccount()) { + $this->mailer = 'mailgun'; + $this->setHostedMailgunMailer(); + return $this; + } if (Ninja::isHosted() && $this->company->account->isPaid() && $this->email_object->settings->email_sending_method == 'default') { @@ -619,7 +619,7 @@ class Email implements ShouldQueue $smtp_username = $company->smtp_username ?? ''; $smtp_password = $company->smtp_password ?? ''; $smtp_encryption = $company->smtp_encryption ?? 'tls'; - $smtp_local_domain = strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null; + $smtp_local_domain = strlen($company->smtp_local_domain ?? '') > 2 ? $company->smtp_local_domain : null; $smtp_verify_peer = $company->smtp_verify_peer ?? true; if(strlen($smtp_host) <= 1 ||