diff --git a/app/Jobs/Util/SystemLogger.php b/app/Jobs/Util/SystemLogger.php index 788c0da466ee..74e467b023fe 100644 --- a/app/Jobs/Util/SystemLogger.php +++ b/app/Jobs/Util/SystemLogger.php @@ -33,7 +33,7 @@ class SystemLogger implements ShouldQueue protected $client; - public function __construct($log, $category_id, $event_id, $type_id, Client $client) + public function __construct($log, $category_id, $event_id, $type_id, ?Client $client) { $this->log = $log; $this->category_id = $category_id; diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 60550ed9daef..60a5261b8a64 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -10,7 +10,9 @@ */ namespace App\Jobs\Util; +use App\Jobs\Util\SystemLogger; use App\Libraries\MultiDB; +use App\Models\SystemLog; use App\Models\Webhook; use App\Transformers\ArraySerializer; use GuzzleHttp\Client; @@ -113,6 +115,15 @@ class WebhookHandler implements ShouldQueue if ($response->getStatusCode() == 410 || $response->getStatusCode() == 200) { $subscription->delete(); } + + SystemLogger::dispatch( + $e->getMessage(), + SystemLog::CATEGORY_WEBHOOK, + SystemLog::EVENT_WEBHOOK_RESPONSE, + SystemLog::TYPE_WEBHOOK_RESPONSE, + $this->company->clients->first(), + ); + } public function failed($exception) diff --git a/app/Models/SystemLog.php b/app/Models/SystemLog.php index 4e54d16ddd06..37f3f2518e21 100644 --- a/app/Models/SystemLog.php +++ b/app/Models/SystemLog.php @@ -33,6 +33,7 @@ class SystemLog extends Model /* Category IDs */ const CATEGORY_GATEWAY_RESPONSE = 1; const CATEGORY_MAIL = 2; + const CATEGORY_WEBHOOK = 3; /* Event IDs*/ const EVENT_PAYMENT_RECONCILIATION_FAILURE = 10; @@ -45,6 +46,8 @@ class SystemLog extends Model const EVENT_MAIL_SEND = 30; const EVENT_MAIL_RETRY_QUEUE = 31; //we use this to queue emails that are spooled and not sent due to the email queue quota being exceeded. + const EVENT_WEBHOOK_RESPONSE = 40; + /*Type IDs*/ const TYPE_PAYPAL = 300; const TYPE_STRIPE = 301; @@ -56,6 +59,8 @@ class SystemLog extends Model const TYPE_QUOTA_EXCEEDED = 400; const TYPE_UPSTREAM_FAILURE = 401; + const TYPE_WEBHOOK_RESPONSE = 500; + protected $fillable = [ 'client_id', 'company_id', diff --git a/tests/Unit/Phantom/PhantomJsTest.php b/tests/Unit/Phantom/PhantomJsTest.php new file mode 100644 index 000000000000..7ac11fdfbc6a --- /dev/null +++ b/tests/Unit/Phantom/PhantomJsTest.php @@ -0,0 +1,46 @@ +assertEquals('application/pdf; charset=binary', $finfo->buffer($pdf)); + + } + + public function testInValidPdfMime() + { + $pdf = file_get_contents(base_path('/tests/Unit/Phantom/invalid.pdf')); + + $finfo = new \finfo(FILEINFO_MIME); + + $this->assertNotEquals('application/pdf; charset=binary', $finfo->buffer($pdf)); + + } + +} diff --git a/tests/Unit/Phantom/invalid.pdf b/tests/Unit/Phantom/invalid.pdf new file mode 100644 index 000000000000..b01f723dc1de --- /dev/null +++ b/tests/Unit/Phantom/invalid.pdf @@ -0,0 +1,483 @@ +
+
+
+
+
+ $company_logo
+
+
+ $client_details
+
+
+
+
+
+
+ $entity.public_notes
+
+
+
+
+ $discount_label
+ $total_tax_labels
+ $line_tax_labels
+
+
+ $discount
+ $total_tax_values
+ $line_tax_values
+
+
+
+
+
+
+
+
+ $terms_label + $terms +
+
+
+
+
+
+
+ $balance_due_label +$balance_due + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||