diff --git a/.travis.yml b/.travis.yml index 0dfa3e6..8f96ad7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,35 @@ language: php php: - - 5.3 - - 5.4 - - 5.5 - 5.6 - - hhvm + - 7.0 + - 7.1 + - 7.2 + - 7.3 -before_script: - - composer install -n --dev --prefer-source - - composer require satooshi/php-coveralls --dev +# This triggers builds to run on the new TravisCI infrastructure. +# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ +sudo: false -script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml +## Cache composer +cache: + directories: + - $HOME/.composer/cache -after_script: -- php vendor/bin/coveralls -v +env: + global: + - symfony="*" + +matrix: + include: + - php: 5.6 + env: symfony="^2.1" + - php: 5.6 + env: symfony="^3" + - php: 7.1 + env: symfony="^4" + +install: + - if [[ $symfony != '*' ]]; then travis_retry composer require symfony/http-foundation:${symfony} --no-update --no-interaction; fi + +script: composer install --prefer-dist --no-interaction diff --git a/composer.json b/composer.json index 71bfc3a..d27c0ff 100644 --- a/composer.json +++ b/composer.json @@ -23,14 +23,17 @@ "psr-4": { "Omnipay\\Beanstream\\" : "src/" } }, "require": { - "omnipay/common": "~2.0" + "php": "^5.6|^7", + "omnipay/common": "^3", + "php-http/guzzle6-adapter": "^1.1" }, "require-dev": { - "omnipay/tests": "~2.0" + "omnipay/tests": "^3.1" }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } - } + }, + "prefer-stable": true } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a35b736..535809e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,9 +14,6 @@ ./tests/ - - - ./src diff --git a/src/Message/AbstractProfileRequest.php b/src/Message/AbstractProfileRequest.php index d9db67f..e84cd67 100644 --- a/src/Message/AbstractProfileRequest.php +++ b/src/Message/AbstractProfileRequest.php @@ -37,41 +37,28 @@ public function setComment($value) public function sendData($data) { $header = base64_encode($this->getMerchantId() . ':' . $this->getApiPasscode()); - // Don't throw exceptions for 4xx errors - $this->httpClient->getEventDispatcher()->addListener( - 'request.error', - function ($event) { - if ($event['response']->isClientError()) { - $event->stopPropagation(); - } - } - ); - + if (!empty($data)) { - $httpRequest = $this->httpClient->createRequest( + $httpResponse = $this->httpClient->request( $this->getHttpMethod(), $this->getEndpoint(), - null, + [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Passcode ' . $header, + ], json_encode($data) ); } else { - $httpRequest = $this->httpClient->createRequest( + $httpResponse = $this->httpClient->request( $this->getHttpMethod(), - $this->getEndpoint() + $this->getEndpoint(), + [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Passcode ' . $header, + ] ); } - $httpResponse = $httpRequest - ->setHeader( - 'Content-Type', - 'application/json' - ) - ->setHeader( - 'Authorization', - 'Passcode ' . $header - ) - ->send(); - - return $this->response = new ProfileResponse($this, $httpResponse->json()); + return $this->response = new ProfileResponse($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index caa103f..1258d23 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -147,41 +147,28 @@ public function getHttpMethod() public function sendData($data) { $header = base64_encode($this->getMerchantId() . ':' . $this->getApiPasscode()); - // Don't throw exceptions for 4xx errors - $this->httpClient->getEventDispatcher()->addListener( - 'request.error', - function ($event) { - if ($event['response']->isClientError()) { - $event->stopPropagation(); - } - } - ); - + if (!empty($data)) { - $httpRequest = $this->httpClient->createRequest( + $httpResponse = $this->httpClient->request( $this->getHttpMethod(), $this->getEndpoint(), - null, + [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Passcode ' . $header, + ], json_encode($data) ); } else { - $httpRequest = $this->httpClient->createRequest( + $httpResponse = $this->httpClient->request( $this->getHttpMethod(), - $this->getEndpoint() + $this->getEndpoint(), + [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Passcode ' . $header, + ] ); } - $httpResponse = $httpRequest - ->setHeader( - 'Content-Type', - 'application/json' - ) - ->setHeader( - 'Authorization', - 'Passcode ' . $header - ) - ->send(); - - return $this->response = new Response($this, $httpResponse->json()); + return $this->response = new Response($this, $httpResponse->getBody()->getContents()); } } diff --git a/src/Message/Response.php b/src/Message/Response.php index 8be4967..46832e5 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -5,6 +5,12 @@ class Response extends AbstractResponse { + public function __construct(RequestInterface $request, $data) + { + $this->request = $request; + $this->data = json_decode($data, true); + } + public function isSuccessful() { return (isset($this->data['approved']) && $this->data['approved'] === "1"); diff --git a/tests/Message/AuthorizeRequestTest.php b/tests/Message/AuthorizeRequestTest.php index 68f5d28..8496e0c 100644 --- a/tests/Message/AuthorizeRequestTest.php +++ b/tests/Message/AuthorizeRequestTest.php @@ -186,7 +186,7 @@ public function testComplete() 'number' => '4111111111111111', 'cvd' => '123', 'expiry_month' => '01', - 'expiry_year' => '2018' + 'expiry_year' => '2020' ); $this->request->setCard($card); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 45eb147..42a610a 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -174,7 +174,7 @@ public function testComplete() 'number' => '4111111111111111', 'cvd' => '123', 'expiry_month' => '01', - 'expiry_year' => '2018' + 'expiry_year' => '2020' ); $this->request->setCard($card); diff --git a/tests/Message/ResponseTest.php b/tests/Message/ResponseTest.php index 1181e6f..c690673 100644 --- a/tests/Message/ResponseTest.php +++ b/tests/Message/ResponseTest.php @@ -9,7 +9,7 @@ class ResponseTest extends TestCase public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertSame('1000001', $response->getTransactionReference()); $this->assertSame('1', $response->getOrderNumber()); @@ -30,7 +30,7 @@ public function testPurchaseSuccess() public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertSame(49, $response->getCode()); $this->assertSame(3, $response->getCategory()); $this->assertSame('Invalid transaction request string', $response->getMessage()); @@ -48,7 +48,7 @@ public function testPurchaseFailure() public function testAuthorizeSuccess() { $httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertSame('1000001', $response->getTransactionReference()); $this->assertSame('1', $response->getOrderNumber()); @@ -69,7 +69,7 @@ public function testAuthorizeSuccess() public function testAuthorizeFailure() { $httpResponse = $this->getMockHttpResponse('AuthorizeFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertSame(49, $response->getCode()); $this->assertSame(3, $response->getCategory()); $this->assertSame('Invalid transaction request string', $response->getMessage());