diff --git a/src/Gateways/Conekta/ConektaGateway.php b/src/Gateways/Conekta/ConektaGateway.php index 9d1f1ea..9844407 100644 --- a/src/Gateways/Conekta/ConektaGateway.php +++ b/src/Gateways/Conekta/ConektaGateway.php @@ -115,12 +115,11 @@ public function commit($method, $url, $params = [], $options = []) } $rawResponse = $this->getHttpClient()->{$method}($url, $request); + $statusCode = $rawResponse->getStatusCode(); - if ($rawResponse->getStatusCode() == 200) { - $response = $this->parseResponse($rawResponse->getBody()); - } else { - $response = $this->responseError($rawResponse->getBody()); - } + $response = $statusCode == 200 + ? $this->parseResponse($rawResponse->getBody()) + : $this->responseError($rawResponse->getBody(), $statusCode); return $this->respond($response); } @@ -364,25 +363,27 @@ protected function parseResponse($body) * Get error response from server or fallback to general error. * * @param string $body + * @param int $httpCode * * @return array */ - protected function responseError($body) + protected function responseError($body, $httpCode) { - return $this->parseResponse($body) ?: $this->jsonError($body); + return $this->parseResponse($body) ?: $this->jsonError($body, $httpCode); } /** * Default JSON response. * * @param string $rawResponse + * @param int $httpCode * * @return array */ - public function jsonError($rawResponse) + public function jsonError($rawResponse, $httpCode) { $msg = 'API Response not valid.'; - $msg .= " (Raw response API {$rawResponse})"; + $msg .= " (Raw response: '{$rawResponse}', HTTP code: {$httpCode})"; return [ 'message_to_purchaser' => $msg, diff --git a/tests/Functional/ConektaTest.php b/tests/Functional/ConektaTest.php index 0d10e29..aeb0587 100644 --- a/tests/Functional/ConektaTest.php +++ b/tests/Functional/ConektaTest.php @@ -2,6 +2,8 @@ namespace Shoperti\Tests\PayMe\Functional; +use Shoperti\PayMe\Gateways\Conekta\Charges; +use Shoperti\PayMe\Gateways\Conekta\ConektaGateway; use Shoperti\PayMe\PayMe; class ConektaTest extends AbstractFunctionalTestCase @@ -11,8 +13,8 @@ public function it_should_create_a_new_conekta_gateway() { $gateway = PayMe::make($this->credentials['conekta']); - $this->assertInstanceOf('Shoperti\PayMe\Gateways\Conekta\ConektaGateway', $gateway->getGateway()); - $this->assertInstanceOf('Shoperti\PayMe\Gateways\Conekta\Charges', $gateway->charges()); + $this->assertInstanceOf(ConektaGateway::class, $gateway->getGateway()); + $this->assertInstanceOf(Charges::class, $gateway->charges()); } /** @test */