mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-31 10:24:25 +00:00
Completes Order Steps on Unity
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Processors;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\GetContractObligations;
|
||||
|
||||
class UpdateObligationsProcessor
|
||||
{
|
||||
private $getContractObligations;
|
||||
|
||||
public function __construct(GetContractObligations $getContractObligations)
|
||||
{
|
||||
$this->getContractObligations = $getContractObligations;
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
return $this->getContractObligations->execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Unity\Processors;
|
||||
|
||||
use Config;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Modules\Unity\Services\UpdatesContractObligation;
|
||||
|
||||
class UpdateObligationsProcessor
|
||||
{
|
||||
private $updatesContractObligations;
|
||||
|
||||
public function __construct(UpdatesContractObligation $updatesContractObligations)
|
||||
{
|
||||
$this->updatesContractObligations = $updatesContractObligations;
|
||||
}
|
||||
|
||||
public function execute($contract_entity_signature, $obligation_hash_id){
|
||||
return $this->updatesContractObligations->execute($contract_entity_signature, $obligation_hash_id);
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,12 @@ class GetAccessToken
|
||||
$this->apiKey = Config::get('unity.auth.api_key.key');
|
||||
$this->cacheName = 'unity_access_token';
|
||||
$this->cacheTime = Config::get('unity.access_token_cache');
|
||||
$this->accessToken = $this->getAccessToken();
|
||||
$this->accessToken = "";
|
||||
}
|
||||
|
||||
public function execute(){
|
||||
|
||||
//if(!empty($this->getAccessToken())) return $this->getAccessToken();
|
||||
if(!empty($this->getCachedAccessToken())) return $this->getCachedAccessToken();
|
||||
|
||||
if(empty($this->apiKey)){
|
||||
$response = Http::post($this->getAccessTokenEndpoint, [
|
||||
@@ -43,20 +43,22 @@ class GetAccessToken
|
||||
'password' => $this->password ,
|
||||
])->object();
|
||||
$this->accessToken = $response->access_token;
|
||||
|
||||
}else{
|
||||
$this->accessToken = $this->apiKey;
|
||||
}
|
||||
|
||||
$this->cacheAccessToken();
|
||||
|
||||
//TODO: Throw error if access token not available
|
||||
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
private function getAccessToken(){
|
||||
$accessToken = $this->accessToken;
|
||||
return Cache::remember($this->cacheName, $this->cacheTime, function () use ( $accessToken ) {
|
||||
return $accessToken??'';
|
||||
});
|
||||
private function getCachedAccessToken(){
|
||||
return Cache::store('file')->get($this->cacheName);
|
||||
}
|
||||
|
||||
private function cacheAccessToken(){
|
||||
Cache::store('file')->put($this->cacheName, $this->accessToken, $this->cacheTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,19 +10,21 @@ class UpdatesContractObligation
|
||||
{
|
||||
private $getAccessToken;
|
||||
|
||||
private $createEntityEndpoint;
|
||||
private $updateContractStatusEndpoint;
|
||||
|
||||
public function __construct(GetAccessToken $getAccessToken)
|
||||
{
|
||||
$this->createEntityEndpoint = Config::get('unity.url').Config::get('unity.create_entity_endpoint');
|
||||
$this->updateContractStatusEndpoint = Config::get('unity.url').Config::get('unity.endpoint.update_obligation_status');
|
||||
$this->getAccessToken = $getAccessToken;
|
||||
}
|
||||
|
||||
public function execute($entity_name){
|
||||
public function execute($contract_entity_signature, $obligation_hash_id){
|
||||
|
||||
$accesToken=$this->getAccessToken->execute();
|
||||
$accessToken=$this->getAccessToken->execute();
|
||||
|
||||
$response = Http::withToken($accesToken)->post($this->createEntityEndpoint,['name'=>$entity_name])->object();
|
||||
$this->updateContractStatusEndpoint = str_replace('{hash}',$obligation_hash_id,$this->updateContractStatusEndpoint);
|
||||
|
||||
$response = Http::withToken($accessToken)->put($this->updateContractStatusEndpoint,['entity_signature_id'=>$contract_entity_signature])->object();
|
||||
|
||||
return (isset($response->data)) ? $response->data : null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user