1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Gateway Client Class |
6
|
|
|
* @category Ticaje |
7
|
|
|
* @package Ticaje_Connector |
8
|
|
|
* @author Hector Luis Barrientos <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Ticaje\Connector\Gateway\Client; |
12
|
|
|
|
13
|
|
|
use Ticaje\Base\Application\Factory\FactoryInterface; |
14
|
|
|
use Ticaje\Connector\Interfaces\Protocol\RestClientInterface; |
15
|
|
|
use Ticaje\Connector\Traits\Gateway\Client\Rest as RestTrait; |
16
|
|
|
use Ticaje\Contract\Patterns\Interfaces\Decorator\ResponderInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Rest |
20
|
|
|
* @package Ticaje\Connector\Gateway\Client |
21
|
|
|
*/ |
22
|
|
|
class Rest extends Base implements RestClientInterface |
23
|
|
|
{ |
24
|
|
|
use RestTrait; |
25
|
|
|
|
26
|
|
|
protected $accessToken; |
27
|
|
|
|
28
|
|
|
protected $baseUriKey; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Rest constructor. |
32
|
|
|
* @param ResponderInterface $responder |
33
|
|
|
* @param FactoryInterface $clientFactory |
34
|
|
|
* @param string $baseUriKey |
35
|
|
|
*/ |
36
|
|
|
public function __construct( |
37
|
|
|
ResponderInterface $responder, |
38
|
|
|
FactoryInterface $clientFactory, |
39
|
|
|
string $baseUriKey |
40
|
|
|
) { |
41
|
|
|
$this->baseUriKey = $baseUriKey; |
42
|
|
|
parent::__construct($responder, $clientFactory); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritDoc |
47
|
|
|
*/ |
48
|
|
|
public function generateClient($credentials) |
49
|
|
|
{ |
50
|
|
|
// If auth problems the log and return void |
51
|
|
|
$this->client = $this->clientFactory->create([ |
52
|
|
|
'config' => [ // Playing a little bit with Magento rules by passing config key, must ve refactored |
53
|
|
|
$this->baseUriKey => $credentials[self::BASE_URI_KEY] |
54
|
|
|
] |
55
|
|
|
]); |
56
|
|
|
return $this->client; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $headers |
61
|
|
|
* @return array |
62
|
|
|
* This method should be abstracted away into a builder class |
63
|
|
|
*/ |
64
|
|
|
protected function generateHeaders($headers) |
65
|
|
|
{ |
66
|
|
|
$authTokenHeader = ["Authorization" => "{$this->accessToken}"]; |
67
|
|
|
return array_merge($headers, $authTokenHeader); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|