18
18
* This service provides for functionalities concerning http transactions.
19
19
*
20
20
* @link https://docs.unzer.com/
21
- *
22
21
*/
23
22
class HttpService
24
23
{
@@ -82,26 +81,26 @@ public function setEnvironmentService(EnvironmentService $environmentService): H
82
81
}
83
82
84
83
/**
85
- * @deprecated use sendRequest() instead.
86
- *
87
84
* send post request to payment server
88
85
*
89
- * @param $uri string|null uri of the target system
86
+ * @param string|null $uri uri of the target system
90
87
* @param ?AbstractUnzerResource $resource
91
- * @param string $httpMethod
92
- * @param string $apiVersion
88
+ * @param string|null $httpMethod
89
+ * @param string|null $apiVersion
93
90
*
94
91
* @return string
95
92
*
96
93
* @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request.
97
94
* @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK.
95
+ * @deprecated use sendRequest() instead.
98
96
*/
99
97
public function send (
100
98
?string $ uri = null ,
101
99
?AbstractUnzerResource $ resource = null ,
102
100
string $ httpMethod = HttpAdapterInterface::REQUEST_GET ,
103
101
?string $ apiVersion = null
104
- ): string {
102
+ ): string
103
+ {
105
104
if (!$ resource instanceof AbstractUnzerResource) {
106
105
throw new RuntimeException ('Transfer object is empty! ' );
107
106
}
@@ -116,14 +115,14 @@ public function send(
116
115
* send post request to payment server
117
116
*
118
117
* @param ApiRequest $request
118
+ *
119
119
* @return string
120
120
*
121
121
* @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request.
122
122
* @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK.
123
123
*/
124
- public function sendRequest (
125
- ApiRequest $ request
126
- ): string {
124
+ public function sendRequest (ApiRequest $ request ): string
125
+ {
127
126
$ unzerObj = $ request ->getResource ()->getUnzerObject ();
128
127
129
128
$ apiConfig = $ request ->getResource ()->getApiConfig ();
@@ -137,8 +136,8 @@ public function sendRequest(
137
136
$ headers = $ this ->composeHttpHeaders ($ unzerObj , $ apiConfig ::getAuthorizationMethod ());
138
137
$ httpMethod = $ request ->getHttpMethod ();
139
138
$ this ->initRequest ($ requestUrl , $ payload , $ httpMethod , $ headers );
140
- $ httpAdapter = $ this ->getAdapter ();
141
- $ response = $ httpAdapter ->execute ();
139
+ $ httpAdapter = $ this ->getAdapter ();
140
+ $ response = $ httpAdapter ->execute ();
142
141
$ responseCode = $ httpAdapter ->getResponseCode ();
143
142
$ httpAdapter ->close ();
144
143
@@ -158,7 +157,7 @@ public function sendRequest(
158
157
* @param string $uri
159
158
* @param string $payload
160
159
* @param string $httpMethod
161
- * @param array $httpHeaders
160
+ * @param array $httpHeaders
162
161
*
163
162
* @throws RuntimeException
164
163
*/
@@ -174,7 +173,7 @@ private function initRequest(string $uri, string $payload, string $httpMethod, a
174
173
* Handles error responses by throwing an UnzerApiException with the returned messages and error code.
175
174
* Returns doing nothing if no error occurred.
176
175
*
177
- * @param string $responseCode
176
+ * @param string $responseCode
178
177
* @param string|null $response
179
178
*
180
179
* @throws UnzerApiException
@@ -187,15 +186,15 @@ private function handleErrors(string $responseCode, ?string $response): void
187
186
188
187
$ responseObject = json_decode ($ response , false );
189
188
if (!is_numeric ($ responseCode ) || (int )$ responseCode >= 400 || isset ($ responseObject ->errors )) {
190
- $ code = null ;
191
- $ errorId = null ;
189
+ $ code = null ;
190
+ $ errorId = null ;
192
191
$ customerMessage = $ code ;
193
192
$ merchantMessage = $ customerMessage ;
194
193
if (isset ($ responseObject ->errors [0 ])) {
195
- $ errors = $ responseObject ->errors [0 ];
194
+ $ errors = $ responseObject ->errors [0 ];
196
195
$ merchantMessage = $ errors ->merchantMessage ?? '' ;
197
196
$ customerMessage = $ errors ->customerMessage ?? '' ;
198
- $ code = $ errors ->code ?? '' ;
197
+ $ code = $ errors ->code ?? '' ;
199
198
}
200
199
if (isset ($ responseObject ->id )) {
201
200
$ errorId = $ responseObject ->id ;
@@ -209,23 +208,24 @@ private function handleErrors(string $responseCode, ?string $response): void
209
208
}
210
209
211
210
/**
212
- * @param Unzer $unzerObj
213
- * @param string $payload
214
- * @param mixed $headers
215
- * @param string $responseCode
216
- * @param string $httpMethod
217
- * @param string $url
211
+ * @param Unzer $unzerObj
212
+ * @param string $payload
213
+ * @param mixed $headers
214
+ * @param string $responseCode
215
+ * @param string $httpMethod
216
+ * @param string $url
218
217
* @param string|null $response
219
218
*/
220
219
public function debugLog (
221
220
Unzer $ unzerObj ,
222
221
string $ payload ,
223
- $ headers ,
224
- string $ responseCode ,
222
+ $ headers ,
223
+ string $ responseCode ,
225
224
string $ httpMethod ,
226
225
string $ url ,
227
226
?string $ response
228
- ): void {
227
+ ): void
228
+ {
229
229
// mask auth string
230
230
$ authHeader = explode (' ' , $ headers ['Authorization ' ]);
231
231
$ authHeader [1 ] = ValueService::maskValue ($ authHeader [1 ]);
@@ -275,16 +275,16 @@ private function buildRequestUrl(ApiRequest $request): string
275
275
*/
276
276
public function composeHttpHeaders (Unzer $ unzer , string $ authorizationMethod = AuthorizationMethods::BASIC ): array
277
277
{
278
- $ locale = $ unzer ->getLocale ();
279
- $ clientIp = $ unzer ->getClientIp ();
280
- $ key = $ unzer ->getKey ();
278
+ $ locale = $ unzer ->getLocale ();
279
+ $ clientIp = $ unzer ->getClientIp ();
280
+ $ key = $ unzer ->getKey ();
281
281
282
282
$ httpHeaders = [
283
283
'Authorization ' => $ this ->findAuthentication ($ unzer , $ authorizationMethod ),
284
- 'Content-Type ' => 'application/json ' ,
285
- 'SDK-VERSION ' => Unzer::SDK_VERSION ,
286
- 'SDK-TYPE ' => Unzer::SDK_TYPE ,
287
- 'PHP-VERSION ' => PHP_VERSION
284
+ 'Content-Type ' => 'application/json ' ,
285
+ 'SDK-VERSION ' => Unzer::SDK_VERSION ,
286
+ 'SDK-TYPE ' => Unzer::SDK_TYPE ,
287
+ 'PHP-VERSION ' => PHP_VERSION
288
288
];
289
289
if (!empty ($ locale )) {
290
290
$ httpHeaders ['Accept-Language ' ] = $ locale ;
@@ -347,6 +347,7 @@ public function isApiConfig($className): bool
347
347
348
348
/**
349
349
* @param Unzer $unzer
350
+ *
350
351
* @return string
351
352
*/
352
353
private function findAuthentication (Unzer $ unzer , string $ authorizationMethod = AuthorizationMethods::BASIC ): string
0 commit comments