Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fadc031

Browse files
committed
Alter AbstractProfileRequest to send requests successfully
1 parent 7002bd2 commit fadc031

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/Message/AbstractProfileRequest.php

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,28 @@ public function setComment($value)
3737
public function sendData($data)
3838
{
3939
$header = base64_encode($this->getMerchantId() . ':' . $this->getApiPasscode());
40-
// Don't throw exceptions for 4xx errors
41-
$this->httpClient->getEventDispatcher()->addListener(
42-
'request.error',
43-
function ($event) {
44-
if ($event['response']->isClientError()) {
45-
$event->stopPropagation();
46-
}
47-
}
48-
);
49-
40+
5041
if (!empty($data)) {
51-
$httpRequest = $this->httpClient->createRequest(
42+
$httpResponse = $this->httpClient->request(
5243
$this->getHttpMethod(),
5344
$this->getEndpoint(),
54-
null,
45+
[
46+
'Content-Type' => 'application/json',
47+
'Authorization' => 'Passcode ' . $header,
48+
],
5549
json_encode($data)
5650
);
5751
} else {
58-
$httpRequest = $this->httpClient->createRequest(
52+
$httpResponse = $this->httpClient->request(
5953
$this->getHttpMethod(),
60-
$this->getEndpoint()
54+
$this->getEndpoint(),
55+
[
56+
'Content-Type' => 'application/json',
57+
'Authorization' => 'Passcode ' . $header,
58+
]
6159
);
6260
}
6361

64-
$httpResponse = $httpRequest
65-
->setHeader(
66-
'Content-Type',
67-
'application/json'
68-
)
69-
->setHeader(
70-
'Authorization',
71-
'Passcode ' . $header
72-
)
73-
->send();
74-
75-
return $this->response = new ProfileResponse($this, $httpResponse->json());
62+
return $this->response = new Response($this, $httpResponse->getBody()->getContents());
7663
}
7764
}

src/Message/AbstractRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public function getHttpMethod()
147147
public function sendData($data)
148148
{
149149
$header = base64_encode($this->getMerchantId() . ':' . $this->getApiPasscode());
150-
// Don't throw exceptions for 4xx errors
151150

152151
if (!empty($data)) {
153152
$httpResponse = $this->httpClient->request(

0 commit comments

Comments
 (0)