Skip to content

Commit

Permalink
XOL-4975 Upgrade to Omnipay 3 (#22)
Browse files Browse the repository at this point in the history
* Upgrade to Omnipay 3

* Fixed code sniffer errors

* Enable composer cache on travis
  • Loading branch information
anush authored Jan 22, 2020
1 parent 9f3e0ff commit 78dfa34
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 77 deletions.
25 changes: 18 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm

# This triggers builds to run on the new TravisCI infrastructure.
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false

cache:
directories:
- $HOME/.composer/cache

env:
global:
- setup=basic

matrix:
allow_failures:
- php: hhvm
include:
- php: 5.6
env: setup=lowest

before_script:
- composer install -n --dev --prefer-source
install:
- if [[ $setup = 'basic' ]]; then travis_retry composer install --prefer-dist --no-interaction; fi
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi

script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@
"psr-4": { "Omnipay\\AuthorizeNet\\" : "src/" }
},
"require": {
"omnipay/common": "~2.5",
"omnipay/common": "^3",
"ext-json": "*",
"ext-simplexml": "*"
},
"require-dev": {
"omnipay/tests": "~2.0"
"omnipay/tests": "^3",
"squizlabs/php_codesniffer": "^3"
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
"dev-master": "3.0.x-dev"
}
}
},
"scripts": {
"test": "phpunit",
"check-style": "phpcs -p --standard=PSR2 src/",
"fix-style": "phpcbf -p --standard=PSR2 src/"
},
"prefer-stable": true
}
3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
<directory>./tests/</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" />
</listeners>
<filter>
<whitelist>
<directory>./src</directory>
Expand Down
4 changes: 2 additions & 2 deletions src/Message/AIMAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->response = new AIMResponse($this, $httpResponse->getBody());
return $this->response = new AIMResponse($this, $httpResponse->getBody()->getContents());
}

/**
Expand Down
26 changes: 12 additions & 14 deletions src/Message/AIMResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function isSuccessful()
*/
public function getResultCode()
{
return intval((string)$this->data->transactionResponse[0]->responseCode);
return intval((string)$this->data->transactionResponse->responseCode);
}

/**
Expand All @@ -60,13 +60,12 @@ public function getReasonCode()
{
$code = null;

if (isset($this->data->transactionResponse[0]->messages)) {
if (isset($this->data->transactionResponse->messages)) {
// In case of a successful transaction, a "messages" element is present
$code = intval((string)$this->data->transactionResponse[0]->messages[0]->message[0]->code);

} elseif (isset($this->data->transactionResponse[0]->errors)) {
$code = intval((string)$this->data->transactionResponse->messages->message->code);
} elseif (isset($this->data->transactionResponse->errors)) {
// In case of an unsuccessful transaction, an "errors" element is present
$code = intval((string)$this->data->transactionResponse[0]->errors[0]->error[0]->errorCode);
$code = intval((string)$this->data->transactionResponse->errors->error->errorCode);
}

return $code;
Expand All @@ -81,21 +80,20 @@ public function getMessage()
{
$message = null;

if (isset($this->data->transactionResponse[0]->messages)) {
if (isset($this->data->transactionResponse->messages)) {
// In case of a successful transaction, a "messages" element is present
$message = (string)$this->data->transactionResponse[0]->messages[0]->message[0]->description;

} elseif (isset($this->data->transactionResponse[0]->errors)) {
$message = (string)$this->data->transactionResponse->messages->message->description;
} elseif (isset($this->data->transactionResponse->errors)) {
// In case of an unsuccessful transaction, an "errors" element is present
$message = (string)$this->data->transactionResponse[0]->errors[0]->error[0]->errorText;
$message = (string)$this->data->transactionResponse->errors->error->errorText;
}

return $message;
}

public function getAuthorizationCode()
{
return (string)$this->data->transactionResponse[0]->authCode;
return (string)$this->data->transactionResponse->authCode;
}

/**
Expand All @@ -105,7 +103,7 @@ public function getAuthorizationCode()
*/
public function getAVSCode()
{
return (string)$this->data->transactionResponse[0]->avsResultCode;
return (string)$this->data->transactionResponse->avsResultCode;
}

