Skip to content

Commit

Permalink
Merge pull request #28 from ruudk/omnipay-v3
Browse files Browse the repository at this point in the history
Upgrade to Omnipay v3
  • Loading branch information
barryvdh committed May 25, 2018
2 parents 6d7a6d6 + 5a4b2ea commit 532adb6
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 65 deletions.
30 changes: 22 additions & 8 deletions .travis.yml
@@ -1,17 +1,31 @@
language: php

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

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

## Cache composer
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
7 changes: 4 additions & 3 deletions composer.json
Expand Up @@ -27,14 +27,15 @@
"psr-4": { "Omnipay\\MultiSafepay\\" : "src/" }
},
"require": {
"omnipay/common": "~2.0"
"omnipay/common": "^3"
},
"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"
}
}
}
3 changes: 0 additions & 3 deletions phpunit.xml.dist
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
7 changes: 4 additions & 3 deletions src/Message/CompletePurchaseRequest.php
Expand Up @@ -41,15 +41,16 @@ public function getData()
*/
public function sendData($data)
{
$httpResponse = $this->httpClient->post(
$httpResponse = $this->httpClient->request(
'POST',
$this->getEndpoint(),
$this->getHeaders(),
$data->asXML()
)->send();
);

$this->response = new CompletePurchaseResponse(
$this,
$httpResponse->xml()
simplexml_load_string($httpResponse->getBody()->getContents())
);

return $this->response;
Expand Down
1 change: 0 additions & 1 deletion src/Message/CompletePurchaseResponse.php
Expand Up @@ -49,7 +49,6 @@ public function isInitialized()
public function isUncleared()
{
return $this->getPaymentStatus() === 'uncleared';

}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Message/FetchIssuersRequest.php
Expand Up @@ -36,15 +36,16 @@ public function getData()
*/
public function sendData($data)
{
$httpResponse = $this->httpClient->post(
$httpResponse = $this->httpClient->request(
'POST',
$this->getEndpoint(),
$this->getHeaders(),
$data->asXML()
)->send();
);

$this->response = new FetchIssuersResponse(
$this,
$httpResponse->xml()
simplexml_load_string($httpResponse->getBody()->getContents())
);

return $this->response;
Expand Down
7 changes: 4 additions & 3 deletions src/Message/FetchPaymentMethodsRequest.php
Expand Up @@ -59,15 +59,16 @@ public function getData()
*/
public function sendData($data)
{
$httpResponse = $this->httpClient->post(
$httpResponse = $this->httpClient->request(
'POST',
$this->getEndpoint(),
$this->getHeaders(),
$data->asXML()
)->send();
);

$this->response = new FetchPaymentMethodsResponse(
$this,
$httpResponse->xml()
simplexml_load_string($httpResponse->getBody()->getContents())
);

return $this->response;
Expand Down
7 changes: 4 additions & 3 deletions src/Message/PurchaseRequest.php
Expand Up @@ -258,15 +258,16 @@ public function getData()
*/
public function sendData($data)
{
$httpResponse = $this->httpClient->post(
$httpResponse = $this->httpClient->request(
'POST',
$this->getEndpoint(),
$this->getHeaders(),
$data->asXML()
)->send();
);

$this->response = new PurchaseResponse(
$this,
$httpResponse->xml()
simplexml_load_string($httpResponse->getBody()->getContents())
);

return $this->response;
Expand Down
25 changes: 4 additions & 21 deletions src/Message/RestAbstractRequest.php
Expand Up @@ -6,7 +6,7 @@
namespace Omnipay\MultiSafepay\Message;

use Omnipay\Common\Message\AbstractRequest;
use Guzzle\Common\Event;
use Psr\Http\Message\ResponseInterface;

/**
* MultiSafepay Rest API Abstract Request class.
Expand Down Expand Up @@ -147,33 +147,16 @@ protected function getHeaders()
*
* @param $method
* @param $endpoint
* @param null $query
* @param null $data
* @return \Guzzle\Http\Message\Response
* @return ResponseInterface
*/
protected function sendRequest($method, $endpoint, $query = null, $data = null)
protected function sendRequest($method, $endpoint, $data = null)
{
$this->httpClient->getEventDispatcher()->addListener('request.error', function (Event $event) {
$response = $event['response'];
if ($response->isError()) {
$event->stopPropagation();
}
});

$httpRequest = $this->httpClient->createRequest(
return $this->httpClient->request(
$method,
$this->getEndpoint() . $endpoint,
$this->getHeaders(),
$data
);

// Add query parameters
if (is_array($query) && ! empty($query)) {
foreach ($query as $itemKey => $itemValue) {
$httpRequest->getQuery()->add($itemKey, $itemValue);
}
}

return $httpRequest->send();
}
}
2 changes: 1 addition & 1 deletion src/Message/RestCompletePurchaseRequest.php
Expand Up @@ -50,7 +50,7 @@ public function sendData($data)

$this->response = new RestCompletePurchaseResponse(
$this,
$httpResponse->json()
json_decode($httpResponse->getBody()->getContents(), true)
);

return $this->response;
Expand Down
2 changes: 1 addition & 1 deletion src/Message/RestFetchIssuersRequest.php
Expand Up @@ -58,7 +58,7 @@ public function sendData($data)

$this->response = new RestFetchIssuersResponse(
$this,
$httpResponse->json()
json_decode($httpResponse->getBody()->getContents(), true)
);

return $this->response;
Expand Down
4 changes: 2 additions & 2 deletions src/Message/RestFetchPaymentMethodsRequest.php
Expand Up @@ -72,11 +72,11 @@ public function getData()
*/
public function sendData($data)
{
$httpResponse = $this->sendRequest('GET', '/gateways', $data);
$httpResponse = $this->sendRequest('GET', '/gateways', json_encode($data));

$this->response = new RestFetchPaymentMethodsResponse(
$this,
$httpResponse->json()
json_decode($httpResponse->getBody()->getContents(), true)
);

return $this->response;
Expand Down
2 changes: 1 addition & 1 deletion src/Message/RestFetchTransactionRequest.php
Expand Up @@ -57,7 +57,7 @@ public function sendData($data)

$this->response = new RestFetchTransactionResponse(
$this,
$httpResponse->json()
json_decode($httpResponse->getBody()->getContents(), true)
);

return $this->response;
Expand Down
15 changes: 6 additions & 9 deletions src/Message/RestPurchaseRequest.php
Expand Up @@ -383,7 +383,7 @@ public function setGoogleAnalyticsCode($value)
return $this->setParameter('google_analytics', $value);
}

/**
/**
* Get items HTML
*
* @return string
Expand All @@ -393,7 +393,7 @@ public function setItemsHtml($itemsHtml)
$this->setParameter('itemsHtml', $itemsHtml);
}

/**
/**
* Get items HTML
*
* @return string
Expand Down Expand Up @@ -474,7 +474,7 @@ protected function getGatewayData()

/**
* Get itembag data.
*
*
* @return array
*/
protected function getItemBagData()
Expand Down Expand Up @@ -521,10 +521,7 @@ public function getData()

// When the gateway is set to IDEAL,
// the issuer parameter is required.
if (
$this->getType() == 'direct' &&
$this->getGateway() == 'IDEAL'
) {
if ($this->getType() == 'direct' && $this->getGateway() == 'IDEAL') {
$this->validate('issuer');
}

Expand Down Expand Up @@ -580,11 +577,11 @@ public function getData()
*/
public function sendData($data)
{
$httpResponse = $this->sendRequest('POST', '/orders', null, $data);
$httpResponse = $this->sendRequest('POST', '/orders', json_encode($data));

$this->response = new RestPurchaseResponse(
$this,
$httpResponse->json()
json_decode($httpResponse->getBody()->getContents(), true)
);

return $this->response;
Expand Down
5 changes: 2 additions & 3 deletions src/Message/RestRefundRequest.php
Expand Up @@ -67,13 +67,12 @@ public function sendData($data)
$httpResponse = $this->sendRequest(
'POST',
'/orders/' . $data['id'] . '/refunds',
null,
$data
json_encode($data)
);

$this->response = new RestRefundResponse(
$this,
$httpResponse->json()
json_decode($httpResponse->getBody()->getContents(), true)
);

return $this->response;
Expand Down

0 comments on commit 532adb6

Please sign in to comment.