From 63c120cf13c2798c56bc9e5dea6d775133bd879d Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 19 Aug 2026 12:39:44 +0800 Subject: [PATCH 1/2] Attempt to disable unity integration and test run at production --- .env.example | 1 + .../Validators/CompanyModuleValidation.php | 7 ++- .../AssignPackingListOrderLogic.php | 56 ++++++++++++------- .../FetchOrderListsFromYdPortalProcessor.php | 4 ++ ...FetchPackingListsFromYdPortalProcessor.php | 6 +- ...FetchOrderListsFromYdPortalV2Processor.php | 15 +++-- ...tchPackingListsFromYdPortalV2Processor.php | 11 +++- .../Unity/Services/ActivatesContract.php | 4 +- .../Unity/Services/CreatesContract.php | 3 +- .../Unity/Services/CreatesContractEntity.php | 4 +- .../Modules/Unity/Services/CreatesEntity.php | 4 +- .../Unity/Services/CreatesEntitySignature.php | 4 +- .../Modules/Unity/Services/GetAccessToken.php | 4 +- .../Unity/Services/GetContractObligations.php | 4 +- .../Unity/Services/UpdatesContractEntity.php | 4 +- .../Services/UpdatesContractObligation.php | 4 +- config/unity.php | 2 + 17 files changed, 98 insertions(+), 39 deletions(-) diff --git a/.env.example b/.env.example index 0cb78979..37dbdf2b 100644 --- a/.env.example +++ b/.env.example @@ -51,6 +51,7 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" UNITY_APP_URL="https://unity.izyim.com" +UNITY_ENABLED=true EXCHANGE_URL=https://dev.exchange.cief-malaysia.com/ MIX_EXCHANGE_URL="${EXCHANGE_URL}" diff --git a/app/Classes/Modules/Companies/Standards/Validators/CompanyModuleValidation.php b/app/Classes/Modules/Companies/Standards/Validators/CompanyModuleValidation.php index 21961ecb..22c66e94 100644 --- a/app/Classes/Modules/Companies/Standards/Validators/CompanyModuleValidation.php +++ b/app/Classes/Modules/Companies/Standards/Validators/CompanyModuleValidation.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Companies\Standards\Validators; use App\Classes\General\Abstracts\AbstractValidation; use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject; +use Config; class CompanyModuleValidation extends AbstractValidation { @@ -25,9 +26,11 @@ class CompanyModuleValidation extends AbstractValidation */ protected function rules(): array { + $required = !config('unity.enabled') ? 'nullable' : 'required'; + return [ - 'unity_hash_id' => 'required', - 'unity_signature' => 'required' + 'unity_hash_id' => $required, + 'unity_signature' => $required ]; } diff --git a/app/Classes/Modules/PackingLists/ControllersLogic/AssignPackingListOrderLogic.php b/app/Classes/Modules/PackingLists/ControllersLogic/AssignPackingListOrderLogic.php index ad53681c..5c8c346e 100644 --- a/app/Classes/Modules/PackingLists/ControllersLogic/AssignPackingListOrderLogic.php +++ b/app/Classes/Modules/PackingLists/ControllersLogic/AssignPackingListOrderLogic.php @@ -132,37 +132,51 @@ class AssignPackingListOrderLogic extends AbstractControllerLogic $transport = $warehouse_packing_list->transports()->first(); $transport = $this->updatesTransportStatus->execute($transport, ApprovalStatus::APPROVED); - $contract = $this->unityCreateContract->execute(); - $contractReference = $contract->hash_id; - $contractObligations = $contract->contract_obligation_list; + if(config('unity.enabled')) { + $contract = $this->unityCreateContract->execute(); + $contractReference = $contract->hash_id; + $contractObligations = $contract->contract_obligation_list; - $this->unityActivateContract->execute($contractReference); - $supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id; + $this->unityActivateContract->execute($contractReference); + $supervisorHashId = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->unity_hash_id; - $supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId); - $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]); + $supervisorContractEntity = $this->unityCreateContractEntity->execute($contractReference, $supervisorHashId); + $order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->update(['entity_hash_id' => $supervisorContractEntity->hash_id, 'entity_signature' => $supervisorContractEntity->entity_signature_hash_id]); - $importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id); - $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]); + $importerContractEntity = $this->unityCreateContractEntity->execute($contractReference, $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->appointee->unity_hash_id); + $order->orderRoles()->where('role_id', '=', OrderRoleTypes::IMPORTER)->first()->update(['entity_hash_id' => $importerContractEntity->hash_id, 'entity_signature' => $importerContractEntity->entity_signature_hash_id]); - $this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations); + $this->unityAssignContractEntity->execute($supervisorContractEntity->hash_id, $contractObligations); - try { - $packing_list = $this->fetchesPackingList->execute([ - 'reference' => $warehouse_packing_list->reference, - 'type' => PackingListType::SHIPPING_PACKING_LIST - ]); + try { + $packing_list = $this->fetchesPackingList->execute([ + 'reference' => $warehouse_packing_list->reference, + 'type' => PackingListType::SHIPPING_PACKING_LIST + ]); - $warehouse_packing_list = $this->updatesPackingListOwner->execute($packing_list, $order); + $warehouse_packing_list = $this->updatesPackingListOwner->execute($packing_list, $order); - $this->updatesPackingListContractReference->execute($packing_list, $contractReference); + $this->updatesPackingListContractReference->execute($packing_list, $contractReference); + + foreach($contractObligations as $obligation) { + $stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id); + $this->createsStep->execute($packing_list, $stepObject); + } + } catch (ResourceNotFoundException $exception) { - foreach($contractObligations as $obligation) { - $stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id); - $this->createsStep->execute($packing_list, $stepObject); } - } catch (ResourceNotFoundException $exception) { + } + else{ + try { + $packing_list = $this->fetchesPackingList->execute([ + 'reference' => $warehouse_packing_list->reference, + 'type' => PackingListType::SHIPPING_PACKING_LIST + ]); + $warehouse_packing_list = $this->updatesPackingListOwner->execute($packing_list, $order); + } catch (ResourceNotFoundException $exception) { + + } } // Update Packing Lists' packages info, diff --git a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php index b655f29d..2ed535b4 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php @@ -37,6 +37,7 @@ use App\Models\Order; use App\Models\PackingList; use App\Models\Transport; use Carbon\Carbon; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; @@ -139,6 +140,9 @@ class FetchOrderListsFromYdPortalProcessor */ public function execute(?Carbon $start = null, ?Carbon $end = null) { + Log::info('FetchOrderListsFromYdPortalProcessor no longer in use, use FetchOrderListsFromYdPortalV2Processor instead'); + return; + ini_set('max_execution_time', '900'); // $missingOrders = ['M202302161513122', 'YW202302161027442', 'YW202302151637022', 'M202302151605025', 'M202302151527103', 'M202302151527356', 'M202302151556019', 'YW202302151520241', 'YW202302151445068', 'M202302151359169', 'YW202302151349223', 'YW202302151336520', 'M202302151334316', 'YW202302151148129', 'M202302151145379', 'M202302151142411', 'M202302151037036', 'M202302151036398', 'M202302150919406', 'M202302141535009', 'YW202302141532318', 'M202302141319463', 'M202302141319045', 'YW202302141405471', 'M202302141334494', 'YW202302141321569', 'YW202302141323005', 'M202302141309053', 'M202302140905116', 'M202302141039558', 'M202302141022333', 'YW202302140943182', 'YW202302140923485', 'YW202302131728233', 'YW202302131702040', 'M202302131649417', 'M202302131638056', 'YW202302131601110', 'YW202302131530436', 'YW202302131411338', 'YW202302131355161', 'YW202302131312526', 'M202302130859076', 'M202302111708070', 'M202302111455134', 'M202302111457501', 'M202302111444041', 'M202302111506514', 'M202302111440286', 'M202302111354585', 'M202302111055551', 'M202302110900216', 'YW202302101743112', 'M202302091559443', 'M202302101716374', 'M202302101700402', 'M202302101633570', 'M202302101612095', 'M202302101611408', 'M202302101542340', 'M202302101408370', 'M202302101323341', 'M202302101129532', 'M202302101025109', 'M202302101006595', 'M202302091706357', 'YW202302091255022', 'YW202302091448196', 'YW202302091446431', 'M202302091138154', 'M202302091129396', 'YW202302091028175', 'M202302091006545', 'YW202302090942033', 'YW202302081743094', 'M202302081530599', 'M202302081531210', 'M202302081508571', 'YW202302081530492', 'M202302081500361', 'M202302081253105', 'M202302081303370', 'M202302071636303', 'M202302071741187', 'YW202302071735407', 'M202302071706323', 'M202302071537501', 'M202302071538092', 'YW202302071516453', 'M202302071311314', 'M202302071148154', 'YW202302071136018', 'M202302071036027', 'M202302071008010', 'M202302061742178', 'M202302061615198', 'M202302061502093', 'M202302061458532', 'M202302061552141', 'M202302061548431', 'M202302061555033', 'YW202302061404567', 'M202302061322463', 'M202302061042556', 'M202302061021277', 'M202302060917276', 'M202302041551570', 'M202302041552382', 'YW202302041515257', 'M202302041405502', 'M202302041030185', 'YW202302041215576', 'YW202302041058469', 'YW202302041024459', 'YW202302040939568', 'M202302031701053', 'M202302031700316', 'M202302031430562', 'M202302031431535', 'M202302031147213', 'YW202302031406529', 'YW202302031322256', 'M202302021718554', 'M202302021417415', 'YW202302021404542', 'M202302021055324', 'YW202302021037462', 'M202302011613381', 'M202302011347586', 'M202302011348245', 'M202301151635132', 'M202301141803516', 'YW202301141653536', 'M202301131504477', 'M202301131538220', 'M202301121327453', 'YW202301111153183', 'M202301091649543', 'M202212311641071', 'YW202212211532191', 'YW202212191605226']; diff --git a/app/Classes/Modules/PackingLists/Processors/FetchPackingListsFromYdPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchPackingListsFromYdPortalProcessor.php index d376878d..23d041ba 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchPackingListsFromYdPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchPackingListsFromYdPortalProcessor.php @@ -27,6 +27,7 @@ use App\Models\Order; use App\Models\PackingList; use Carbon\Carbon; use GuzzleHttp\Exception\GuzzleException; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -107,6 +108,9 @@ class FetchPackingListsFromYdPortalProcessor */ public function execute(?Carbon $start = null, ?Carbon $end = null) { + Log::info('FetchPackingListsFromYdPortalProcessor no longer in use, use FetchPackingListsFromYdPortalV2Processor instead'); + return; + $from = $end ? Carbon::today()->diff($end)->days : 0; $to = $start ? Carbon::today()->diff($start)->days : 10; @@ -143,7 +147,7 @@ class FetchPackingListsFromYdPortalProcessor if (strpos($customerno, '正确唛头YD') !== false) { $customerno = explode('正确唛头YD', $customerno)[1]; } - + $customerno = preg_split('/[-()\/]/', $customerno); $orderNumber = $customerno[array_key_last($customerno)]; diff --git a/app/Classes/Modules/PackingLists/Processors/V2/FetchOrderListsFromYdPortalV2Processor.php b/app/Classes/Modules/PackingLists/Processors/V2/FetchOrderListsFromYdPortalV2Processor.php index 60bb6a4c..38351fc6 100644 --- a/app/Classes/Modules/PackingLists/Processors/V2/FetchOrderListsFromYdPortalV2Processor.php +++ b/app/Classes/Modules/PackingLists/Processors/V2/FetchOrderListsFromYdPortalV2Processor.php @@ -38,6 +38,7 @@ use App\Models\Order; use App\Models\PackingList; use App\Models\Transport; use Carbon\Carbon; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; @@ -139,6 +140,12 @@ class FetchOrderListsFromYdPortalV2Processor */ public function execute(Carbon $startDate = null, Carbon $endDate = null) { + // cief todo: 172 + // if(!config('unity.enabled')) { + // Log::info('FetchOrderListsFromYdPortalV2Processor skipped: UNITY_ENABLED is false'); + // return; + // } + Log::info('FetchOrderListsFromYdPortalV2Processor starts for start date: ' . $startDate . ', and end date: ' . $endDate); // return; @@ -303,7 +310,7 @@ class FetchOrderListsFromYdPortalV2Processor $transportObject = new TransportObject(TransportType::LAND, null, $row->kuaidilist, Carbon::parse($receiveDate), Carbon::parse($receiveDate), $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); $transport = $this->createsTransport->execute($transportObject, $warehouseReceiveList); - if ($allow_contract) { + if (config('unity.enabled') && $allow_contract) { $contract = $this->unityCreateContract->execute(); @@ -328,7 +335,7 @@ class FetchOrderListsFromYdPortalV2Processor /** @var PackingList $packingList */ $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); - if ($allow_contract) { + if (config('unity.enabled') && $allow_contract) { foreach ($contractObligations as $obligation) { $stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id); $this->createsStep->execute($packingList, $stepObject); @@ -432,7 +439,7 @@ class FetchOrderListsFromYdPortalV2Processor $packingList->save(); } - if ($allow_contract) { + if (config('unity.enabled') && $allow_contract) { $signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture; foreach($packingList->steps()->where('reference', '!=', 'DELIVERY')->get() as $step){ $this->updatesContractObligations->execute($signature, $step->obligation_hash_id); @@ -455,7 +462,7 @@ class FetchOrderListsFromYdPortalV2Processor $this->createsSchedule->execute($transport, new ScheduleObject($deliveryDate, $deliveryDate, ApprovalStatus::APPROVED)); - if ($allow_contract) { + if (config('unity.enabled') && $allow_contract) { $deliveryStep = $packingList->steps()->where('reference', '=', 'LAST_MILE_DELIVERY')->first(); $signature = $packingList->owner->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->entity_sigiture; $this->updatesContractObligations->execute($signature, $deliveryStep->obligation_hash_id); diff --git a/app/Classes/Modules/PackingLists/Processors/V2/FetchPackingListsFromYdPortalV2Processor.php b/app/Classes/Modules/PackingLists/Processors/V2/FetchPackingListsFromYdPortalV2Processor.php index 1952cd2f..23a89928 100644 --- a/app/Classes/Modules/PackingLists/Processors/V2/FetchPackingListsFromYdPortalV2Processor.php +++ b/app/Classes/Modules/PackingLists/Processors/V2/FetchPackingListsFromYdPortalV2Processor.php @@ -31,6 +31,7 @@ use Carbon\Carbon; use DateTime; use Illuminate\Support\Facades\Cache; use GuzzleHttp\Exception\GuzzleException; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -111,6 +112,12 @@ class FetchPackingListsFromYdPortalV2Processor */ public function execute(Carbon $startDate = null, Carbon $endDate = null) { + // cief todo: 172 + // if(!config('unity.enabled')) { + // Log::info('FetchPackingListsFromYdPortalV2Processor skipped: UNITY_ENABLED is false'); + // return; + // } + Log::info('FetchPackingListsFromYdPortalV2Processor starts for start date: ' . $startDate . ', and end date: ' . $endDate); // return; @@ -200,7 +207,7 @@ class FetchPackingListsFromYdPortalV2Processor $transportObject = new TransportObject(TransportType::LAND, null, $row->kuaidilist, Carbon::parse($receiveDate), Carbon::parse($receiveDate), $allow_contract ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); $transport = $this->createsTransport->execute($transportObject, $warehouseReceiveList); - if ($allow_contract) { + if (config('unity.enabled') && $allow_contract) { $contract = $this->unityCreateContract->execute(); @@ -226,7 +233,7 @@ class FetchPackingListsFromYdPortalV2Processor $packingList = $this->createPackingListProcessor->execute($packingListObject, $order); Log::info('Create SHIPPING_PACKING_LIST id: ' . $packingList->id); - if ($allow_contract) { + if (config('unity.enabled') && $allow_contract) { foreach ($contractObligations as $obligation) { $stepObject = new StepsObject($order->orderRoles()->where('role_id', '=', OrderRoleTypes::SUPERVISOR)->first()->appointee->id, $obligation->reference, $obligation->sequence, $obligation->hash_id); $this->createsStep->execute($packingList, $stepObject); diff --git a/app/Classes/Modules/Unity/Services/ActivatesContract.php b/app/Classes/Modules/Unity/Services/ActivatesContract.php index 05f193ae..cbaadad0 100644 --- a/app/Classes/Modules/Unity/Services/ActivatesContract.php +++ b/app/Classes/Modules/Unity/Services/ActivatesContract.php @@ -20,11 +20,13 @@ class ActivatesContract public function execute($contract_hash_id){ + if(!config('unity.enabled')) return null; + $accessToken=$this->getAccessToken->execute(); $this->activateEntityEndpoint = str_replace('{hash}',$contract_hash_id,$this->activateEntityEndpoint); - $response = Http::withToken($accessToken)->put($this->activateEntityEndpoint)->object(); + $response = Http::withoutVerifying()->withToken($accessToken)->put($this->activateEntityEndpoint)->object(); return (isset($response->data)) ? $response->data : null; diff --git a/app/Classes/Modules/Unity/Services/CreatesContract.php b/app/Classes/Modules/Unity/Services/CreatesContract.php index 88ef138d..023fcb6a 100644 --- a/app/Classes/Modules/Unity/Services/CreatesContract.php +++ b/app/Classes/Modules/Unity/Services/CreatesContract.php @@ -23,10 +23,11 @@ class CreatesContract public function execute(){ + if(!config('unity.enabled')) return null; $accessToken=$this->getAccessToken->execute(); - $response = Http::withToken($accessToken)->post($this->createEntityEndpoint,['contract_template_id'=>[$this->contract_hash_id]])->object(); + $response = Http::withoutVerifying()->withToken($accessToken)->post($this->createEntityEndpoint,['contract_template_id'=>[$this->contract_hash_id]])->object(); return (isset($response->data)) ? $response->data : null; diff --git a/app/Classes/Modules/Unity/Services/CreatesContractEntity.php b/app/Classes/Modules/Unity/Services/CreatesContractEntity.php index dd0bb135..0bbe7cbc 100644 --- a/app/Classes/Modules/Unity/Services/CreatesContractEntity.php +++ b/app/Classes/Modules/Unity/Services/CreatesContractEntity.php @@ -23,8 +23,10 @@ class CreatesContractEntity public function execute(string $new_contract_id, string $entity_hash_ids){ + if(!config('unity.enabled')) return null; + $accesToken=$this->getAccessToken->execute(); - $response = Http::withToken($accesToken)->post($this->createContractEntityEndpoint,['contract_id'=>[$new_contract_id],'entity_id'=>$entity_hash_ids])->object(); + $response = Http::withoutVerifying()->withToken($accesToken)->post($this->createContractEntityEndpoint,['contract_id'=>[$new_contract_id],'entity_id'=>$entity_hash_ids])->object(); return (isset($response->data)) ? $response->data : null; } diff --git a/app/Classes/Modules/Unity/Services/CreatesEntity.php b/app/Classes/Modules/Unity/Services/CreatesEntity.php index 1eacbe00..68ac312d 100644 --- a/app/Classes/Modules/Unity/Services/CreatesEntity.php +++ b/app/Classes/Modules/Unity/Services/CreatesEntity.php @@ -20,9 +20,11 @@ class CreatesEntity public function execute($entity_name){ + if(!config('unity.enabled')) return (object)['hash_id' => '']; + $accesToken= $this->getAccessToken->execute(); - $response = Http::withToken($accesToken)->post($this->createEntityEndpoint,['name'=>$entity_name])->object(); + $response = Http::withoutVerifying()->withToken($accesToken)->post($this->createEntityEndpoint,['name'=>$entity_name])->object(); return (isset($response->data)) ? $response->data : null; diff --git a/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php b/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php index 45dc3895..ca1c177a 100644 --- a/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php +++ b/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php @@ -20,9 +20,11 @@ class CreatesEntitySignature public function execute(string $entity_hash_id){ + if(!config('unity.enabled')) return (object)['hash_id' => '']; + $accesToken=$this->getAccessToken->execute(); - $response = Http::withToken($accesToken)->post($this->createEntitySignatureEndpoint,['entity_id'=>[$entity_hash_id], 'type'=>'1'])->object(); + $response = Http::withoutVerifying()->withToken($accesToken)->post($this->createEntitySignatureEndpoint,['entity_id'=>[$entity_hash_id], 'type'=>'1'])->object(); return (isset($response->data)) ? $response->data : null; diff --git a/app/Classes/Modules/Unity/Services/GetAccessToken.php b/app/Classes/Modules/Unity/Services/GetAccessToken.php index 40cf5883..93a6094e 100644 --- a/app/Classes/Modules/Unity/Services/GetAccessToken.php +++ b/app/Classes/Modules/Unity/Services/GetAccessToken.php @@ -35,10 +35,12 @@ class GetAccessToken public function execute(){ + if(!config('unity.enabled')) return ""; + if(!empty($this->getCachedAccessToken())) return $this->getCachedAccessToken(); if(empty($this->apiKey)){ - $response = Http::post($this->getAccessTokenEndpoint, [ + $response = Http::withoutVerifying()->post($this->getAccessTokenEndpoint, [ 'email' => $this->username, 'password' => $this->password , ])->object(); diff --git a/app/Classes/Modules/Unity/Services/GetContractObligations.php b/app/Classes/Modules/Unity/Services/GetContractObligations.php index fed54aa8..9d3acf78 100644 --- a/app/Classes/Modules/Unity/Services/GetContractObligations.php +++ b/app/Classes/Modules/Unity/Services/GetContractObligations.php @@ -21,9 +21,11 @@ class GetContractObligations public function execute(){ + if(!config('unity.enabled')) return []; + $accesToken=$this->getAccessToken->execute(); - $response = Http::withToken($accesToken)->get($this->getContractObligationsEndpoint)->object(); + $response = Http::withoutVerifying()->withToken($accesToken)->get($this->getContractObligationsEndpoint)->object(); return (isset($response->data)) ? $response->data : []; diff --git a/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php b/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php index 4b0515eb..34eb67c5 100644 --- a/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php +++ b/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php @@ -20,11 +20,13 @@ class UpdatesContractEntity public function execute(string $obligation_hash_id, array $entity_hash_id){ + if(!config('unity.enabled')) return null; + $accessToken=$this->getAccessToken->execute(); $this->assignEntityEndpoint = str_replace('{hash}',$obligation_hash_id,$this->assignEntityEndpoint); - $response = Http::withToken($accessToken)->put( $this->assignEntityEndpoint,['contract_entity_id'=>$entity_hash_id])->object(); + $response = Http::withoutVerifying()->withToken($accessToken)->put( $this->assignEntityEndpoint,['contract_entity_id'=>$entity_hash_id])->object(); return (isset($response->data)) ? $response->data : null; diff --git a/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php b/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php index 25a5c0f5..95fa2b61 100644 --- a/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php +++ b/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php @@ -20,11 +20,13 @@ class UpdatesContractObligation public function execute($contract_entity_signature, $obligation_hash_id){ + if(!config('unity.enabled')) return (object)['status' => 3, 'completed_at' => date('Y-m-d H:i:s')]; + $accessToken=$this->getAccessToken->execute(); $this->updateContractStatusEndpoint = str_replace('{hash}', $obligation_hash_id, $this->updateContractStatusEndpoint); - $response = Http::withToken($accessToken)->put($this->updateContractStatusEndpoint,['entity_signature_id'=>$contract_entity_signature])->object(); + $response = Http::withoutVerifying()->withToken($accessToken)->put($this->updateContractStatusEndpoint,['entity_signature_id'=>$contract_entity_signature])->object(); return (isset($response->data)) ? $response->data : null; diff --git a/config/unity.php b/config/unity.php index 49eceaf1..6a7d308f 100644 --- a/config/unity.php +++ b/config/unity.php @@ -41,6 +41,8 @@ return [ 'on_error_email' => env('UNITY_ON_ERROR_EMAIL','dev@shipping.com,dev@unity.com'), + 'enabled' => env('UNITY_ENABLED', false), + 'contract_template_hash_id' => env('UNITY_CONTRACT_TEMPLATE_HASH_ID', 'Kp3qzMV82m5R2PZg6eX0'), 'contract_template_cache' => env('UNITY_CONTRACT_TEMPLATE_CACHE','60'), From 4fee6d9349665bff269d0a2d74cebc6b0255a45d Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Fri, 21 Aug 2026 10:33:08 +0800 Subject: [PATCH 2/2] Attempt to disable unity integration and test run at production --- app/Classes/Modules/Unity/Services/ActivatesContract.php | 5 +++++ app/Classes/Modules/Unity/Services/CreatesContract.php | 3 +++ .../Modules/Unity/Services/CreatesContractEntity.php | 6 ++++++ app/Classes/Modules/Unity/Services/CreatesEntity.php | 5 +++++ .../Modules/Unity/Services/CreatesEntitySignature.php | 5 +++++ app/Classes/Modules/Unity/Services/GetAccessToken.php | 3 +++ .../Modules/Unity/Services/GetContractObligations.php | 3 +++ .../Modules/Unity/Services/UpdatesContractEntity.php | 6 ++++++ .../Modules/Unity/Services/UpdatesContractObligation.php | 6 ++++++ 9 files changed, 42 insertions(+) diff --git a/app/Classes/Modules/Unity/Services/ActivatesContract.php b/app/Classes/Modules/Unity/Services/ActivatesContract.php index cbaadad0..1a031b91 100644 --- a/app/Classes/Modules/Unity/Services/ActivatesContract.php +++ b/app/Classes/Modules/Unity/Services/ActivatesContract.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class ActivatesContract @@ -22,6 +23,10 @@ class ActivatesContract if(!config('unity.enabled')) return null; + Log::info('[ActivatesContract] UNITY CALLED', [ + 'contract_hash_id' => $contract_hash_id, + ]); + $accessToken=$this->getAccessToken->execute(); $this->activateEntityEndpoint = str_replace('{hash}',$contract_hash_id,$this->activateEntityEndpoint); diff --git a/app/Classes/Modules/Unity/Services/CreatesContract.php b/app/Classes/Modules/Unity/Services/CreatesContract.php index 023fcb6a..d103d3ed 100644 --- a/app/Classes/Modules/Unity/Services/CreatesContract.php +++ b/app/Classes/Modules/Unity/Services/CreatesContract.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class CreatesContract @@ -25,6 +26,8 @@ class CreatesContract if(!config('unity.enabled')) return null; + Log::info('[CreatesContract] UNITY CALLED'); + $accessToken=$this->getAccessToken->execute(); $response = Http::withoutVerifying()->withToken($accessToken)->post($this->createEntityEndpoint,['contract_template_id'=>[$this->contract_hash_id]])->object(); diff --git a/app/Classes/Modules/Unity/Services/CreatesContractEntity.php b/app/Classes/Modules/Unity/Services/CreatesContractEntity.php index 0bbe7cbc..35272d74 100644 --- a/app/Classes/Modules/Unity/Services/CreatesContractEntity.php +++ b/app/Classes/Modules/Unity/Services/CreatesContractEntity.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class CreatesContractEntity @@ -25,6 +26,11 @@ class CreatesContractEntity if(!config('unity.enabled')) return null; + Log::info('[CreatesContractEntity] UNITY CALLED', [ + 'new_contract_id' => $new_contract_id, + 'entity_hash_ids' => $entity_hash_ids, + ]); + $accesToken=$this->getAccessToken->execute(); $response = Http::withoutVerifying()->withToken($accesToken)->post($this->createContractEntityEndpoint,['contract_id'=>[$new_contract_id],'entity_id'=>$entity_hash_ids])->object(); return (isset($response->data)) ? $response->data : null; diff --git a/app/Classes/Modules/Unity/Services/CreatesEntity.php b/app/Classes/Modules/Unity/Services/CreatesEntity.php index 68ac312d..aed21ccc 100644 --- a/app/Classes/Modules/Unity/Services/CreatesEntity.php +++ b/app/Classes/Modules/Unity/Services/CreatesEntity.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class CreatesEntity @@ -22,6 +23,10 @@ class CreatesEntity if(!config('unity.enabled')) return (object)['hash_id' => '']; + Log::info('[CreatesEntity] UNITY CALLED', [ + 'entity_name' => $entity_name, + ]); + $accesToken= $this->getAccessToken->execute(); $response = Http::withoutVerifying()->withToken($accesToken)->post($this->createEntityEndpoint,['name'=>$entity_name])->object(); diff --git a/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php b/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php index ca1c177a..67db50cd 100644 --- a/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php +++ b/app/Classes/Modules/Unity/Services/CreatesEntitySignature.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class CreatesEntitySignature @@ -22,6 +23,10 @@ class CreatesEntitySignature if(!config('unity.enabled')) return (object)['hash_id' => '']; + Log::info('[CreatesEntitySignature] UNITY CALLED', [ + 'entity_hash_id' => $entity_hash_id, + ]); + $accesToken=$this->getAccessToken->execute(); $response = Http::withoutVerifying()->withToken($accesToken)->post($this->createEntitySignatureEndpoint,['entity_id'=>[$entity_hash_id], 'type'=>'1'])->object(); diff --git a/app/Classes/Modules/Unity/Services/GetAccessToken.php b/app/Classes/Modules/Unity/Services/GetAccessToken.php index 93a6094e..e1a68fa0 100644 --- a/app/Classes/Modules/Unity/Services/GetAccessToken.php +++ b/app/Classes/Modules/Unity/Services/GetAccessToken.php @@ -5,6 +5,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Cache; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; class GetAccessToken { @@ -39,6 +40,8 @@ class GetAccessToken if(!empty($this->getCachedAccessToken())) return $this->getCachedAccessToken(); + Log::info('[GetAccessToken] UNITY CALLED'); + if(empty($this->apiKey)){ $response = Http::withoutVerifying()->post($this->getAccessTokenEndpoint, [ 'email' => $this->username, diff --git a/app/Classes/Modules/Unity/Services/GetContractObligations.php b/app/Classes/Modules/Unity/Services/GetContractObligations.php index 9d3acf78..46430158 100644 --- a/app/Classes/Modules/Unity/Services/GetContractObligations.php +++ b/app/Classes/Modules/Unity/Services/GetContractObligations.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class GetContractObligations @@ -23,6 +24,8 @@ class GetContractObligations if(!config('unity.enabled')) return []; + Log::info('[GetContractObligations] UNITY CALLED'); + $accesToken=$this->getAccessToken->execute(); $response = Http::withoutVerifying()->withToken($accesToken)->get($this->getContractObligationsEndpoint)->object(); diff --git a/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php b/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php index 34eb67c5..c409b8ea 100644 --- a/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php +++ b/app/Classes/Modules/Unity/Services/UpdatesContractEntity.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class UpdatesContractEntity @@ -22,6 +23,11 @@ class UpdatesContractEntity if(!config('unity.enabled')) return null; + Log::info('[UpdatesContractEntity] UNITY CALLED', [ + 'obligation_hash_id' => $obligation_hash_id, + 'entity_hash_id' => $entity_hash_id, + ]); + $accessToken=$this->getAccessToken->execute(); $this->assignEntityEndpoint = str_replace('{hash}',$obligation_hash_id,$this->assignEntityEndpoint); diff --git a/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php b/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php index 95fa2b61..2371aeff 100644 --- a/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php +++ b/app/Classes/Modules/Unity/Services/UpdatesContractObligation.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Unity\Services; use Config; use Illuminate\Support\Facades\Http; +use Illuminate\Support\Facades\Log; use App\Classes\Modules\Unity\Services\GetAccessToken; class UpdatesContractObligation @@ -22,6 +23,11 @@ class UpdatesContractObligation if(!config('unity.enabled')) return (object)['status' => 3, 'completed_at' => date('Y-m-d H:i:s')]; + Log::info('[UpdatesContractObligation] UNITY CALLED', [ + 'contract_entity_signature' => $contract_entity_signature, + 'obligation_hash_id' => $obligation_hash_id, + ]); + $accessToken=$this->getAccessToken->execute(); $this->updateContractStatusEndpoint = str_replace('{hash}', $obligation_hash_id, $this->updateContractStatusEndpoint);