/**
Expand All @@ -118,7 +116,7 @@ public function getAVSCode()
public function getTransactionReference($serialize = true)
{
if ($this->isSuccessful()) {
$body = $this->data->transactionResponse[0];
$body = $this->data->transactionResponse;
$transactionRef = new TransactionReference();
$transactionRef->setApprovalCode((string)$body->authCode);
$transactionRef->setTransId((string)$body->transId);
Expand Down
4 changes: 2 additions & 2 deletions src/Message/CIMAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->response = new CIMResponse($this, $httpResponse->getBody());
return $this->response = new CIMResponse($this, $httpResponse->getBody()->getContents());
}
}
5 changes: 1 addition & 4 deletions src/Message/CIMAbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(RequestInterface $request, $data)
// Check if this is an error response
$isError = strpos((string)$data, '<ErrorResponse');

$xmlRootElement = $isError !== false ? 'ErrorResponse' : $this->responseType;
$xmlRootElement = ($isError !== false ? 'ErrorResponse' : $this->responseType);
// Strip out the xmlns junk so that PHP can parse the XML
$xml = preg_replace('/<' . $xmlRootElement . '[^>]+>/', '<' . $xmlRootElement . '>', (string)$data);

Expand Down Expand Up @@ -58,7 +58,6 @@ public function getResultCode()
return 3;
default:
return null;

}
}

Expand Down Expand Up @@ -125,8 +124,6 @@ public function getCardReference()
}

/**
* http://bookofzeus.com/articles/convert-simplexml-object-into-php-array/
*
* Convert a simpleXMLElement in to an array
*
* @param \SimpleXMLElement $xml
Expand Down
1 change: 0 additions & 1 deletion src/Message/CIMAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ protected function addPayment(\SimpleXMLElement $data)
if ($this->isCardPresent()) {
// Prefer the track data if present over the payment profile (better rate)
return parent::addPayment($data);

} else {
$this->validate('cardReference');

Expand Down
4 changes: 2 additions & 2 deletions src/Message/CIMCreateCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

$response = new CIMCreateCardResponse($this, $httpResponse->getBody());
$response = new CIMCreateCardResponse($this, $httpResponse->getBody()->getContents());

if (!$response->isSuccessful() && $response->getReasonCode() == 'E00039') {
// Duplicate profile. Try adding a new payment profile for the same profile and get the response
Expand Down
4 changes: 2 additions & 2 deletions src/Message/CIMCreatePaymentProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->response = new CIMCreatePaymentProfileResponse($this, $httpResponse->getBody());
return $this->response = new CIMCreatePaymentProfileResponse($this, $httpResponse->getBody()->getContents());
}
}
4 changes: 2 additions & 2 deletions src/Message/CIMGetPaymentProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->response = new CIMGetPaymentProfileResponse($this, $httpResponse->getBody());
return $this->response = new CIMGetPaymentProfileResponse($this, $httpResponse->getBody()->getContents());
}
}
4 changes: 2 additions & 2 deletions src/Message/CIMGetProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->response = new CIMGetProfileResponse($this, $httpResponse->getBody());
return $this->response = new CIMGetProfileResponse($this, $httpResponse->getBody()->getContents());
}
}
4 changes: 2 additions & 2 deletions src/Message/CIMUpdatePaymentProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function sendData($data)
{
$headers = array('Content-Type' => 'text/xml; charset=utf-8');
$data = $data->saveXml();
$httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), $headers, $data);

return $this->response = new CIMUpdatePaymentProfileResponse($this, $httpResponse->getBody());
return $this->response = new CIMUpdatePaymentProfileResponse($this, $httpResponse->getBody()->getContents());
}
}
4 changes: 2 additions & 2 deletions src/Message/SIMAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ protected function getBillingData()

public function sendData($data)
{
$httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send();
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], http_build_query($data));

return $this->response = new AIMResponse($this, $httpResponse->getBody());
return $this->response = new AIMResponse($this, $httpResponse->getBody()->getContents());
}

public function getEndpoint()
Expand Down
1 change: 1 addition & 0 deletions tests/CIMGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public function testPurchaseFailure()

public function testRefundSuccess()
{
self::markTestSkipped();
// $this->setMockHttpResponse('CIMRefundSuccess.txt');
//
// $response = $this->gateway->refund($this->refundOptions)->send();
Expand Down
10 changes: 5 additions & 5 deletions tests/Message/AIMAbstractRequestTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php


namespace Message;


use Omnipay\AuthorizeNet\Message\AIMAbstractRequest;
use Omnipay\Common\Http\ClientInterface;
use Omnipay\Tests\TestCase;

class AIMAbstractRequestTest extends \PHPUnit_Framework_TestCase
class AIMAbstractRequestTest extends TestCase
{
/** @var AIMAbstractRequest */
private $request;
Expand All @@ -16,8 +16,8 @@ public function setUp()
$this->request = $this->getMockForAbstractClass(
'\Omnipay\AuthorizeNet\Message\AIMAbstractRequest',
array(
$this->getMock('\Guzzle\Http\ClientInterface'),
$this->getMock('\Symfony\Component\HttpFoundation\Request')
$this->createMock(ClientInterface::class),
$this->createMock('\Symfony\Component\HttpFoundation\Request')
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/AIMResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getMockRequest($className = '\Omnipay\AuthorizeNet\Message\AIMAb

public function testConstructEmpty()
{
$this->setExpectedException('\Omnipay\Common\Exception\InvalidResponseException');
$this->expectException('\Omnipay\Common\Exception\InvalidResponseException');
new AIMResponse($this->getMockRequest(), '');
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMCreateCardFailure.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMCreateCardFailureWithDuplicate.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMCreateCardSuccess.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml;charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMCreatePaymentProfileFailure.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMCreatePaymentProfileFailureMaxProfileLimit.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMCreatePaymentProfileSuccess.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMGetMultipleProfilesSuccess.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
3 changes: 1 addition & 2 deletions tests/Mock/CIMGetPaymentProfileSuccess.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 746
Content-Type: text/xml;
charset=utf-8
Content-Type: text/xml;charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Expand Down
Loading

0 comments on commit 78dfa34

Please sign in to comment.