From 3d503c178ea48514b3724d8918060bb95d9656c7 Mon Sep 17 00:00:00 2001 From: Andres Garcia Date: Tue, 12 Jun 2018 12:43:53 -0400 Subject: [PATCH] Support to omnipay version 3 (#8) * Update to omnipay 3 - Update to omnipay 3 is necessary to be able to work with laravel 5.6 Signed-off-by: Andres Garcia * Update Readme Signed-off-by: Andres Garcia * Change createRequest for request method Signed-off-by: Andres Garcia * Rewind stream to avoid null messages Signed-off-by: Andres Garcia * Update composer json and fix EOL Signed-off-by: Andres Garcia --- README.md | 2 +- composer.json | 7 ++++--- phpunit.xml.dist | 21 +++++++-------------- src/Gateway.php | 24 +++++++++++++++++++----- src/Message/AbstractRequest.php | 14 ++++++-------- src/Message/Response.php | 7 +++++-- 6 files changed, 42 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 5dfd6f8..f130e38 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ to your `composer.json` file: ```json { "require": { - "dranes/omnipay-paysimple": "1.2.*" + "dranes/omnipay-paysimple": "~2.0" } } ``` diff --git a/composer.json b/composer.json index 522f913..827552a 100755 --- a/composer.json +++ b/composer.json @@ -26,14 +26,15 @@ "psr-4": { "Omnipay\\Paysimple\\" : "src/" } }, "require": { - "omnipay/common": "~2.0" + "league/omnipay": "^3.0", + "squizlabs/php_codesniffer": "^3" }, "require-dev": { - "omnipay/tests": "~2.0" + "omnipay/tests": "^3.0" }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 84defe8..d212d94 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,22 @@ - + stopOnFailure="false" + syntaxCheck="false"> - - tests + + ./tests/ - src/ + ./src - - - - - - - \ No newline at end of file diff --git a/src/Gateway.php b/src/Gateway.php index 2049184..dfe8476 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -67,18 +67,18 @@ * } else { * $response = $transaction->getMessage(); * } - * - * // Retrieving bank accounts + * + * // Retrieving bank accounts * $response = $gateway->retrieveBankAccounts(['CustomerId' => '1234567'])->send(); * $accounts = $response->getMessage(); - * + * * // Retrieving credit card * $response = $gateway->retrieveCreditCards(['CustomerId' => '1234567'])->send(); * $accounts = $response->getMessage(); - * + * * // Delete a credit card * $response = $gateway->deleteCreditCard(['AccountId' => '635402'])->send(); - * + * * // Delete a bank account * $response = $gateway->deleteBankAccount(['AccountId' => '635402'])->send(); * @@ -93,6 +93,20 @@ public function getName() return 'Paysimple'; } + /** + * Get default parameters for this gateway + * + * @return void + */ + public function getDefaultParameters() + { + return [ + 'username' => '', + 'secret' => '', + 'testMode' => false + ]; + } + /** * Get the gateway username key * diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 06175eb..28ff25f 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -70,15 +70,13 @@ public function sendData($data, array $headers = null) $data = json_encode($data); } - $httpRequest = $this->httpClient->createRequest( - $this->getHttpMethod(), - $this->getEndPoint(), - $headers, - $data - ); - try { - $httpResponse = $httpRequest->send(); + $httpResponse = $this->httpClient->request( + $this->getHttpMethod(), + $this->getEndPoint(), + $headers, + $data + ); } catch (ClientErrorResponseException $e) { $httpResponse = $e->getResponse(); } diff --git a/src/Message/Response.php b/src/Message/Response.php index 6f7dba8..46b7b66 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -40,7 +40,8 @@ public function isCancelled() public function getMessage() { - return $this->response->json(); + $this->response->getBody()->rewind(); + return json_decode($this->response->getBody()->getContents(), true); } public function getCode() @@ -50,7 +51,9 @@ public function getCode() public function getTransactionReference() { - $json = $this->response->json(); + + $this->response->getBody()->rewind(); + $json = json_decode($this->response->getBody()->getContents(), true); return $json['Response']['Id']; }