diff --git a/src/Picqer/Financials/Moneybird/Connection.php b/src/Picqer/Financials/Moneybird/Connection.php index 016136d..833964a 100644 --- a/src/Picqer/Financials/Moneybird/Connection.php +++ b/src/Picqer/Financials/Moneybird/Connection.php @@ -420,7 +420,7 @@ public function needsAuthentication() private function parseResponse(Response $response) { try { - $response->getBody()->rewind(); + Psr7\Message::rewindBody($response); $json = json_decode($response->getBody()->getContents(), true); return $json; @@ -483,7 +483,7 @@ private function acquireAccessToken() $response = $this->client()->post($this->getTokenUrl(), $body); if ($response->getStatusCode() == 200) { - $response->getBody()->rewind(); + Psr7\Message::rewindBody($response); $body = json_decode($response->getBody()->getContents(), true); if (json_last_error() === JSON_ERROR_NONE) { @@ -517,7 +517,7 @@ private function parseExceptionForErrorMessages(Exception $exception) return new ApiException('Response is NULL.', 0, $exception); } - $response->getBody()->rewind(); + Psr7\Message::rewindBody($response); $responseBody = $response->getBody()->getContents(); $decodedResponseBody = json_decode($responseBody, true); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index b85af0b..bf0d9b9 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -5,6 +5,7 @@ use GuzzleHttp\Exception\BadResponseException; use GuzzleHttp\Middleware; use GuzzleHttp\Promise\PromiseInterface; +use GuzzleHttp\Psr7; use PHPUnit\Framework\TestCase; use Picqer\Financials\Moneybird\Connection; use Picqer\Financials\Moneybird\Entities\Contact; @@ -109,7 +110,7 @@ public function testClientTriesToGetAccessTokenWhenNoneGiven() $request = $this->getRequestFromHistoryContainer(); $this->assertEquals('POST', $request->getMethod()); - $request->getBody()->rewind(); + Psr7\Message::rewindBody($request); $this->assertEquals( 'redirect_uri=testRedirectUrl&grant_type=authorization_code&client_id=testClientId&client_secret=testClientSecret&code=testAuthorizationCode', $request->getBody()->getContents()