From 67d0f525af6fa098aafdee7a8af1740e18e2dae2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Feb 2021 20:46:01 +1100 Subject: [PATCH 1/2] Postmark webhooks --- app/Http/Controllers/CreditController.php | 9 ++ app/Http/Controllers/PostMarkController.php | 156 ++++++++++++++++++++ routes/api.php | 2 + 3 files changed, 167 insertions(+) create mode 100644 app/Http/Controllers/PostMarkController.php diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 4974cbb875fc..efdec9af28a2 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -1,4 +1,13 @@ header('X-API-SECURITY') && $request->header('X-API-SECURITY') == config('postmark.secret')) + { + + } + + } + + + + + +// { +// "RecordType": "Delivery", +// "ServerID": 23, +// "MessageStream": "outbound", +// "MessageID": "00000000-0000-0000-0000-000000000000", +// "Recipient": "john@example.com", +// "Tag": "welcome-email", +// "DeliveredAt": "2021-02-21T16:34:52Z", +// "Details": "Test delivery webhook details", +// "Metadata": { +// "example": "value", +// "example_2": "value" +// } +// } + private function processDelivery($request) + { + + } + +// { +// "Metadata": { +// "example": "value", +// "example_2": "value" +// }, +// "RecordType": "Bounce", +// "ID": 42, +// "Type": "HardBounce", +// "TypeCode": 1, +// "Name": "Hard bounce", +// "Tag": "Test", +// "MessageID": "00000000-0000-0000-0000-000000000000", +// "ServerID": 1234, +// "MessageStream": "outbound", +// "Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).", +// "Details": "Test bounce details", +// "Email": "john@example.com", +// "From": "sender@example.com", +// "BouncedAt": "2021-02-21T16:34:52Z", +// "DumpAvailable": true, +// "Inactive": true, +// "CanActivate": true, +// "Subject": "Test subject", +// "Content": "Test content" +// } + + private function processBounce($request) + { + + } + +// { +// "Metadata": { +// "example": "value", +// "example_2": "value" +// }, +// "RecordType": "SpamComplaint", +// "ID": 42, +// "Type": "SpamComplaint", +// "TypeCode": 100001, +// "Name": "Spam complaint", +// "Tag": "Test", +// "MessageID": "00000000-0000-0000-0000-000000000000", +// "ServerID": 1234, +// "MessageStream": "outbound", +// "Description": "The subscriber explicitly marked this message as spam.", +// "Details": "Test spam complaint details", +// "Email": "john@example.com", +// "From": "sender@example.com", +// "BouncedAt": "2021-02-21T16:34:52Z", +// "DumpAvailable": true, +// "Inactive": true, +// "CanActivate": false, +// "Subject": "Test subject", +// "Content": "Test content" +// } + private function processSpamComplaint($request) + { + + } + + +} diff --git a/routes/api.php b/routes/api.php index bc148ded9fc6..48fdd6c4e244 100644 --- a/routes/api.php +++ b/routes/api.php @@ -177,4 +177,6 @@ Route::match(['get', 'post'], 'payment_webhook/{company_key}/{company_gateway_id ->middleware(['guest', 'api_db']) ->name('payment_webhook'); +Route::post('postmark_webhook', 'PostMarkController@webhook'); + Route::fallback('BaseController@notFound'); From c7048e8cb1568ce35e76fc1882b82f93b53a568a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 22 Feb 2021 20:54:46 +1100 Subject: [PATCH 2/2] Fixes for user present name --- app/Jobs/Mail/NinjaMailerJob.php | 4 ++-- app/Models/User.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index a040556d386a..a33eb48ca8eb 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -142,7 +142,7 @@ class NinjaMailerJob implements ShouldQueue $user = User::find($this->decodePrimaryKey($sending_user)); - nlog("Sending via {$user->present()->name()}"); + nlog("Sending via {$user->name()}"); $google = (new Google())->init(); $google->getClient()->setAccessToken(json_encode($user->oauth_user_token)); @@ -164,7 +164,7 @@ class NinjaMailerJob implements ShouldQueue $this->nmo ->mailable - ->from($user->email, $user->present()->name()) + ->from($user->email, $user->name()) ->withSwiftMessage(function ($message) use($token) { $message->getHeaders()->addTextHeader('GmailToken', $token); }); diff --git a/app/Models/User.php b/app/Models/User.php index f5e94281a502..36c7aec6ac39 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -103,6 +103,12 @@ class User extends Authenticatable implements MustVerifyEmail 'deleted_at' => 'timestamp', ]; + + public function name() + { + return $this->first_name . ' ' . $this->last_name; + } + public function getEntityType() { return self::class;