From acaf554031c588f9d659060dc08b098cd35399d1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Sep 2021 11:04:50 +1000 Subject: [PATCH] Fixes for postmark reporting --- app/Jobs/Mail/NinjaMailerJob.php | 17 ++++++++++++++--- .../Subscription/SubscriptionService.php | 12 ++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index bbff9eafe394..8954722e7796 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -121,18 +121,29 @@ class NinjaMailerJob implements ShouldQueue $message = $e->getMessage(); + /** + * Post mark buries the proper message in a a guzzle response + * this merges a text string with a json object + * need to harvest the ->Message property using the following + */ if($e instanceof ClientException) { //postmark specific failure $response = $e->getResponse(); + $message_body = json_decode($response->getBody()->getContents()); + + if(property_exists($message_body, 'Message')){ + $message = $message_body->Message; + nlog($message); + } - nlog($response); - // $message = $response->Message; } + /* If the is an entity attached to the message send a failure mailer */ if($this->nmo->entity) $this->entityEmailFailed($message); - if(Ninja::isHosted() && (!$e instanceof ClientException)) // Don't send postmark failures to Sentry + /* Don't send postmark failures to Sentry */ + if(Ninja::isHosted() && (!$e instanceof ClientException)) app('sentry')->captureException($e); } } diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 85dde2d02b01..eff83c90f644 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -38,6 +38,7 @@ use App\Utils\Traits\MakesHash; use App\Utils\Traits\SubscriptionHooker; use Carbon\Carbon; use GuzzleHttp\RequestOptions; +use Illuminate\Contracts\Container\BindingResolutionException; class SubscriptionService { @@ -950,7 +951,12 @@ class SubscriptionService return redirect($default_redirect); } - public function planPaid($invoice) + /** + * @param Invoice $invoice + * @return true + * @throws BindingResolutionException + */ + public function planPaid(Invoice $invoice) { $recurring_invoice_hashed_id = $invoice->recurring_invoice()->exists() ? $invoice->recurring_invoice->hashed_id : null; @@ -959,12 +965,14 @@ class SubscriptionService 'subscription' => $this->subscription->hashed_id, 'recurring_invoice' => $recurring_invoice_hashed_id, 'client' => $invoice->client->hashed_id, - 'contact' => $invoice->client->primary_contact()->first() ? $invoice->client->contacts->first() : false, + 'contact' => $invoice->client->primary_contact()->first() ? $invoice->client->primary_contact()->first(): $invoice->client->contacts->first(), 'invoice' => $invoice->hashed_id, ]; $response = $this->triggerWebhook($context); + nlog($response); + return true; } }