|
1
|
|
|
<?php |
|
2
|
|
|
namespace CultureKings\Afterpay\Service\Merchant; |
|
3
|
|
|
|
|
4
|
|
|
use CultureKings\Afterpay\Exception\ApiException; |
|
5
|
|
|
use CultureKings\Afterpay\Model\ErrorResponse; |
|
6
|
|
|
use CultureKings\Afterpay\Model\Merchant\Authorization; |
|
7
|
|
|
use CultureKings\Afterpay\Model\Merchant\Configuration as ConfigurationModel; |
|
8
|
|
|
use CultureKings\Afterpay\Traits; |
|
9
|
|
|
use GuzzleHttp\ClientInterface; |
|
10
|
|
|
use GuzzleHttp\Exception\BadResponseException; |
|
11
|
|
|
use JMS\Serializer\SerializerInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class Configuration |
|
15
|
|
|
* |
|
16
|
|
|
* @package CultureKings\Afterpay\Service\Merchant |
|
17
|
|
|
*/ |
|
18
|
|
|
class Configuration |
|
19
|
|
|
{ |
|
20
|
|
|
use Traits\AuthorizationTrait; |
|
21
|
|
|
use Traits\ClientTrait; |
|
22
|
|
|
use Traits\SerializerTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Configuration constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param ClientInterface $client |
|
28
|
|
|
* @param Authorization $authorization |
|
29
|
|
|
* @param SerializerInterface $serializer |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( |
|
32
|
|
|
ClientInterface $client, |
|
33
|
|
|
Authorization $authorization, |
|
34
|
|
|
SerializerInterface $serializer |
|
35
|
|
|
) { |
|
36
|
|
|
$this->setClient($client); |
|
|
|
|
|
|
37
|
|
|
$this->setAuthorization($authorization); |
|
38
|
|
|
$this->setSerializer($serializer); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
|
|
public function get() |
|
45
|
|
|
{ |
|
46
|
|
|
try { |
|
47
|
|
|
$result = $this->getClient()->get( |
|
48
|
|
|
'configuration', |
|
49
|
|
|
[ |
|
50
|
|
|
'auth' => [ |
|
51
|
|
|
$this->getAuthorization()->getMerchantId(), |
|
|
|
|
|
|
52
|
|
|
$this->getAuthorization()->getSecret(), |
|
|
|
|
|
|
53
|
|
|
], |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
} catch (BadResponseException $exception) { |
|
57
|
|
|
throw new ApiException( |
|
58
|
|
|
$this->getSerializer()->deserialize( |
|
59
|
|
|
(string) $exception->getResponse()->getBody(), |
|
60
|
|
|
ErrorResponse::class, |
|
61
|
|
|
'json' |
|
62
|
|
|
), |
|
63
|
|
|
$exception |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $this->getSerializer()->deserialize( |
|
68
|
|
|
(string) $result->getBody(), |
|
69
|
|
|
sprintf('array<%s>', ConfigurationModel::class), |
|
70
|
|
|
'json' |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.