Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Add search by order id request
Browse files Browse the repository at this point in the history
This way we can search BT transactions for a specific order
  • Loading branch information
Zhanna Smolovich committed May 7, 2020
1 parent 54846f2 commit 2bd8a3a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 16 deletions.
18 changes: 2 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "omnipay/braintree",
"name": "theiconic/omnipay-braintree",
"type": "library",
"description": "Braintree gateway for Omnipay payment processing library",
"keywords": [
Expand All @@ -11,22 +11,8 @@
"braintree",
"purchase"
],
"homepage": "https://github.com/thephpleague/omnipay-braintree",
"homepage": "https://github.com/theiconic/omnipay-braintree",
"license": "MIT",
"authors": [
{
"name": "Kayla Daniels",
"email": "[email protected]"
},
{
"name": "Barry vd. Heuvel",
"email": "[email protected]"
},
{
"name": "Omnipay Contributors",
"homepage": "https://github.com/thephpleague/omnipay-braintree/contributors"
}
],
"autoload": {
"psr-4": { "Omnipay\\Braintree\\" : "src/" }
},
Expand Down
9 changes: 9 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,13 @@ public function fetchTransaction(array $parameters = array())
{
return $this->createRequest('\Omnipay\Braintree\Message\FindRequest', $parameters);
}

/**
* @param array $parameters
* @return Message\SearchRequest
*/
public function searchTransaction(array $parameters = array())
{
return $this->createRequest('\Omnipay\Braintree\Message\SearchRequest', $parameters);
}
}
43 changes: 43 additions & 0 deletions src/Message/SearchRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Omnipay\Braintree\Message;

use Braintree\TransactionSearch;
use Omnipay\Common\Message\ResponseInterface;

class SearchRequest extends AbstractRequest
{
/**
* Authorize Request
*
* @method Response send()
*/
public function getData()
{
$this->validate('purchaseOrderNumber');

return array(
'purchaseOrderNumber' => $this->getPurchaseOrderNumber(),
);
}

/**
* Send the request with specified data
*
* @param mixed $data The data to send
* @return ResponseInterface
*/
public function sendData($data)
{
$response = $this->braintree->transaction()->search([
TransactionSearch::orderId()->is($data['purchaseOrderNumber']),
]);

$transactions = [];
foreach($response as $transaction) {
$transactions[] = $transaction;
}

return $this->createResponse($transactions);
}
}
6 changes: 6 additions & 0 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ public function testParseNotification()
}
}

public function testSearchTransaction()
{
$request = $this->gateway->searchTransaction(['purchaseOrderNumber' => '2187588535']);
$this->assertInstanceOf('Omnipay\Braintree\Message\SearchRequest', $request);
}

/**
* @param $payload
*
Expand Down
32 changes: 32 additions & 0 deletions tests/Message/SearchRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Omnipay\Braintree\Message;

use Omnipay\Tests\TestCase;

class SearchRequestTest extends TestCase
{
/**
* @var SearchRequest
*/
private $request;

public function setUp()
{
parent::setUp();

$this->request = new SearchRequest($this->getHttpClient(), $this->getHttpRequest(), \Braintree_Configuration::gateway());
$this->request->initialize(
array(
'purchaseOrderNumber' => '2187588535',
)
);
}

public function testGetData()
{
$data = $this->request->getData();

$this->assertSame('2187588535', $data['purchaseOrderNumber']);
}
}

0 comments on commit 2bd8a3a

Please sign in to comment.