diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
new file mode 100644
index 0000000..e9229c0
--- /dev/null
+++ b/.github/workflows/run-tests.yml
@@ -0,0 +1,47 @@
+name: Unit Tests
+
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ branches:
+ - "*"
+ schedule:
+ - cron: '0 0 * * *'
+
+jobs:
+ php-tests:
+ runs-on: ubuntu-latest
+ timeout-minutes: 15
+ env:
+ COMPOSER_NO_INTERACTION: 1
+
+ strategy:
+ matrix:
+ php: [8.1, 8.0, 7.4, 7.3, 7.2]
+ dependency-version: [prefer-lowest, prefer-stable]
+
+ name: P${{ matrix.php }} - ${{ matrix.dependency-version }}
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ coverage: none
+ tools: composer:v2
+
+ - name: Install dependencies
+ run: |
+ composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
+
+ - name: Execute Unit Tests
+ run: composer test
+
+ - name: Check Code Style
+ run: composer check-style
+ if: ${{ matrix.dependency-version == 'prefer-stable' }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 77109ff..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-language: php
-
-php:
- - 5.4
- - 5.5
- - 5.6
- - 7.0
- - 7.1
- - hhvm
-
-env:
- global:
- - setup=basic
-
-matrix:
- include:
- - php: 5.3
- env: setup=lowest
- dist: precise
- - php: 5.5
- env: setup=stable
-
-sudo: false
-
-before_install:
- - travis_retry composer self-update
-
-install:
- - if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist; fi
- - if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable; 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
diff --git a/README.md b/README.md
index f9c29b6..8d70713 100644
--- a/README.md
+++ b/README.md
@@ -2,30 +2,21 @@
**PayPal driver for the Omnipay PHP payment processing library**
-[](https://travis-ci.org/thephpleague/omnipay-paypal)
+[](https://github.com/thephpleague/omnipay-paypal/actions/workflows/run-tests.yml)
[](https://packagist.org/packages/omnipay/paypal)
[](https://packagist.org/packages/omnipay/paypal)
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
-processing library for PHP 5.3+. This package implements PayPal support for Omnipay.
+processing library for PHP. This package implements PayPal support for Omnipay.
## Installation
-Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it
-to your `composer.json` file:
+Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `omnipay/paypal` with Composer:
-```json
-{
- "require": {
- "omnipay/paypal": "~2.0"
- }
-}
+```
+composer require league/omnipay omnipay/paypal
```
-And run composer to update your dependencies:
-
- $ curl -s http://getcomposer.org/installer | php
- $ php composer.phar update
## Basic Usage
diff --git a/composer.json b/composer.json
index d7e259d..100c82d 100644
--- a/composer.json
+++ b/composer.json
@@ -27,15 +27,22 @@
"psr-4": { "Omnipay\\PayPal\\" : "src/" }
},
"require": {
- "omnipay/common": "~2.0"
+ "php": "^7.2|^8.0",
+ "omnipay/common": "^3"
},
"require-dev": {
- "omnipay/tests": "~2.0"
+ "omnipay/tests": "^4.1.2",
+ "squizlabs/php_codesniffer": "^3"
},
"extra": {
"branch-alias": {
- "dev-master": "2.3.x-dev"
+ "dev-master": "3.0.x-dev"
}
},
- "minimum-stability": "dev"
+ "scripts": {
+ "test": "phpunit",
+ "check-style": "phpcs -p --standard=PSR2 src/",
+ "fix-style": "phpcbf -p --standard=PSR2 src/"
+ },
+ "prefer-stable": true
}
diff --git a/grumphp.yml b/grumphp.yml
new file mode 100644
index 0000000..4b767a0
--- /dev/null
+++ b/grumphp.yml
@@ -0,0 +1,15 @@
+parameters:
+ git_dir: .
+ bin_dir: vendor/bin
+ tasks:
+ phpunit:
+ config_file: ~
+ testsuite: ~
+ group: []
+ always_execute: false
+ phpcs:
+ standard: PSR2
+ warning_severity: ~
+ ignore_patterns:
+ - tests/
+ triggered_by: [php]
\ No newline at end of file
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/AbstractRequest.php b/src/Message/AbstractRequest.php
index 0885093..532736c 100644
--- a/src/Message/AbstractRequest.php
+++ b/src/Message/AbstractRequest.php
@@ -24,11 +24,11 @@
* Account; it also gives the merchant the flexibility to change payment
* processors without having to re-do their technical integration. When using
* PayPal Payments Pro (Payflow Edition) using Payflow Gateway integration,
- * merchants can use Transparent Redirect feature to help manage PCI compliance.
+ * merchants can use Transparent Redirect feature to help manage PCI compliance.
*
* @link https://developer.paypal.com/docs/classic/products/payflow-gateway/
* @link https://developer.paypal.com/docs/classic/express-checkout/gs_expresscheckout/
- * @link https://developer.paypal.com/docs/classic/products/ppp-payflow-edition/
+ * @link https://developer.paypal.com/docs/classic/products/ppp-payflow-edition/
* @link https://devtools-paypal.com/integrationwizard/
* @link http://paypal.github.io/sdk/
*/
@@ -38,6 +38,11 @@ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
protected $liveEndpoint = 'https://api-3t.paypal.com/nvp';
protected $testEndpoint = 'https://api-3t.sandbox.paypal.com/nvp';
+
+ /**
+ * @var bool
+ */
+ protected $negativeAmountAllowed = true;
public function getUsername()
{
@@ -320,11 +325,9 @@ protected function getItemData()
public function sendData($data)
{
- $httpRequest = $this->httpClient->post($this->getEndpoint(), null, http_build_query($data, '', '&'));
- $httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35
- $httpResponse = $httpRequest->send();
+ $httpResponse = $this->httpClient->request('POST', $this->getEndpoint(), [], http_build_query($data, '', '&'));
- return $this->createResponse($httpResponse->getBody());
+ return $this->createResponse($httpResponse->getBody()->getContents());
}
protected function getEndpoint()
diff --git a/src/Message/AbstractRestRequest.php b/src/Message/AbstractRestRequest.php
index 19ef31e..8a9dbe0 100644
--- a/src/Message/AbstractRestRequest.php
+++ b/src/Message/AbstractRestRequest.php
@@ -62,6 +62,29 @@ abstract class AbstractRestRequest extends \Omnipay\Common\Message\AbstractReque
*/
protected $payerId = null;
+ protected $referrerCode;
+
+ /**
+ * @var bool
+ */
+ protected $negativeAmountAllowed = true;
+
+ /**
+ * @return string
+ */
+ public function getReferrerCode()
+ {
+ return $this->referrerCode;
+ }
+
+ /**
+ * @param string $referrerCode
+ */
+ public function setReferrerCode($referrerCode)
+ {
+ $this->referrerCode = $referrerCode;
+ }
+
public function getClientId()
{
return $this->getParameter('clientId');
@@ -122,39 +145,15 @@ protected function getEndpoint()
public function sendData($data)
{
- // don't throw exceptions for 4xx errors
- $this->httpClient->getEventDispatcher()->addListener(
- 'request.error',
- function ($event) {
- if ($event['response']->isClientError()) {
- $event->stopPropagation();
- }
- }
- );
// Guzzle HTTP Client createRequest does funny things when a GET request
// has attached data, so don't send the data if the method is GET.
if ($this->getHttpMethod() == 'GET') {
- $httpRequest = $this->httpClient->createRequest(
- $this->getHttpMethod(),
- $this->getEndpoint() . '?' . http_build_query($data),
- array(
- 'Accept' => 'application/json',
- 'Authorization' => 'Bearer ' . $this->getToken(),
- 'Content-type' => 'application/json',
- )
- );
+ $requestUrl = $this->getEndpoint() . '?' . http_build_query($data);
+ $body = null;
} else {
- $httpRequest = $this->httpClient->createRequest(
- $this->getHttpMethod(),
- $this->getEndpoint(),
- array(
- 'Accept' => 'application/json',
- 'Authorization' => 'Bearer ' . $this->getToken(),
- 'Content-type' => 'application/json',
- ),
- $this->toJSON($data)
- );
+ $body = $this->toJSON($data);
+ $requestUrl = $this->getEndpoint();
}
// Might be useful to have some debug code here, PayPal especially can be
@@ -163,11 +162,20 @@ function ($event) {
// echo "Data == " . json_encode($data) . "\n";
try {
- $httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35
- $httpResponse = $httpRequest->send();
+ $httpResponse = $this->httpClient->request(
+ $this->getHttpMethod(),
+ $this->getEndpoint(),
+ array(
+ 'Accept' => 'application/json',
+ 'Authorization' => 'Bearer ' . $this->getToken(),
+ 'Content-type' => 'application/json',
+ 'PayPal-Partner-Attribution-Id' => $this->getReferrerCode(),
+ ),
+ $body
+ );
// Empty response body should be parsed also as and empty array
- $body = $httpResponse->getBody(true);
- $jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array();
+ $body = (string) $httpResponse->getBody()->getContents();
+ $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array();
return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode());
} catch (\Exception $e) {
throw new InvalidResponseException(
diff --git a/src/Message/RestAuthorizeRequest.php b/src/Message/RestAuthorizeRequest.php
index 8694df0..19762f9 100644
--- a/src/Message/RestAuthorizeRequest.php
+++ b/src/Message/RestAuthorizeRequest.php
@@ -230,6 +230,7 @@ public function getData()
'total' => $this->getAmount(),
'currency' => $this->getCurrency(),
),
+ 'invoice_number' => $this->getTransactionId()
)
),
'experience_profile_id' => $this->getExperienceProfileId()
diff --git a/src/Message/RestCompletePurchaseRequest.php b/src/Message/RestCompletePurchaseRequest.php
index b246fce..4603755 100644
--- a/src/Message/RestCompletePurchaseRequest.php
+++ b/src/Message/RestCompletePurchaseRequest.php
@@ -29,8 +29,8 @@
*
* // Once the transaction has been approved, we need to complete it.
* $transaction = $gateway->completePurchase(array(
- * 'payer_id' => $payer_id,
- * 'transactionReference' => $sale_id,
+ * 'payer_id' => $payerId,
+ * 'transactionReference' => $paymentId,
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
diff --git a/src/Message/RestCreateWebhookRequest.php b/src/Message/RestCreateWebhookRequest.php
new file mode 100644
index 0000000..24842ef
--- /dev/null
+++ b/src/Message/RestCreateWebhookRequest.php
@@ -0,0 +1,66 @@
+ \array_map(
+ function ($value) {
+ return ['name' => $value];
+ },
+ $this->getEventTypes()
+ ),
+ 'url' => $this->getUrl(),
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ public function getEventTypes()
+ {
+ return $this->getParameter('event_types') ?: [];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getEndpoint()
+ {
+ return parent::getEndpoint().'/notifications/webhooks';
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getUrl()
+ {
+ return $this->getParameter('webhook_url');
+ }
+
+ /**
+ * @param array $eventTypes
+ *
+ * @return $this
+ */
+ public function setEventTypes(array $eventTypes)
+ {
+ return $this->setParameter('event_types', $eventTypes);
+ }
+
+ /**
+ * @param string $url
+ *
+ * @return $this
+ */
+ public function setUrl($url)
+ {
+ return $this->setParameter('webhook_url', $url);
+ }
+}
diff --git a/src/Message/RestListWebhooksRequest.php b/src/Message/RestListWebhooksRequest.php
new file mode 100755
index 0000000..30a67a0
--- /dev/null
+++ b/src/Message/RestListWebhooksRequest.php
@@ -0,0 +1,37 @@
+httpClient->getEventDispatcher()->addListener(
- 'request.error',
- function ($event) {
- if ($event['response']->isClientError()) {
- $event->stopPropagation();
- }
- }
- );
-
- $httpRequest = $this->httpClient->createRequest(
+ $body = $data ? http_build_query($data, '', '&') : null;
+ $httpResponse = $this->httpClient->request(
$this->getHttpMethod(),
$this->getEndpoint(),
- array('Accept' => 'application/json'),
- $data
+ array(
+ 'Accept' => 'application/json',
+ 'Authorization' => 'Basic ' . base64_encode("{$this->getClientId()}:{$this->getSecret()}"),
+ ),
+ $body
);
-
- $httpResponse = $httpRequest->setAuth($this->getClientId(), $this->getSecret())->send();
// Empty response body should be parsed also as and empty array
- $body = $httpResponse->getBody(true);
- $jsonToArrayResponse = !empty($body) ? $httpResponse->json() : array();
+ $body = (string) $httpResponse->getBody()->getContents();
+ $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array();
return $this->response = new RestResponse($this, $jsonToArrayResponse, $httpResponse->getStatusCode());
}
}
diff --git a/src/Message/RestVerifyWebhookSignatureRequest.php b/src/Message/RestVerifyWebhookSignatureRequest.php
new file mode 100644
index 0000000..f96c6a3
--- /dev/null
+++ b/src/Message/RestVerifyWebhookSignatureRequest.php
@@ -0,0 +1,170 @@
+getParameter('auth_algo');
+ }
+
+ /**
+ * @return string
+ */
+ public function getCertUrl()
+ {
+ return $this->getParameter('cert_url');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getData()
+ {
+ return [
+ 'transmission_id' => $this->getTransmissionId(),
+ 'auth_algo' => $this->getAuthAlgo(),
+ 'cert_url' => $this->getCertUrl(),
+ 'transmission_sig' => $this->getTransmissionSig(),
+ 'transmission_time' => $this->getTransmissionTime(),
+ 'webhook_event' => $this->getWebhookEvent(),
+ 'webhook_id' => $this->getWebhookId(),
+ ];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getEndpoint()
+ {
+ return parent::getEndpoint().'/notifications/verify-webhook-signature';
+ }
+
+ /**
+ * @return string
+ */
+ public function getTransmissionId()
+ {
+ return $this->getParameter('transmission_id');
+ }
+
+ /**
+ * @return string
+ */
+ public function getTransmissionSig()
+ {
+ return $this->getParameter('transmission_sig');
+ }
+
+ /**
+ * @return string
+ */
+ public function getTransmissionTime()
+ {
+ return $this->getParameter('transmission_time');
+ }
+
+ /**
+ * @return string
+ */
+ public function getWebhookEvent()
+ {
+ return $this->getParameter('webhook_event');
+ }
+
+ /**
+ * @return string
+ */
+ public function getWebhookId()
+ {
+ return $this->getParameter('webhook_id');
+ }
+
+ /**
+ * @param string $authAlgo
+ *
+ * @return $this
+ */
+ public function setAuthAlgo($authAlgo)
+ {
+ return $this->setParameter('auth_algo', $authAlgo);
+ }
+
+ /**
+ * @param string $certUrl
+ *
+ * @return $this
+ */
+ public function setCertUrl($certUrl)
+ {
+ return $this->setParameter('cert_url', $certUrl);
+ }
+
+ /**
+ * @param string $transmissionId
+ *
+ * @return $this
+ */
+ public function setTransmissionId($transmissionId)
+ {
+ return $this->setParameter('transmission_id', $transmissionId);
+ }
+
+ /**
+ * @param string $transmissionSig
+ *
+ * @return $this
+ */
+ public function setTransmissionSig($transmissionSig)
+ {
+ return $this->setParameter('transmission_sig', $transmissionSig);
+ }
+
+ /**
+ * @param string $transmissionTime
+ *
+ * @return $this
+ */
+ public function setTransmissionTime($transmissionTime)
+ {
+ return $this->setParameter('transmission_time', $transmissionTime);
+ }
+
+ /**
+ * @param array $webhookEvent
+ *
+ * @return $this
+ */
+ public function setWebhookEvent(array $webhookEvent)
+ {
+ return $this->setParameter('webhook_event', $webhookEvent);
+ }
+
+ /**
+ * @param string $webhookId
+ *
+ * @return $this
+ */
+ public function setWebhookId($webhookId)
+ {
+ return $this->setParameter('webhook_id', $webhookId);
+ }
+
+ /**
+ * @param $data
+ * @param $statusCode
+ *
+ * @return RestVerifyWebhookSignatureResponse
+ */
+ protected function createResponse($data, $statusCode)
+ {
+ return $this->response = new RestVerifyWebhookSignatureResponse($this, $data, $statusCode);
+ }
+}
diff --git a/src/Message/RestVerifyWebhookSignatureResponse.php b/src/Message/RestVerifyWebhookSignatureResponse.php
new file mode 100644
index 0000000..96d54d3
--- /dev/null
+++ b/src/Message/RestVerifyWebhookSignatureResponse.php
@@ -0,0 +1,31 @@
+getVerificationStatus();
+ }
+
+ /**
+ * The status of the signature verification. Value is `SUCCESS` or `FAILURE`.
+ *
+ * @return string
+ */
+ public function getVerificationStatus()
+ {
+ return $this->data['verification_status'];
+ }
+}
diff --git a/src/RestGateway.php b/src/RestGateway.php
index 7013053..d6ae4f3 100644
--- a/src/RestGateway.php
+++ b/src/RestGateway.php
@@ -9,6 +9,9 @@
use Omnipay\PayPal\Message\ProAuthorizeRequest;
use Omnipay\PayPal\Message\CaptureRequest;
use Omnipay\PayPal\Message\RefundRequest;
+use Omnipay\PayPal\Message\RestCreateWebhookRequest;
+use Omnipay\PayPal\Message\RestListWebhooksRequest;
+use Omnipay\PayPal\Message\RestVerifyWebhookSignatureRequest;
/**
* PayPal Pro Class using REST API
@@ -416,6 +419,16 @@ public function completePurchase(array $parameters = array())
return $this->createRequest('\Omnipay\PayPal\Message\RestCompletePurchaseRequest', $parameters);
}
+ /**
+ * @param array $parameters
+ *
+ * @return RestCreateWebhookRequest
+ */
+ public function createWebhook(array $parameters = [])
+ {
+ return $this->createRequest(RestCreateWebhookRequest::class, $parameters);
+ }
+
// TODO: Update a payment resource https://developer.paypal.com/docs/api/#update-a-payment-resource
//
@@ -710,6 +723,26 @@ public function searchTransaction(array $parameters = array())
return $this->createRequest('\Omnipay\PayPal\Message\RestSearchTransactionRequest', $parameters);
}
+ /**
+ * @param array $parameters
+ *
+ * @return RestListWebhooksRequest
+ */
+ public function listWebhooks(array $parameters = [])
+ {
+ return $this->createRequest(RestListWebhooksRequest::class, $parameters);
+ }
+
+ /**
+ * @param array $parameters
+ *
+ * @return RestVerifyWebhookSignatureRequest
+ */
+ public function verifyWebhookSignature(array $parameters = [])
+ {
+ return $this->createRequest(RestVerifyWebhookSignatureRequest::class, $parameters);
+ }
+
// TODO: Update an agreement
// TODO: Retrieve an agreement
// TODO: Set outstanding agreement amounts
diff --git a/tests/ExpressGatewayTest.php b/tests/ExpressGatewayTest.php
index 186f692..9721f4a 100644
--- a/tests/ExpressGatewayTest.php
+++ b/tests/ExpressGatewayTest.php
@@ -21,7 +21,7 @@ class ExpressGatewayTest extends GatewayTestCase
*/
protected $voidOptions;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -170,7 +170,7 @@ public function testCompletePurchaseHttpOptions()
$response = $this->gateway->completePurchase(array(
'amount' => '10.00',
- 'currency' => 'BYR',
+ 'currency' => 'EUR',
))->send();
$httpRequests = $this->getMockedRequests();
@@ -192,7 +192,7 @@ public function testCompletePurchaseCustomOptions()
$response = $this->gateway->completePurchase(array(
'amount' => '10.00',
- 'currency' => 'BYR',
+ 'currency' => 'EUR',
'token' => 'CUSTOM_TOKEN',
'payerid' => 'CUSTOM_PAYERID',
))->send();
diff --git a/tests/ExpressInContextGatewayTest.php b/tests/ExpressInContextGatewayTest.php
index b1a0b79..cfc5f86 100644
--- a/tests/ExpressInContextGatewayTest.php
+++ b/tests/ExpressInContextGatewayTest.php
@@ -21,7 +21,7 @@ class ExpressInContextGatewayTest extends GatewayTestCase
*/
protected $voidOptions;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/CaptureRequestTest.php b/tests/Message/CaptureRequestTest.php
index 104ebd6..f68f8f8 100644
--- a/tests/Message/CaptureRequestTest.php
+++ b/tests/Message/CaptureRequestTest.php
@@ -12,7 +12,7 @@ class CaptureRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/ExpressAuthorizeRequestTest.php b/tests/Message/ExpressAuthorizeRequestTest.php
index 1b9b5fe..e3913d8 100644
--- a/tests/Message/ExpressAuthorizeRequestTest.php
+++ b/tests/Message/ExpressAuthorizeRequestTest.php
@@ -3,6 +3,7 @@
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
+use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\PayPal\Message\ExpressAuthorizeRequest;
use Omnipay\PayPal\Support\InstantUpdateApi\BillingAgreement;
use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption;
@@ -15,7 +16,7 @@ class ExpressAuthorizeRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -306,10 +307,8 @@ public function testDataWithCallbackAndNoDefaultShippingOption()
'shippingOptions' => $shippingOptions,
)));
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'One of the supplied shipping options must be set as default'
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('One of the supplied shipping options must be set as default');
$this->request->getData();
}
@@ -321,10 +320,8 @@ public function testNoAmount()
$this->request->initialize($baseData);
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'The amount parameter is required'
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The amount parameter is required');
$this->request->getData();
}
@@ -337,10 +334,8 @@ public function testAmountButNoReturnUrl()
$this->request->initialize($baseData);
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'The returnUrl parameter is required'
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The returnUrl parameter is required');
$this->request->getData();
}
@@ -368,7 +363,7 @@ public function testBadCallbackConfiguration()
// from the docblock on this exception -
// Thrown when a request is invalid or missing required fields.
// callback has been set but no shipping options so expect one of these:
- $this->setExpectedException('\Omnipay\Common\Exception\InvalidRequestException');
+ $this->expectException(InvalidRequestException::class);
$this->request->getData();
}
@@ -413,10 +408,8 @@ public function testGetDataWithBillingAgreementOptionalParameters()
*/
public function testGetDataWithBillingAgreementWrongPaymentType()
{
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- "The 'paymentType' parameter can be only 'Any' or 'InstantOnly'"
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage("The 'paymentType' parameter can be only 'Any' or 'InstantOnly'");
$billingAgreement = new BillingAgreement(false, 'Some Stuff', 'BadType', 'Some custom annotation');
}
diff --git a/tests/Message/ExpressCompleteAuthorizeRequestTest.php b/tests/Message/ExpressCompleteAuthorizeRequestTest.php
index a2f8c27..f61090e 100644
--- a/tests/Message/ExpressCompleteAuthorizeRequestTest.php
+++ b/tests/Message/ExpressCompleteAuthorizeRequestTest.php
@@ -12,7 +12,7 @@ class ExpressCompleteAuthorizeRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
diff --git a/tests/Message/ExpressCompletePurchaseRequestTest.php b/tests/Message/ExpressCompletePurchaseRequestTest.php
index 87345a2..fb8de02 100644
--- a/tests/Message/ExpressCompletePurchaseRequestTest.php
+++ b/tests/Message/ExpressCompletePurchaseRequestTest.php
@@ -12,7 +12,7 @@ class ExpressCompletePurchaseRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
diff --git a/tests/Message/ExpressFetchCheckoutRequestTest.php b/tests/Message/ExpressFetchCheckoutRequestTest.php
index 8d94e1c..5b85df5 100644
--- a/tests/Message/ExpressFetchCheckoutRequestTest.php
+++ b/tests/Message/ExpressFetchCheckoutRequestTest.php
@@ -12,7 +12,7 @@ class ExpressFetchCheckoutRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
diff --git a/tests/Message/ExpressInContextAuthorizeRequestTest.php b/tests/Message/ExpressInContextAuthorizeRequestTest.php
index 8471fb0..a5cb73f 100644
--- a/tests/Message/ExpressInContextAuthorizeRequestTest.php
+++ b/tests/Message/ExpressInContextAuthorizeRequestTest.php
@@ -3,6 +3,7 @@
namespace Omnipay\PayPal\Message;
use Omnipay\Common\CreditCard;
+use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\PayPal\Message\ExpressInContextAuthorizeRequest;
use Omnipay\PayPal\Support\InstantUpdateApi\ShippingOption;
use Omnipay\Tests\TestCase;
@@ -14,7 +15,7 @@ class ExpressInContextAuthorizeRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -305,10 +306,8 @@ public function testDataWithCallbackAndNoDefaultShippingOption()
'shippingOptions' => $shippingOptions,
)));
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'One of the supplied shipping options must be set as default'
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('One of the supplied shipping options must be set as default');
$this->request->getData();
}
@@ -320,10 +319,8 @@ public function testNoAmount()
$this->request->initialize($baseData);
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'The amount parameter is required'
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The amount parameter is required');
$this->request->getData();
}
@@ -336,10 +333,8 @@ public function testAmountButNoReturnUrl()
$this->request->initialize($baseData);
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'The returnUrl parameter is required'
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The returnUrl parameter is required');
$this->request->getData();
}
@@ -367,7 +362,7 @@ public function testBadCallbackConfiguration()
// from the docblock on this exception -
// Thrown when a request is invalid or missing required fields.
// callback has been set but no shipping options so expect one of these:
- $this->setExpectedException('\Omnipay\Common\Exception\InvalidRequestException');
+ $this->expectException(InvalidRequestException::class);
$this->request->getData();
}
diff --git a/tests/Message/ExpressTransactionSearchRequestTest.php b/tests/Message/ExpressTransactionSearchRequestTest.php
index c0164b5..ec8191d 100644
--- a/tests/Message/ExpressTransactionSearchRequestTest.php
+++ b/tests/Message/ExpressTransactionSearchRequestTest.php
@@ -2,6 +2,7 @@
namespace Omnipay\PayPal\Message;
+use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Tests\TestCase;
class ExpressTransactionSearchRequestTest extends TestCase
@@ -11,7 +12,7 @@ class ExpressTransactionSearchRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -73,10 +74,8 @@ public function testWithoutStartDate()
{
$this->request->initialize(array());
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'The startDate parameter is required'
- );
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The startDate parameter is required');
$this->request->getData();
}
@@ -85,11 +84,9 @@ public function testAmountWithoutCurrency()
{
$this->request->setStartDate('2015-01-01');
$this->request->setAmount(150.00);
-
- $this->setExpectedException(
- '\Omnipay\Common\Exception\InvalidRequestException',
- 'The currency parameter is required'
- );
+
+ $this->expectException(InvalidRequestException::class);
+ $this->expectExceptionMessage('The currency parameter is required');
$this->request->getData();
}
diff --git a/tests/Message/ExpressVoidRequestTest.php b/tests/Message/ExpressVoidRequestTest.php
index 91f8a05..2fc4130 100644
--- a/tests/Message/ExpressVoidRequestTest.php
+++ b/tests/Message/ExpressVoidRequestTest.php
@@ -12,7 +12,7 @@ class ExpressVoidRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/FetchTransactionRequestTest.php b/tests/Message/FetchTransactionRequestTest.php
index 8ac7873..642ed44 100644
--- a/tests/Message/FetchTransactionRequestTest.php
+++ b/tests/Message/FetchTransactionRequestTest.php
@@ -12,7 +12,7 @@ class FetchTransactionRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
diff --git a/tests/Message/ProAuthorizeRequestTest.php b/tests/Message/ProAuthorizeRequestTest.php
index 6e9af31..5767694 100644
--- a/tests/Message/ProAuthorizeRequestTest.php
+++ b/tests/Message/ProAuthorizeRequestTest.php
@@ -12,7 +12,7 @@ class ProAuthorizeRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/ProPurchaseRequestTest.php b/tests/Message/ProPurchaseRequestTest.php
index 9f88c10..d406a2d 100644
--- a/tests/Message/ProPurchaseRequestTest.php
+++ b/tests/Message/ProPurchaseRequestTest.php
@@ -12,7 +12,7 @@ class ProPurchaseRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/RefundRequestTest.php b/tests/Message/RefundRequestTest.php
index 036f6d2..4604b7d 100644
--- a/tests/Message/RefundRequestTest.php
+++ b/tests/Message/RefundRequestTest.php
@@ -12,7 +12,7 @@ class RefundRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
diff --git a/tests/Message/RestAuthorizeRequestTest.php b/tests/Message/RestAuthorizeRequestTest.php
index 5f0f962..89f1b56 100644
--- a/tests/Message/RestAuthorizeRequestTest.php
+++ b/tests/Message/RestAuthorizeRequestTest.php
@@ -12,7 +12,7 @@ class RestAuthorizeRequestTest extends TestCase
*/
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/RestAuthorizeResponseTest.php b/tests/Message/RestAuthorizeResponseTest.php
index 5e1bb20..b3bfee9 100644
--- a/tests/Message/RestAuthorizeResponseTest.php
+++ b/tests/Message/RestAuthorizeResponseTest.php
@@ -11,7 +11,9 @@ class RestAuthorizeResponseTest extends TestCase
public function testRestPurchaseWithoutCardSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestPurchaseWithoutCardSuccess.txt');
- $response = new RestAuthorizeResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+
+ $response = new RestAuthorizeResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('PAY-3TJ47806DA028052TKTQGVYI', $response->getTransactionReference());
diff --git a/tests/Message/RestCancelSubscriptionRequestTest.php b/tests/Message/RestCancelSubscriptionRequestTest.php
index 7d6397d..4ebaa34 100644
--- a/tests/Message/RestCancelSubscriptionRequestTest.php
+++ b/tests/Message/RestCancelSubscriptionRequestTest.php
@@ -10,7 +10,7 @@ class RestCancelSubscriptionRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestCancelSubscriptionRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestCompletePurchaseRequestTest.php b/tests/Message/RestCompletePurchaseRequestTest.php
index 4dfbf98..bad9162 100644
--- a/tests/Message/RestCompletePurchaseRequestTest.php
+++ b/tests/Message/RestCompletePurchaseRequestTest.php
@@ -14,7 +14,7 @@ class RestCompletePurchaseRequestTest extends TestCase
private $request;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/RestCompleteSubscriptionRequestTest.php b/tests/Message/RestCompleteSubscriptionRequestTest.php
index 9c014f8..b72ac55 100644
--- a/tests/Message/RestCompleteSubscriptionRequestTest.php
+++ b/tests/Message/RestCompleteSubscriptionRequestTest.php
@@ -10,7 +10,7 @@ class RestCompleteSubscriptionRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestCompleteSubscriptionRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestCreateCardRequestTest.php b/tests/Message/RestCreateCardRequestTest.php
index 0574a0d..8e6d6df 100644
--- a/tests/Message/RestCreateCardRequestTest.php
+++ b/tests/Message/RestCreateCardRequestTest.php
@@ -13,7 +13,7 @@ class RestCreateCardRequestTest extends TestCase
/** @var CreditCard */
protected $card;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/RestCreatePlanRequestTest.php b/tests/Message/RestCreatePlanRequestTest.php
index b6a50b2..d1159cf 100644
--- a/tests/Message/RestCreatePlanRequestTest.php
+++ b/tests/Message/RestCreatePlanRequestTest.php
@@ -10,7 +10,7 @@ class RestCreatePlanRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestCreatePlanRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestCreateSubscriptionRequestTest.php b/tests/Message/RestCreateSubscriptionRequestTest.php
index 2ae9cd5..dc8e894 100644
--- a/tests/Message/RestCreateSubscriptionRequestTest.php
+++ b/tests/Message/RestCreateSubscriptionRequestTest.php
@@ -10,7 +10,7 @@ class RestCreateSubscriptionRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestCreateSubscriptionRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestCreateWebhookRequestTest.php b/tests/Message/RestCreateWebhookRequestTest.php
new file mode 100644
index 0000000..c4b92c2
--- /dev/null
+++ b/tests/Message/RestCreateWebhookRequestTest.php
@@ -0,0 +1,60 @@
+getHttpClient();
+ $request = $this->getHttpRequest();
+ $this->request = new RestCreateWebhookRequest($client, $request);
+ }
+
+ public function testGetData()
+ {
+ $event1 = 'PAYMENT.AUTHORIZATION.CREATED';
+ $event2 = 'PAYMENT.AUTHORIZATION.VOIDED';
+ $url = 'https://foo.bar/baz';
+ $this->request->initialize(
+ [
+ 'event_types' => [$event1, $event2],
+ 'url' => $url,
+ ]
+ );
+
+ $this->assertEquals(
+ [
+ 'event_types' => [['name' => $event1], ['name' => $event2]],
+ 'url' => $url,
+ ],
+ $this->request->getData()
+ );
+ }
+
+ public function testGetEndpoint()
+ {
+ $this->assertStringEndsWith('/notifications/webhooks', $this->request->getEndpoint());
+ }
+
+ public function testGetEventTypes()
+ {
+ $value = ['PAYMENT.AUTHORIZATION.CREATED'];
+ $this->request->setEventTypes($value);
+ self::assertSame($value, $this->request->getEventTypes());
+ }
+
+ public function testGetUrl()
+ {
+ $value = 'https://foo.bar/baz';
+ $this->request->setUrl($value);
+ self::assertSame($value, $this->request->getUrl());
+ }
+}
diff --git a/tests/Message/RestDeleteCardRequestTest.php b/tests/Message/RestDeleteCardRequestTest.php
index e17620a..90cd68d 100644
--- a/tests/Message/RestDeleteCardRequestTest.php
+++ b/tests/Message/RestDeleteCardRequestTest.php
@@ -13,7 +13,7 @@ class RestDeleteCardRequestTest extends TestCase
/** @var CreditCard */
private $card;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
diff --git a/tests/Message/RestFetchPurchaseRequestTest.php b/tests/Message/RestFetchPurchaseRequestTest.php
index 8bf27d9..e4c8c55 100644
--- a/tests/Message/RestFetchPurchaseRequestTest.php
+++ b/tests/Message/RestFetchPurchaseRequestTest.php
@@ -9,7 +9,7 @@ class RestFetchPurchaseRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestFetchPurchaseRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestFetchTransactionRequestTest.php b/tests/Message/RestFetchTransactionRequestTest.php
index 9ba5a38..0623265 100644
--- a/tests/Message/RestFetchTransactionRequestTest.php
+++ b/tests/Message/RestFetchTransactionRequestTest.php
@@ -9,7 +9,7 @@ class RestFetchTransactionRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestFetchTransactionRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestListPlanRequestTest.php b/tests/Message/RestListPlanRequestTest.php
index ba1867e..4a99fef 100644
--- a/tests/Message/RestListPlanRequestTest.php
+++ b/tests/Message/RestListPlanRequestTest.php
@@ -9,7 +9,7 @@ class RestListPlanRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestListPlanRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestListWebhooksRequestTest.php b/tests/Message/RestListWebhooksRequestTest.php
new file mode 100644
index 0000000..e5e5d1f
--- /dev/null
+++ b/tests/Message/RestListWebhooksRequestTest.php
@@ -0,0 +1,30 @@
+getHttpClient();
+ $request = $this->getHttpRequest();
+ $this->request = new RestListWebhooksRequest($client, $request);
+ }
+
+ public function testEndpoint()
+ {
+ $this->assertStringEndsWith('/notifications/webhooks', $this->request->getEndpoint());
+ }
+
+ public function testGetData()
+ {
+ $this->assertEmpty($this->request->getData());
+ }
+}
diff --git a/tests/Message/RestReactivateSubscriptionRequestTest.php b/tests/Message/RestReactivateSubscriptionRequestTest.php
index c8301f4..0f8571e 100644
--- a/tests/Message/RestReactivateSubscriptionRequestTest.php
+++ b/tests/Message/RestReactivateSubscriptionRequestTest.php
@@ -10,7 +10,7 @@ class RestReactivateSubscriptionRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestReactivateSubscriptionRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestResponseTest.php b/tests/Message/RestResponseTest.php
index c4e4d9d..ce852bb 100644
--- a/tests/Message/RestResponseTest.php
+++ b/tests/Message/RestResponseTest.php
@@ -9,7 +9,8 @@ class RestResponseTest extends TestCase
public function testPurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestPurchaseSuccess.txt');
- $response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+ $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('44E89981F8714392Y', $response->getTransactionReference());
@@ -19,7 +20,8 @@ public function testPurchaseSuccess()
public function testPurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('RestPurchaseFailure.txt');
- $response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+ $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
@@ -29,7 +31,9 @@ public function testPurchaseFailure()
public function testCompletePurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestCompletePurchaseSuccess.txt');
- $response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+
+ $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('9EA05739TH369572R', $response->getTransactionReference());
@@ -39,7 +43,9 @@ public function testCompletePurchaseSuccess()
public function testCompletePurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('RestCompletePurchaseFailure.txt');
- $response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+
+ $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
@@ -49,7 +55,9 @@ public function testCompletePurchaseFailure()
public function testTokenFailure()
{
$httpResponse = $this->getMockHttpResponse('RestTokenFailure.txt');
- $response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+
+ $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertFalse($response->isSuccessful());
$this->assertSame('Client secret does not match for this client', $response->getMessage());
@@ -58,7 +66,9 @@ public function testTokenFailure()
public function testAuthorizeSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestAuthorizationSuccess.txt');
- $response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+
+ $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('58N7596879166930B', $response->getTransactionReference());
@@ -68,7 +78,9 @@ public function testAuthorizeSuccess()
public function testCreateCardSuccess()
{
$httpResponse = $this->getMockHttpResponse('RestCreateCardSuccess.txt');
- $response = new RestResponse($this->getMockRequest(), $httpResponse->json(), $httpResponse->getStatusCode());
+ $data = json_decode($httpResponse->getBody()->getContents(), true);
+
+ $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
$this->assertTrue($response->isSuccessful());
$this->assertSame('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference());
diff --git a/tests/Message/RestSearchTransactionRequestTest.php b/tests/Message/RestSearchTransactionRequestTest.php
index e66b200..ab7ffd5 100644
--- a/tests/Message/RestSearchTransactionRequestTest.php
+++ b/tests/Message/RestSearchTransactionRequestTest.php
@@ -10,7 +10,7 @@ class RestSearchTransactionRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestSearchTransactionRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestSuspendSubscriptionRequestTest.php b/tests/Message/RestSuspendSubscriptionRequestTest.php
index 19d88fc..6cda5ed 100644
--- a/tests/Message/RestSuspendSubscriptionRequestTest.php
+++ b/tests/Message/RestSuspendSubscriptionRequestTest.php
@@ -10,7 +10,7 @@ class RestSuspendSubscriptionRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestSuspendSubscriptionRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestUpdatePlanRequestTest.php b/tests/Message/RestUpdatePlanRequestTest.php
index a682f15..1b12f6c 100644
--- a/tests/Message/RestUpdatePlanRequestTest.php
+++ b/tests/Message/RestUpdatePlanRequestTest.php
@@ -10,7 +10,7 @@ class RestUpdatePlanRequestTest extends TestCase
/** @var \Omnipay\PayPal\Message\RestUpdatePlanRequest */
private $request;
- public function setUp()
+ public function setUp() : void
{
$client = $this->getHttpClient();
$request = $this->getHttpRequest();
diff --git a/tests/Message/RestVerifyWebhookSignatureRequestTest.php b/tests/Message/RestVerifyWebhookSignatureRequestTest.php
new file mode 100644
index 0000000..b61b1d8
--- /dev/null
+++ b/tests/Message/RestVerifyWebhookSignatureRequestTest.php
@@ -0,0 +1,63 @@
+getHttpClient();
+ $request = $this->getHttpRequest();
+ $this->request = new RestVerifyWebhookSignatureRequest($client, $request);
+ }
+
+ public function testGetData()
+ {
+ $data = [
+ 'transmission_id' => 'foo',
+ 'auth_algo' => 'bar',
+ 'cert_url' => 'baz',
+ 'transmission_sig' => 'qux',
+ 'transmission_time' => 'foobar',
+ 'webhook_event' => ['bar' => 'baz'],
+ 'webhook_id' => 'barbaz',
+ ];
+
+ $this->request->initialize($data);
+
+ $this->assertEquals($data, $this->request->getData());
+ }
+
+ public function testGettersAndSetters() {
+ $authAlgo = 'foo';
+ $certUrl = 'bar';
+ $transmissionId = 'baz';
+ $transmissionTime = 'qux';
+ $transmissionSig = 'foobar';
+ $webhookEvent = ['bar' => 'baz'];
+ $webhookId = 'barfoo';
+
+ $this->request->setAuthAlgo($authAlgo);
+ $this->request->setCertUrl($certUrl);
+ $this->request->setTransmissionId($transmissionId);
+ $this->request->setTransmissionTime($transmissionTime);
+ $this->request->setTransmissionSig($transmissionSig);
+ $this->request->setWebhookEvent($webhookEvent);
+ $this->request->setWebhookId($webhookId);
+
+ $this->assertEquals($authAlgo, $this->request->getAuthAlgo());
+ $this->assertEquals($certUrl,$this->request->getCertUrl());
+ $this->assertEquals($transmissionId, $this->request->getTransmissionId());
+ $this->assertEquals($transmissionTime, $this->request->getTransmissionTime());
+ $this->assertEquals($transmissionSig, $this->request->getTransmissionSig());
+ $this->assertEquals($webhookEvent, $this->request->getWebhookEvent());
+ $this->assertEquals($webhookId, $this->request->getWebhookId());
+ }
+}
diff --git a/tests/Message/RestVerifyWebhookSignatureResponseTest.php b/tests/Message/RestVerifyWebhookSignatureResponseTest.php
new file mode 100644
index 0000000..a9a1e87
--- /dev/null
+++ b/tests/Message/RestVerifyWebhookSignatureResponseTest.php
@@ -0,0 +1,49 @@
+getMockRequest(),
+ ['verification_status' => 'SUCCESS']
+ );
+
+ $this->assertSame('SUCCESS', $response->getVerificationStatus());
+ }
+
+ public function testIsSuccessfulWillReturnFalseIfParentCheckIsSuccesfullButVerificationFailed()
+ {
+ $response = new RestVerifyWebhookSignatureResponse(
+ $this->getMockRequest(),
+ ['verification_status' => 'FAILED']
+ );
+
+ $this->assertFalse($response->isSuccessful());
+ }
+
+ public function testIsSuccessfulWillReturnFalseIfParentCheckIsUnsuccesfull()
+ {
+ $response = new RestVerifyWebhookSignatureResponse(
+ $this->getMockRequest(),
+ ['verification_status' => 'foobar'],
+ 400
+ );
+
+ $this->assertFalse($response->isSuccessful());
+ }
+
+ public function testIsSuccessfulWillReturnTrueIfEverythingIsOk()
+ {
+ $response = new RestVerifyWebhookSignatureResponse(
+ $this->getMockRequest(),
+ ['verification_status' => 'SUCCESS']
+ );
+
+ $this->assertTrue($response->isSuccessful());
+ }
+}
diff --git a/tests/Mock/RestGenericSubscriptionSuccess.txt b/tests/Mock/RestGenericSubscriptionSuccess.txt
index e099ab1..dc0ec05 100644
--- a/tests/Mock/RestGenericSubscriptionSuccess.txt
+++ b/tests/Mock/RestGenericSubscriptionSuccess.txt
@@ -5,3 +5,5 @@ Paypal-Debug-Id: 217a9ddefd384
SERVER_INFO: identitysecuretokenserv:v1.oauth2.token&CalThreadId=91&TopLevelTxnStartTime=146fbfe679a&Host=slcsbidensectoken502.slc.paypal.com&pid=29059
CORRELATION-ID: 217a9ddefd384
Date: Thu, 03 Jul 2014 11:31:32 GMT
+
+{}
diff --git a/tests/ProGatewayTest.php b/tests/ProGatewayTest.php
index cdb05e2..76c7938 100644
--- a/tests/ProGatewayTest.php
+++ b/tests/ProGatewayTest.php
@@ -7,7 +7,7 @@
class ProGatewayTest extends GatewayTestCase
{
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -20,7 +20,7 @@ public function setUp()
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '12',
- 'expiryYear' => '2017',
+ 'expiryYear' => date('Y'),
'cvv' => '123',
)),
);
diff --git a/tests/RestGatewayTest.php b/tests/RestGatewayTest.php
index db89871..9febb27 100644
--- a/tests/RestGatewayTest.php
+++ b/tests/RestGatewayTest.php
@@ -2,8 +2,11 @@
namespace Omnipay\PayPal;
-use Omnipay\Tests\GatewayTestCase;
use Omnipay\Common\CreditCard;
+use Omnipay\PayPal\Message\RestCreateWebhookRequest;
+use Omnipay\PayPal\Message\RestListWebhooksRequest;
+use Omnipay\PayPal\Message\RestVerifyWebhookSignatureRequest;
+use Omnipay\Tests\GatewayTestCase;
class RestGatewayTest extends GatewayTestCase
{
@@ -16,7 +19,7 @@ class RestGatewayTest extends GatewayTestCase
/** @var array */
public $subscription_options;
- public function setUp()
+ public function setUp() : void
{
parent::setUp();
@@ -31,7 +34,7 @@ public function setUp()
'lastName' => 'User',
'number' => '4111111111111111',
'expiryMonth' => '12',
- 'expiryYear' => '2017',
+ 'expiryYear' => date('Y'),
'cvv' => '123',
)),
);
@@ -218,6 +221,15 @@ public function testCreateCard()
$this->assertNull($response->getMessage());
}
+ public function testCreateWebhook()
+ {
+ $request = $this->gateway->createWebhook([]);
+
+ $this->assertInstanceOf(RestCreateWebhookRequest::class, $request);
+ $this->assertSame('https://api.paypal.com/v1/notifications/webhooks', $request->getEndpoint());
+ $this->assertEquals(['event_types' => [], 'url' => null], $request->getData());
+ }
+
public function testPayWithSavedCard()
{
$this->setMockHttpResponse('RestCreateCardSuccess.txt');
@@ -277,7 +289,7 @@ public function testRefundCapture()
$this->assertSame('abc123', $request->getTransactionReference());
$endPoint = $request->getEndpoint();
$this->assertSame('https://api.paypal.com/v1/payments/capture/abc123/refund', $endPoint);
-
+
$request->setAmount('15.99');
$request->setCurrency('BRL');
$request->setDescription('Test Description');
@@ -300,4 +312,33 @@ public function testVoid()
$data = $request->getData();
$this->assertEmpty($data);
}
+
+ public function testListWebhooks()
+ {
+ $request = $this->gateway->listWebhooks([]);
+
+ $this->assertInstanceOf(RestListWebhooksRequest::class, $request);
+ $this->assertSame('https://api.paypal.com/v1/notifications/webhooks', $request->getEndpoint());
+ $this->assertEmpty($request->getData());
+ }
+
+ public function testVerifyWebhook()
+ {
+ $request = $this->gateway->verifyWebhookSignature([]);
+
+ $this->assertInstanceOf(RestVerifyWebhookSignatureRequest::class, $request);
+ $this->assertSame('https://api.paypal.com/v1/notifications/verify-webhook-signature', $request->getEndpoint());
+ $this->assertEquals(
+ [
+ 'transmission_id' => null,
+ 'auth_algo' => null,
+ 'cert_url' => null,
+ 'transmission_sig' => null,
+ 'transmission_time' => null,
+ 'webhook_event' => null,
+ 'webhook_id' => null,
+ ],
+ $request->getData()
+ );
+ }
}