From a5fc80f40828d59e6f62e996e9873b2a9ee3227b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 23 Mar 2023 13:03:37 +1100 Subject: [PATCH] Dynamically apply the mailgun endpoint --- app/DataMapper/CompanySettings.php | 3 +++ app/Jobs/Mail/NinjaMailerJob.php | 8 +++++++- app/Providers/AppServiceProvider.php | 5 ++--- app/Services/Email/Email.php | 9 ++++++++- openapi/api-docs.yaml | 7 ++----- openapi/components/parameters.yaml | 2 +- openapi/paths/clients.yaml | 2 +- openapi/paths/recurring_invoices.yaml | 3 --- 8 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 1e64f0ec1c10..37eea6e463e0 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -449,6 +449,8 @@ class CompanySettings extends BaseSettings public $mailgun_domain = ''; + public $mailgun_endpoint = 'api.mailgun.net'; //api.eu.mailgun.net + public $auto_bill_standard_invoices = false; public $email_alignment = 'center'; // center , left, right @@ -476,6 +478,7 @@ class CompanySettings extends BaseSettings public $sync_invoice_quote_columns = true; public static $casts = [ + 'mailgun_endpoint' => 'string', // 'client_initiated_payments_recurring'=> 'bool', 'client_initiated_payments' => 'bool', 'client_initiated_payments_minimum' => 'float', diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 871595f1c0ef..72ce0a95d6d1 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -128,7 +128,13 @@ class NinjaMailerJob implements ShouldQueue } if ($this->client_mailgun_secret) { - $mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain); + + $endpoint = 'api.mailgun.net'; + + if(strpos($this->client_mailgun_secret, 'key') !== false) + $endpoint = 'api.eu.mailgun.net'; + + $mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain, $endpoint); } $mailer diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ed8b2a643c0c..8e2071a6ff3e 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -101,12 +101,12 @@ class AppServiceProvider extends ServiceProvider return $this; }); - Mailer::macro('mailgun_config', function (string $secret, string $domain) { + Mailer::macro('mailgun_config', function (string $secret, string $domain, string $endpoint = 'api.mailgun.net') { Mailer::setSymfonyTransport(app('mail.manager')->createSymfonyTransport([ 'transport' => 'mailgun', 'secret' => $secret, 'domain' => $domain, - 'endpoint' => config('services.mailgun.endpoint'), + 'endpoint' => $endpoint, 'scheme' => config('services.mailgun.scheme'), ])); @@ -114,7 +114,6 @@ class AppServiceProvider extends ServiceProvider }); /* Extension for custom mailers */ - /* Convenience helper for testing s*/ ParallelTesting::setUpTestDatabase(function ($database, $token) { diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index 7c8d7f072aee..d47d3c5f6b16 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -233,7 +233,14 @@ class Email implements ShouldQueue } if ($this->client_mailgun_secret) { - $mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain); + + $endpoint = 'api.mailgun.net'; + + if (strpos($this->client_mailgun_secret, 'key') !== false) { + $endpoint = 'api.eu.mailgun.net'; + } + + $mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain, $endpoint); } /* Attempt the send! */ diff --git a/openapi/api-docs.yaml b/openapi/api-docs.yaml index 7531e69a90ce..37e00cfc09fd 100644 --- a/openapi/api-docs.yaml +++ b/openapi/api-docs.yaml @@ -8776,7 +8776,7 @@ paths: multipart/form-data: schema: type: object - properties: + items: _method: type: string example: POST @@ -12386,10 +12386,7 @@ paths: Archives the recurring invoice. The recurring invoice will not fire in this state. - `delete` Deletes a recurring invoice. - - required: true ids: - required: true type: array items: description: "Array of hashed IDs to be bulk 'actioned - ['D2J234DFA','D2J234DFA','D2J234DFA']" @@ -13015,7 +13012,7 @@ components: name: include in: query description: Include child relations of the BankIntegration object. Format is comma separated. - require: false + required: false schema: type: string examples: diff --git a/openapi/components/parameters.yaml b/openapi/components/parameters.yaml index 2ec66fbb7dc9..c5de428986f5 100644 --- a/openapi/components/parameters.yaml +++ b/openapi/components/parameters.yaml @@ -36,7 +36,7 @@ name: include in: query description: Include child relations of the BankIntegration object. Format is comma separated. - require: false + required: false schema: type: string examples: diff --git a/openapi/paths/clients.yaml b/openapi/paths/clients.yaml index ba4fb19277a4..7bc0bf95b8d8 100644 --- a/openapi/paths/clients.yaml +++ b/openapi/paths/clients.yaml @@ -390,7 +390,7 @@ multipart/form-data: schema: type: object - properties: + items: _method: type: string example: POST diff --git a/openapi/paths/recurring_invoices.yaml b/openapi/paths/recurring_invoices.yaml index bb3a30f28fab..5fa973116856 100644 --- a/openapi/paths/recurring_invoices.yaml +++ b/openapi/paths/recurring_invoices.yaml @@ -333,10 +333,7 @@ Archives the recurring invoice. The recurring invoice will not fire in this state. - `delete` Deletes a recurring invoice. - - required: true ids: - required: true type: array items: description: "Array of hashed IDs to be bulk 'actioned - ['D2J234DFA','D2J234DFA','D2J234DFA']"