From d6c224e538088a4d065c3e083e9d973fe72fee7f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 24 Aug 2020 21:21:35 +1000 Subject: [PATCH 1/2] Fixes for QuoteWasApproved --- app/Events/Quote/QuoteWasApproved.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Events/Quote/QuoteWasApproved.php b/app/Events/Quote/QuoteWasApproved.php index bea13b86a6..dba6ff43ad 100644 --- a/app/Events/Quote/QuoteWasApproved.php +++ b/app/Events/Quote/QuoteWasApproved.php @@ -11,6 +11,7 @@ namespace App\Events\Quote; +use App\Models\ClientContact; use App\Models\Company; use App\Models\Quote; use Illuminate\Broadcasting\Channel; From 044c35266e80a7421ead8b79d39c7201100f91e3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 24 Aug 2020 21:53:22 +1000 Subject: [PATCH 2/2] Fixes for zapier --- app/Jobs/Util/WebhookHandler.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index a8f5f4795f..6c6a4ca8c6 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -2,6 +2,7 @@ namespace App\Jobs\Util; +use GuzzleHttp\RequestOptions; use App\Transformers\ArraySerializer; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -24,7 +25,7 @@ class WebhookHandler implements ShouldQueue * * @return void */ - + public function __construct($event_id, $entity) { $this->event_id = $event_id; @@ -38,11 +39,9 @@ class WebhookHandler implements ShouldQueue */ public function handle() :bool { - - if(!$this->entity->company || $this->entity->company->company_users->first()->is_migrating) - return true; - //info("i got past the check"); + if(!$this->entity->company || $this->entity->company->company_users->first()->is_migrating == true) + return true; $subscriptions = \App\Models\Webhook::where('company_id', $this->entity->company_id) ->where('event_id', $this->event_id) @@ -58,14 +57,15 @@ class WebhookHandler implements ShouldQueue return true; } - private function process($subscription) { // generate JSON data $manager = new Manager(); $manager->setSerializer(new ArraySerializer()); - $transformer = new $this->getTransformerClassName(); + $class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity)); + + $transformer = new $class(); $resource = new Item($this->entity, $transformer, $this->entity->getEntityType()); $data = $manager->createData($resource)->toArray(); @@ -73,24 +73,18 @@ class WebhookHandler implements ShouldQueue $this->postData($subscription, $data, []); } - private function getTransformerClassName() - { - return sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity)); - } - private function postData($subscription, $data, $headers = []) { + $base_headers = [ - 'Content-Length' => strlen($data), + 'Content-Length' => strlen(json_encode($data)), 'Accept' => 'application/json' ]; $client = new \GuzzleHttp\Client(['headers' => array_merge($base_headers, $headers)]); - - //$response = $client->request('POST', $subscription->target_url, ['form_params' => $data]); - + $response = $client->post($subscription->target_url, [ - GuzzleHttp\RequestOptions::JSON => $data // or 'json' => [...] + RequestOptions::JSON => $data // or 'json' => [...] ]); if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) { @@ -102,6 +96,7 @@ class WebhookHandler implements ShouldQueue { info(print_r($exception->getMessage(),1)); - + } } + \ No newline at end of file