fix: getVendor / getClient

This commit is contained in:
paulwer 2024-04-03 15:01:57 +02:00
parent f0d61a8261
commit b7a29bb2c7
6 changed files with 32 additions and 15 deletions

View File

@ -14,6 +14,7 @@ namespace App\Http\Controllers;
use App\Jobs\Brevo\ProcessBrevoInboundWebhook;
use App\Jobs\Brevo\ProcessBrevoWebhook;
use App\Libraries\MultiDB;
use App\Models\Company;
use Illuminate\Http\Request;
use Log;
@ -77,6 +78,9 @@ class BrevoController extends BaseController
/**
* Process Brevo Inbound Webhook.
*
* IMPORTANT NOTICE: brevo strips old sended emails, therefore only current attachements are present
*
* IMPORTANT NOTICE: brevo saves the message and attachemnts for later retrieval, therefore we can process it within a async job for performance reasons
*
* @OA\Post(
* path="/api/v1/brevo_inbound_webhook",
@ -187,17 +191,18 @@ class BrevoController extends BaseController
$input = $request->all();
// validation for client mail credentials by recipient
// if ($request->has('company')) {
// if (!($request->has('token')))
// return response()->json(['message' => 'Unauthorized'], 403);
if ($request->has('company_key')) {
if (!($request->has('token')))
return response()->json(['message' => 'Unauthorized'], 403);
// $company = MultiDB::findAndSetDbByCompanyId($request->has('company'));
// $company_brevo_secret = $company?->settings?->email_sending_method === 'client_brevo' && $company?->settings?->brevo_secret ? $company->settings->brevo_secret : null;
// if (!$company || !$company_brevo_secret || $request->get('token') !== $company_brevo_secret)
// return response()->json(['message' => 'Unauthorized'], 403);
MultiDB::findAndSetDbByCompanyKey($request->has('company_key'));
$company = Company::where('company_key', $request->has('company_key'))->first();
$company_brevo_secret = $company?->settings?->email_sending_method === 'client_brevo' && $company?->settings?->brevo_secret ? $company->settings->brevo_secret : null;
if (!$company || !$company_brevo_secret || $request->get('token') !== $company_brevo_secret)
return response()->json(['message' => 'Unauthorized'], 403);
// } else if (!($request->has('token') && $request->get('token') == config('services.brevo.secret')))
// return response()->json(['message' => 'Unauthorized'], 403);
} else if (!($request->has('token') && $request->get('token') == config('services.brevo.secret')))
return response()->json(['message' => 'Unauthorized'], 403);
if (!array_key_exists('items', $input)) {
Log::info('Failed: Message could not be parsed, because required parameters are missing.');

View File

@ -80,6 +80,10 @@ class MailgunController extends BaseController
/**
* Process Mailgun Inbound Webhook.
*
* IMPORTANT NOTICE: mailgun does NOT strip old sended emails, therefore all past attachements are present
*
* IMPORTANT NOTICE: mailgun saves the message and attachemnts for later retrieval, therefore we can process it within a async job for performance reasons
*
*
* @OA\Post(
* path="/api/v1/mailgun_inbound_webhook",

View File

@ -78,6 +78,9 @@ class PostMarkController extends BaseController
/**
* Process Postmark Webhook.
*
* IMPORTANT NOTICE: postmark does NOT strip old sended emails, therefore also all past attachements are present
*
* IMPORTANT NOTICE: postmark does not saves attachements for later retrieval, therefore we cannot process it within a async job
*
* @OA\Post(
* path="/api/v1/postmark_inbound_webhook",

View File

@ -33,6 +33,9 @@ class ProcessBrevoInboundWebhook implements ShouldQueue
/**
* Create a new job instance.
*
* IMPORTANT NOTICE: brevo strips old sended emails, therefore only current attachements are present
*
* $input consists of json/serialized-array:
*
* array (
@ -111,8 +114,6 @@ class ProcessBrevoInboundWebhook implements ShouldQueue
/**
* Execute the job.
*
* TODO: insert Mail from Storage
*
* @return void
*/
public function handle()

View File

@ -40,6 +40,8 @@ class ProcessMailgunInboundWebhook implements ShouldQueue
/**
* Execute the job.
*
* IMPORTANT NOTICE: mailgun does NOT strip old sended emails, therefore all past attachements are present
*
* Mail from Storage
* {
* "Content-Type": "multipart/related; boundary=\"00000000000022bfbe0613e8b7f5\"",

View File

@ -237,16 +237,18 @@ class InboundMailEngine
private function getClient(Company $company, InboundMail $email)
{
$clientContact = ClientContact::where("company_id", $company->id)->where("email", $email->from)->first();
$client = $clientContact->client();
if (!$clientContact)
return null;
return $client;
return $clientContact->client();
}
private function getVendor(Company $company, InboundMail $email)
{
$vendorContact = VendorContact::where("company_id", $company->id)->where("email", $email->from)->first();
$vendor = $vendorContact->vendor();
if (!$vendorContact)
return null;
return $vendor;
return $vendorContact->vendor();
}
private function logBlocked(Company $company, string $data)
{