Skip to content

Commit 098e133

Browse files
committed
Upgrade to omnipay/common 3.x
1 parent 13ecf41 commit 098e133

9 files changed

+77
-79
lines changed

.travis.yml

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
language: php
22

33
php:
4-
- 5.4
5-
- 5.5
6-
- 5.6
7-
- 7.0
84
- 7.1
9-
- hhvm
5+
- 7.2
106

117
env:
128
global:
139
- setup=basic
1410

1511
matrix:
1612
include:
17-
- php: 5.3
13+
- php: 7.1
1814
env: setup=lowest
19-
dist: precise
20-
- php: 5.5
21-
env: setup=stable
2215

2316
sudo: false
2417

@@ -27,7 +20,6 @@ before_install:
2720

2821
install:
2922
- if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist; fi
30-
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable; fi
3123
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi
3224

3325
script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text

composer.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727
"psr-4": { "Omnipay\\PayPal\\" : "src/" }
2828
},
2929
"require": {
30-
"omnipay/common": "~2.0"
30+
"omnipay/common": "^3@beta"
3131
},
3232
"require-dev": {
33-
"omnipay/tests": "~2.0"
33+
"omnipay/tests": "^3",
34+
"squizlabs/php_codesniffer": "^3",
35+
"phpro/grumphp": "^0.14"
3436
},
3537
"extra": {
3638
"branch-alias": {
37-
"dev-master": "2.3.x-dev"
39+
"dev-master": "3.0.x-dev"
3840
}
3941
},
40-
"minimum-stability": "dev"
42+
"minimum-stability": "dev",
43+
"prefer-stable": true
4144
}

grumphp.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
git_dir: .
3+
bin_dir: vendor/bin
4+
tasks:
5+
phpunit:
6+
config_file: ~
7+
testsuite: ~
8+
group: []
9+
always_execute: false
10+
phpcs:
11+
standard: PSR2
12+
warning_severity: ~
13+
ignore_patterns:
14+
- tests/
15+
triggered_by: [php]

src/Message/AbstractRequest.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
* Account; it also gives the merchant the flexibility to change payment
2525
* processors without having to re-do their technical integration. When using
2626
* PayPal Payments Pro (Payflow Edition) using Payflow Gateway integration,
27-
* merchants can use Transparent Redirect feature to help manage PCI compliance.
27+
* merchants can use Transparent Redirect feature to help manage PCI compliance.
2828
*
2929
* @link https://developer.paypal.com/docs/classic/products/payflow-gateway/
3030
* @link https://developer.paypal.com/docs/classic/express-checkout/gs_expresscheckout/
31-
* @link https://developer.paypal.com/docs/classic/products/ppp-payflow-edition/
31+
* @link https://developer.paypal.com/docs/classic/products/ppp-payflow-edition/
3232
* @link https://devtools-paypal.com/integrationwizard/
3333
* @link http://paypal.github.io/sdk/
3434
*/
@@ -320,11 +320,9 @@ protected function getItemData()
320320

321321
public function sendData($data)
322322
{
323-
$httpRequest = $this->httpClient->post($this->getEndpoint(), null, http_build_query($data, '', '&'));
324-
$httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35
325-
$httpResponse = $httpRequest->send();
323+
$httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], http_build_query($data, '', '&'));
326324

327-
return $this->createResponse($httpResponse->getBody());
325+
return $this->createResponse($httpResponse->getBody()->getContents());
328326
}
329327

330328
protected function getEndpoint()

src/Message/AbstractRestRequest.php

+16-32
Original file line numberDiff line numberDiff line change
@@ -122,39 +122,15 @@ protected function getEndpoint()
122122

