mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:07:32 -05:00 
			
		
		
		
	
						commit
						ff2f8c8905
					
				@ -11,6 +11,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Events\Quote;
 | 
					namespace App\Events\Quote;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Models\ClientContact;
 | 
				
			||||||
use App\Models\Company;
 | 
					use App\Models\Company;
 | 
				
			||||||
use App\Models\Quote;
 | 
					use App\Models\Quote;
 | 
				
			||||||
use Illuminate\Broadcasting\Channel;
 | 
					use Illuminate\Broadcasting\Channel;
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Jobs\Util;
 | 
					namespace App\Jobs\Util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use GuzzleHttp\RequestOptions;
 | 
				
			||||||
use App\Transformers\ArraySerializer;
 | 
					use App\Transformers\ArraySerializer;
 | 
				
			||||||
use Illuminate\Bus\Queueable;
 | 
					use Illuminate\Bus\Queueable;
 | 
				
			||||||
use Illuminate\Contracts\Queue\ShouldQueue;
 | 
					use Illuminate\Contracts\Queue\ShouldQueue;
 | 
				
			||||||
@ -24,7 +25,7 @@ class WebhookHandler implements ShouldQueue
 | 
				
			|||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return void
 | 
					     * @return void
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    public function __construct($event_id, $entity)
 | 
					    public function __construct($event_id, $entity)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->event_id = $event_id;
 | 
					        $this->event_id = $event_id;
 | 
				
			||||||
@ -38,11 +39,9 @@ class WebhookHandler implements ShouldQueue
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function handle() :bool
 | 
					    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)
 | 
					        $subscriptions = \App\Models\Webhook::where('company_id', $this->entity->company_id)
 | 
				
			||||||
                                    ->where('event_id', $this->event_id)
 | 
					                                    ->where('event_id', $this->event_id)
 | 
				
			||||||
@ -58,14 +57,15 @@ class WebhookHandler implements ShouldQueue
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private function process($subscription)
 | 
					    private function process($subscription)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // generate JSON data
 | 
					        // generate JSON data
 | 
				
			||||||
        $manager = new Manager();
 | 
					        $manager = new Manager();
 | 
				
			||||||
        $manager->setSerializer(new ArraySerializer());
 | 
					        $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());
 | 
					        $resource = new Item($this->entity, $transformer, $this->entity->getEntityType());
 | 
				
			||||||
        $data = $manager->createData($resource)->toArray();
 | 
					        $data = $manager->createData($resource)->toArray();
 | 
				
			||||||
@ -73,24 +73,18 @@ class WebhookHandler implements ShouldQueue
 | 
				
			|||||||
        $this->postData($subscription, $data, []);
 | 
					        $this->postData($subscription, $data, []);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private function getTransformerClassName()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return sprintf('App\\Transformers\\%sTransformer', class_basename($this->entity));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private function postData($subscription, $data, $headers = [])
 | 
					    private function postData($subscription, $data, $headers = [])
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $base_headers = [
 | 
					        $base_headers = [
 | 
				
			||||||
            'Content-Length' => strlen($data),
 | 
					            'Content-Length' => strlen(json_encode($data)),
 | 
				
			||||||
            'Accept'         => 'application/json'
 | 
					            'Accept'         => 'application/json'
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $client = new \GuzzleHttp\Client(['headers' => array_merge($base_headers, $headers)]);
 | 
					        $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, [
 | 
					        $response = $client->post($subscription->target_url, [
 | 
				
			||||||
                        GuzzleHttp\RequestOptions::JSON => $data // or 'json' => [...]
 | 
					                        RequestOptions::JSON => $data // or 'json' => [...]
 | 
				
			||||||
                    ]);
 | 
					                    ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) {
 | 
					        if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) {
 | 
				
			||||||
@ -102,6 +96,7 @@ class WebhookHandler implements ShouldQueue
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        info(print_r($exception->getMessage(),1));
 | 
					        info(print_r($exception->getMessage(),1));
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					                             
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user