Overview
  • Package
  • Class

Packages

  • Klarna
    • Checkout
  • Payment
    • Klarna
      • HTTP
      • Interfaces
      • Unit
        • Tests

Classes

  • Klarna_Checkout_HTTP_CURLFactory
  • Klarna_Checkout_HTTP_Transport
  1 <?php
  2 /**
  3  * Copyright 2015 Klarna AB
  4  *
  5  * Licensed under the Apache License, Version 2.0 (the "License");
  6  * you may not use this file except in compliance with the License.
  7  * You may obtain a copy of the License at
  8  *
  9  *     http://www.apache.org/licenses/LICENSE-2.0
 10  *
 11  * Unless required by applicable law or agreed to in writing, software
 12  * distributed under the License is distributed on an "AS IS" BASIS,
 13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  * See the License for the specific language governing permissions and
 15  * limitations under the License.
 16  *
 17  * File containing the Klarna_HTTP_Response class
 18  *
 19  * PHP version 5.3
 20  *
 21  * @category   Payment
 22  * @package    Payment_Klarna
 23  * @subpackage HTTP
 24  * @author     Klarna <support@klarna.com>
 25  * @copyright  2015 Klarna AB
 26  * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
 27  * @link       http://developers.klarna.com/
 28  */
 29 
 30 /**
 31  * Klarna HTTP Response class
 32  *
 33  * @category   Payment
 34  * @package    Payment_Klarna
 35  * @subpackage HTTP
 36  * @author     Klarna <support@klarna.com>
 37  * @copyright  2015 Klarna AB
 38  * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0
 39  * @link       http://developers.klarna.com/
 40  */
 41 class Klarna_Checkout_HTTP_Response
 42 {
 43     /**
 44      * HTTP response status code
 45      *
 46      * @var int
 47      */
 48     protected $status;
 49 
 50     /**
 51      * Request object
 52      *
 53      * @var Klarna_Checkout_HTTP_Request
 54      */
 55     protected $request;
 56 
 57     /**
 58      * HTTP header
 59      *
 60      * @var array
 61      */
 62     protected $headers;
 63 
 64     /**
 65      * Data
 66      *
 67      * @var string
 68      */
 69     protected $data;
 70 
 71     /**
 72      * Initializes a new instance of the HTTP response class.
 73      *
 74      * @param Klarna_Checkout_HTTP_Request $request the origin request.
 75      * @param array                        $headers the response HTTP headers.
 76      * @param int                          $status  the HTTP status code.
 77      * @param string                       $data    the response payload.
 78      */
 79     public function __construct(
 80         Klarna_Checkout_HTTP_Request $request, array $headers, $status, $data
 81     ) {
 82         $this->request = $request;
 83         $this->headers = array();
 84         foreach ($headers as $key => $value) {
 85             $this->headers[strtolower($key)] = $value;
 86         }
 87         $this->status = $status;
 88         $this->data = $data;
 89     }
 90 
 91     /**
 92      * Gets the HTTP status code.
 93      *
 94      * @return int HTTP status code.
 95      */
 96     public function getStatus()
 97     {
 98         return $this->status;
 99     }
100 
101     /**
102      * Gets the HTTP request this response originated from.
103      *
104      * @return Klarna_Checkout_HTTP_Request
105      */
106     public function getRequest()
107     {
108         return $this->request;
109     }
110 
111     /**
112      * Gets specified HTTP header.
113      *
114      * @param string $name the header name.
115      *
116      * @throws InvalidArgumentException If the specified argument
117      *                                  is not of type string.
118      * @return string|null Null if header doesn't exist, else header value.
119      */
120     public function getHeader($name)
121     {
122         $name = strtolower($name);
123         if (!array_key_exists($name, $this->headers)) {
124             return null;
125         }
126 
127         return $this->headers[$name];
128     }
129 
130     /**
131      * Gets the headers specified for the response.
132      *
133      * @return array
134      */
135     public function getHeaders()
136     {
137         return $this->headers;
138     }
139 
140     /**
141      * Gets the data (payload) for the response.
142      *
143      * @return string the response payload.
144      */
145     public function getData()
146     {
147         return $this->data;
148     }
149 }
150 
API documentation generated by ApiGen