123123
public function sendData($data)
124124
{
125-
// don't throw exceptions for 4xx errors
126-
$this->httpClient->getEventDispatcher()->addListener(
127-
'request.error',
128-
function ($event) {
129-
if ($event['response']->isClientError()) {
130-
$event->stopPropagation();
131-
}
132-
}
133-
);
134125

135126
// Guzzle HTTP Client createRequest does funny things when a GET request
136127
// has attached data, so don't send the data if the method is GET.
137128
if ($this->getHttpMethod() == 'GET') {
138-
$httpRequest = $this->httpClient->createRequest(
139-
$this->getHttpMethod(),
140-
$this->getEndpoint() . '?' . http_build_query($data),
141-
array(
142-
'Accept' => 'application/json',
143-
'Authorization' => 'Bearer ' . $this->getToken(),
144-
'Content-type' => 'application/json',
145-
)
146-
);
129+
$requestUrl = $this->getEndpoint() . '?' . http_build_query($data);
130+
$body = null;
147131
} else {
148-
$httpRequest = $this->httpClient->createRequest(
149-
$this->getHttpMethod(),
150-
$this->getEndpoint(),
151-
array(
152-
'Accept' => 'application/json',
153-
'Authorization' => 'Bearer ' . $this->getToken(),
154-
'Content-type' => 'application/json',
155-
),
156-
$this->toJSON($data)
157-
);
132+
$body = $this->toJSON($data);
133+
$requestUrl = $this->getEndpoint();
158134
}
159135

160136
// Might be useful to have some debug code here, PayPal especially can be
@@ -163,11 +139,19 @@ function ($event) {
163139
// echo "Data == " . json_encode($data) . "\n";
164140

165141
try {
166-
$httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35
167-
$httpResponse = $httpRequest->send();
142+
$httpResponse = $this->httpClient->request(
143+
$this->getHttpMethod(),
144+
$this->getEndpoint(),
145+
array(
146+
'Accept' => 'application/json',
147+
'Authorization' => 'Bearer ' . $this->getToken(),
148+
'Content-type' => 'application/json',
149+
),
150+
$body
151+
);
168152
// Empty response body should be parsed also as and empty array
169-
$body = $httpResponse->getBody(true);
170-
$jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array();
153+
$body = (string) $httpResponse->getBody()->getContents();
154+
$jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array();
171155
return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode());
172156
} catch (\Exception $e) {
173157
throw new InvalidResponseException(

src/Message/RestTokenRequest.php

+9-17
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,19 @@ protected function getEndpoint()
3030

3131
public function sendData($data)
3232
{
33-
// don't throw exceptions for 4xx errors
34-
$this->httpClient->getEventDispatcher()->addListener(
35-
'request.error',
36-
function ($event) {
37-
if ($event['response']->isClientError()) {
38-
$event->stopPropagation();
39-
}
40-
}
41-
);
42-
43-
$httpRequest = $this->httpClient->createRequest(
33+
$body = $data ? http_build_query($data, '', '&') : null;
34+
$httpResponse = $this->httpClient->request(
4435
$this->getHttpMethod(),
4536
$this->getEndpoint(),
46-
array('Accept' => 'application/json'),
47-
$data
37+
array(
38+
'Accept' => 'application/json',
39+
'Authorization' => 'Bearer ' . base64_encode("{$this->getClientId()}:{$this->getSecret()}"),
40+
),
41+
$body
4842
);
49-
50-
$httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send();
5143
// Empty response body should be parsed also as and empty array
52-
$body = $httpResponse->getBody(true);
53-
$jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array();
44+
$body = (string) $httpResponse->getBody()->getContents();
45+
$jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array();
5446
return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode());
5547
}
5648
}

tests/ExpressGatewayTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function testCompletePurchaseHttpOptions()
170170

171171
$response = $this->gateway->completePurchase(array(
172172
'amount' => '10.00',
173-
'currency' => 'BYR',
173+
'currency' => 'EUR',
174174
))->send();
175175

176176
$httpRequests = $this->getMockedRequests();
@@ -192,7 +192,7 @@ public function testCompletePurchaseCustomOptions()
192192

193193
$response = $this->gateway->completePurchase(array(
194194
'amount' => '10.00',
195-
'currency' => 'BYR',
195+
'currency' => 'EUR',
196196
'token' => 'CUSTOM_TOKEN',
197197
'payerid' => 'CUSTOM_PAYERID',
198198
))->send();

tests/Message/RestAuthorizeResponseTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class RestAuthorizeResponseTest extends TestCase
1111
public function testRestPurchaseWithoutCardSuccess()
1212
{
1313
$httpResponse = $this->getMockHttpResponse('RestPurchaseWithoutCardSuccess.txt');
14-
$response = new RestAuthorizeResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
14+
$data = json_decode($httpResponse->getBody()->getContents(), true);
15+
16+
$response = new RestAuthorizeResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
1517

1618
$this->assertTrue($response->isSuccessful());
1719
$this->assertSame('PAY-3TJ47806DA028052TKTQGVYI', $response->getTransactionReference());

tests/Message/RestResponseTest.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class RestResponseTest extends TestCase
99
public function testPurchaseSuccess()
1010
{
1111
$httpResponse = $this->getMockHttpResponse('RestPurchaseSuccess.txt');
12-
$response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
12+
$data = json_decode($httpResponse->getBody()->getContents(), true);
13+
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
1314

1415
$this->assertTrue($response->isSuccessful());
1516
$this->assertSame('44E89981F8714392Y', $response->getTransactionReference());
@@ -19,7 +20,8 @@ public function testPurchaseSuccess()
1920
public function testPurchaseFailure()
2021
{
2122
$httpResponse = $this->getMockHttpResponse('RestPurchaseFailure.txt');
22-
$response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
23+
$data = json_decode($httpResponse->getBody()->getContents(), true);
24+
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
2325

2426
$this->assertFalse($response->isSuccessful());
2527
$this->assertNull($response->getTransactionReference());
@@ -29,7 +31,9 @@ public function testPurchaseFailure()
2931
public function testCompletePurchaseSuccess()
3032
{
3133
$httpResponse = $this->getMockHttpResponse('RestCompletePurchaseSuccess.txt');
32-
$response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
34+
$data = json_decode($httpResponse->getBody()->getContents(), true);
35+
36+
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
3337

3438
$this->assertTrue($response->isSuccessful());
3539
$this->assertSame('9EA05739TH369572R', $response->getTransactionReference());
@@ -39,7 +43,9 @@ public function testCompletePurchaseSuccess()
3943
public function testCompletePurchaseFailure()
4044
{
4145
$httpResponse = $this->getMockHttpResponse('RestCompletePurchaseFailure.txt');
42-
$response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
46+
$data = json_decode($httpResponse->getBody()->getContents(), true);
47+
48+
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
4349

4450
$this->assertFalse($response->isSuccessful());
4551
$this->assertNull($response->getTransactionReference());
@@ -49,7 +55,9 @@ public function testCompletePurchaseFailure()
4955
public function testTokenFailure()
5056
{
5157
$httpResponse = $this->getMockHttpResponse('RestTokenFailure.txt');
52-
$response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
58+
$data = json_decode($httpResponse->getBody()->getContents(), true);
59+
60+
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
5361

5462
$this->assertFalse($response->isSuccessful());
5563
$this->assertSame('Client secret does not match for this client', $response->getMessage());
@@ -58,7 +66,9 @@ public function testTokenFailure()
5866
public function testAuthorizeSuccess()
5967
{
6068
$httpResponse = $this->getMockHttpResponse('RestAuthorizationSuccess.txt');
61-
$response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
69+
$data = json_decode($httpResponse->getBody()->getContents(), true);
70+
71+
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
6272

6373
$this->assertTrue($response->isSuccessful());
6474
$this->assertSame('58N7596879166930B', $response->getTransactionReference());
@@ -68,7 +78,9 @@ public function testAuthorizeSuccess()
6878
public function testCreateCardSuccess()
6979
{
7080
$httpResponse = $this->getMockHttpResponse('RestCreateCardSuccess.txt');
71-
$response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
81+
$data = json_decode($httpResponse->getBody()->getContents(), true);
82+
83+
$response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
7284

7385
$this->assertTrue($response->isSuccessful());
7486
$this->assertSame('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference());

0 commit comments

Comments
 (0)