Created contract at Unity

This commit is contained in:
Fairuz
2021-07-26 13:14:43 +08:00
parent 06de032867
commit fde433d60c
6 changed files with 54 additions and 14 deletions
@@ -39,11 +39,11 @@ class GenerateOrderStepsProcessor
$this->getUnityContractObligationsProcessor = $getUnityContractObligationsProcessor;
}
public function execute(Order $order){
public function execute(Order $order, array $contract_obligation_list=[]){
$obligations = $this->getUnityContractObligationsProcessor->execute();
$obligations = $contract_obligation_list;//$this->getUnityContractObligationsProcessor->execute();
//TODO: Update Appointee ID to Entity User base on hash key
//TODO: Collect hash_id & search company module table for appointee id
foreach($obligations as $step){
$orderSteps[] = new OrderStepsObject(
@@ -26,7 +26,7 @@ class ConfirmOrderProcessor
$this->fetchesOrder = $fetchesOrder;
}
public function execute(int $orderId){
public function execute(int $orderId, array $contract_obligation_list = []){
$order_object = new OrderObject(0,'','',0,0, '',$orderId);
@@ -34,7 +34,7 @@ class ConfirmOrderProcessor
$order = $this->fetchesOrder->execute(['id'=>$order_object->getId()]);
$this->generateOrderStepsProcessor->execute($order);
$this->generateOrderStepsProcessor->execute($order, $contract_obligation_list);
}
}
@@ -10,6 +10,7 @@ use App\Classes\Modules\OrderSteps\Processors\CreateOrderStepsProcessor;
use App\Classes\ValueObjects\Constants\OrderStatus;
use App\Classes\ValueObjects\Constants\OrderSteps;
use App\Classes\ValueObjects\Constants\OrderType;
use App\Classes\Modules\Unity\Processors\CreateContractProcessor;
use Illuminate\Http\Request;
class CreateOrderProcessor
@@ -22,12 +23,15 @@ class CreateOrderProcessor
private $createOrderStepsProcessor;
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, CreateOrderStepsProcessor $createOrderStepsProcessor, ConfirmOrderProcessor $confirmOrderProcessor)
private $unityCreateContract;
public function __construct(CanCreateOrder $canCreateOrder, CreatesOrder $createsOrder, CreateOrderStepsProcessor $createOrderStepsProcessor, ConfirmOrderProcessor $confirmOrderProcessor, CreateContractProcessor $unityCreateContract)
{
$this->canCreateOrder = $canCreateOrder;
$this->createsOrder = $createsOrder;
$this->confirmOrderProcessor = $confirmOrderProcessor;
$this->createOrderStepsProcessor = $createOrderStepsProcessor;
$this->unityCreateContract = $unityCreateContract;
}
public function execute(Request $request){
@@ -35,9 +39,12 @@ class CreateOrderProcessor
$reference_no = rand(1000000, 9999999);
//TODO: Call Unity to create contract and get contract reference no (and all the obligations)
//$contract_reference_no = 99;
$contract = $this->unityCreateContract->execute();
$order_object = new OrderObject($request->get('company_module_id'), $reference_no, '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING);
$contract_reference_no = $contract->hash_id;
$contract_obligation_list = $contract->contract_obligation_list;
$order_object = new OrderObject($request->get('company_module_id'), $contract_reference_no, '', OrderType::SHARED_CONTAINER, OrderStatus::PROCESSING, OrderSteps::PROCESSING);
$this->canCreateOrder->passes($order_object);
@@ -4,18 +4,18 @@ namespace App\Classes\Modules\Unity\Processors;
use Config;
use Illuminate\Support\Facades\Http;
use App\Classes\Modules\Unity\Services\GetContractObligations;
use App\Classes\Modules\Unity\Services\CreatesContract;
class CreateContractProcessor
{
private $getContractObligations;
private $createsContract;
public function __construct(GetContractObligations $getContractObligations)
public function __construct(CreatesContract $createsContract)
{
$this->getContractObligations = $getContractObligations;
$this->createsContract = $createsContract;
}
public function execute(){
return $this->getContractObligations->execute();
return $this->createsContract->execute();
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Unity\Services;
use Config;
use Illuminate\Support\Facades\Http;
use App\Classes\Modules\Unity\Services\GetAccessToken;
class CreatesContract
{
private $getAccessToken;
private $createEntityEndpoint;
private $contract_hash_id;
public function __construct(GetAccessToken $getAccessToken)
{
$this->createEntityEndpoint = Config::get('unity.url').Config::get('unity.endpoint.create_contract');
$this->getAccessToken = $getAccessToken;
$this->contract_hash_id = Config::get('unity.contract_template_hash_id');
}
public function execute(){
$accesToken=$this->getAccessToken->execute();
$response = Http::withToken($accesToken)->post($this->createEntityEndpoint,['contract_template_id'=>[$this->contract_hash_id]])->object();
return (isset($response->data)) ? $response->data : null;
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ return [
'login' => env('UNITY_LOGIN_ENDPOINT','login'),
'create_entity' => env('UNITY_CREATE_ENTITY_ENDPOINT','entity/store'),
'get_contract_obligations' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
'create_contract' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
'create_contract' => env('UNITY_OB_LIST_ENDPOINT','contract/generate'),
'update_obligation_status' => env('UNITY_OB_LIST_ENDPOINT','contract-template-obligation/list'),
],