mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
wac webhook
This commit is contained in:
@@ -169,16 +169,17 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
|||||||
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
|
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!app()->environment(['production'])){
|
if(app()->environment(['production'])){
|
||||||
// call wac webhook
|
// call wac webhook
|
||||||
$url = 'https://wacontact.readyspace.com/rest/trigger/9fe03daf-2ace-4095-b064-601ef6d9bfe7';
|
$url = config('wagWebhookUrl.account_registration_url');
|
||||||
$payload = [
|
$payload = [
|
||||||
'name' => $request->input('name'),
|
'name' => $request->input('name'),
|
||||||
'email' => $request->input('email'),
|
'email' => $request->input('email'),
|
||||||
'phone' => $request->input('phone'),
|
'phone' => $request->input('phone'),
|
||||||
|
'portal' => 'izyim'
|
||||||
];
|
];
|
||||||
$response = Http::post($url, $payload);
|
$response = Http::post($url, $payload);
|
||||||
Log::channel('wac_webhook')->info(json_encode($response));
|
Log::channel('wac_webhook')->info('Register Account: ' . json_encode($response));
|
||||||
}
|
}
|
||||||
|
|
||||||
// $this->generateEmailVerificationAttemptProcessor->execute($user);
|
// $this->generateEmailVerificationAttemptProcessor->execute($user);
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use Illuminate\Http\JsonResponse;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
class CreateInvoiceTransactionProcessor
|
class CreateInvoiceTransactionProcessor
|
||||||
{
|
{
|
||||||
@@ -239,6 +240,41 @@ class CreateInvoiceTransactionProcessor
|
|||||||
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
|
$this->createsTransactionDetail->execute($invoice_transaction, $object_detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// call wac webhook
|
||||||
|
$hasInvoiceCreated = Transaction::withTrashed()
|
||||||
|
->where('type', TransactionType::SHIPPING_INVOICE)
|
||||||
|
->where('owner_type', PackingList::class)
|
||||||
|
->where('owner_id', $packingList->id)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
Log::channel('wac_webhook')->info('Regenerating Invoice for PackingList: ' . $packingList->id . '. No call wac api.');
|
||||||
|
|
||||||
|
if (app()->environment('production') && !$hasInvoiceCreated) {
|
||||||
|
$order = $packingList->owner;
|
||||||
|
$companyModule = $order->companyModule;
|
||||||
|
$company = $companyModule->company;
|
||||||
|
$companyContact = $company->contacts()->first();
|
||||||
|
$employee = $companyModule->employees()->first();
|
||||||
|
|
||||||
|
$invoiceCount = Transaction::where('type', TransactionType::SHIPPING_INVOICE)
|
||||||
|
->where('receiver', $companyModule->id)
|
||||||
|
->where('status', ApprovalStatus::APPROVED)
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
'name' => $employee->name,
|
||||||
|
'email' => $employee->email,
|
||||||
|
'phone' => $companyContact->phone,
|
||||||
|
'order_reference' => $order->reference,
|
||||||
|
'portal' => 'izyim',
|
||||||
|
'invoice_count' => $invoiceCount,
|
||||||
|
];
|
||||||
|
|
||||||
|
Log::channel('wac_webhook')->info('Attempt to send wac_webhook - Invoice Created: ' . json_encode($payload));
|
||||||
|
$response = Http::post(config('wagWebhookUrl.invoice_created_url'), $payload);
|
||||||
|
Log::channel('wac_webhook')->info('Invoice Created: ' . json_encode($response));
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Wac\ControllersLogic;
|
||||||
|
|
||||||
|
use App\Classes\Exceptions\RequestValidationException;
|
||||||
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||||
|
use App\Classes\Modules\Accounts\DataTransferObjects\RegistrationObject;
|
||||||
|
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
||||||
|
use App\Classes\Modules\HelpMenu\Standards\Rules\CanFetchHelpMenuQuestion;
|
||||||
|
use App\Classes\Modules\HelpMenu\Processors\FetchFirstQuestionQAProcessor;
|
||||||
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||||
|
use App\Http\Resources\HelpMenuQuestionResource;
|
||||||
|
use App\Models\User;
|
||||||
|
use ErrorException;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use App\Classes\Modules\Companies\Processors\AssignEmployeeProcessor;
|
||||||
|
use App\Classes\Modules\Accounts\Services\CreatesUser;
|
||||||
|
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||||
|
|
||||||
|
class RegisterExchangeEmailLogic extends AbstractControllerLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function notification(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => 'Register Exchange Email',
|
||||||
|
'message' => 'You have successfully registered an exchange email address'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var AssignEmployeeProcessor */
|
||||||
|
private $assignEmployeeProcessor;
|
||||||
|
|
||||||
|
/** @var CreatesUser */
|
||||||
|
private $createsUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RegisterEmailLogic constructor.
|
||||||
|
* @param AssignEmployeeProcessor $assignEmployeeProcessor
|
||||||
|
*/
|
||||||
|
public function __construct(AssignEmployeeProcessor $assignEmployeeProcessor, CreatesUser $createsUser)
|
||||||
|
{
|
||||||
|
$this->assignEmployeeProcessor = $assignEmployeeProcessor;
|
||||||
|
$this->createsUser = $createsUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @return JsonResponse
|
||||||
|
* @throws ErrorException
|
||||||
|
*/
|
||||||
|
public function logic(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
// Validate the request inputs
|
||||||
|
$validator = Validator::make(
|
||||||
|
$request->all(),
|
||||||
|
[
|
||||||
|
'izyim_email' => 'email|required',
|
||||||
|
'exchange_email' => 'email|required',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
throw new RequestValidationException($validator->messages()->first());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the validated emails from the request
|
||||||
|
$izyimEmail = $request->input('izyim_email');
|
||||||
|
$exchangeEmail = $request->input('exchange_email');
|
||||||
|
|
||||||
|
// Check if both emails are the same
|
||||||
|
if ($izyimEmail === $exchangeEmail) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Both emails are the same.',
|
||||||
|
'status' => 'ok',
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the exchange email already exists in the system
|
||||||
|
$existingUser = User::where('email', $exchangeEmail)->first();
|
||||||
|
if ($existingUser) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'The Exchange email already exists in the system.',
|
||||||
|
'status' => 'error',
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the izyim user
|
||||||
|
$izyimUser = User::where('email', $izyimEmail)->first();
|
||||||
|
if (!$izyimUser) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'The Izyim email not found in system.',
|
||||||
|
'status' => 'error',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newUser = new User();
|
||||||
|
$newUser->name = $izyimUser->name;
|
||||||
|
$newUser->email = $exchangeEmail;
|
||||||
|
$newUser->password = $izyimUser->password;
|
||||||
|
$newUser->type = RoleTypes::USER;
|
||||||
|
$newUser->status = ApprovalStatus::APPROVED;
|
||||||
|
$newUser->save();
|
||||||
|
|
||||||
|
Log::channel('wac_webhook')->info('Wac created user: ' . $exchangeEmail);
|
||||||
|
|
||||||
|
$companyModule = $izyimUser->companyModule->first();
|
||||||
|
$Object = new EmploymentObject($companyModule, $newUser);
|
||||||
|
|
||||||
|
$this->assignEmployeeProcessor->execute($Object);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Exchange email registered successfully.',
|
||||||
|
'status' => 'success',
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Wac;
|
||||||
|
|
||||||
|
use App\Classes\Modules\Wac\ControllersLogic\RegisterExchangeEmailLogic;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class RegisterExchangeEmailController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param FetchQuestionQALogic $logic
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function register(Request $request, RegisterExchangeEmailLogic $logic): JsonResponse {
|
||||||
|
return $logic->execute($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'account_registration_url' => 'https://wacontact.readyspace.com/rest/trigger/9fe03daf-2ace-4095-b064-601ef6d9bfe7',
|
||||||
|
'invoice_created_url' => 'https://wacontact.readyspace.com/rest/trigger/c0d38aa7-91ac-458b-8014-cf3287a636e4',
|
||||||
|
];
|
||||||
@@ -12,5 +12,9 @@ Route::group(['middleware' => 'apipub', 'prefix' => 'v1', 'as' => 'apipub.'], fu
|
|||||||
Route::group(['prefix' => 'feedback', 'as' => 'feedback.', 'namespace' => 'HelpMenu'], function () {
|
Route::group(['prefix' => 'feedback', 'as' => 'feedback.', 'namespace' => 'HelpMenu'], function () {
|
||||||
Route::post('/generate', 'GenerateFeedbackUrlController@generate')->name('feedback.url.generate');
|
Route::post('/generate', 'GenerateFeedbackUrlController@generate')->name('feedback.url.generate');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::group(['prefix' => 'wac', 'as' => 'wac.', 'namespace' => 'Wac'], function () {
|
||||||
|
Route::post('/register-email', 'RegisterExchangeEmailController@register')->name('register_email');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user