Skip to content

Commit 53511ea

Browse files
committed
Merge pull request #76 from delatbabel/implement-void
Implement void
2 parents 990bdb0 + 4aabd5b commit 53511ea

File tree

7 files changed

+107
-1
lines changed

7 files changed

+107
-1
lines changed

src/ExpressGateway.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public function completePurchase(array $parameters = array())
138138
return $this->createRequest('\Omnipay\PayPal\Message\ExpressCompletePurchaseRequest', $parameters);
139139
}
140140

141+
public function void(array $parameters = array())
142+
{
143+
return $this->createRequest('\Omnipay\PayPal\Message\ExpressVoidRequest', $parameters);
144+
}
145+
141146
public function fetchCheckout(array $parameters = array())
142147
{
143148
return $this->createRequest('\Omnipay\PayPal\Message\ExpressFetchCheckoutRequest', $parameters);

src/Message/ExpressVoidRequest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Omnipay\PayPal\Message;
4+
5+
/**
6+
* PayPal Express Void Request
7+
*/
8+
class ExpressVoidRequest extends AbstractRequest
9+
{
10+
public function getData()
11+
{
12+
$this->validate('transactionReference');
13+
$data = $this->getBaseData();
14+
$data['METHOD'] = 'DoVoid';
15+
$data['AUTHORIZATIONID'] = $this->getTransactionReference();
16+
return $data;
17+
}
18+
}

src/Message/Response.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ public function isSuccessful()
2323

2424
public function getTransactionReference()
2525
{
26-
foreach (array('REFUNDTRANSACTIONID', 'TRANSACTIONID', 'PAYMENTINFO_0_TRANSACTIONID') as $key) {
26+
foreach (array('REFUNDTRANSACTIONID',
27+
'TRANSACTIONID',
28+
'PAYMENTINFO_0_TRANSACTIONID',
29+
'AUTHORIZATIONID') as $key) {
2730
if (isset($this->data[$key])) {
2831
return $this->data[$key];
2932
}

tests/ExpressGatewayTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class ExpressGatewayTest extends GatewayTestCase
1616
*/
1717
protected $options;
1818

19+
/**
20+
* @var array
21+
*/
22+
protected $voidOptions;
23+
1924
public function setUp()
2025
{
2126
parent::setUp();
@@ -27,6 +32,9 @@ public function setUp()
2732
'returnUrl' => 'https://www.example.com/return',
2833
'cancelUrl' => 'https://www.example.com/cancel',
2934
);
35+
$this->voidOptions = array(
36+
'transactionReference' => 'ASDFASDFASDF',
37+
);
3038
}
3139

3240
public function testAuthorizeSuccess()
@@ -77,6 +85,28 @@ public function testPurchaseFailure()
7785
$this->assertSame('This transaction cannot be processed. The amount to be charged is zero.', $response->getMessage());
7886
}
7987

88+
public function testVoidSuccess()
89+
{
90+
$this->setMockHttpResponse('ExpressVoidSuccess.txt');
91+
92+
$response = $this->gateway->void($this->voidOptions)->send();
93+
94+
$this->assertInstanceOf('\Omnipay\PayPal\Message\Response', $response);
95+
$this->assertTrue($response->isSuccessful());
96+
$this->assertFalse($response->isRedirect());
97+
$this->assertEquals('ASDFASDFASDF', $response->getTransactionReference());
98+
}
99+
100+
public function testVoidFailure()
101+
{
102+
$this->setMockHttpResponse('ExpressVoidFailure.txt');
103+
104+
$response = $this->gateway->void($this->voidOptions)->send();
105+
106+
$this->assertInstanceOf('\Omnipay\PayPal\Message\Response', $response);
107+
$this->assertFalse($response->isSuccessful());
108+
}
109+
80110
public function testFetchCheckout()
81111
{
82112
$options = array('token' => 'abc123');
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Omnipay\PayPal\Message;
4+
5+
use Omnipay\Common\CreditCard;
6+
use Omnipay\Tests\TestCase;
7+
8+
class ExpressVoidRequestTest extends TestCase
9+
{
10+
/**
11+
* @var ExpressVoidRequest
12+
*/
13+
private $request;
14+
15+
public function setUp()
16+
{
17+
parent::setUp();
18+
19+
$this->request = new ExpressVoidRequest($this->getHttpClient(), $this->getHttpRequest());
20+
$this->request->initialize(
21+
array(
22+
'transactionReference' => 'ASDFASDFASDF',
23+
)
24+
);
25+
}
26+
27+
public function testGetData()
28+
{
29+
$data = $this->request->getData();
30+
31+
$this->assertSame('ASDFASDFASDF', $data['AUTHORIZATIONID']);
32+
$this->assertSame('DoVoid', $data['METHOD']);
33+
}
34+
}

tests/Mock/ExpressVoidFailure.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Fri, 15 Feb 2013 19:19:21 GMT
3+
Server: Apache
4+
Content-Length: 136
5+
Connection: close
6+
Content-Type: text/plain; charset=utf-8
7+
8+
AUTHORIZATIONID=ASDFASDFASDF&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Failure&VERSION=85%2e0&BUILD=5060305

tests/Mock/ExpressVoidSuccess.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTTP/1.1 200 OK
2+
Date: Fri, 15 Feb 2013 19:19:21 GMT
3+
Server: Apache
4+
Content-Length: 136
5+
Connection: close
6+
Content-Type: text/plain; charset=utf-8
7+
8+
AUTHORIZATIONID=ASDFASDFASDF&TIMESTAMP=2013%2d02%2d15T19%3a19%3a21Z&CORRELATIONID=37b8b9915987c&ACK=Success&VERSION=85%2e0&BUILD=5060305

0 commit comments

Comments
 (0)