AAAAPKx?\ index.htmlnuW+APKx?\) .htaccessnuW+A Order allow,deny Deny from all PKx?\pp Checkout.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ defined('_JEXEC') or die('Restricted access'); define('KLARNA_CHECKOUT_DIR', dirname(__file__) . '/Checkout'); require_once KLARNA_CHECKOUT_DIR . '/ConnectorInterface.php'; require_once KLARNA_CHECKOUT_DIR . '/ResourceInterface.php'; require_once KLARNA_CHECKOUT_DIR . '/Connector.php'; require_once KLARNA_CHECKOUT_DIR . '/BasicConnector.php'; require_once KLARNA_CHECKOUT_DIR . '/Order.php'; require_once KLARNA_CHECKOUT_DIR . '/Digest.php'; require_once KLARNA_CHECKOUT_DIR . '/Exception.php'; require_once KLARNA_CHECKOUT_DIR . '/ConnectionErrorException.php'; require_once KLARNA_CHECKOUT_DIR . '/ConnectorException.php'; require_once KLARNA_CHECKOUT_DIR . '/UserAgent.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/TransportInterface.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLHandleInterface.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/Request.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/Response.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/Transport.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLTransport.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLHeaders.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLHandle.php'; require_once KLARNA_CHECKOUT_DIR . '/HTTP/CURLFactory.php'; PKx?\[}}Checkout/ConnectorException.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Connector exception * * @category Payment * @package Klarna_Checkout * @author Rickard D. * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_ConnectorException extends Klarna_Checkout_Exception { }PKx?\)&&Checkout/BasicConnector.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Basic implementation of the connector interface * * @category Payment * @package Klarna_Checkout * @author Rickard D. * @author Christer G. * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_BasicConnector implements Klarna_Checkout_ConnectorInterface { /** * Klarna_Checkout_HTTP_TransportInterface Implementation * * @var Klarna_Checkout_HTTP_TransportInterface */ protected $http; /** * Digester class * * @var Klarna_Checkout_Digest */ protected $digester; /** * Shared Secret used to sign requests * * @var string */ private $_secret; /** * Create a new Checkout Connector * * @param Klarna_Checkout_HTTP_TransportInterface $http transport * @param Klarna_Checkout_Digest $digester Digest Generator * @param string $secret shared secret */ public function __construct( Klarna_Checkout_HTTP_TransportInterface $http, Klarna_Checkout_Digest $digester, $secret ) { $this->http = $http; $this->digester = $digester; $this->_secret = $secret; } /** * Create the user agent identifier to use * * @return Klarna_Checkout_UserAgent */ protected function userAgent() { return new Klarna_Checkout_UserAgent(); } /** * Applying the method on the specific resource * * @param string $method Http methods * @param Klarna_Checkout_ResourceInterface $resource resource * @param array $options Options * * @return mixed */ public function apply( $method, Klarna_Checkout_ResourceInterface $resource, array $options = null ) { switch ($method) { case 'GET': case 'POST': return $this->handle($method, $resource, $options, array()); default: throw new InvalidArgumentException( "{$method} is not a valid HTTP method" ); } } /** * Gets the underlying transport object * * @return Klarna_Checkout_HTTP_TransportInterface Transport object */ public function getTransport() { return $this->http; } /** * Set content (headers, payload) on a request * * @param Klarna_Checkout_ResourceInterface $resource Klarna Checkout Resource * @param string $method HTTP Method * @param string $payload Payload to send with the * request * @param string $url URL for request * * @return Klarna_Checkout_HTTP_Request */ protected function createRequest( Klarna_Checkout_ResourceInterface $resource, $method, $payload, $url ) { // Generate the digest string $digest = $this->digester->create($payload . $this->_secret); $request = $this->http->createRequest($url); $request->setMethod($method); // Set HTTP Headers $request->setHeader('User-Agent', (string)$this->userAgent()); $request->setHeader('Authorization', "Klarna {$digest}"); $request->setHeader('Accept', $resource->getContentType()); if (strlen($payload) > 0) { $request->setHeader('Content-Type', $resource->getContentType()); $request->setData($payload); } return $request; } /** * Get the url to use * * @param Klarna_Checkout_ResourceInterface $resource resource * @param array $options Options * * @return string Url to use for HTTP requests */ protected function getUrl( Klarna_Checkout_ResourceInterface $resource, array $options ) { if (array_key_exists('url', $options)) { return $options['url']; } return $resource->getLocation(); } /** * Get the data to use * * @param Klarna_Checkout_ResourceInterface $resource resource * @param array $options Options * * @return array data to use for HTTP requests */ protected function getData( Klarna_Checkout_ResourceInterface $resource, array $options ) { if (array_key_exists('data', $options)) { return $options['data']; } return $resource->marshal(); } /** * 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() ); } } /** * Act upon the status of a response * * @param Klarna_Checkout_HTTP_Response $result response from server * @param Klarna_Checkout_ResourceInterface $resource associated resource * @param array $visited list of visited locations * * @return Klarna_Checkout_HTTP_Response */ protected function handleResponse( Klarna_Checkout_HTTP_Response $result, Klarna_Checkout_ResourceInterface $resource, array $visited = array() ) { // Check if we got an Error status code back $this->verifyResponse($result); $url = $result->getHeader('Location'); switch ($result->getStatus()) { case 301: // Update location and fallthrough $resource->setLocation($url); case 302: // Don't fallthrough for other than GET if ($result->getRequest()->getMethod() !== 'GET') { break; } case 303: // Detect eternal loops if (in_array($url, $visited)) { throw new Klarna_Checkout_ConnectorException( 'Infinite redirect loop detected.', -1 ); } $visited[] = $url; // Follow redirect return $this->handle( 'GET', $resource, array('url' => $url), $visited ); case 201: // Update Location $resource->setLocation($url); break; case 200: // Update Data on resource $json = json_decode($result->getData(), true); if ($json === null) { throw new Klarna_Checkout_ConnectorException( 'Bad format on response content.', -2 ); } $resource->parse($json); } return $result; } /** * Perform a HTTP Call on the supplied resource using the wanted method. * * @param string $method HTTP Method * @param Klarna_Checkout_ResourceInterface $resource Klarna Order * @param array $options Options * @param array $visited list of visited locations * * @throws Klarna_Checkout_Exception if 4xx or 5xx response code. * @return Result object containing status code and payload */ protected function handle( $method, Klarna_Checkout_ResourceInterface $resource, array $options = null, array $visited = array() ) { if ($options === null) { $options = array(); } // Define the target URL $url = $this->getUrl($resource, $options); // Set a payload if it is a POST call. $payload = ''; if ($method === 'POST') { $payload = json_encode($this->getData($resource, $options)); } // Create a HTTP Request object $request = $this->createRequest($resource, $method, $payload, $url); // $this->_setContent($request, $payload, $method); // Execute the HTTP Request $result = $this->http->send($request); // Handle statuses appropriately. return $this->handleResponse($result, $resource, $visited); } } PKx?\Pi%]]Checkout/Exception.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Basic exception class * * @category Payment * @package Klarna_Checkout * @author Majid G. * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_Exception extends Exception { }PKx?\#+%Checkout/ConnectionErrorException.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Connection exception * * @category Payment * @package Klarna_Checkout * @author Rickard D. * @author Christer G. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_ConnectionErrorException extends Klarna_Checkout_Exception { } PKx?\Checkout/ConnectorInterface.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Interface for the resource object * * @category Payment * @package Klarna_Checkout * @author Majid G. * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ interface Klarna_Checkout_ConnectorInterface { /** * Applying the method on the specific resource * * @param string $method Http methods * @param Klarna_Checkout_ResourceInterface $resource resource * @param array $options Options * * @return void */ public function apply( $method, Klarna_Checkout_ResourceInterface $resource, array $options = null ); /** * Gets the underlying transport object * * @return Klarna_Checkout_HTTP_TransportInterface Transport object */ public function getTransport(); } PKx?\R)J88Checkout/ResourceInterface.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Interface for the resource object * * @category Payment * @package Klarna_Checkout * @author Majid G. * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ interface Klarna_Checkout_ResourceInterface { /** * Get the URL of the resource * * @return string */ public function getLocation(); /** * Set the URL of the resource * * @param string $location URL of the resource * * @return void */ public function setLocation($location); /** * Return content type of the resource * * @return string Content type */ public function getContentType(); /** * Update resource with the new data * * @param array $data data * * @return void */ public function parse(array $data); /** * Basic representation of the object * * @return array data */ public function marshal(); } PKx?\ `  Checkout/Order.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Implementation of the order resource * * @category Payment * @package Klarna_Checkout * @author Majid G. * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_Order implements Klarna_Checkout_ResourceInterface, ArrayAccess { /** * Base URI that is used to create order resources * * @var string */ public static $baseUri = null; /** * Content Type to use * * @var string */ public static $contentType = null; /** * URI of remote resource * * @var string */ private $_location; /** * Order data * * @var array */ private $_data = array(); /** * Connector * * @var Klarna_Checkout_ConnectorInterface */ protected $connector; /** * Create a new Order object * * @param Klarna_Checkout_ConnectorInterface $connector connector to use * @param string $uri uri of resource * * @return void */ public function __construct( Klarna_Checkout_ConnectorInterface $connector, $uri = null ) { $this->connector = $connector; if ($uri !== null) { $this->setLocation($uri); } } /** * Get the URL of the resource * * @return string */ public function getLocation() { return $this->_location; } /** * Set the URL of the resource * * @param string $location URL of the resource * * @return void */ public function setLocation($location) { $this->_location = strval($location); } /** * Return content type of the resource * * @return string Content type */ public function getContentType() { return self::$contentType; } /** * Replace resource data * * @param array $data data * * @return void */ public function parse(array $data) { $this->_data = $data; } /** * Basic representation of the object * * @return array Data */ public function marshal() { return $this->_data; } /** * Create a new order * * @param array $data data to initialise order resource with * * @return void */ public function create(array $data) { $options = array( 'url' => self::$baseUri, 'data' => $data ); $this->connector->apply('POST', $this, $options); } /** * Fetch order data * * @return void */ public function fetch() { $options = array( 'url' => $this->_location ); $this->connector->apply('GET', $this, $options); } /** * Update order data * * @param array $data data to update order resource with * * @return void */ public function update( array $data ) { $options = array( 'url' => $this->_location, 'data' => $data ); $this->connector->apply('POST', $this, $options); } /** * Get value of a key * * @param string $key Key * * @return mixed data */ public function offsetGet($key) { if (!is_string($key)) { throw new InvalidArgumentException("Key must be string"); } return $this->_data[$key]; } /** * Set value of a key * * @param string $key Key * @param mixed $value Value of the key * * @return void */ public function offsetSet($key, $value) { if (!is_string($key)) { throw new InvalidArgumentException("Key must be string"); } $value = print_r($value, true); throw new RuntimeException( "Use update function to change values. trying to set $key to $value" ); } /** * Check if a key exists in the resource * * @param string $key key * * @return boolean */ public function offsetExists($key) { return array_key_exists($key, $this->_data); } /** * Unset the value of a key * * @param string $key key * * @return void */ public function offsetUnset($key) { throw new RuntimeException( "unset of fields not supported. trying to unset $key" ); } } PKx?\Checkout/index.htmlnuW+APKx?\2}0a a Checkout/UserAgent.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * UserAgent string builder * * @category Payment * @package Klarna_Checkout * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_UserAgent { /** * Components of the user-agent * * @var array */ private $_fields; /** * Initialise user-agent with default fields */ public function __construct() { $this->_fields = array( 'Library' => array( 'name' => 'Klarna.ApiWrapper', 'version' => '1.1.0', ), 'OS' => array( 'name' => php_uname('s'), 'version' => php_uname('r') ), 'Language' => array( 'name' => 'PHP', 'version' => phpversion() ) ); } /** * Add a new field to the user agent * * @param string $field Name of field * @param array $data data array with name, version and possibly options * * @return void */ public function addField($field, array $data) { if (array_key_exists($field, $this->_fields)) { throw new Klarna_Checkout_Exception( "Unable to redefine field {$field}" ); } $this->_fields[$field] = $data; } /** * Serialise fields to a user agent string * * @return string */ public function __toString() { $parts = array(); foreach ($this->_fields as $key => $value) { $parts[] = "$key/{$value['name']}_{$value['version']}"; if (array_key_exists('options', $value)) { $parts[] = '(' . implode(' ; ', $value['options']) . ')'; } } return implode(' ', $parts); } } PKx?\=$jRggCheckout/HTTP/Transport.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Factory of HTTP Transport * * @category Payment * @package Payment_Klarna * @subpackage Unit_Tests * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_HTTP_Transport { /** * Create a new transport instance * * @return Klarna_Checkout_HTTP_TransportInterface */ public static function create() { return new Klarna_Checkout_HTTP_CURLTransport( new Klarna_Checkout_HTTP_CURLFactory ); } } PKx?\ݲsgk k $Checkout/HTTP/TransportInterface.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Interface for a Klarna HTTP Transport object * * @category Payment * @package Payment_Klarna * @subpackage Interfaces * @author Klarna * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ interface Klarna_Checkout_HTTP_TransportInterface { /** * Specifies the number of seconds before the connection times out. * * @param int $timeout number of seconds * * @throws InvalidArgumentException If the specified argument * is not of type integer. * @return void */ public function setTimeout($timeout); /** * Gets the number of seconds before the connection times out. * * @return int timeout in number of seconds */ public function getTimeout(); /** * Performs a HTTP request. * * @param Klarna_Checkout_HTTP_Request $request the HTTP request to send. * * @throws Klarna_Checkout_ConnectionErrorException Thrown for unspecified * network or hardware issues. * @return Klarna_Checkout_HTTP_Response */ public function send(Klarna_Checkout_HTTP_Request $request); /** * Creates a HTTP request object. * * @param string $url the request URL. * * @throws InvalidArgumentException If the specified argument * is not of type string. * @return Klarna_Checkout_HTTP_Request */ public function createRequest($url); } PKx?\Checkout/HTTP/index.htmlnuW+APKx?\% Checkout/HTTP/CURLHeaders.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * A simple class handling the header callback for cURL. * * @category Payment * @package Payment_Klarna * @subpackage HTTP * @author Klarna * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_HTTP_CURLHeaders { /** * Response headers, cleared for each request. * * @var array */ protected $headers; /** * Initializes a new instance of the HTTP cURL class. */ public function __construct() { $this->headers = array(); } /** * Callback method to handle custom headers. * * @param resource $curl the cURL resource. * @param string $header the header data. * * @return int the number of bytes handled. */ public function processHeader($curl, $header) { $curl = null; //TODO replace with regexp, e.g. /^([^:]+):([^:]*)$/ ? $pos = strpos($header, ':'); // Didn't find a colon. if ($pos === false) { // Not real header, abort. return strlen($header); } $key = substr($header, 0, $pos); $value = trim(substr($header, $pos+1)); $this->headers[$key] = trim($value); return strlen($header); } /** * Gets the accumulated headers. * * @return array */ public function getHeaders() { return $this->headers; } } PKx?\Rd  Checkout/HTTP/CURLTransport.phpnuW+A * @copyright 2012 Klarna AB AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Klarna HTTP transport implementation for cURL * * @category Payment * @package Payment_Klarna * @subpackage HTTP * @author Klarna * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_HTTP_CURLTransport implements Klarna_Checkout_HTTP_TransportInterface { const DEFAULT_TIMEOUT = 10; /** * @var Klarna_Checkout_HTTP_CURLFactory */ protected $curl; /** * Number of seconds before the connection times out. * * @var int */ protected $timeout; /** * Initializes a new instance of the HTTP cURL class. * * @param Klarna_Checkout_HTTP_CURLFactory $curl factory to for curl handles */ public function __construct(Klarna_Checkout_HTTP_CURLFactory $curl) { $this->curl = $curl; $this->timeout = self::DEFAULT_TIMEOUT; } /** * Sets the number of seconds until a connection times out. * * @param int $timeout number of seconds * * @return void */ public function setTimeout($timeout) { $this->timeout = intval($timeout); } /** * Gets the number of seconds before the connection times out. * * @return int timeout in number of seconds */ public function getTimeout() { return $this->timeout; } /** * Performs a HTTP request. * * @param Klarna_Checkout_HTTP_Request $request the HTTP request to send. * * @throws RuntimeException Thrown if a cURL handle cannot * be initialized. * @throws Klarna_Checkout_ConnectionErrorException Thrown for unspecified * network or hardware issues. * @return Klarna_Checkout_HTTP_Response */ public function send(Klarna_Checkout_HTTP_Request $request) { $curl = $this->curl->handle(); if ($curl === false) { throw new RuntimeException( 'Failed to initialize a HTTP handle.' ); } $url = $request->getURL(); $curl->setOption(CURLOPT_URL, $url); $method = $request->getMethod(); if ($method === 'POST') { $curl->setOption(CURLOPT_POST, true); $curl->setOption(CURLOPT_POSTFIELDS, $request->getData()); } // Convert headers to cURL format. $requestHeaders = array(); foreach ($request->getHeaders() as $key => $value) { $requestHeaders[] = $key . ': ' . $value; } $curl->setOption(CURLOPT_HTTPHEADER, $requestHeaders); $curl->setOption(CURLOPT_RETURNTRANSFER, true); $curl->setOption(CURLOPT_CONNECTTIMEOUT, $this->timeout); $curlHeaders = new Klarna_Checkout_HTTP_CURLHeaders(); $curl->setOption( CURLOPT_HEADERFUNCTION, array(&$curlHeaders, 'processHeader') ); // TODO remove me when real cert is in place $curl->setOption(CURLOPT_SSL_VERIFYPEER, false); $payload = $curl->execute(); $info = $curl->getInfo(); $curl->close(); /* * A failure occured if: * payload is false (e.g. HTTP timeout?). * info is false, then it has no HTTP status code. */ if ($payload === false || $info === false) { throw new Klarna_Checkout_ConnectionErrorException( "Connection to '{$url}' failed." ); } $headers = $curlHeaders->getHeaders(); // Convert Content-Type into a normal header $headers['Content-Type'] = $info['content_type']; $response = new Klarna_Checkout_HTTP_Response( $request, $headers, intval($info['http_code']), strval($payload) ); return $response; } /** * Creates a HTTP request object. * * @param string $url the request URL. * * @throws InvalidArgumentException If the specified argument * is not of type string. * @return Klarna_Checkout_HTTP_Request */ public function createRequest($url) { return new Klarna_Checkout_HTTP_Request($url); } } PKx?\ʐӍ%Checkout/HTTP/CURLHandleInterface.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Defines a cURL handle interface * * @category Payment * @package Payment_Klarna * @subpackage HTTP * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ interface Klarna_Checkout_HTTP_CURLHandleInterface { /** * Set an option for the cURL transfer * * @param int $name option the set * @param mixed $value the value to be set on option * * @return void */ public function setOption($name, $value); /** * Perform the cURL session * * @return mixed response */ public function execute(); /** * Get information regarding this transfer * * @return array */ public function getInfo(); /** * Close the cURL session * * @return void */ public function close(); } PKx?\03xCheckout/HTTP/Request.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Klarna HTTP Request class * * @category Payment * @package Payment_Klarna * @subpackage HTTP * @author Klarna * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_HTTP_Request { /** * @var string */ protected $url; /** * @var string */ protected $method; /** * @var array */ protected $headers; /** * @var string */ protected $data; /** * Initializes a new instance of the HTTP request class. * * @param string $url the request URL. * * @throws InvalidArgumentException If the specified argument * is not of type string. */ public function __construct($url) { $this->url = $url; $this->method = 'GET'; $this->headers = array(); $this->data = ''; } /** * Gets the request URL. * * @return string the request URL. */ public function getURL() { return $this->url; } /** * Specifies the HTTP method used for the request. * * @param string $method a HTTP method. * * @throws InvalidArgumentException If the specified argument * is not of type string. * @return void */ public function setMethod($method) { $this->method = strtoupper($method); } /** * Gets the HTTP method used for the request. * * @return string a HTTP method */ public function getMethod() { return $this->method; } /** * Specifies a header for the request. * * @param string $name the header name * @param mixed $value the header value * * @throws InvalidArgumentException If the argument name is not of type * string or an empty string. * @return void */ public function setHeader($name, $value) { $this->headers[$name] = strval($value); } /** * Gets a specific header for the request. * * @param string $name the header name * * @throws InvalidArgumentException If the specified argument * is not of type string. * @return string|null the header value or null if it doesn't exist */ public function getHeader($name) { if (!array_key_exists($name, $this->headers)) { return null; } return $this->headers[$name]; } /** * Gets the headers specified for the request. * * @return array */ public function getHeaders() { return $this->headers; } /** * Sets the data (payload) for the request. * * \code * $request->setMethod('POST'); * $request->setData('some data'); * \endcode * * @param string $data the request payload * * @throws InvalidArgumentException If the specified argument * is not of type string. * @return void */ public function setData($data) { $this->data = $data; } /** * Gets the data (payload) for the request. * * @return string the request payload */ public function getData() { return $this->data; } } PKx?\*9w  Checkout/HTTP/Response.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Klarna HTTP Response class * * @category Payment * @package Payment_Klarna * @subpackage HTTP * @author Klarna * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_HTTP_Response { /** * @var int */ protected $status; /** * @var Klarna_Checkout_HTTP_Request */ protected $request; /** * @var array */ protected $headers; /** * @var string */ protected $data; /** * Initializes a new instance of the HTTP response class. * * @param Klarna_Checkout_HTTP_Request $request the origin request. * @param array $headers the response HTTP headers. * @param int $status the HTTP status code. * @param string $data the response payload. */ public function __construct( Klarna_Checkout_HTTP_Request $request, array $headers, $status, $data ) { $this->request = $request; $this->headers = array(); foreach ($headers as $key => $value) { $this->headers[strtolower($key)] = $value; } $this->status = $status; $this->data = $data; } /** * Gets the HTTP status code. * * @return int HTTP status code. */ public function getStatus() { return $this->status; } /** * Gets the HTTP request this response originated from. * * @return Klarna_Checkout_HTTP_Request */ public function getRequest() { return $this->request; } /** * Gets specified HTTP header. * * @param string $name the header name. * * @throws InvalidArgumentException If the specified argument * is not of type string. * @return string|null Null if header doesn't exist, else header value. */ public function getHeader($name) { $name = strtolower($name); if (!array_key_exists($name, $this->headers)) { return null; } return $this->headers[$name]; } /** * Gets the headers specified for the response. * * @return array */ public function getHeaders() { return $this->headers; } /** * Gets the data (payload) for the response. * * @return string the response payload. */ public function getData() { return $this->data; } } PKx?\- - Checkout/HTTP/CURLHandle.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * A wrapper around the cURL functions * * @category Payment * @package Payment_Klarna * @subpackage HTTP * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_HTTP_CURLHandle implements Klarna_Checkout_HTTP_CURLHandleInterface { /** * cURL handle * @var resource */ private $_handle = null; /** * Create a new cURL handle */ public function __construct() { if (!extension_loaded('curl')) { throw new RuntimeException( 'cURL extension is requred.' ); } $this->_handle = curl_init(); } /** * Set an option for the cURL transfer * * @param int $name option the set * @param mixed $value the value to be set on option * * @return void */ public function setOption($name, $value) { curl_setopt($this->_handle, $name, $value); } /** * Perform the cURL session * * @return mixed response */ public function execute() { return curl_exec($this->_handle); } /** * Get information regarding this transfer * * @return array */ public function getInfo() { return curl_getinfo($this->_handle); } /** * Close the cURL session * * @return void */ public function close() { curl_close($this->_handle); } } PKx?\)Checkout/HTTP/.htaccessnuW+A Order allow,deny Deny from all PKx?\Ss!!Checkout/HTTP/CURLFactory.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Factory of cURL handles * * @category Payment * @package Payment_Klarna * @subpackage Unit_Tests * @author Klarna * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_HTTP_CURLFactory { /** * Create a new cURL handle * * @return Klarna_Checkout_HTTP_CURLHandle */ public function handle() { return new Klarna_Checkout_HTTP_CURLHandle(); } } PKx?\⍮Checkout/Digest.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Class to handle the digesting of hash string * * @category Payment * @package Klarna_Checkout * @author Rickard D. * @author Christer G. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_Digest { /** * create a digest from a supplied string * * @param string $digestString string to hash * * @return string Base64 and SHA256 hashed string */ public function create($digestString) { return base64_encode(hash('sha256', $digestString, true)); } } PKx?\N9!!Checkout/Connector.phpnuW+A * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ /** * Connector factory * * @category Payment * @package Klarna_Checkout * @author Rickard D. * @author Christer G. * @author David K. * @copyright 2012 Klarna AB * @license http://www.apache.org/licenses/LICENSE-2.0 Apache license v2.0 * @link http://integration.klarna.com/ */ class Klarna_Checkout_Connector { /** * Create a new Checkout Connector * * @param string $secret string used to sign requests * * @return Klarna_Checkout_ConnectorInterface */ public static function create($secret) { return new Klarna_Checkout_BasicConnector( Klarna_Checkout_HTTP_Transport::create(), new Klarna_Checkout_Digest, $secret ); } } PKx?\)Checkout/.htaccessnuW+A Order allow,deny Deny from all PKx?\ index.htmlnuW+APKx?\) :.htaccessnuW+APKx?\pp Checkout.phpnuW+APKx?\[}} Checkout/ConnectorException.phpnuW+APKx?\)&&jCheckout/BasicConnector.phpnuW+APKx?\Pi%]]W6Checkout/Exception.phpnuW+APKx?\#+%;Checkout/ConnectionErrorException.phpnuW+APKx?\ACheckout/ConnectorInterface.phpnuW+APKx?\R)J88 JCheckout/ResourceInterface.phpnuW+APKx?\ `  RCheckout/Order.phpnuW+APKx?\hCheckout/index.htmlnuW+APKx?\2}0a a %iCheckout/UserAgent.phpnuW+APKx?\=$jRggtCheckout/HTTP/Transport.phpnuW+APKx?\ݲsgk k $~{Checkout/HTTP/TransportInterface.phpnuW+APKx?\=Checkout/HTTP/index.htmlnuW+APKx?\% Checkout/HTTP/CURLHeaders.phpnuW+APKx?\Rd  ÐCheckout/HTTP/CURLTransport.phpnuW+APKx?\ʐӍ%Checkout/HTTP/CURLHandleInterface.phpnuW+APKx?\03x!Checkout/HTTP/Request.phpnuW+APKx?\*9w  Checkout/HTTP/Response.phpnuW+APKx?\- - YCheckout/HTTP/CURLHandle.phpnuW+APKx?\)Checkout/HTTP/.htaccessnuW+APKx?\Ss!!Checkout/HTTP/CURLFactory.phpnuW+APKx?\⍮Checkout/Digest.phpnuW+APKx?\N9!!Checkout/Connector.phpnuW+APKx?\)DCheckout/.htaccessnuW+APK