Example #1
0
    /**
     * Make sure that the initial state is correct.
     *
     * @return void
     */
    public function testConstructor()
    {
        $request = new Klarna_Checkout_HTTP_Request('url');

        $response = new Klarna_Checkout_HTTP_Response(
            $request, array('test' => 'value'), 203, 'my data'
        );

        $this->assertSame($request, $response->getRequest());

        $header = $response->getHeader('test');
        $this->assertInternalType('string', $header);
        $this->assertEquals('value', $header);
        $this->assertEquals(array('test' => 'value'), $response->getHeaders());
        $this->assertNull($response->getHeader('undefined'));

        $status = $response->getStatus();
        $this->assertInternalType('int', $status);
        $this->assertEquals(203, $status);

        $data = $response->getData();
        $this->assertInternalType('string', $data);
        $this->assertEquals('my data', $data);
    }
 /**
  * Throw an exception if the server responds with an error code.
  *
  * @param Klarna_Checkout_HTTP_Response $result HTTP Response object
  *
  * @throws Klarna_Checkout_HTTP_Status_Exception
  * @return void
  */
 protected function verifyResponse(Klarna_Checkout_HTTP_Response $result)
 {
     // Error Status Code recieved. Throw an exception.
     if ($result->getStatus() >= 400 && $result->getStatus() <= 599) {
         throw new Klarna_Checkout_ConnectorException(
             $result->getData(), $result->getStatus()
         );
     }
 }
Example #3
0
 /**
  * Throw an exception if the server responds with an error code.
  *
  * @param Klarna_Checkout_HTTP_Response $result HTTP Response object
  *
  * @throws Klarna_Checkout_ApiErrorException
  * @return void
  */
 protected function verifyResponse(Klarna_Checkout_HTTP_Response $result)
 {
     // Error Status Code recieved. Throw an exception.
     if ($result->getStatus() >= 400 && $result->getStatus() <= 599) {
         $json = json_decode($result->getData(), true);
         $payload = $json && is_array($json) ? $json : array();
         throw new Klarna_Checkout_ApiErrorException("API Error", $result->getStatus(), $payload);
     }
 }