Skip to content

Commit bbf2cec

Browse files
committed
Add void/refund/capture/find request
1 parent 2b6cf03 commit bbf2cec

File tree

5 files changed

+180
-2
lines changed

5 files changed

+180
-2
lines changed

src/Gateway.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public function authorize(array $parameters = array())
6767
* @param array $parameters
6868
* @return Message\PurchaseRequest
6969
*/
70-
public function purchase(array $parameters = array())
70+
public function capture(array $parameters = array())
7171
{
72-
return $this->createRequest('\Omnipay\Braintree\Message\PurchaseRequest', $parameters);
72+
return $this->createRequest('\Omnipay\Braintree\Message\CaptureRequest', $parameters);
7373
}
7474

7575
/**
@@ -80,4 +80,40 @@ public function clientToken(array $parameters = array())
8080
{
8181
return $this->createRequest('\Omnipay\Braintree\Message\ClientTokenRequest', $parameters);
8282
}
83+
84+
/**
85+
* @param array $parameters
86+
* @return Message\PurchaseRequest
87+
*/
88+
public function find(array $parameters = array())
89+
{
90+
return $this->createRequest('\Omnipay\Braintree\Message\FindRequest', $parameters);
91+
}
92+
93+
/**
94+
* @param array $parameters
95+
* @return Message\PurchaseRequest
96+
*/
97+
public function purchase(array $parameters = array())
98+
{
99+
return $this->createRequest('\Omnipay\Braintree\Message\PurchaseRequest', $parameters);
100+
}
101+
102+
/**
103+
* @param array $parameters
104+
* @return Message\PurchaseRequest
105+
*/
106+
public function refund(array $parameters = array())
107+
{
108+
return $this->createRequest('\Omnipay\Braintree\Message\RefundRequest', $parameters);
109+
}
110+
111+
/**
112+
* @param array $parameters
113+
* @return Message\PurchaseRequest
114+
*/
115+
public function void(array $parameters = array())
116+
{
117+
return $this->createRequest('\Omnipay\Braintree\Message\VoidRequest', $parameters);
118+
}
83119
}

src/Message/CaptureRequest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace Omnipay\Braintree\Message;
3+
4+
use Braintree_Transaction;
5+
use Omnipay\Common\Message\ResponseInterface;
6+
7+
/**
8+
* Authorize Request
9+
*
10+
* @method Response send()
11+
*/
12+
class CaptureRequest extends AbstractRequest
13+
{
14+
public function getData()
15+
{
16+
$this->validate('transactionReference');
17+
18+
return array(
19+
'transactionReference' => $this->getTransactionReference(),
20+
'amount' => $this->getAmount(),
21+
);
22+
}
23+
24+
/**
25+
* Send the request with specified data
26+
*
27+
* @param mixed $data The data to send
28+
* @return ResponseInterface
29+
*/
30+
public function sendData($data)
31+
{
32+
$response = Braintree_Transaction::submitForSettlement($data['transactionReference'], $data['amount']);
33+
34+
return $this->createResponse($response);
35+
}
36+
}

src/Message/FindRequest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Omnipay\Braintree\Message;
3+
4+
use Braintree_Transaction;
5+
use Omnipay\Common\Message\ResponseInterface;
6+
7+
/**
8+
* Authorize Request
9+
*
10+
* @method Response send()
11+
*/
12+
class FindRequest extends AbstractRequest
13+
{
14+
public function getData()
15+
{
16+
$this->validate('transactionReference');
17+
18+
return array(
19+
'transactionReference' => $this->getTransactionReference(),
20+
);
21+
}
22+
23+
/**
24+
* Send the request with specified data
25+
*
26+
* @param mixed $data The data to send
27+
* @return ResponseInterface
28+
*/
29+
public function sendData($data)
30+
{
31+
$response = Braintree_Transaction::find($data['transactionReference']);
32+
33+
return $this->createResponse($response);
34+
}
35+
}

src/Message/RefundRequest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
namespace Omnipay\Braintree\Message;
3+
4+
use Braintree_Transaction;
5+
use Omnipay\Common\Message\ResponseInterface;
6+
7+
/**
8+
* Authorize Request
9+
*
10+
* @method Response send()
11+
*/
12+
class RefundRequest extends AbstractRequest
13+
{
14+
public function getData()
15+
{
16+
$this->validate('transactionReference');
17+
18+
return array(
19+
'transactionReference' => $this->getTransactionReference(),
20+
'amount' => $this->getAmount(),
21+
);
22+
}
23+
24+
/**
25+
* Send the request with specified data
26+
*
27+
* @param mixed $data The data to send
28+
* @return ResponseInterface
29+
*/
30+
public function sendData($data)
31+
{
32+
$response = Braintree_Transaction::void($data['transactionReference'], $data['amount']);
33+
34+
return $this->createResponse($response);
35+
}
36+
}

src/Message/VoidRequest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Omnipay\Braintree\Message;
3+
4+
use Braintree_Transaction;
5+
use Omnipay\Common\Message\ResponseInterface;
6+
7+
/**
8+
* Authorize Request
9+
*
10+
* @method Response send()
11+
*/
12+
class VoidRequest extends AbstractRequest
13+
{
14+
public function getData()
15+
{
16+
$this->validate('transactionReference');
17+
18+
return array(
19+
'transactionReference' => $this->getTransactionReference(),
20+
);
21+
}
22+
23+
/**
24+
* Send the request with specified data
25+
*
26+
* @param mixed $data The data to send
27+
* @return ResponseInterface
28+
*/
29+
public function sendData($data)
30+
{
31+
$response = Braintree_Transaction::void($data['transactionReference']);
32+
33+
return $this->createResponse($response);
34+
}
35+
}

0 commit comments

Comments
 (0)