diff --git a/.travis.yml b/.travis.yml index d779432..67753ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 - hhvm before_script: diff --git a/README.md b/README.md index c3d073b..9f3724b 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ **Coinbase driver for the Omnipay PHP payment processing library** -[![Build Status](https://travis-ci.org/omnipay/coinbase.png?branch=master)](https://travis-ci.org/omnipay/coinbase) +[![Build Status](https://travis-ci.org/thephpleague/omnipay-coinbase.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-coinbase) [![Latest Stable Version](https://poser.pugx.org/omnipay/coinbase/version.png)](https://packagist.org/packages/omnipay/coinbase) [![Total Downloads](https://poser.pugx.org/omnipay/coinbase/d/total.png)](https://packagist.org/packages/omnipay/coinbase) -[Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment +[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Coinbase support for Omnipay. ## Installation @@ -33,7 +33,7 @@ The following gateways are provided by this package: * Coinbase -For general usage instructions, please see the main [Omnipay](https://github.com/omnipay/omnipay) +For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. ## Support @@ -46,5 +46,5 @@ If you want to keep up to date with release anouncements, discuss ideas for the or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to. -If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/omnipay/coinbase/issues), +If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-coinbase/issues), or better yet, fork the library and submit a pull request. diff --git a/composer.json b/composer.json index 8303b0a..4936eed 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "pay", "payment" ], - "homepage": "https://github.com/omnipay/coinbase", + "homepage": "https://github.com/thephpleague/omnipay-coinbase", "license": "MIT", "authors": [ { @@ -19,7 +19,7 @@ }, { "name": "Omnipay Contributors", - "homepage": "https://github.com/omnipay/coinbase/contributors" + "homepage": "https://github.com/thephpleague/omnipay-coinbase/contributors" } ], "autoload": { diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index b5e091d..e80a503 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -9,7 +9,10 @@ */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { - protected $endpoint = 'https://coinbase.com/api/v1'; + const API_VERSION = 'v2'; + + protected $liveEndpoint = 'https://api.coinbase.com'; + protected $testEndpoint = 'https://api.sandbox.coinbase.com'; public function getApiKey() { @@ -54,10 +57,11 @@ function ($event) { ); $nonce = $this->generateNonce(); - $url = $this->endpoint.$action; + $url = $this->getEndpoint().$action; $body = $data ? http_build_query($data) : null; $httpRequest = $this->httpClient->createRequest($method, $url, null, $body); + $httpRequest->setHeader('Content-Type', 'application/x-www-form-urlencoded'); $httpRequest->setHeader('ACCESS_KEY', $this->getApiKey()); $httpRequest->setHeader('ACCESS_SIGNATURE', $this->generateSignature($url, $body, $nonce)); $httpRequest->setHeader('ACCESS_NONCE', $nonce); @@ -76,4 +80,10 @@ public function generateSignature($url, $body, $nonce) return hash_hmac('sha256', $message, $this->getSecret()); } + + protected function getEndpoint() + { + $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; + return $base . '/' . self::API_VERSION; + } } diff --git a/src/Message/PurchaseResponse.php b/src/Message/PurchaseResponse.php index 4230bd9..02a1c5e 100644 --- a/src/Message/PurchaseResponse.php +++ b/src/Message/PurchaseResponse.php @@ -9,7 +9,10 @@ */ class PurchaseResponse extends Response implements RedirectResponseInterface { - protected $redirectEndpoint = 'https://coinbase.com/checkouts'; + const API_VERSION = 'v2'; + + protected $redirectLiveEndpoint = 'https://api.coinbase.com'; + protected $redirectTestEndpoint = 'https://api.sandbox.coinbase.com'; public function isSuccessful() { @@ -29,7 +32,7 @@ public function getRedirectMethod() public function getRedirectUrl() { if ($this->isRedirect()) { - return $this->redirectEndpoint.'/'.$this->getTransactionReference(); + return $this->getCheckoutEndpoint().'/'.$this->getTransactionReference(); } } @@ -44,4 +47,10 @@ public function getTransactionReference() return $this->data['button']['code']; } } + + protected function getCheckoutEndpoint() + { + $base = $this->getRequest()->getTestMode() ? $this->redirectTestEndpoint : $this->redirectLiveEndpoint; + return $base . '/' . self::API_VERSION . '/checkouts'; + } } diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index d07ffd6..1640653 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -63,7 +63,7 @@ public function testSendSuccess() $this->assertTrue($response->isRedirect()); $this->assertNull($response->getMessage()); $this->assertSame('GET', $response->getRedirectMethod()); - $this->assertSame('https://coinbase.com/checkouts/30dae91b81299066ba126e3858f89fd8', $response->getRedirectUrl()); + $this->assertSame('https://api.coinbase.com/v2/checkouts/30dae91b81299066ba126e3858f89fd8', $response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('30dae91b81299066ba126e3858f89fd8', $response->getTransactionReference()); } diff --git a/tests/Message/PurchaseResponseTest.php b/tests/Message/PurchaseResponseTest.php index 4fce973..72f4e65 100644 --- a/tests/Message/PurchaseResponseTest.php +++ b/tests/Message/PurchaseResponseTest.php @@ -9,13 +9,15 @@ class PurchaseResponseTest extends TestCase public function testSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); - $response = new PurchaseResponse($this->getMockRequest(), $httpResponse->json()); + $request = $this->getMockRequest(); + $request->shouldReceive('getTestMode')->once()->andReturn(false); + $response = new PurchaseResponse($request, $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getMessage()); $this->assertSame('GET', $response->getRedirectMethod()); - $this->assertSame('https://coinbase.com/checkouts/30dae91b81299066ba126e3858f89fd8', $response->getRedirectUrl()); + $this->assertSame('https://api.coinbase.com/v2/checkouts/30dae91b81299066ba126e3858f89fd8', $response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('30dae91b81299066ba126e3858f89fd8', $response->getTransactionReference()); }