Skip to content

Commit 4294904

Browse files
committed
Merge pull request #14 from c0nstantx/master
Add findCustomer method to Gateway
2 parents c67ebdd + 5db9946 commit 4294904

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

src/Gateway.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ public function clientToken(array $parameters = array())
113113
return $this->createRequest('\Omnipay\Braintree\Message\ClientTokenRequest', $parameters);
114114
}
115115

116+
/**
117+
* @param string $id
118+
* @return Message\FindCustomerRequest
119+
*/
120+
public function findCustomer($id)
121+
{
122+
return $this->createRequest('\Omnipay\Braintree\Message\FindCustomerRequest', array('customerId' => $id));
123+
}
124+
116125
/**
117126
* @param array $parameters
118127
* @return Message\CreateCustomerRequest

src/Message/FindCustomerRequest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace Omnipay\Braintree\Message;
3+
4+
/**
5+
* Find Customer Request
6+
*
7+
* @method CustomerResponse send()
8+
*/
9+
class FindCustomerRequest extends AbstractRequest
10+
{
11+
public function getData()
12+
{
13+
return $this->getCustomerData();
14+
}
15+
16+
/**
17+
* Send the request with specified data
18+
*
19+
* @param mixed $data The data to send
20+
* @return CustomerResponse
21+
*/
22+
public function sendData($data)
23+
{
24+
$response = $this->braintree->customer()->find($this->getCustomerId());
25+
26+
return $this->response = new CustomerResponse($this, $response);
27+
}
28+
}

tests/GatewayTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ public function setUp()
2424
);
2525
}
2626

27+
public function testFindCustomer()
28+
{
29+
$request = $this->gateway->findCustomer(1);
30+
$this->assertInstanceOf('\Omnipay\Braintree\Message\FindCustomerRequest', $request);
31+
$this->assertEquals(1, $request->getCustomerId());
32+
}
33+
2734
public function testAuthorize()
2835
{
2936
$request = $this->gateway->authorize(array('amount' => '10.00'));
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
namespace Omnipay\Braintree\Message;
3+
4+
use Omnipay\Tests\TestCase;
5+
6+
class FindCustomerRequestTest extends TestCase
7+
{
8+
/**
9+
* @var CreateCustomerRequest
10+
*/
11+
private $request;
12+
13+
public function setUp()
14+
{
15+
parent::setUp();
16+
17+
$gateway = $this->buildMockGateway();
18+
$this->request = new FindCustomerRequest($this->getHttpClient(), $this->getHttpRequest(), $gateway);
19+
$this->request->initialize(array('customerId' => 1));
20+
}
21+
22+
public function testGetData()
23+
{
24+
$data = $this->request->getData();
25+
$this->assertNull($data);
26+
}
27+
28+
public function testSendData()
29+
{
30+
$data = array();
31+
$response = $this->request->sendData($data);
32+
33+
$this->assertInstanceOf('Omnipay\Braintree\Message\CustomerResponse', $response);
34+
}
35+
36+
protected function buildMockGateway()
37+
{
38+
$gateway = $this->getMockBuilder('\Braintree_Gateway')
39+
->disableOriginalConstructor()
40+
->setMethods(array(
41+
'customer'
42+
))
43+
->getMock();
44+
45+
$customer = $this->getMockBuilder('\Braintree_CustomerGateway')
46+
->disableOriginalConstructor()
47+
->getMock();
48+
49+
$gateway->expects($this->any())
50+
->method('customer')
51+
->will($this->returnValue($customer));
52+
53+
return $gateway;
54+
}
55+
}

0 commit comments

Comments
 (0)