Skip to content

Commit

Permalink
Instant notification data is posted as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
amacneil committed May 12, 2014
1 parent aaf7534 commit 1cc3a82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ class CompletePurchaseRequest extends FetchTransactionRequest
{
public function getData()
{
// check both GET and POST
$order = $this->httpRequest->request->get('order') ?:
$this->httpRequest->query->get('order');
// check GET
$order = $this->httpRequest->query->get('order');

// check JSON POST data
if (!$order && $this->httpRequest->getContent()) {
$content = json_decode($this->httpRequest->getContent(), true);
if (isset($content['order'])) {
$order = $content['order'];
}
}

if (empty($order['id'])) {
throw new InvalidRequestException('Missing Order ID');
Expand Down
16 changes: 12 additions & 4 deletions tests/Message/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Omnipay\Coinbase\Message;

use Omnipay\Tests\TestCase;
use Symfony\Component\HttpFoundation\Request as HttpRequest;

class CompletePurchaseRequestTest extends TestCase
{
Expand Down Expand Up @@ -30,8 +31,15 @@ public function testGetDataGet()

public function testGetDataPost()
{
$this->httpRequest->request->replace(
array('order' => array('id' => '9XMWP4YG'))
// post data is sent as JSON
$content = '{"order":{"id":"9XMWP4YG","created_at":"2014-05-11T22:15:41-07:00","status":"completed"}}';
$this->httpRequest = new HttpRequest(array(), array(), array(), array(), array(), array(), $content);
$this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->httpRequest);
$this->request->initialize(
array(
'apiKey' => 'abc123',
'secret' => 'shhh',
)
);

$data = $this->request->getData();
Expand All @@ -49,7 +57,7 @@ public function testGetDataInvalid()

public function testSendSuccess()
{
$this->httpRequest->request->replace(
$this->httpRequest->query->replace(
array('order' => array('id' => '9XMWP4YG'))
);
$this->setMockHttpResponse('FetchTransactionSuccess.txt');
Expand All @@ -63,7 +71,7 @@ public function testSendSuccess()

public function testSendFailure()
{
$this->httpRequest->request->replace(
$this->httpRequest->query->replace(
array('order' => array('id' => '9XMWP4YG'))
);
$this->setMockHttpResponse('FetchTransactionFailure.txt');
Expand Down

0 comments on commit 1cc3a82

Please sign in to comment.