8000 Added Annul option · thephpleague/omnipay-netaxept@04b19ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 04b19ce

Browse files
committed
Added Annul option
1 parent eeab142 commit 04b19ce

File tree

6 files changed

+151
-15
lines changed

6 files changed

+151
-15
lines changed

src/Message/AnnulRequest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Common\Exception\InvalidResponseException;
6+
use Omnipay\Common\Message\AbstractRequest;
7+
8+
/**
9+
* Netaxept Annul Request
10+
*
11+
* @author Antonio Peric-Mazar <antonio@locastic.com>
12+
*/
13+
class AnnulRequest extends PurchaseRequest
14+
{
15+
public function getData()
16+
{
17+
$data = array();
18+
$data['transactionAmount'] = $this->getAmountInteger();
19+
$data['transactionId'] = $this->getTransactionId();
20+
$data['merchantId'] = $this->getMerchantId();
21+
$data['token'] = $this->getPassword();
22+
$data['operation'] = 'ANNUL';
23+
24+
if (empty($data['transactionAmount']) || empty($data['transactionId'])) {
25+
throw new InvalidResponseException;
26+
}
27+
28+
return $data;
29+
}
30+
31+
public function sendData($data)
32+
{
33+
$url = $this->getEndpoint().'/Netaxept/Process.aspx?';
34+
$httpResponse = $this->httpClient->get($url.http_build_query($data))->send();
35+
36+
return $this->response = new Response($this, $httpResponse->xml());
37+
}
38+
}

tests/GatewayTest.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@ public function testCompletePurchaseFailure()
107107

108108
public function testCaptureSuccess()
109109
{
110-
$this->getHttpRequest()->query->replace(
111-
array(
112-
'responseCode' => 'OK',
113-
'transactionId' => 'abc123',
114-
)
115-
);
116-
117110
$this->setMockHttpResponse('CaptureSuccess.txt');
118111

119112
$response = $this->gateway->capture($this->options)->send();
@@ -126,13 +119,6 @@ public function testCaptureSuccess()
126119

127120
public function testCaptureFailure()
128121
{
129-
$this->getHttpRequest()->query->replace(
130-
8000 array(
131-
'responseCode' => 'OK',
132-
'transactionId' => 'abc123',
133-
)
134-
);
135-
136122
$this->setMockHttpResponse('CaptureFailure.txt');
137123

138124
$response = $this->gateway->capture($this->options)->send();
@@ -142,4 +128,28 @@ public function testCaptureFailure()
142128
$this->assertNull($response->getTransactionReference());
143129
$this->assertSame('Unable to find transaction', $response->getMessage());
144130
}
131+
132+
public function testAnnulSuccess()
133+
{
134+
$this->setMockHttpResponse('AnnulSuccess.txt');
135+
136+
$response = $this->gateway->capture($this->options)->send();
137+
138+
$this->assertTrue($response->isSuccessful());
139+
$this->assertFalse($response->isRedirect());
140+
$this< 6DB6 /span>->assertEquals('3fece3574598c6ae3932fae5f38bc8af', $response->getTransactionReference());
141+
$this->assertSame('OK', $response->getMessage());
142+
}
143+
144+
public function testAnnulFailure()
145+
{
146+
$this->setMockHttpResponse('AnnulFailure.txt');
147+
148+
$response = $this->gateway->capture($this->options)->send();
149+
150+
$this->assertFalse($response->isSuccessful());
151+
$this->assertFalse($response->isRedirect());
152+
$this->assertNull($response->getTransactionReference());
153+
$this->assertSame('Unable to find transaction', $response->getMessage());
154+
}
145155
}

tests/Message/AnnulRequestTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Omnipay\Netaxept\Message;
4+
5+
use Omnipay\Tests\TestCase;
6+
7+
/**
8+
* @author Antonio Peric-Mazar <antonio@locastic.com>
9+
*/
10+
class AnnulRequestTest extends TestCase
11+
{
12+
/**
13+
* @var \Symfony\Component\HttpFoundation\Request
14+
*/
15+
private $httpRequest;
16+
17+
/**
18+
* @var \Omnipay\Netaxept\Message\AnnulRequest
19+
*/
20+
private $request;
21+
22+
public function setUp()
23+
{
24+
$client = $this->getHttpClient();
25+
$this->httpRequest = $this->getHttpRequest();
26+
27+
$this->request = new AnnulRequest($client, $this->httpRequest);
28+
}
29+
30+
/**
31+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
32+
*/
33+
public function testGetDataThrowsExceptionWithoutTransactionAmount()
34+
{
35+
$this->httpRequest->query->set('transactionId', 'TRANS-123');
36+
37+
$this->request->getData();
38+
}
39+
40+
/**
41+
* @expectedException \Omnipay\Common\Exception\InvalidResponseException
42+
*/
43+
public function testGetDataThrowsExceptionWithoutTransactionId()
44+
{
45+
$this->httpRequest->query->set('transactionAmount', 'ABC-123');
46+
47+
$this->request->getData();
48+
}
49+
}

tests/Message/CaptureRequestTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Omnipay\Tests\TestCase;
66

7+
/**
8+
* @author Antonio Peric-Mazar <antonio@locastic.com>
9+
*/
710
class CaptureRequestTest extends TestCase
811
{
912
/**
@@ -12,7 +15,7 @@ class CaptureRequestTest extends TestCase
1215
private $httpRequest;
1316

1417
/**
15-
* @var \Omnipay\Netaxept\Message\CompletePurchaseRequest
18+
* @var \Omnipay\Netaxept\Message\CaptureRequest
1619
*/
1720
private $request;
1821

tests/Mock/AnnulFailure.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: private
3+
Content-Type: text/xml
4+
Server: Microsoft-IIS/7.5
5+
X-AspNet-Version: 4.0.30319
6+
X-Powered-By: ASP.NET
7+
Date: Fri, 22 Feb 2013 16:55:41 GMT
8+
Content-Length: 245
9+
10+
<?xml version="1.0"?>
11+
<GenericError xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
12+
<Error xsi:type="GenericError">
13+
<Message>Unable to find transaction</Message>
14+
</Error>
15+
</GenericError>

tests/Mock/AnnulSuccess.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
HTTP/1.1 200 OK
2+
Cache-Control: private
3+
Content-Type: text/xml
4+
Server: Microsoft-IIS/7.5
5+
X-AspNet-Version: 4.0.30319
6+
X-Powered-By: ASP.NET
7+
Date: Thu, 7 May 2015 16:53:34 GMT
8+
Content-Length: 474
9+
10+
<?xml version="1.0"?>
11+
<Result xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
12+
<SessionNumber>389</SessionNumber>
13+
<IssuerId>3</IssuerId>
14+
<ResponseCode>OK</ResponseCode>
15+
<TransactionId>3fece3574598c6ae3932fae5f38bc8af</TransactionId>
16+
<ExecutionTime>2015-05-07T17:58:14.7503418+02:00</ExecutionTime>
17+
<MarchantId>562923</MarchantId>
18+
<MaskedPan>
19+
<MessageId>f12ed1e42982455f866dfc52e56aa1af</MessageId>
20+
</MaskedPan>
21+
</Result>

0 commit comments

Comments
 (0)
0