From ff5add7bbbc686591001e926f643c7db1c288c01 Mon Sep 17 00:00:00 2001 From: Adrian Macneil Date: Sat, 6 Sep 2014 15:43:10 -0700 Subject: [PATCH 1/6] Update links --- README.md | 6 +++--- composer.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c3d073b..fc3db96 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![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": { From c8056c10d07b0b808034227f86cd4b69e26550f3 Mon Sep 17 00:00:00 2001 From: Adrian Macneil Date: Sat, 6 Sep 2014 15:44:55 -0700 Subject: [PATCH 2/6] Update links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc3db96..9f3724b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **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) From 4cdea1a16104505e54960adbf70470ed2495e071 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 16 Sep 2014 20:41:54 -0400 Subject: [PATCH 3/6] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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: From 2b5c54fe4a4a7103317415a8a1ac6a3ac0b611bc Mon Sep 17 00:00:00 2001 From: Adrian Macneil Date: Wed, 25 Feb 2015 11:49:53 -0800 Subject: [PATCH 4/6] Add missing Content-Type header --- src/Message/AbstractRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index b5e091d..5dd0021 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -58,6 +58,7 @@ function ($event) { $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); From 2a8d2477acc51bcc3e78fe44a9980a372b5e7ad0 Mon Sep 17 00:00:00 2001 From: Adrian Macneil Date: Wed, 25 Feb 2015 11:50:33 -0800 Subject: [PATCH 5/6] Update API endpoint --- src/Message/AbstractRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 5dd0021..607edd5 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -9,7 +9,7 @@ */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { - protected $endpoint = 'https://coinbase.com/api/v1'; + protected $endpoint = 'https://api.coinbase.com/v1'; public function getApiKey() { From 0c3bd1a20fc6c6ec2d021512a237e53ad4a401c5 Mon Sep 17 00:00:00 2001 From: truonghoang Date: Fri, 7 Aug 2015 21:33:07 +0700 Subject: [PATCH 6/6] support coinbase v2 and sandbox API --- src/Message/AbstractRequest.php | 13 +++++++++++-- src/Message/PurchaseResponse.php | 13 +++++++++++-- tests/Message/PurchaseRequestTest.php | 2 +- tests/Message/PurchaseResponseTest.php | 6 ++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 607edd5..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://api.coinbase.com/v1'; + const API_VERSION = 'v2'; + + protected $liveEndpoint = 'https://api.coinbase.com'; + protected $testEndpoint = 'https://api.sandbox.coinbase.com'; public function getApiKey() { @@ -54,7 +57,7 @@ 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); @@ -77,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()); }