diff --git a/README.md b/README.md index 9912759..e1c1bea 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,36 @@ PAYMILL-PHP =========== -[![Build Status](https://travis-ci.org/paymill/paymill-php.png)](https://travis-ci.org/paymill/paymill-php) -[![Latest Stable Version](https://poser.pugx.org/paymill/paymill/v/stable.png)](https://packagist.org/packages/paymill/paymill) -[![Total Downloads](https://poser.pugx.org/paymill/paymill/downloads.png)](https://packagist.org/packages/paymill/paymill) +[![Build Status](https://travis-ci.org/paymill/paymill-php.png)](https://travis-ci.org/paymill/paymill-php)[![Latest Stable Version](https://poser.pugx.org/paymill/paymill/v/stable.png)](https://packagist.org/packages/paymill/paymill)[![Total Downloads](https://poser.pugx.org/paymill/paymill/downloads.png)](https://packagist.org/packages/paymill/paymill) VERSIONING ---------- -This wrapper is using the api v2.1 launched in June 2014. -If you wish to use the old api v2.0 please use the wrapper in branch v2: https://github.com/paymill/paymill-php/tree/v2. +This wrapper is using the api v2.1 launched in June 2014. If you wish to use the old api v2.0 please use the wrapper in branch v2: https://github.com/paymill/paymill-php/tree/v2. How to test ----------- -There are different credit card numbers, frontend and backend error codes, which can be used for testing. -For more information, please read our testing reference. -https://www.paymill.com/en-gb/documentation-3/reference/testing/ +There are different credit card numbers, frontend and backend error codes, which can be used for testing. For more information, please read our testing reference. https://www.paymill.com/en-gb/documentation-3/reference/testing/ Getting started with PAYMILL ---------------------------- + If you don't already use Composer, then you probably should read the installation guide http://getcomposer.org/download/. Please include this library via Composer in your composer.json and execute **composer update** to refresh the autoload.php. ```json { - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/paymill/paymill-php" - } - ], - "require": { - "paymill/paymill": "dev-master" + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/paymill/paymill-php" } + ], + "require": { + "paymill/paymill": "dev-master" + } } ``` @@ -45,76 +41,82 @@ Lets say you have two files, which are going to use the PAYMILL lib. First one i To load the PAYMILL library from the file, which is located in *your project root folder*, you need to **require** PAYMILL's **autoload** script like this: ```php - require './paymill-php/autoload.php'; +require './paymill-php/autoload.php'; ``` To load the PAYMILL library from the file, which is located in *the app folder*, you need to **require** PAYMILL's **autoload** script like this: ```php - require '../paymill-php/autoload.php'; +require '../paymill-php/autoload.php'; +``` + +1. Instantiate the request class with the following parameters: $apiKey: First parameter is always your private API (test) Key + +```php +$request = new Paymill\Request($apiKey); +``` + +1. Instantiate the model class with the parameters described in the API-reference: + +```php +$payment = new Paymill\Models\Request\Payment(); +$payment->setToken("098f6bcd4621d373cade4e832627b4f6"); +``` + +1. Use your desired function: + +```php +$response = $request->create($payment); +$paymentId = $response->getId(); ``` -1. Instantiate the request class with the following parameters: - $apiKey: First parameter is always your private API (test) Key - - ```php - $request = new Paymill\Request($apiKey); - ``` -2. Instantiate the model class with the parameters described in the API-reference: - - ```php - $payment = new Paymill\Models\Request\Payment(); - $payment->setToken("098f6bcd4621d373cade4e832627b4f6"); - ``` -3. Use your desired function: - - ```php - $response = $request->create($payment); - $paymentId = $response->getId(); - ``` - - It recommend to wrap it into a "try/catch" to handle exceptions like this: - ```php - try{ - $response = $request->create($payment); - $paymentId = $response->getId(); - }catch(PaymillException $e){ - //Do something with the error informations below - $e->getResponseCode(); - $e->getStatusCode(); - $e->getErrorMessage(); - } - ``` +It recommend to wrap it into a "try/catch" to handle exceptions like this: + +```php +try{ + $response = $request->create($payment); + $paymentId = $response->getId(); +}catch(PaymillException $e){ + //Do something with the error informations below + $e->getResponseCode(); + $e->getStatusCode(); + $e->getErrorMessage(); +} +``` Receiving Response --------------- +------------------ -This section shows diffrent ways how to receive a response. -The followings examples show how to get the Id for a transaction. +This section shows diffrent ways how to receive a response. The followings examples show how to get the Id for a transaction. + +1. The default response is one of the response-models. -1. The default response is one of the response-models. ```php - $response = $request->create($payment); - $response->getId(); +$response = $request->create($payment); +$response->getId(); ``` -2. getLastResponse() returns the unconverted response from the API. +1. getLastResponse() returns the unconverted response from the API. + ```php - $request->create($payment); - $response = $request->getLastResponse(); - $response['body']['data']['id']; +$request->create($payment); +$response = $request->getLastResponse(); +$response['body']['data']['id']; ``` -3. getJSONObject returns the response as stdClass-Object. +1. getJSONObject returns the response as stdClass-Object. + ```php - $request->create($payment); - $response = $request->getJSONObject(); - $response->data->id; +$request->create($payment); +$response = $request->getJSONObject(); +$response->data->id; ``` Using Root certificate ----------------------------- +---------------------- + If the error below occurres on your system please follow the steps below to configure curl. + ```php Paymill\Services\PaymillException: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed @@ -122,16 +124,23 @@ error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile Windows / OS X / Linux -1. Download http://curl.haxx.se/ca/cacert.pem and save it on your server. -2. Open php.ini with an editor and add the line `curl.cainfo=PathToYourCACertFile` -3. Restart your Webserver +1. Download http://curl.haxx.se/ca/cacert.pem and save it on your server. +2. Open php.ini with an editor and add the line `curl.cainfo=PathToYourCACertFile` +3. Restart your Webserver Update Root certificate on Linux(ubuntu) -1. Run `sudo update-ca-certificates` -2. Restart your Webserver +1. Run `sudo update-ca-certificates` +2. Restart your Webserver + +Changelog +--------- + +#### 3.2.1 + +- bugfix: [#92](https://github.com/paymill/paymill-php/pull/92) remove typecheck for http response code Documentation --------------- +------------- For further information, please refer to our official PHP library reference: https://www.paymill.com/en-gb/documentation-3/reference/api-reference/index.html diff --git a/lib/Paymill/Request.php b/lib/Paymill/Request.php index 5116625..0000384 100644 --- a/lib/Paymill/Request.php +++ b/lib/Paymill/Request.php @@ -12,7 +12,7 @@ /** * Base - * @version 3.2.0 + * @version 3.2.1 */ class Request { @@ -35,14 +35,14 @@ class Request /** * @var string */ - private $_version = "3.2.0"; + private $_version = "3.2.1"; /** * @var string */ private $_source; - /** + /** * @var \Paymill\Services\Util */ private $_util; @@ -55,7 +55,7 @@ class Request public function __construct($privateKey = null) { $this->_util = new \Paymill\Services\Util(); - if(!is_null($privateKey)){ + if(!is_null($privateKey)){ $this->setConnectionClass(new Curl($privateKey)); } } @@ -217,7 +217,7 @@ private function _request(Base $model, $method) throw new PaymillException(null,'The connection class is missing!'); } $convertedResponse = null; - $httpMethod = $this->_getHTTPMethod($method); + $httpMethod = $this->_getHTTPMethod($method); $parameter = $model->parameterize($method); $serviceResource = $model->getServiceResource() . $model->getId(); if(is_a($model, "\Paymill\Models\Request\Transaction") && $method === "create"){ @@ -231,17 +231,17 @@ private function _request(Base $model, $method) ); $this->_lastResponse = $response; $responseHandler = new ResponseHandler(); - if($method === "getAllAsModel" && $responseHandler->validateResponse($response) && $this->_util->isNumericArray($response['body']['data'])){ - foreach($response['body']['data'] as $object){ - $convertedResponse[] = $responseHandler->convertResponse($object, $model->getServiceResource()); - } - }elseif($method === "getAll" && $responseHandler->validateResponse($response)){ + if($method === "getAllAsModel" && $responseHandler->validateResponse($response) && $this->_util->isNumericArray($response['body']['data'])){ + foreach($response['body']['data'] as $object){ + $convertedResponse[] = $responseHandler->convertResponse($object, $model->getServiceResource()); + } + }elseif($method === "getAll" && $responseHandler->validateResponse($response)){ $convertedResponse = $response['body']['data']; - }elseif($responseHandler->validateResponse($response)){ - $convertedResponse = $responseHandler->convertResponse($response['body']['data'], $model->getServiceResource()); - }else{ - $convertedResponse = $responseHandler->convertErrorToModel($response, $model->getServiceResource()); - } + }elseif($responseHandler->validateResponse($response)){ + $convertedResponse = $responseHandler->convertResponse($response['body']['data'], $model->getServiceResource()); + }else{ + $convertedResponse = $responseHandler->convertErrorToModel($response, $model->getServiceResource()); + } } catch (\Exception $e) { $errorModel = new Error(); $convertedResponse = $errorModel->setErrorMessage($e->getMessage());