diff --git a/app/Helpers/Mail/GmailTransport.php b/app/Helpers/Mail/GmailTransport.php new file mode 100644 index 000000000000..5d52ddc07103 --- /dev/null +++ b/app/Helpers/Mail/GmailTransport.php @@ -0,0 +1,67 @@ +gmail = $gmail; + $this->token = $token + } + + + public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) + { + $this->beforeSendPerformed($message); + + $this->gmail->using($this->token); + $this->gmail->to($message->getTo()); + $this->gmail->from($message->getFrom()); + $this->gmail->subject($message->getSubject()); + //$this->gmail->message($message->getBody()); + $this->gmail->message($message->toString()); + $this->gmail->cc($message->getCc()); + $this->gmail->bcc($message->getBcc()); + + $this->gmail->send(); + + $this->sendPerformed($message); + + return $this->numberOfRecipients($message); + } diff --git a/app/Helpers/Mail/GmailTransportConfig.php b/app/Helpers/Mail/GmailTransportConfig.php index 81fb4ed4a2f6..7ee046b9cccc 100644 --- a/app/Helpers/Mail/GmailTransportConfig.php +++ b/app/Helpers/Mail/GmailTransportConfig.php @@ -11,62 +11,34 @@ namespace App\Helpers\Mail; +use App\Libraries\MultiDB; use App\Models\User; +use App\Providers\MailServiceProvider; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Mail; - /** * GmailTransportConfig */ class GmailTransportConfig { - public function test() + public function test() { - -// $transport = (new Swift_SmtpTransport('smtp.googlemail.com', 465, 'ssl')) -// ->setUsername('YOUR_GMAIL_USERNAME') -// ->setPassword('YOUR_GMAIL_PASSWORD') -// ; -// -// $transport = \Swift_SmtpTransport::newInstance($host, $port); - // set encryption - // if (isset($encryption)) $transport->setEncryption($encryption); - // // set username and password - // if (isset($username)) - // { - // $transport->setUsername($username); - // $transport->setPassword($password); - // } - -// -// -// // Create the Transport - - -// // Create the Mailer using your created Transport -// $mailer = new Swift_Mailer($transport); - /********************* We may need to fetch a new token on behalf of the client ******************************/ + $query = [ + 'email' => 'david@invoiceninja.com', + ]; - $query = [ - 'email' => 'david@invoicninja.com', - 'oauth_provider_id'=>'google' - ]; + $user = MultiDB::hasUser($query); - $user = MultiDB::hasUser($query); - - $transport = (new Swift_SmtpTransport('smtp.gmail.com', 587, 'tls')) - ->setAuthMode('XOAUTH2') - ->setUsername($user->email) - ->setPassword($user->oauth_user_token); - - // set new swift mailer - Mail::setSwiftMailer(new \Swift_Mailer($transport)); + Config::set('mail.driver', 'gmail'); + Config::set('services.gmail.token', $user->oauth_user_token); + (new MailServiceProvider(app()))->register(); - Mail::to('david@romulus.com.au') - ->send('test'); + Mail::to('david@romulus.com.au') + ->send(new SupportMessageSent('a cool message')); } @@ -81,3 +53,4 @@ class GmailTransportConfig + diff --git a/app/Helpers/Mail/GmailTransportManager.php b/app/Helpers/Mail/GmailTransportManager.php new file mode 100644 index 000000000000..1cdebe70f1c6 --- /dev/null +++ b/app/Helpers/Mail/GmailTransportManager.php @@ -0,0 +1,18 @@ +app['config']->get('services.gmail.token', []); + + return new GmailTransport(Mail $mail, string $token); + } + +} \ No newline at end of file diff --git a/app/Providers/MailServiceProvider.php b/app/Providers/MailServiceProvider.php new file mode 100644 index 000000000000..0dde7863d433 --- /dev/null +++ b/app/Providers/MailServiceProvider.php @@ -0,0 +1,17 @@ +app->singleton('swift.transport', function ($app) { + return new GmailTransportManager($app); + }); + } + +} \ No newline at end of file diff --git a/composer.json b/composer.json index 9de5e01fa134..7acdcdd4b691 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "php": ">=7.3", "anahkiasen/former": "^4.2", "asgrim/ofxparser": "^1.2", + "dacastro4/laravel-gmail": "^3.2", "davejamesmiller/laravel-breadcrumbs": "5.x", "fideloper/proxy": "^4.0", "google/apiclient": "^2.0", diff --git a/config/app.php b/config/app.php index e77cb438b142..407b86b8a0d7 100644 --- a/config/app.php +++ b/config/app.php @@ -148,7 +148,8 @@ return [ Illuminate\Filesystem\FilesystemServiceProvider::class, Illuminate\Foundation\Providers\FoundationServiceProvider::class, Illuminate\Hashing\HashServiceProvider::class, - Illuminate\Mail\MailServiceProvider::class, + App\Providers\MailServiceProvider::class, + //Illuminate\Mail\MailServiceProvider::class, Illuminate\Notifications\NotificationServiceProvider::class, Illuminate\Pagination\PaginationServiceProvider::class, Illuminate\Pipeline\PipelineServiceProvider::class, diff --git a/config/mail.php b/config/mail.php index bb92224c59db..124c11687888 100644 --- a/config/mail.php +++ b/config/mail.php @@ -12,7 +12,7 @@ return [ | your application here. By default, Laravel is setup for SMTP mail. | | Supported: "smtp", "sendmail", "mailgun", "mandrill", "ses", - | "sparkpost", "log", "array" + | "sparkpost", "log", "array", "gmail" | */ diff --git a/config/ninja.php b/config/ninja.php index 1d5830a5c9ec..e749a77460cb 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -60,7 +60,6 @@ return [ 'paypal' => env('PAYPAL_KEYS', ''), 'travis' => env('TRAVIS', false), ], - 'contact' => [ 'email' => env('MAIL_FROM_ADDRESS'), 'from_name' => env('MAIL_FROM_NAME'), diff --git a/config/services.php b/config/services.php index 284df60d78cd..06204558c37d 100644 --- a/config/services.php +++ b/config/services.php @@ -33,7 +33,9 @@ return [ 'sparkpost' => [ 'secret' => env('SPARKPOST_SECRET'), ], - + 'gmail' => [ + 'token' => '', + ], 'postmark' => env('POSTMARK_API_TOKEN', ''), 'postmark_ticket' => env('POSTMARK_API_TICKET_TOKEN'), 'postmark_ticket_2' => env('POSTMARK_API_TICKET_TOKEN_2'), diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 953fc0404499..36df17e6012e 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -511,6 +511,9 @@ class CreateUsersTable extends Migration $t->string('tax_name3')->nullable(); $t->decimal('tax_rate3', 13, 3)->default(0); + $t->decimal('total_taxes', 13, 3)->default(0); + + $t->string('custom_value1')->nullable(); $t->string('custom_value2')->nullable(); $t->string('custom_value3')->nullable(); @@ -573,6 +576,9 @@ class CreateUsersTable extends Migration $t->string('tax_name3')->nullable(); $t->decimal('tax_rate3', 13, 3)->default(0); + $t->decimal('total_taxes', 13, 3)->default(0); + + $t->string('custom_value1')->nullable(); $t->string('custom_value2')->nullable(); $t->string('custom_value3')->nullable(); @@ -636,6 +642,8 @@ class CreateUsersTable extends Migration $t->string('tax_name3')->nullable(); $t->decimal('tax_rate3', 13, 3)->default(0); + $t->decimal('total_taxes', 13, 3)->default(0); + $t->boolean('uses_inclusive_taxes')->default(0); $t->string('custom_value1')->nullable();