1 | <?php |
||
14 | abstract class AbstractHttpClient |
||
15 | { |
||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $timeout; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | protected $baseUrl = Paybox::API_URL_TEST; |
||
25 | |||
26 | /** |
||
27 | * @var string[] |
||
28 | */ |
||
29 | private $baseParameters; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | private $defaultDevise; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $questionNumber; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | */ |
||
44 | final public function __construct() |
||
48 | |||
49 | /** |
||
50 | * @param array $options |
||
51 | */ |
||
52 | final public function setOptions($options) |
||
65 | |||
66 | /** |
||
67 | * Calls PayBox Direct platform with given operation type and parameters. |
||
68 | * |
||
69 | * @param int $type Request type |
||
70 | * @param string[] $parameters Request parameters |
||
71 | * @param string $responseClass |
||
72 | * |
||
73 | * @return ResponseInterface The response content |
||
74 | * |
||
75 | * @throws PayboxException |
||
76 | */ |
||
77 | public function call($type, array $parameters, $responseClass) |
||
78 | { |
||
79 | if (!in_array(ResponseInterface::class, class_implements($responseClass))) { |
||
80 | throw new \InvalidArgumentException('The response class must implement '.ResponseInterface::class.'.'); |
||
81 | } |
||
82 | |||
83 | $bodyParams = array_merge($parameters, $this->baseParameters); |
||
84 | $bodyParams['TYPE'] = $type; |
||
85 | $bodyParams['NUMQUESTION'] = $this->questionNumber; |
||
86 | $bodyParams['DATEQ'] = null !== $parameters['DATEQ'] ? $parameters['DATEQ'] : date('dmYHis'); |
||
87 | // Restore default_currency from parameters if given |
||
88 | if (array_key_exists('DEVISE', $parameters)) { |
||
89 | $bodyParams['DEVISE'] = null !== $parameters['DEVISE'] ? $parameters['DEVISE'] : $this->defaultDevise; |
||
90 | } |
||
91 | |||
92 | $response = $this->request($bodyParams); |
||
93 | |||
94 | // Generate results array |
||
95 | $results = []; |
||
96 | foreach (explode('&', $response) as $element) { |
||
97 | list($key, $value) = explode('=', $element); |
||
98 | $value = utf8_encode(trim($value)); |
||
99 | $results[$key] = $value; |
||
100 | } |
||
101 | |||
102 | $this->questionNumber = (int) $results['NUMQUESTION'] + 1; |
||
103 | |||
104 | if ('00000' !== $results['CODEREPONSE']) { |
||
105 | throw new PayboxException($results['COMMENTAIRE'], $results['CODEREPONSE']); |
||
106 | } |
||
107 | |||
108 | return new $responseClass($results); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Init and setup http client with PayboxDirectPlus SDK options. |
||
113 | */ |
||
114 | abstract public function init(); |
||
115 | |||
116 | /** |
||
117 | * Sends a request to the server, receive a response and returns it as a string. |
||
118 | * |
||
119 | * @param string[] $parameters Request parameters |
||
120 | * |
||
121 | * @return string The response content |
||
122 | */ |
||
123 | abstract protected function request($parameters); |
||
124 | } |
||
125 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..