From b292b86906e9e5905d5d550152d12efc31579802 Mon Sep 17 00:00:00 2001 From: Anush Ramani Date: Tue, 28 Jan 2020 14:21:53 -0800 Subject: [PATCH] XOL-4975 Upgrade to Omnipay 3 (#14) * XOL-4975 upgrade to omnipay 3 * XOL-4975 fix issue with level3 * XOL-4975 fix travis errors * XOL-4975 fix lint errors --- .travis.yml | 14 ++- composer.json | 19 ++-- src/Gateway.php | 8 +- src/Message/AbstractRequest.php | 86 +++++-------------- src/Message/AuthorizeRequest.php | 32 ++++++- src/Message/Response.php | 34 +++++--- src/StripeItem.php | 36 ++++++++ src/StripeItemBag.php | 32 +++++++ src/Util/StripeQueryAggregator.php | 33 ------- tests/Message/AbstractRequestTest.php | 65 ++++++-------- tests/Message/AuthorizeRequestTest.php | 3 + .../Message/CancelSubscriptionRequestTest.php | 3 + tests/Message/CreatePlanRequestTest.php | 3 + tests/Message/DeleteCardRequestTest.php | 3 + tests/Message/PurchaseRequestTest.php | 4 +- tests/Message/ResponseTest.php | 34 ++++---- .../Transfers/CreateTransferRequestTest.php | 6 +- .../CreateTransferReversalRequestTest.php | 5 +- .../Transfers/FetchTransferRequestTest.php | 9 +- .../FetchTransferReversalRequestTest.php | 9 +- .../ListTransferReversalsRequestTest.php | 9 +- .../Transfers/ListTransfersRequestTest.php | 9 +- .../Transfers/UpdateTransferRequestTest.php | 9 +- .../UpdateTransferReversalRequestTest.php | 9 +- tests/Message/VoidRequestTest.php | 3 + tests/Util/StripeQueryAggregatorTest.php | 24 ------ 26 files changed, 255 insertions(+), 246 deletions(-) create mode 100644 src/StripeItem.php create mode 100644 src/StripeItemBag.php delete mode 100644 src/Util/StripeQueryAggregator.php delete mode 100644 tests/Util/StripeQueryAggregatorTest.php diff --git a/.travis.yml b/.travis.yml index 3ded76a8..3297f776 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,18 @@ language: php php: - - 5.3 - - 5.4 - - 5.5 - 5.6 + - 7.0 + - 7.1 + - 7.2 + +sudo: false + +cache: + directories: + - $HOME/.composer/cache before_script: - - composer install -n --dev --prefer-source + - composer install --prefer-dist --no-interaction script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text diff --git a/composer.json b/composer.json index 9b14232c..2e8c68df 100644 --- a/composer.json +++ b/composer.json @@ -22,24 +22,17 @@ "homepage": "https://github.com/thephpleague/omnipay-stripe/contributors" } ], - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/xola/omnipay-common" - } - ], "autoload": { "psr-4": { "Omnipay\\Stripe\\" : "src/" } }, "require": { - "omnipay/common": "^2.5.4" + "ext-json": "*", + "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" - } - } + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/src/Gateway.php b/src/Gateway.php index 85713d92..abca0fec 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -158,9 +158,9 @@ public function setApiKey($value) * * @return Gateway provides a fluent interface */ - public function setApiVersion($value) + public function setStripeVersion($value) { - return $this->setParameter('apiVersion', $value); + return $this->setParameter('stripeVersion', $value); } /** @@ -168,9 +168,9 @@ public function setApiVersion($value) * * @return string */ - public function getApiVersion() + public function getStripeVersion() { - return $this->getParameter('apiVersion'); + return $this->getParameter('stripeVersion'); } /** diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 3571e7f7..6a73858f 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -6,9 +6,6 @@ namespace Omnipay\Stripe\Message; -use Guzzle\Common\Event; -use Omnipay\Stripe\Util\StripeQueryAggregator; - use Omnipay\Common\Message\ResponseInterface; /** @@ -65,14 +62,14 @@ public function setApiKey($value) return $this->setParameter('apiKey', $value); } - public function getApiVersion() + public function getStripeVersion() { - return $this->getParameter('apiVersion'); + return $this->getParameter('stripeVersion'); } - public function setApiVersion($value) + public function setStripeVersion($value) { - return $this->setParameter('apiVersion', $value); + return $this->setParameter('stripeVersion', $value); } /** @@ -147,7 +144,7 @@ public function getConnectedStripeAccountHeader() /** * @param string $value * - * @return \Omnipay\Common\Message\AbstractRequest + * @return AbstractRequest */ public function setConnectedStripeAccountHeader($value) { @@ -167,7 +164,7 @@ public function getIdempotencyKeyHeader() /** * @param string $value * - * @return \Omnipay\Common\Message\AbstractRequest + * @return AbstractRequest */ public function setIdempotencyKeyHeader($value) { @@ -220,10 +217,10 @@ public function getHeaders() $headers['Idempotency-Key'] = $this->getIdempotencyKeyHeader(); } - $apiVersion = $this->getApiVersion(); - if (!empty($apiVersion)) { + $stripeVersion = $this->getStripeVersion(); + if (!empty($stripeVersion)) { // If user has set an API version use that https://stripe.com/docs/api#versioning - $headers['Stripe-Version'] = $this->getApiVersion(); + $headers['Stripe-Version'] = $this->getStripeVersion(); } return $headers; @@ -247,16 +244,20 @@ public function send() public function sendData($data, array $headers = null) { - $httpRequest = $this->createClientRequest($data, $headers); - $httpResponse = $httpRequest->send(); + $headers = array_merge( + $this->getHeaders(), + array('Authorization' => 'Basic ' . base64_encode($this->getApiKey() . ':')) + ); - $this->response = new Response($this, $httpResponse->json()); + $body = $data ? http_build_query($data, '', '&') : null; + $httpResponse = $this->httpClient->request($this->getHttpMethod(), $this->getEndpoint(), $headers, $body); - if ($httpResponse->hasHeader('Request-Id')) { - $this->response->setRequestId((string) $httpResponse->getHeader('Request-Id')); - } + return $this->createResponse($httpResponse->getBody()->getContents(), $httpResponse->getHeaders()); + } - return $this->response; + protected function createResponse($data, $headers = []) + { + return $this->response = new Response($this, $data, $headers); } /** @@ -277,51 +278,6 @@ public function setSource($value) return $this->setParameter('source', $value); } - /** - * @param $data - * @param array $headers - * - * @return \Guzzle\Http\Message\RequestInterface - */ - protected function createClientRequest($data, array $headers = null) - { - // Stripe only accepts TLS >= v1.2, so make sure Curl is told - $config = $this->httpClient->getConfig(); - $curlOptions = $config->get('curl.options'); - $curlOptions[CURLOPT_SSLVERSION] = 6; - $config->set('curl.options', $curlOptions); - $this->httpClient->setConfig($config); - - // For query params with an array value, Stripe accepts only one format for aggregating these values. This type - // of query aggregation is not supported by default by Guzzle so we have to use a custom query aggregator - $this->httpClient->getEventDispatcher()->addListener('request.before_send', function (Event $event) { - $request = $event['request']; - if ($request->getMethod() === 'POST') { - $request->getQuery()->setAggregator(new StripeQueryAggregator()); - } - }); - - // don't throw exceptions for 4xx errors - $this->httpClient->getEventDispatcher()->addListener( - 'request.error', - function ($event) { - if ($event['response']->isClientError()) { - $event->stopPropagation(); - } - } - ); - - $httpRequest = $this->httpClient->createRequest( - $this->getHttpMethod(), - $this->getEndpoint(), - $headers, - $data - ); - - return $httpRequest; - } - - /** * Get the card data. * @@ -362,7 +318,7 @@ protected function getCardData() $data['address_zip'] = $card->getPostcode(); $data['address_state'] = $card->getState(); $data['address_country'] = $card->getCountry(); - $data['email'] = $card->getEmail(); + $data['email'] = $card->getEmail(); return $data; } diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index 26d6a54d..08d9d118 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -5,6 +5,9 @@ */ namespace Omnipay\Stripe\Message; +use Omnipay\Common\ItemBag; +use Omnipay\Stripe\StripeItemBag; + /** * Stripe Authorize Request. * @@ -207,6 +210,30 @@ public function setReceiptEmail($email) return $this; } + /** + * A list of items in this order + * + * @return ItemBag|null A bag containing items in this order + */ + public function getItems() + { + return $this->getParameter('items'); + } + + /** + * Set the items in this order + * + * @param array $items An array of items in this order + * @return AuthorizeRequest + */ + public function setItems($items) + { + if ($items && !$items instanceof ItemBag) { + $items = new StripeItemBag($items); + } + return $this->setParameter('items', $items); + } + public function getData() { $this->validate('amount', 'currency'); @@ -219,8 +246,9 @@ public function getData() $data['metadata'] = $this->getMetadata(); $data['capture'] = 'false'; - $apiVersion = $this->getApiVersion(); - if (is_null($apiVersion) || (!is_null($apiVersion) && $apiVersion >= self::API_VERSION_STATEMENT_DESCRIPTOR)) { + $stripeVersion = $this->getStripeVersion(); + if (is_null($stripeVersion) || (!is_null($stripeVersion) + && $stripeVersion >= self::API_VERSION_STATEMENT_DESCRIPTOR)) { $data['statement_descriptor'] = $this->getStatementDescriptor(); } else { $data['statement_description'] = $this->getStatementDescriptor(); diff --git a/src/Message/Response.php b/src/Message/Response.php index f79bc3e7..06f58ed0 100644 --- a/src/Message/Response.php +++ b/src/Message/Response.php @@ -6,6 +6,7 @@ namespace Omnipay\Stripe\Message; use Omnipay\Common\Message\AbstractResponse; +use Omnipay\Common\Message\RequestInterface; /** * Stripe Response. @@ -22,7 +23,19 @@ class Response extends AbstractResponse * @var string URL */ protected $requestId = null; - + + /** + * @var array + */ + protected $headers = []; + + public function __construct(RequestInterface $request, $data, $headers = []) + { + $this->request = $request; + $this->data = json_decode($data, true); + $this->headers = $headers; + } + /** * Is the transaction successful? * @@ -113,7 +126,6 @@ public function getCustomerReference() public function getCardReference() { if (isset($this->data['object']) && 'customer' === $this->data['object']) { - if (isset($this->data['default_card']) && !empty($this->data['default_card'])) { return $this->data['default_card']; } @@ -359,22 +371,16 @@ public function getType() return null; } - + /** - * @return string + * @return string|null */ public function getRequestId() { - return $this->requestId; - } + if (isset($this->headers['Request-Id'])) { + return $this->headers['Request-Id'][0]; + } - /** - * Set request id - * - * @return AbstractRequest provides a fluent interface. - */ - public function setRequestId($requestId) - { - $this->requestId = $requestId; + return null; } } diff --git a/src/StripeItem.php b/src/StripeItem.php new file mode 100644 index 00000000..cb8ee8cb --- /dev/null +++ b/src/StripeItem.php @@ -0,0 +1,36 @@ +getParameter('taxes'); + } + + public function setTaxes($value) + { + $this->setParameter('taxes', $value); + } + + public function getDiscount() + { + return $this->getParameter('discount'); + } + + public function setDiscount($value) + { + $this->setParameter('discount', $value); + } +} diff --git a/src/StripeItemBag.php b/src/StripeItemBag.php new file mode 100644 index 00000000..511bd9ad --- /dev/null +++ b/src/StripeItemBag.php @@ -0,0 +1,32 @@ +items[] = $item; + } else { + $this->items[] = new StripeItem($item); + } + } +} diff --git a/src/Util/StripeQueryAggregator.php b/src/Util/StripeQueryAggregator.php deleted file mode 100644 index 572f8ab5..00000000 --- a/src/Util/StripeQueryAggregator.php +++ /dev/null @@ -1,33 +0,0 @@ - ['bar', 'baz']] - * The query param will be sent in any request as: http://test.com?foo[]=bar&foo[]=baz - * - * @param string $key The name of the query string parameter - * @param array $value The values of the parameter - * @param QueryString $query The query string that is being aggregated - * - * @return array Returns an array of the combined values - */ - public function aggregate($key, $value, QueryString $query) - { - if ($query->isUrlEncoding()) { - return array($query->encodeValue($key) . '[]' => array_map(array($query, 'encodeValue'), $value)); - } else { - return array($key . '[]' => $value); - } - } -} diff --git a/tests/Message/AbstractRequestTest.php b/tests/Message/AbstractRequestTest.php index 06b5b001..99f7a790 100644 --- a/tests/Message/AbstractRequestTest.php +++ b/tests/Message/AbstractRequestTest.php @@ -2,13 +2,15 @@ namespace Omnipay\Stripe\Message; -use Guzzle\Common\Event; +use GuzzleHttp\Psr7\Request; use Mockery; -use Omnipay\Stripe\Util\StripeQueryAggregator; use Omnipay\Tests\TestCase; class AbstractRequestTest extends TestCase { + /** @var Mockery\Mock|AbstractRequest */ + private $request; + public function setUp() { $this->request = Mockery::mock('\Omnipay\Stripe\Message\AbstractRequest')->makePartial(); @@ -70,17 +72,15 @@ public function testIdempotencyKey() $this->assertArrayHasKey('Idempotency-Key', $headers); $this->assertSame('UUID', $headers['Idempotency-Key']); - $httpRequest = $this->getHttpClient()->createRequest( + $httpRequest = new Request( 'GET', '/', - $headers, - array() + $headers ); $this->assertTrue($httpRequest->hasHeader('Idempotency-Key')); } - public function testConnectedStripeAccount() { $this->request->setConnectedStripeAccountHeader('ACCOUNT_ID'); @@ -92,51 +92,38 @@ public function testConnectedStripeAccount() $this->assertArrayHasKey('Stripe-Account', $headers); $this->assertSame('ACCOUNT_ID', $headers['Stripe-Account']); - $httpRequest = $this->getHttpClient()->createRequest( + $httpRequest = new Request( 'GET', '/', - $headers, - array() + $headers ); $this->assertTrue($httpRequest->hasHeader('Stripe-Account')); } - public function testExpand() + public function testStripeVersion() { - $this->assertSame($this->request, $this->request->setExpand(array('foo' => 'bar'))); - $this->assertSame(array('foo' => 'bar'), $this->request->getExpand()); - } + $this->request->setStripeVersion('2019-05-16'); - public function testShouldUseCustomQueryAggregator() - { - $this->setMockHttpResponse('PurchaseSuccess.txt'); - $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); - - $this->request->sendData(array()); - - $listeners = $this->getHttpClient()->getEventDispatcher()->getListeners(); - $beforeSendListeners = $listeners['request.before_send']; - $this->assertCount(2, $beforeSendListeners); - $this->assertEquals(function(Event $event) { - $request = $event['request']; - if ($request->getMethod() === 'POST') { - $request->getQuery()->setAggregator(new StripeQueryAggregator()); - } - }, $beforeSendListeners[1]); - } -} + $this->assertSame('2019-05-16', $this->request->getStripeVersion()); -class AbstractRequestTest_MockAbstractRequest extends AbstractRequest -{ + $headers = $this->request->getHeaders(); - public function getEndpoint() - { - return ''; + $this->assertArrayHasKey('Stripe-Version', $headers); + $this->assertSame('2019-05-16', $headers['Stripe-Version']); + + $httpRequest = new Request( + 'GET', + '/', + $headers + ); + + $this->assertTrue($httpRequest->hasHeader('Stripe-Version')); } - public function getData() + public function testExpand() { - return array(); + $this->assertSame($this->request, $this->request->setExpand(array('foo' => 'bar'))); + $this->assertSame(array('foo' => 'bar'), $this->request->getExpand()); } -} +} \ No newline at end of file diff --git a/tests/Message/AuthorizeRequestTest.php b/tests/Message/AuthorizeRequestTest.php index 609c8a44..2e6a5afd 100644 --- a/tests/Message/AuthorizeRequestTest.php +++ b/tests/Message/AuthorizeRequestTest.php @@ -6,6 +6,9 @@ class AuthorizeRequestTest extends TestCase { + /** @var AuthorizeRequest */ + private $request; + public function setUp() { $this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); diff --git a/tests/Message/CancelSubscriptionRequestTest.php b/tests/Message/CancelSubscriptionRequestTest.php index 015197f4..9c2e9440 100644 --- a/tests/Message/CancelSubscriptionRequestTest.php +++ b/tests/Message/CancelSubscriptionRequestTest.php @@ -6,6 +6,9 @@ class CancelSubscriptionRequestTest extends TestCase { +/** @var CancelSubscriptionRequest */ + private $request; + public function setUp() { $this->request = new CancelSubscriptionRequest($this->getHttpClient(), $this->getHttpRequest()); diff --git a/tests/Message/CreatePlanRequestTest.php b/tests/Message/CreatePlanRequestTest.php index bb771349..0e4f58b0 100644 --- a/tests/Message/CreatePlanRequestTest.php +++ b/tests/Message/CreatePlanRequestTest.php @@ -6,6 +6,9 @@ class CreatePlanRequestTest extends TestCase { + /** @var CreatePlanRequest */ + private $request; + public function setUp() { $this->request = new CreatePlanRequest($this->getHttpClient(), $this->getHttpRequest()); diff --git a/tests/Message/DeleteCardRequestTest.php b/tests/Message/DeleteCardRequestTest.php index 344fc01d..171fa881 100644 --- a/tests/Message/DeleteCardRequestTest.php +++ b/tests/Message/DeleteCardRequestTest.php @@ -6,6 +6,9 @@ class DeleteCardRequestTest extends TestCase { + /** @var DeleteCardRequest */ + private $request; + public function setUp() { $this->request = new DeleteCardRequest($this->getHttpClient(), $this->getHttpRequest()); diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 96e90f1f..0490ee6c 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -189,9 +189,9 @@ public function testShouldNotReturnLevel3DataIfItemsAmountsDoNotAddUpToAmountCha $this->assertEquals($expected, $data); } - public function testShouldUseOlderKeyOfStatementDescriptorWhenApiVersionIsBeforeDec2014() + public function testShouldUseOlderKeyOfStatementDescriptorWhenStripeVersionIsBeforeDec2014() { - $this->request->setApiVersion('2014-06-17'); + $this->request->setStripeVersion('2014-06-17'); $data = $this->request->getData(); diff --git a/tests/Message/ResponseTest.php b/tests/Message/ResponseTest.php index 29ac58d9..698c3926 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(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -22,7 +22,7 @@ public function testPurchaseSuccess() public function testPurchaseWithSourceSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseWithSourceSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -34,7 +34,7 @@ public function testPurchaseWithSourceSuccess() public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -47,7 +47,7 @@ public function testPurchaseFailure() public function testPurchaseFailureWithoutMessage() { $httpResponse = $this->getMockHttpResponse('PurchaseFailureWithoutMessage.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -60,7 +60,7 @@ public function testPurchaseFailureWithoutMessage() public function testPurchaseFailureWithoutCode() { $httpResponse = $this->getMockHttpResponse('PurchaseFailureWithoutCode.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -73,7 +73,7 @@ public function testPurchaseFailureWithoutCode() public function testCreateCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('CreateCustomerSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -85,7 +85,7 @@ public function testCreateCustomerSuccess() public function testCreateCustomerFailure() { $httpResponse = $this->getMockHttpResponse('CreateCustomerFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -97,7 +97,7 @@ public function testCreateCustomerFailure() public function testUpdateCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('UpdateCustomerSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -109,7 +109,7 @@ public function testUpdateCustomerSuccess() public function testUpdateCustomerFailure() { $httpResponse = $this->getMockHttpResponse('UpdateCustomerFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -121,7 +121,7 @@ public function testUpdateCustomerFailure() public function testDeleteCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('DeleteCustomerSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -133,7 +133,7 @@ public function testDeleteCustomerSuccess() public function testDeleteCustomerFailure() { $httpResponse = $this->getMockHttpResponse('DeleteCustomerFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -145,7 +145,7 @@ public function testDeleteCustomerFailure() public function testCreateCardSuccess() { $httpResponse = $this->getMockHttpResponse('CreateCardSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -157,7 +157,7 @@ public function testCreateCardSuccess() public function testCreateCardFailure() { $httpResponse = $this->getMockHttpResponse('CreateCardFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -169,7 +169,7 @@ public function testCreateCardFailure() public function testUpdateCardSuccess() { $httpResponse = $this->getMockHttpResponse('UpdateCardSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -181,7 +181,7 @@ public function testUpdateCardSuccess() public function testUpdateCardFailure() { $httpResponse = $this->getMockHttpResponse('UpdateCardFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -193,7 +193,7 @@ public function testUpdateCardFailure() public function testDeleteCardSuccess() { $httpResponse = $this->getMockHttpResponse('DeleteCardSuccess.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); @@ -205,7 +205,7 @@ public function testDeleteCardSuccess() public function testDeleteCardFailure() { $httpResponse = $this->getMockHttpResponse('DeleteCardFailure.txt'); - $response = new Response($this->getMockRequest(), $httpResponse->json()); + $response = new Response($this->getMockRequest(), (string) $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); diff --git a/tests/Message/Transfers/CreateTransferRequestTest.php b/tests/Message/Transfers/CreateTransferRequestTest.php index 59334446..d5327e0b 100644 --- a/tests/Message/Transfers/CreateTransferRequestTest.php +++ b/tests/Message/Transfers/CreateTransferRequestTest.php @@ -2,8 +2,8 @@ namespace Omnipay\Stripe\Message\Transfers; -use Guzzle\Http\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class CreateTransferRequestTest extends TestCase { @@ -67,7 +67,7 @@ public function testDataWithSourceTransactionReference() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/CreateTransferRequestSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir . '/CreateTransferRequestSuccess.txt'))) ); $response = $this->request->send(); @@ -80,7 +80,7 @@ public function testSendSuccess() public function testSendError() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/CreateTransferRequestFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir . '/CreateTransferRequestFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/Transfers/CreateTransferReversalRequestTest.php b/tests/Message/Transfers/CreateTransferReversalRequestTest.php index b7ed959e..b8342c21 100644 --- a/tests/Message/Transfers/CreateTransferReversalRequestTest.php +++ b/tests/Message/Transfers/CreateTransferReversalRequestTest.php @@ -4,6 +4,7 @@ use Guzzle\Http\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class CreateTransferReversalRequestTest extends TestCase { @@ -45,7 +46,7 @@ public function testGetData() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/CreateTransferReversalRequestSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir . '/CreateTransferReversalRequestSuccess.txt'))) ); /** @var \Omnipay\Stripe\Message\Response $response */ @@ -60,7 +61,7 @@ public function testSendSuccess() public function testSendFailure() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/Transfers/FetchTransferRequestTest.php b/tests/Message/Transfers/FetchTransferRequestTest.php index 2de2350d..e34cf2d0 100644 --- a/tests/Message/Transfers/FetchTransferRequestTest.php +++ b/tests/Message/Transfers/FetchTransferRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Stripe\Message\Transfers; -use Guzzle\Http\Message\Response; +use Omnipay\Stripe\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class FetchTransferRequestTest extends TestCase { @@ -35,10 +36,10 @@ public function testEndpoint() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/FetchTransferSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/FetchTransferSuccess.txt'))) ); - /** @var \Omnipay\Stripe\Message\Response $response */ + /** @var Response $response */ $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); @@ -50,7 +51,7 @@ public function testSendSuccess() public function testSendFailure() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/FetchTransferFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/FetchTransferFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/Transfers/FetchTransferReversalRequestTest.php b/tests/Message/Transfers/FetchTransferReversalRequestTest.php index a8ecdddf..b03ddec6 100644 --- a/tests/Message/Transfers/FetchTransferReversalRequestTest.php +++ b/tests/Message/Transfers/FetchTransferReversalRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Stripe\Message\Transfers; -use Guzzle\Http\Message\Response; +use Omnipay\Stripe\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class FetchTransferReversalRequestTest extends TestCase { @@ -36,10 +37,10 @@ public function testEndpoint() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/FetchTransferReversalSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalSuccess.txt'))) ); - /** @var \Omnipay\Stripe\Message\Response $response */ + /** @var Response $response */ $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); @@ -51,7 +52,7 @@ public function testSendSuccess() public function testSendFailure() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/Transfers/ListTransferReversalsRequestTest.php b/tests/Message/Transfers/ListTransferReversalsRequestTest.php index b4b37b3d..5ed6b039 100644 --- a/tests/Message/Transfers/ListTransferReversalsRequestTest.php +++ b/tests/Message/Transfers/ListTransferReversalsRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Stripe\Message\Transfers; -use Guzzle\Http\Message\Response; +use Omnipay\Stripe\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class ListTransferReversalsRequestTest extends TestCase { @@ -35,10 +36,10 @@ public function testEndpoint() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/ListTransferReversalsSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/ListTransferReversalsSuccess.txt'))) ); - /** @var \Omnipay\Stripe\Message\Response $response */ + /** @var Response $response */ $response = $this->request->send(); $data = $response->getData(); @@ -55,7 +56,7 @@ public function testSendFailure() $this->request->setTransferReference('NOTFOUND'); $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/ListTransferReversalsFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/ListTransferReversalsFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/Transfers/ListTransfersRequestTest.php b/tests/Message/Transfers/ListTransfersRequestTest.php index 8a190a9f..928e4482 100644 --- a/tests/Message/Transfers/ListTransfersRequestTest.php +++ b/tests/Message/Transfers/ListTransfersRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Stripe\Message\Transfers; -use Guzzle\Http\Message\Response; +use Omnipay\Stripe\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class ListTransfersRequestTest extends TestCase { @@ -31,10 +32,10 @@ public function testEndpoint() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/ListTransfersSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/ListTransfersSuccess.txt'))) ); - /** @var \Omnipay\Stripe\Message\Response $response */ + /** @var Response $response */ $response = $this->request->send(); $data = $response->getData(); @@ -51,7 +52,7 @@ public function testSendFailure() $this->request->setTransferGroup('NOTFOUND'); $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/ListTransfersFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/ListTransfersFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/Transfers/UpdateTransferRequestTest.php b/tests/Message/Transfers/UpdateTransferRequestTest.php index a35b120f..b4566e9c 100644 --- a/tests/Message/Transfers/UpdateTransferRequestTest.php +++ b/tests/Message/Transfers/UpdateTransferRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Stripe\Message\Transfers; -use Guzzle\Http\Message\Response; +use Omnipay\Stripe\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class UpdateTransferRequestTest extends TestCase { @@ -45,9 +46,9 @@ public function testData() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/CreateTransferRequestSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/CreateTransferRequestSuccess.txt'))) ); - /** @var \Omnipay\Stripe\Message\Response $response */ + /** @var Response $response */ $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); @@ -59,7 +60,7 @@ public function testSendSuccess() public function testSendFailure() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/FetchTransferFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/FetchTransferFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/Transfers/UpdateTransferReversalRequestTest.php b/tests/Message/Transfers/UpdateTransferReversalRequestTest.php index 35dffe35..ba831524 100644 --- a/tests/Message/Transfers/UpdateTransferReversalRequestTest.php +++ b/tests/Message/Transfers/UpdateTransferReversalRequestTest.php @@ -2,8 +2,9 @@ namespace Omnipay\Stripe\Message\Transfers; -use Guzzle\Http\Message\Response; +use Omnipay\Stripe\Message\Response; use Omnipay\Tests\TestCase; +use function GuzzleHttp\Psr7\parse_response; class UpdateTransferReversalRequestTest extends TestCase { @@ -48,9 +49,9 @@ public function testData() public function testSendSuccess() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/CreateTransferReversalRequestSuccess.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/CreateTransferReversalRequestSuccess.txt'))) ); - /** @var \Omnipay\Stripe\Message\Response $response */ + /** @var Response $response */ $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); @@ -62,7 +63,7 @@ public function testSendSuccess() public function testSendFailure() { $this->setMockHttpResponse( - array(Response::fromMessage(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt'))) + array(parse_response(file_get_contents($this->mockDir.'/FetchTransferReversalFailure.txt'))) ); $response = $this->request->send(); diff --git a/tests/Message/VoidRequestTest.php b/tests/Message/VoidRequestTest.php index 5ef16c1a..bee2f452 100644 --- a/tests/Message/VoidRequestTest.php +++ b/tests/Message/VoidRequestTest.php @@ -6,6 +6,9 @@ class VoidRequestTest extends TestCase { + /** @var VoidRequest */ + private $request; + public function setUp() { $this->request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest()); diff --git a/tests/Util/StripeQueryAggregatorTest.php b/tests/Util/StripeQueryAggregatorTest.php deleted file mode 100644 index d53726d7..00000000 --- a/tests/Util/StripeQueryAggregatorTest.php +++ /dev/null @@ -1,24 +0,0 @@ -aggregator = new StripeQueryAggregator(); - } - - public function testShouldAggregateArrayQueryParamsWithoutIndex() - { - $expected = array('foo[]' => array('bar', 'baz')); - - $actual = $this->aggregator->aggregate('foo', array('bar', 'baz'), new QueryString()); - - $this->assertEquals($expected, $actual); - } -} \ No newline at end of file